// pages/my/my.js import { getAccountNmber, appointmentList } from '../../api/appointment' import { documentList } from "../../api/document" import { appGetConfigImg } from '../../api/index' const app = getApp() Page({ /** * 页面的初始数据 */ data: { appHeadImg: '', appUserName: '', count: 0, isFirstGetCount: true, // 是否为第一次获取检测机会的次数 gridList: [ { id: 0, title: '我的地址', url: '/pages/address/address?form=my&back=0', imgUrl: '../../imaes/dizhi@2x.png' }, { id: 1, title: '我的档案', url: '/pages/myFile/myFile?form=my', imgUrl: '../../imaes/dangan@2x.png' }, { id: 2, title: '我的预约', url: '/pages/myAppointment/myAppointment?form=my', imgUrl: '../../imaes/yuyue@2x.png' }, { id: 7, title: '实体卡兑换', url: '/pages/exchange/exchange?form=my', imgUrl: '../../imaes/chongzhi.png' }, { id: 3, title: '我的记录', url: '/pages/myRecord/myRecord?form=my', imgUrl: '../../imaes/jilu@2x.png' }, { id: 4, title: '我的报告', url: '/pages/report/report?form=my', imgUrl: '../../imaes/baogao2@2x.png' }, /* { id: 5, title: '开通区域', url: '/pages/openArea/openArea?form=my', imgUrl: '../../imaes/quyu@2x.png' }, */ { id: 7, title: '设置', url: '/pages/set/set?form=my', imgUrl: '../../imaes/shezhi@2x.png' }, /* { id: 7, title: '测试页面', url: '/pages/aatest/test', imgUrl: '../../imaes/shezhi@2x.png' } */ ], imageList: [] }, onShow () { if (!this.data.isFirstGetCount) { this.initMyPage() } }, /** * 生命周期函数--监听页面加载 * 调用login接口,判断是否需要绑定手机号和头像昵称 */ onLoad(options) { app.globalData.selectedInex = 2 wx.setStorageSync('selectedInex', 2) var headImg = wx.getStorageSync('headImg') var userName = wx.getStorageSync('userName') this.setData({ appHeadImg: headImg, appUserName: userName }) this.initMyPage() }, async initMyPage () { await this.getAccountNmberFn() await this.appointmentListFn() await this.getAppGetConfigImg() }, getAppGetConfigImg() { const that = this wx.showNavigationBarLoading() // 类型 【1.关于我的 2.用户协议 3.我的 4.实体卡兑换说明 】 return new Promise((reslove,rej) => { appGetConfigImg({ 'imgType': '3' }).then(configRes => { wx.hideNavigationBarLoading() that.setData({ imageList: configRes.data || [] }) reslove(configRes) }) }) }, // 获取用户档案信息 getDocumentList () { var that = this wx.showLoading({ title: '加载中...', mask: true }) documentList({ currentPage: 1 }).then(res => { wx.hideLoading() const response = res.data.vos || [] if (response.length == 0) { wx.showModal({ content: '预约用户前需要先添加检测人员信息', cancelColor: '#666', confirmColor: '#333', success (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/createFile/createFile?from=index' }) } } }) } else { that.authNavTo('/pages/appointment/appointment') } }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, // 获取用户预约信息 appointmentListFn () { wx.showNavigationBarLoading() return new Promise((resolve, reject) => { appointmentList({ status: 1, currentPage: 1 }).then(res => { wx.hideNavigationBarLoading() if (res.data.vos.length !== 0) { app.globalData.hasAppointment = true } else { app.globalData.hasAppointment = false } resolve(res) }).catch(e => { wx.hideNavigationBarLoading() }) }) }, // 获取用户剩余检测机会 getAccountNmberFn () { var that = this wx.showNavigationBarLoading() return new Promise((resolve, reject) => { getAccountNmber({}).then(res => { wx.hideNavigationBarLoading() that.setData({ count: res.data, isFirstGetCount: false }) app.globalData.useNumber = res.data resolve(res) }).catch(e => { wx.hideNavigationBarLoading() }) }) }, // 路由跳转 handleNavTo (e) { var url = e.currentTarget.dataset.url this.authNavTo(url) }, // 去充值 handleCharge () { this.authNavTo('/pages/buy/buy?from=my') }, // 立即预约 handleAppoint () { if (app.globalData.hasAppointment) { wx.showModal({ content: '您预约的健康筛查还未体验,请先体验', cancelColor: '#666', cancelText: '取消', confirmText: '我的预约', confirmColor: '#333', success (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/myAppointment/myAppointment', }) } } }) } else { this.getDocumentList() } }, /** * 路由拦截 * **/ authNavTo (url) { if (url.indexOf('/report') !== -1) { app.globalData.selectedInex = 1 wx.setStorageSync('selectedInex', 1) wx.switchTab({ url: url, }) } else { wx.navigateTo({ url: url, }) } } })