zengh
2022-09-14 8ea19a6bb34daab1410f6186992a4c1e90299c92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<template>
    <view>
        <view class="initiatorInfo">
            <view class="Info1">
                <u-avatar :src="src" class="uavatar"></u-avatar>
                <view class="infotxt">
                    <view class="name">{{ creatName }}</view>
                    <view class="fqr_txt">投票发起人</view>
                </view>
            </view>
            <view class="Info2">
                <view class="tp_status">
                    <u-tag text="待开始" v-if="data.status == 1" type="warning" mode="light" size="mini" />
                    <u-tag text="投票中" v-if="data.status == 2" type="success" mode="light" size="mini" />
                    <u-tag text="已结束" v-if="data.status == 3" type="info" mode="light" size="mini" />
                </view>
                <view class="enddate" v-if="data.status != 1">{{ data.endTime }} 结束</view>
                <view class="enddate" v-else>{{ data.startTime }} 开始</view>
            </view>
        </view>
 
        <view class="titInfo1">
            <view class="tit">{{ data.activityTitle }}</view>
            <view class="sharer_">
                <u-button size="mini" @click="rankingBtn">
                    票数排名<u-icon name="arrow-right"></u-icon>
                </u-button>
            </view>
        </view>
 
 
        <view class="hd_rule">
            <view class="">
                <u-tag text="投票规则" type="warning" mode="dark" bg-color="#103289" />
            </view>
            <view class="item_rule">
                <view class="startTit">开始时间</view>
                <view class="">{{ data.startTime }}</view>
            </view>
            <view class="item_rule">
                <view class="startTit">结束时间</view>
                <view class="">{{ data.endTime }}</view>
            </view>
            <view class="item_rule">
                <view class="startTit">投票规则</view>
                <view class="">每人{{ data.voteMoreTxt }}</view>
            </view>
        </view>
        <view class="hd_rule">
            <view class="">
                <u-tag text="投票详情" type="warning" mode="dark" bg-color="#103289" />
            </view>
            <view class="item_rule">
                <view>{{ data.voteIntroduce }}</view>
            </view>
        </view>
 
        <view class="hdOption" :style="data.voteType=='videoTextVote'?'flex-wrap:wrap;':'flex-wrap:nowrap;'"
            v-for="(item, index) in data.voteItemlist" :key="index">
            <view class="imgOption" v-if="data.voteType=='ImageTextVote'">
                <image @click="selectImage(item.imgList)" :src="item.imgList[0]"
                    style="width:110rpx;height:110rpx;overflow:hidden;border-radius: 10rpx;"></image>
            </view>
            <view class="videoOption" v-if="data.voteType=='videoTextVote'">
                <video :src="item.video" style="width:100%;height:100%;"></video>
            </view>
            <view :class="activeItem == index ? 'hdOptionBtn active-bgc' : 'hdOptionBtn'"
                @click="selectItme(index, item)">
                <text>{{ item.content }}</text>
                <u-count-to :start-val="0" font-size="40" :end-val="item.vote+''" class="voteNum"></u-count-to>
                <!-- <u-icon name="checkbox-mark" color="#2979ff" size="28"></u-icon> -->
            </view>
        </view>
 
        <view class="zwf_"></view>
        <!-- <view class="content_1">
            <u-button shape="circle" class="custom-style" @click="submitData" :ripple="true">投票</u-button>
        </view> -->
 
        <view class="but">
            <u-button class="custom-style" type="primary" @click="submitData" :ripple="true">投票</u-button>
        </view>
 
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                banner: '',
                src: '',
                creatName: '',
                data: '',
                activeItem: '*',
                activeobj: {},
            }
        },
        onLoad(event) {
            // TODO 后面把参数名替换成 payload
            const payload = event.detailDate || event.payload;
            // 目前在某些平台参数会被主动 decode,暂时这样处理。
            try {
                this.banner = JSON.parse(decodeURIComponent(payload));
            } catch (error) {
                this.banner = JSON.parse(payload);
            }
            console.log(this.banner);
            uni.setNavigationBarTitle({
                title: this.banner.title
            });
            this.getDetail();
            console.log(this.getUrl());
        },
        //分享给朋友
        onShareAppMessage(res) {
            return {
                title: this.banner.title,
                path: this.getUrl(),
                success: res => {
                    console.info(res)
                }
            }
        },
        //分享到朋友圈
        onShareTimeline(res) {
            return {
                title: "迅投,快来投票吧!",
                query: this.getUrl(),
            }
        },
        filters: {
            total(data) {
                let num = 0;
                for (let i = 0; i < data.length; i++) {
                    num = num + data[i].vote;
                }
                return num;
            }
        },
        methods: {
            getUrl() {
                let pages = getCurrentPages() //获取加载的页面
                let currentPage = pages[pages.length - 1] //获取当前页面的对象
                let url = currentPage.route //当前页面url
                let options = currentPage.options //如果要获取url中所带的参数可以查看options    参数多时通过&拼接url的参数
                let urlWithArgs = url + '?'
                for (let key in options) {
                    let value = options[key]
                    urlWithArgs += key + '=' + value + '&'
                }
                urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
                return urlWithArgs;
            },
            // 进入排名
            rankingBtn() {
                let detail = this.banner;
                uni.navigateTo({
                    url: "../rankinglist/rankinglist?detailDate=" +
                        encodeURIComponent(JSON.stringify(detail)),
                });
            },
            getDetail() {
                uni.showLoading({
                    title: '加载中...',
                    mask: true
                });
                let that = this;
                console.log(that.banner.type);
                uniCloud.callFunction({
                    name: 'getDetail',
                    data: {
                        _id: that.banner._id,
                        type: that.banner.type
                    },
                    success(res) {
                        uni.hideLoading();
                        console.log(res);
                        if (res.result.data) {
                            that.data = res.result.data[0];
                            that.src = that.data.creatUserInfo.avatarUrl;
                            that.creatName = that.data.creatUserInfo.nickName;
                            that.updateView();
                        }
                    },
                    fail(error) {
                        uni.hideLoading();
                        that.$operate.toast({
                            title: '网络请求错误!'
                        });
                    }
                });
            },
            updateView() {
                let that = this;
                uniCloud.callFunction({
                    name: 'updatePageView',
                    data: {
                        name: that.banner.type,
                        _id: that.banner._id,
                        hot_id: that.data.hot_id,
                        voteType: that.data.voteType,
                        switchVal: that.data.switchVal
                    },
                    success(res) {
                        console.log(res);
                        if (res.result.data) {
                            that.data = res.result.data[0];
                            that.src = that.data.creatUserInfo.avatarUrl;
                            that.creatName = that.data.creatUserInfo.nickName;
                        }
                    },
                    fail(error) {
                        that.$operate.toast({
                            title: '网络请求错误!'
                        });
                    }
                });
            },
            selectItme(index, item) {
                this.activeItem = index;
                this.activeobj = item;
                console.log(index, item);
            },
            selectImage(url) {
                uni.previewImage({
                    urls: url,
                    current: 0
                });
            },
            submitData() {
                if (JSON.stringify(this.activeobj) != '{}') {
                    let that = this;
                    uni.showLoading({
                        title: '提交中...',
                        mask: true
                    });
                    // uniCloud.callFunction({
                    //     name: 'update_vote',
                    //     data: {
                    //         name: that.banner.type,
                    //         voteType:that.data.voteType,
                    //         hot_id:that.data.hot_id,
                    //         _id: that.banner._id,
                    //         voteData: that.activeobj,
                    //         userInfo: uni.getStorageSync('userInfo'),
                    //         switchVal: that.data.switchVal,
                    //         vcs:{
                    //             voteMoreTxt: that.data.voteMoreTxt,
                    //             voteMore: that.data.voteMore,
                    //         }
                    //     },
                    //     success(res) {
                    //         uni.hideLoading();
                    //         console.log(res);
                    //         if (res.result.updated) {
                    //             that.data.voteItemlist[that.activeItem].vote++;
                    //             that.activeItem = '*';
                    //             that.activeobj = {};
                    //             uni.showToast({
                    //                 title: "投票成功",
                    //                 duration: 2000
                    //             });
                    //         } else {
                    //             that.$operate.toast({
                    //                 title: res.result.msg
                    //             })
                    //         }
                    //     },
                    //     fail(error) {
                    //         console.log(error);
                    //         uni.hideLoading();
                    //         that.$operate.toast({
                    //             title: '网络请求错误!'
                    //         });
                    //     }
                    // });
                } else {
                    this.$operate.toast({
                        title: '请选择投票项!'
                    });
                }
            }
        }
    };
