import { handleShareAppMsg } from '../../utils/configs' import { onMaiDian } from '../../utils/maiDian' import { onGoH5Page } from '../../utils/getUserInfo' import { apiGetHome } from '../../api/index/index' Page({ data: { avatarUrl: '/assets/images/index/icon_head_nologin.png', phone: '', // 用户手机号 isMultiple: false, // 是否是多账号 homeInfo: {} as any }, // 获取首页状态 handleGetHomePage () { wx.showLoading({ title: '加载中', mask: true }) // 授信状态 authStatus (0初始化状态;-1风控拒绝状态;1风控通过状态;2审核中&维护中;9额度失效) // 借款状态 borrowStatus(0不存在未结清的借款;1存在未结清的借款;2审核中;8待放款) // 实名状态 realNameStatus (0未实名;1实名) apiGetHome().then((res: any)=> { if (res.code === '1000') { wx.hideLoading() const homeInfoData = res.data wx.setStorage({ key: 'unique_code', data: { uniqueCode: res.data.uniqueCode } }) // 判断地理位置信息是否过期 try { const locationTime = wx.getStorageSync('locationTime') const afterTime24 = new Date().getTime() + 1 * 60 * 60 * 1000 if (locationTime) { if (locationTime > afterTime24) { this.handleGetLocation() } } else { this.handleGetLocation() } } catch (e) { console.log('判断地理位置catch:', e) } // 是否登录 if (homeInfoData.loginStatus) { try { const user_info = wx.getStorageSync('user_info') if (user_info) { this.setData({ phone: user_info.phone, avatarUrl: '/assets/images/index/icon_head.png' }) } } catch (e) { console.log('获取首页状态catch:', e) } } else { this.setData({ avatarUrl: '/assets/images/index/icon_head_nologin.png' }) } const topTips = `${homeInfoData.authStatus === 1 ? '' : '最高'}可借金额(元)` let buttonTips = '' if ([0].includes(res.data.authStatus)) { buttonTips = '马上领钱' } else if ([2].includes(res.data.authStatus)) { buttonTips = '审核中' } else if ([-1].includes(res.data.authStatus)) { buttonTips = '去借钱' } else if ([1].includes(res.data.authStatus)) { if ([0, 1].includes(res.data.borrowStatus)) { buttonTips = '去借钱' } else if ([2].includes(res.data.borrowStatus)) { buttonTips = '审核中' } else if ([8].includes(res.data.borrowStatus)) { buttonTips = '即将放款' } } else if ([9].includes(res.data.authStatus)) { buttonTips = '重新评估' } Object.assign(homeInfoData, { topTips: topTips, singleBorrow: res.data.singleBorrow && String(res.data.singleBorrow).replace(/(\d+)(\d{3})$/, `$1,$2`), authAmountFormat: res.data.authAmount && String(res.data.authAmount).replace(/(\d+)(\d{3})$/, `$1,$2`), buttonTips: buttonTips }) this.setData({ isMultiple: homeInfoData.multiple ? true : false, homeInfo: homeInfoData }) // 停止下拉刷新 setTimeout(() => { wx.stopPullDownRefresh() }, 3000) } else { wx.showToast({ title: res.msg, icon: 'none' }) } }) }, // 关闭多账号弹窗 onCloseDialogMultiple () { this.setData({ isMultiple: false }) }, // 点击banner onBanner() { onMaiDian('首页-点击-下载APP') onGoH5Page({ is_need_login: true, url: this.data.homeInfo.wxDownDto.downloadUrl }) }, // 点击去登录 onLogin() { if (this.data.homeInfo.loginStatus) { wx.navigateTo({ url: `/pages/setup/index?realNameStatus=${this.data.homeInfo.realNameStatus}` }) } else { onMaiDian('首页-点击-注册登录') wx.navigateTo({ url: '/pages/login/index' }) } }, // 下拉刷新 onPullDownRefresh () { this.handleGetHomePage() }, // 用户点击右上角分享 onShareAppMessage() { handleShareAppMsg() }, // 获取地理位置 handleGetLocation() { wx.getFuzzyLocation({ type: 'wgs84', success (res) { const { latitude, longitude } = res wx.setStorage({ key: 'locationData', data: { coordinateX: longitude, // 经度 coordinateY: latitude // 纬度 } }) wx.setStorage({ key: 'locationTime', data: new Date().getTime() }) }, fail (err) { console.log('获取地理位置err---', err) } }) }, onShow () { this.handleGetHomePage() } })