forked from gzzfw/frontEnd/gzDyh

liuwh
2024-09-07 d7ca134342a0a2004d9c15fab49fd0a41557e29c
gz-wxparty/pages/homePage/index.js
@@ -2,7 +2,7 @@
const $$ = require('../../utils/util');
const app = getApp();
// 热门资讯 与 视频
// 咨询动态
function getVideoAndMessageApi(param) {
    return $$.request({
        url: 'paHotNews/listShow',
@@ -16,20 +16,10 @@
// 调解资源
function getResourseApi(param) {
    return $$.request({
        url: 'paCaseInfo/mediatePower',
    url: 'ctUnit/countUnit',
        type: 'get',
        submitData: param || {},
        service: 'mediate',
        noToken: true
    });
}
// 消息提醒
function getPopupMsgApi() {
    return $$.request({
        url: 'paCaseInfo/newsRemind',
        type: 'get',
        service: 'mediate'
    service: 'cust'
    });
}
@@ -44,7 +34,13 @@
}
function registerApi(submitData) {
   return $$.request({ url: 'paAccount/empower', type: 'post', submitData, service: 'cust', noToken: true });
  return $$.request({
    url: 'paAccount/empower',
    type: 'post',
    submitData,
    service: 'cust',
    noToken: true
  });
}
Page({
@@ -58,31 +54,8 @@
        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',
            },
        ], // 调解资源
    countUnitData: {}, //化解资源
    userInfo: {}, //用户信息
        video: [], // 热门视频
        videoMore: false,
        newMessage: [], // 最新资讯
@@ -91,12 +64,11 @@
        // 底部弹窗消息
        popupMsg: [{
            show: false,
            type: 1, // 1:实名认证提醒,2:调解中提醒,3:预约提醒,4:司法确认中提醒
            title: '',
            subTitle: '',
            content: [],
            buttonText: '',
        }, ],
      type: 1,
      title: '实名认证提醒',
      subTitle: '您尚未通过实名认证,请尽快前往认证',
      buttonText: '前往认证',
    }],
    },
    // 跳转资讯链接
@@ -107,37 +79,26 @@
        });
    },
    // 校验登录 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: '功能暂未开启,敬请期待'
    let url = e.currentTarget.dataset.url;
    if (type === 'register') {
      if (!$$.userTest('all', 'bottom')) {
        this.setData({
          popupMsg: [{
            show: true,
            type: 1,
            title: '实名认证提醒',
            subTitle: '您尚未通过实名认证,请尽快前往认证',
            buttonText: '前往认证',
          }, ],
            });
        } else if (type === 'register') {
            if ($$.userTest('all')) {
                wx.navigateTo({
                    url: '../../pages/register/index',
                });
        return;
            }
      wx.navigateTo({
        url: url,
      });
        } else {
            if ($$.userTest('login')) {
                wx.navigateTo({
@@ -152,6 +113,14 @@
        let type = e.currentTarget.dataset.type;
        wx.navigateTo({
            url: `../../pages/homePageInfo/index?type=${type}`,
    });
  },
  // 跳转
  _handleGoPage(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
        });
    },
@@ -218,99 +187,8 @@
            });
            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) {
@@ -334,17 +212,9 @@
    // 获取首页调解资源数量
    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
      countUnitData: res.data
            });
        }
    },
    // 获取服务协议
@@ -361,54 +231,6 @@
            });
        }
    },
    // 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();
@@ -509,56 +331,7 @@
                                },
                            });
                        }
                    }
                    // 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('登录失败,请稍后重试');
@@ -567,125 +340,31 @@
        })
    },
    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();
    },
  onLoad: function (options) {},
    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'
            });
    if (!$$.userTest('login')) {
      return
        }
    let userInfo = wx.getStorageSync('userInfo') || {};
        let appid = wx.getAccountInfoSync().miniProgram.appId;
        this.getResourse({
            appid
    this.setData({
      userInfo
        });
        let that = this;
        wx.getStorage({
            key: 'homePageNewMsgTime',
            complete: (res) => {
                if (that.data.video.length === 0 || that.data.newMessage.length == 0) {
        if (that.data.video.length === 0 || !that.data.countUnitData) {
                    this.getVideoAndMessage({
            appid
          });
          this.getResourse({
                        appid
                    });
                    return;
@@ -694,37 +373,37 @@
                    this.getVideoAndMessage({
                        appid
                    });
          this.getResourse({
            appid
          });
                }
            },
        });
    let agreement = wx.getStorageSync('agreement');
        // 获取弹窗信息提醒
        if (app.globalData.token) {
      if (!agreement) {
        this.getAgreement();
        return;
      }
            if (!$$.userTest('realName', 'bottom')) {
                this.setData({
                    popupMsg: [{
                        show: true,
                        type: 1,
                        title: '实名认证提醒',
                        subTitle: '您尚未通过实名认证,根据调解实名制规定,建议您尽快前往认证。',
            subTitle: '您尚未通过实名认证,请尽快前往认证',
                        buttonText: '前往认证',
                    }, ],
                });
                return;
            }
            this.getPopupMsg();
        }
    },
    onHide() {
        if (!!this.msgCheckId) {
            wx.setStorage({
                key: 'homePageMsgOut',
                data: {
                    time: $$.timeFormat(new Date(), 'YYYY-MM-DD'),
                    value: this.msgCheckId,
                },
            });
        }
    },
    /**