</script>
 
<style lang="scss">
    page {
        background: #ffffff;
    }
 
    .initiatorInfo {
        background: #ffffff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx;
 
        .Info1 {
            display: flex;
            align-items: center;
 
            .uavatar {
                margin-right: 20rpx;
            }
        }
 
        .name,
        .tp_status {
            line-height: 60rpx;
        }
 
        .tp_status {
            text-align: right;
        }
 
        .fqr_txt,
        .enddate {
            color: #bababa;
            // line-height: 40rpx;
        }
    }
 
    .titInfo1 {
        padding: 0 30rpx;
        margin-top: 40rpx;
        display: flex;
 
        .tit {
            // text-align: center;
            font-size: 36rpx;
            width: 85%;
            margin-right: 20rpx;
        }
 
        .sharer_ {}
    }
 
    .hd_rule {
        padding: 30rpx;
        font-size: 32rpx;
 
        .item_rule {
            margin: 36rpx 0;
            display: flex;
 
            .startTit {
                width: 200rpx;
                font-weight: 600;
            }
        }
    }
 
    .hdOption {
        margin-bottom: 40rpx;
        display: flex;
        padding: 0 15px;
 
        .imgOption {
            width: 110rpx;
            height: 110rpx;
            margin-right: 40rpx;
            flex-grow: 0;
            felx-shrink: 0;
        }
 
        .videoOption {
            width: 100%;
            height: 400rpx;
        }
 
        .hdOptionBtn {
            border: 1px solid #dcdcdc;
            padding: 36rpx;
            width: 100%;
            border-radius: 10rpx;
            font-size: 40rpx;
        }
 
        .voteNum {
            margin-left: 20rpx;
            float: right;
        }
    }
 
    .custom-style {
        margin: 30rpx 85rpx 50rpx;
        border: none;
        width: 572rpx;
        height: 86rpx;
        line-height: 86rpx;
        box-sizing: border-box;
        border-radius: 15rpx;
        background-color: #103289 !important;
        color: #ffffff;
    }
 
    .zwf_ {
        height: 140rpx;
    }
 
    .active-bgc {
        border-color: #103289 !important;
        background-color: #fbeadc;
    }
</style>