// pages/index/index.js import { homePage } from '../../api/index' import { createQRcode } from "../../api/document"; const app = getApp() Page({ /** * 页面的初始数据 */ data: { locationStr: '定位地址…', useNumber: 0, // 剩余预约次数 documentVos: [], // 档案信息 cardNo: '', cardSecret: '', scanTimer: null, baseStr: 'data:image/jpg;base64,', QRCodeBase64: '', qrcodeDialog: false }, onShow () { app.globalData.selectedInex = 0 if (app.globalData.userInfo.login) { this.initIndexData() } else { wx.reLaunch({ url: '/pages/my/my' }) } }, onPullDownRefresh () { wx.vibrateShort({ type: 'medium' }) this.initIndexData(true) }, onShareAppMessage () { return { title: 'ITTHealth', path: '/pages/index/index' } }, // 获取首页信息 initIndexData (pullDownRefresh = false) { var that = this wx.showLoading({ title: '加载中...', mask: true }) homePage({}).then(hoemRes => { wx.hideLoading() if (pullDownRefresh) { wx.stopPullDownRefresh() } var response = hoemRes.data.documentVos || [] response.map(item => { item.birthDay = item.birthday.split(' ')[0] }) that.setData({ useNumber: hoemRes.data.useNumber, documentVos: response }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, // 打开地图选择位置。 openMap () { wx.chooseLocation() }, /** * 处理套餐 购买 or 预约 * useNumber: 0-购买 1-预约 * **/ handlePackage () { var type = this.data.useNumber > 0 ? 1 : 0 switch (type) { case 0: wx.navigateTo({ url: '/pages/buy/buy?from=index', }) break; case 1: wx.navigateTo({ url: '/pages/appointment/appointment?from=index', }) break; } }, // 点击全部档案 handleAllFile () { wx.navigateTo({ url: '/pages/myFile/myFile', }) }, // 点击查看报告 handleRepoetDetail (e) { var reportid = e.currentTarget.dataset.reportid wx.navigateTo({ url: '/pages/reportDetail/reportDetail?reportid=' + reportid }) }, // 添加检测人 handleAddCheck () { wx.navigateTo({ url: '/pages/createFile/createFile?form=index', }) }, /* 车子的图片 做跳转交互,跳转做判断,0次则跳出去充值弹框,充值弹窗有两个选择 :若激活卡,则跳转至实体卡兑换页面;若充值,则跳转至体验卡购买页面 */ handlActions () { if (this.data.useNumber == 0) { wx.showModal({ title: '去充值', cancelColor: '#666', cancelText: '激活卡', confirmText: '去充值', confirmColor: '#333', success (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/buy/buy?from=index', }) } else if (res.cancel) { wx.navigateTo({ url: '/pages/exchange/exchange', }) } } }) } else { wx.navigateTo({ url: '/pages/appointment/appointment?from=index' }) } }, handleShowQRCode (e) { var that = this var id = e.currentTarget.dataset.id wx.showLoading({ title: '生成中...' }) createQRcode({ documentId: id }).then(res => { wx.hideLoading() that.setData({ QRCodeBase64: that.data.baseStr + res.data, qrcodeDialog: true }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, handleCloseQRCode (e) { this.setData({ qrcodeDialog: false, QRCodeBase64: '' }) } })