forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-09-12 8e9f556423b0e3a19ce70df2bca8c351035368b0
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
// pages/homePage/index.js
const $$ = require('../../utils/util');
const app = getApp();
 
// 热门资讯 与 视频
function getVideoAndMessageApi(param) {
    return $$.request({
        url: 'paHotNews/listShow',
        type: 'get',
        submitData: param || {},
        service: 'sys',
        noToken: true
    });
}
 
// 调解资源
function getResourseApi(param) {
    return $$.request({
        url: 'paCaseInfo/mediatePower',
        type: 'get',
        submitData: param || {},
        service: 'mediate',
        noToken: true
    });
}
 
// 消息提醒
function getPopupMsgApi() {
    return $$.request({
        url: 'paCaseInfo/newsRemind',
        type: 'get',
        service: 'mediate'
    });
}
 
function loginApi(submitData) {
    return $$.request({
        url: 'paAccount/tryRegister',
        type: 'post',
        submitData,
        service: 'cust',
        noToken: true
    });
}
 
function registerApi(submitData) {
    return $$.request({ url: 'paAccount/empower', type: 'post', submitData, service: 'cust', noToken: true });
}
 
Page({
    /**
     * 页面的初始数据
     */
    msgCheckId: null, // 已经阅读过的提示不在弹出
    data: {
        visible: true,
        imgUrl: $$.url.img,
        agreementMsg: '', // 服务协议
        popupVisible: false,
        banner: [`${$$.url.img}banner-1.png`, `${$$.url.img}banner-2.jpg`, `${$$.url.img}banner-3.jpg`], // 轮播图
        resources: [{
                icon: `${$$.url.img}case.png`,
                num: '0',
                unit: '件',
                title: '累计调解案件',
                color: '#EB4D55',
                type: 'case',
            },
            {
                icon: `${$$.url.img}mediater.png`,
                num: '0',
                unit: '名',
                title: '注册调解员',
                color: '#D10269',
                type: 'mediater',
            },
            {
                icon: `${$$.url.img}organizations.png`,
                num: '0',
                unit: '家',
                title: '入驻调解组织',
                color: '#02D1D1',
                type: 'organization',
            },
        ], // 调解资源
        video: [], // 热门视频
        videoMore: false,
        newMessage: [], // 最新资讯
        newMessageMore: false,
        message: [{}], // 消息通知
        // 底部弹窗消息
        popupMsg: [{
            show: false,
            type: 1, // 1:实名认证提醒,2:调解中提醒,3:预约提醒,4:司法确认中提醒
            title: '',
            subTitle: '',
            content: [],
            buttonText: '',
        }, ],
    },
 
    // 跳转资讯链接
    goSeeMessage(e) {
        let url = e.currentTarget.dataset.url;
        wx.navigateTo({
            url: '../webview/index?showUrl=' + url
        });
    },
 
    // 校验登录 or 实名
    userTest(type) {
        if (!app.globalData.token && (type === 'login' || type === 'all')) {
            $$.showModal({
                content: '抱歉您未登录,是否前往登录?',
                success: (res) => {
                    if (res.confirm) {
                        wx.navigateTo({
                            url: '../../pages/login/index',
                        });
                    }
                },
            });
            return false;
        }
        $$.hideLoading();
    },
 
    // 调解资源去看看
    handleNavigateTo(e) {
        let type = e.currentTarget.dataset.type;
        if (type === 'case') {
            $$.showToast({
                title: '功能暂未开启,敬请期待'
            });
        } else if (type === 'register') {
            if ($$.userTest('all')) {
                wx.navigateTo({
                    url: '../../pages/register/index',
                });
            }
        } else {
            if ($$.userTest('login')) {
                wx.navigateTo({
                    url: '../../pages/findAdjust/index?type=' + (type === 'mediater' ? '1' : '2'),
                });
            }
        }
    },
 
    // 查看更多
    handleGetMore(e) {
        let type = e.currentTarget.dataset.type;
        wx.navigateTo({
            url: `../../pages/homePageInfo/index?type=${type}`,
        });
    },
 
    // 平台协议操作
    handleAgree(e) {
        let type = e.currentTarget.dataset.type;
        if (type === 'noAgree') {
            this.selectComponent('#tabbar-page').loginOut();
            $$.loginOutClearData();
        } else {
            // 同意协议之后退出登录后不重复弹出
            wx.setStorage({
                key: 'agreement',
                data: 1
            });
        }
        this.setData({
            popupVisible: false
        });
    },
 
    // 跳转至我的消息
    handleGoToMessageCenter() {
        wx.navigateTo({
            url: '../../pages/messageCenter/index',
        });
    },
 
    // 关闭消息弹窗
    handleClosePopupMsg(e) {
        let index = e.currentTarget.dataset.index;
        this.data.popupMsg[index].show = false;
        this.data.popupMsg[index].content?.forEach((x) => {
            this.msgCheckId = [...(this.msgCheckId || []), x.caseId];
        });
        this.setData({
            popupMsg: this.data.popupMsg
        });
    },
 
    // 消息弹窗操作, TODO:跳转至详情页面的代码屏蔽,暂无用到,后续不用可删除
    handleClickPopupMsg(e) {
        let value = e.currentTarget.dataset.item;
        // let t = e.currentTarget.dataset.t;
        if (e.currentTarget.dataset.type === 'more' && value.content.length === 1) {
            return;
        }
        this.handleClosePopupMsg(e);
        if (value.type === 1) {
            wx.navigateTo({
                url: '../../pages/realNameAuthentication/index'
            });
            return;
        }
        if (value.type === 2 || (value.type === 3 && value.content[t].meetType === '22_00020-1')) {
            wx.navigateTo({
                url: '../../pages/myMediate/index'
            });
            return;
        }
        if (value.type === 4 || (value.type === 3 && value.content[t].meetType === '22_00020-2')) {
            wx.navigateTo({
                url: '../../pages/myJudicialConfirmation/index'
            });
            return;
        }
        // let caseId = value.content[t][value.type === 2 ? 'caseId' : 'id'];
        // let pageType = '1';
        // if (value.type === 2 || (value.type === 3 && value.content[t].meetType === '22_00020-1')) {
        //     pageType = '1'; // 调解
        // }
        // if (value.type === 4 || (value.type === 3 && value.content[t].meetType === '22_00020-2')) {
        //     pageType = '2'; // 司法确认
        // }
    },
 
    // 获取底部弹窗消息提醒
    async getPopupMsg() {
        const res = await getPopupMsgApi();
        if (res.type) {
            let homePageMsgOut = [];
            try {
                let obj = wx.getStorageSync('homePageMsgOut');
                if (obj.time === $$.timeFormat(new Date(), 'YYYY-MM-DD')) {
                    homePageMsgOut = obj.value;
                }
            } catch (e) {}
            let meetRemind = {
                show: false,
                type: 3,
                title: '预约提醒',
                content: [],
                buttonText: '了解详情'
            };
            let meetRemindVisible = false;
            if (res.data.meetRemind) {
                res.data.meetRemind.forEach((x) => {
                    if (homePageMsgOut.includes(x.caseId)) {
                        return;
                    }
                    let nowTime = $$.moment();
                    let startTime = $$.moment(x.orderStartTime);
                    let diffTime = startTime.diff(nowTime, 'hours');
                    // 距离预约开始时间小于一个小时并且未过期的时候提醒
                    if (diffTime > 0 && diffTime <= 1) {
                        meetRemind.content.push(x);
                        meetRemindVisible = true;
                    }
                });
                if (meetRemindVisible) {
                    meetRemind.show = true;
                }
            }
            let caseRemind = {
                show: false,
                type: 2,
                title: '调解中提醒',
                content: [],
                buttonText: '进入调解'
            };
            let caseRemindVisible = false;
            if (res.data.caseRemind) {
                res.data.caseRemind.forEach((x) => {
                    if (homePageMsgOut.includes(x.caseId)) {
                        return;
                    }
                    caseRemind.content.push(x);
                    caseRemindVisible = true;
                });
                if (caseRemindVisible) {
                    caseRemind.show = true;
                }
            }
            let judicRemind = {
                show: false,
                type: 4,
                title: '司法确认中提醒',
                content: [],
                buttonText: '进入司法确认'
            };
            let judicRemindVisible = false;
            if (res.data.judicRemind) {
                res.data.judicRemind.forEach((x) => {
                    if (homePageMsgOut.includes(x.caseId)) {
                        return;
                    }
                    judicRemind.content.push(x);
                    judicRemindVisible = true;
                });
                if (judicRemindVisible) {
                    judicRemind.show = true;
                }
            }
            this.msgCheckId = homePageMsgOut;
            this.setData({
                popupMsg: [meetRemind, caseRemind, judicRemind]
            });
        }
    },
 
    // 获取首页视频资讯数据
    async getVideoAndMessage(param) {
        const res = await getVideoAndMessageApi(param);
        if (res.type) {
            let hotVideoList = res.data.hotVideoList || [];
            let hotNewsList = res.data.hotNewsList || [];
            wx.setStorage({
                key: 'homePageNewMsgTime',
                data: $$.timeFormat(new Date(), 'YYYY-MM-DD HH:mm:ss'),
            });
            this.setData({
                video: hotVideoList.filter((item, index) => index < 2),
                videoMore: hotVideoList.length > 2 ? true : false,
                newMessage: hotNewsList.filter((item, index) => index < 2),
                newMessageMore: hotNewsList.length > 2 ? true : false,
            });
        }
    },
 
    // 获取首页调解资源数量
    async getResourse(param) {
        const res = await getResourseApi(param);
        let resources = {
            ...this.data.resources
        };
        if (res.type) {
            resources[0].num = res.data.caseNum || 0; //累计案件
            resources[1].num = res.data.mediatorNum || 0; //调解员
            resources[2].num = res.data.unitNum || 0; //调解组织
            this.setData({
                resources
            });
        }
    },
 
    // 获取服务协议
    async getAgreement() {
        const res = await $$.commonRequest({
            url: `${$$.url.txt}agree.txt`,
            type: 'get'
        });
        if (res) {
            this.data.popupVisible = true;
            this.setData({
                popupVisible: true,
                agreementMsg: `<pre class="pre">${res || '-'}</pre>`
            });
        }
    },
 
    // getLogin(formData) {
    //     $$.showLoading();
    //     wx.login({
    //         async success(res) {
    //             const submitData = {
    //                 ...formData,
    //                 code: res.code
    //             }
    //             const res1 = await getjumpApi(submitData)
    //             $$.hideLoading();
    //             if (res1.resp_code === "000000000000") {
    //                 wx.setStorage({
    //                     key: 'userInfo',
    //                     data: res1.data
    //                 });
    //                 app.globalData.token = res1.data.token;
    //                 $$.showToast({
    //                     title: '登录成功',
    //                     icon: 'success'
    //                 });
    //                 await $$.sleep();
    //                 wx.reLaunch({
    //                     url: '../../pages/homePage/index',
    //                 });
    //             } else {
    //                 $$.showModal({
    //                     title: '提示',
    //                     content: '您尚未注册,是否前往注册?',
    //                     cancelText: '取消',
    //                     confirmText: '前往',
    //                     success: (res) => {
    //                         if (res.confirm) {
    //                             wx.navigateTo({
    //                                 url: '../../pages/realNameAuthentication/index?backNum=2',
    //                             });
    //                         } else {
    //                             wx.navigateBack({
    //                                 delta: 1,
    //                             });
    //                         }
    //                     },
    //                 });
    //             }
 
    //         }
    //     })
    // },
 
    async dd() {
        $$.showLoading();
        wx.login({
            async success(res) {
                if (res.code) {
                    const accountInfo = wx.getAccountInfoSync();
                    const submitData = {
                        appid: accountInfo.miniProgram.appId,
                        code: res.code,
                    }
                    const res1 = await loginApi(submitData);
                    if (res1.type) {
                        console.log(res1.data, 'res1111')
                        if (res1.data.state === '1') {
                            $$.hideLoading();
                            console.log(res1, 'res1');
                            wx.setStorage({
                                key: 'userInfo',
                                data: res1.data
                            });
                            app.globalData.token = res1.data.token;
                            $$.showToast({
                                title: '登录成功',
                                icon: 'success'
                            });
                            await $$.sleep();
                            wx.reLaunch({
                                url: '../../pages/homePage/index',
                            });
 
                        } else {
                            $$.hideLoading();
                            app.globalData.access_token = wx.getStorageSync('access_token');
                            $$.showModal({
                                title: '提示',
                                content: '您尚未注册,是否前往注册?',
                                cancelText: '取消',
                                confirmText: '前往',
                                success: (res) => {
                                    if (res.confirm) {
                                        $$.showLoading();
                                        wx.getUserProfile({
                                            desc: '完善用户信息',
                                            complete(res) {
                                                if (res.errMsg === 'getUserProfile:ok') {
                                                    wx.login({
                                                        async success(res2) {
                                                            if (res2.code) {
                                                                const accountInfo = wx.getAccountInfoSync();
                                                                const submitData = {
                                                                    appid: accountInfo.miniProgram.appId,
                                                                    code: res2.code,
                                                                    avatar: res?.userInfo.avatarUrl,
                                                                    encryptedData: res.encryptedData,
                                                                    ivStr: res.iv,
                                                                };
                                                                const res3 = await registerApi(submitData);
                                                                $$.hideLoading();
                                                                if (res3.type) {
                                                                    wx.setStorage({
                                                                        key: 'userInfo',
                                                                        data: res3.data
                                                                    });
                                                                    app.globalData.token = res3.data.token;
                                                                    $$.showToast({
                                                                        title: '登录成功',
                                                                        icon: 'success'
                                                                    });
                                                                    await $$.sleep();
                                                                    wx.reLaunch({
                                                                        url: '../../pages/homePage/index',
                                                                    });
                                                                }
                                                            } else {
                                                                $$.hideLoading();
                                                                $$.showToast('登录失败,请稍后重试');
                                                            }
                                                        },
                                                    });
                                                } else {
                                                    $$.hideLoading();
                                                    $$.showToast({
                                                        title: '抱歉!授权失败'
                                                    });
                                                }
                                            },
                                        });
 
                                        // wx.navigateTo({
                                        //     url: '../../pages/login/index',
                                        // });
                                    } else {
                                        wx.navigateBack({
                                            delta: 1,
                                        });
                                    }
                                },
                            });
                        }
 
                    }
 
                    // app.globalData.access_token = wx.getStorageSync('access_token');
                    // console.log(res, 'res')
                    // console.log(app.globalData.access_token, 'app.globalData.access_token')
                    // $$.showModal({
                    //     title: '提示',
                    //     content: '您尚未注册,是否前往注册?',
                    //     cancelText: '取消',
                    //     confirmText: '前往',
                    //     success: (res) => {
                    //         if (res.confirm) {
                    //             wx.navigateTo({
                    //                 url: '../../pages/login/index',
                    //             });
                    //         } else {
                    //             wx.navigateBack({
                    //                 delta: 1,
                    //             });
                    //         }
                    //     },
                    // });
 
                    // const accountInfo = wx.getAccountInfoSync();
                    // const submitData = {
                    //     appid: accountInfo.miniProgram.appId,
                    //     code: res.code,
                    // }
                    // app.globalData.access_token = wx.getStorageSync('access_token');
                    // const res1 = await loginApi(submitData);
                    // console.log(res1, 'res1')
                    // $$.hideLoading();
                    // console.log(res1, 'res1');
                    // if (res1.type) {
                    //     wx.setStorage({
                    //         key: 'userInfo',
                    //         data: res1.data
                    //     });
                    //     app.globalData.token = res1.data.token;
                    //     $$.showToast({
                    //         title: '登录成功',
                    //         icon: 'success'
                    //     });
                    //     await $$.sleep();
                    //     wx.reLaunch({
                    //         url: '../../pages/homePage/index',
                    //     });
                    // }
 
                } else {
                    $$.hideLoading();
                    $$.showToast('登录失败,请稍后重试');
                }
            }
        })
    },
 
    aa() {
        wx.navigateTo({
            url: '../../pages/homePage/index?access_token=2',
        });
    },
 
    cc() {
        wx.navigateTo({
            url: '../../pages/realNameAuthentication/index',
        });
    },
 
    bb() {
        wx.request({
            url: 'https://xcx.pinganbaiyun.cn/p_060_cs_intf/api_001/sv_002_get_paby_login_info', //仅为示例,并非真实的接口地址
            data: {
                "access_token": "测试token",
                "app_id": "测试",
                "secret": "测试"
            },
            method: 'post',
            success(res) {
                console.log(res.data, '平安白云')
            }
        })
    },
 
 
 
    // async handleGetUserInfo() {
    //     $$.showLoading();
    //     wx.getUserProfile({
    //         desc: '完善用户信息',
    //         complete(res) {
    //             if (res.errMsg === 'getUserProfile:ok') {
    //                 wx.login({
    //                     async success(res2) {
    //                         if (res2.code) {
    //                             const accountInfo = wx.getAccountInfoSync();
    //                             const submitData = {
    //                                 appid: accountInfo.miniProgram.appId,
    //                                 code: res2.code,
    //                                 avatar: res?.userInfo.avatarUrl,
    //                                 encryptedData: res.encryptedData,
    //                                 ivStr: res.iv,
    //                             };
    //                             const res3 = await loginApi(submitData);
    //                             $$.hideLoading();
    //                             if (res3.type) {
    //                                 wx.setStorage({
    //                                     key: 'userInfo',
    //                                     data: res3.data
    //                                 });
    //                                 app.globalData.token = res3.data.token;
    //                                 $$.showToast({
    //                                     title: '登录成功',
    //                                     icon: 'success'
    //                                 });
    //                                 await $$.sleep();
    //                                 wx.reLaunch({
    //                                     url: '../../pages/homePage/index',
    //                                 });
    //                             }
    //                         } else {
    //                             $$.hideLoading();
    //                             $$.showToast('登录失败,请稍后重试');
    //                         }
    //                     },
    //                 });
    //             } else {
    //                 $$.hideLoading();
    //                 $$.showToast({
    //                     title: '抱歉!授权失败'
    //                 });
    //             }
    //         },
    //     });
    // },
 
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // const formData = {
        //     access_token: options.access_token,
        //     appid: options.appid,
        //     secret: options.secret
        // // }
 
        // this.dd();
        // this.handleGetUserInfo()
        // 当登录后返回时弹出协议
        let agreement = wx.getStorageSync('agreement');
        if (!agreement && app.globalData.token) this.getAgreement();
    },
 
    onShow(options) {
        console.log(options,'options')
        if (options.extraData.access_token && !app.globalData.token) {
            wx.setStorage({
                key: 'access_token',
                data: options.extraData.access_token
            });
            this.dd();
            $$.showToast({
                title: '已监测到平安白云传入的access_token',
                icon: 'success'
            });
        }
        let appid = wx.getAccountInfoSync().miniProgram.appId;
        this.getResourse({
            appid
        });
        let that = this;
        wx.getStorage({
            key: 'homePageNewMsgTime',
            complete: (res) => {
                if (that.data.video.length === 0 || that.data.newMessage.length == 0) {
                    this.getVideoAndMessage({
                        appid
                    });
                    return;
                }
                if (res.data && $$.moment().diff($$.moment(res.data), 'minute') > 60) {
                    this.getVideoAndMessage({
                        appid
                    });
                }
            },
        });
        // 获取弹窗信息提醒
        if (app.globalData.token) {
            if (!$$.userTest('realName', 'bottom')) {
                this.setData({
                    popupMsg: [{
                        show: true,
                        type: 1,
                        title: '实名认证提醒',
                        subTitle: '您尚未通过实名认证,根据调解实名制规定,建议您尽快前往认证。',
                        buttonText: '前往认证',
                    }, ],
                });
                return;
            }
            this.getPopupMsg();
        }
    },
 
    onHide() {
        if (!!this.msgCheckId) {
            wx.setStorage({
                key: 'homePageMsgOut',
                data: {
                    time: $$.timeFormat(new Date(), 'YYYY-MM-DD'),
                    value: this.msgCheckId,
                },
            });
        }
    },
 
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
});