123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- // 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:
- this.appointmentAuth()
- break;
- }
- },
- // 预约前判断是否存在一位检测人
- appointmentAuth () {
- if (this.data.documentVos.length == 0) {
- wx.showModal({
- content: '预约用户前需要先添加检测人员信息',
- cancelColor: '#666',
- confirmColor: '#333',
- success (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/createFile/createFile?from=index'
- })
- }
- }
- })
- } else {
- wx.navigateTo({
- url: '/pages/appointment/appointment?from=index',
- })
- }
- },
-
- // 点击全部档案
- 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 {
- this.appointmentAuth()
- }
- },
- 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: ''
- })
- }
- })
|