index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // pages/index/index.js
  2. import { homePage } from '../../api/index'
  3. import { createQRcode } from "../../api/document";
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. locationStr: '定位地址…',
  11. useNumber: 0, // 剩余预约次数
  12. documentVos: [], // 档案信息
  13. cardNo: '',
  14. cardSecret: '',
  15. scanTimer: null,
  16. baseStr: 'data:image/jpg;base64,',
  17. QRCodeBase64: '',
  18. qrcodeDialog: false
  19. },
  20. onShow () {
  21. app.globalData.selectedInex = 0
  22. if (app.globalData.userInfo.login) {
  23. this.initIndexData()
  24. } else {
  25. wx.reLaunch({
  26. url: '/pages/my/my'
  27. })
  28. }
  29. },
  30. onPullDownRefresh () {
  31. wx.vibrateShort({
  32. type: 'medium'
  33. })
  34. this.initIndexData(true)
  35. },
  36. onShareAppMessage () {
  37. return {
  38. title: 'ITTHealth',
  39. path: '/pages/index/index'
  40. }
  41. },
  42. // 获取首页信息
  43. initIndexData (pullDownRefresh = false) {
  44. var that = this
  45. wx.showLoading({
  46. title: '加载中...',
  47. mask: true
  48. })
  49. homePage({}).then(hoemRes => {
  50. wx.hideLoading()
  51. if (pullDownRefresh) {
  52. wx.stopPullDownRefresh()
  53. }
  54. var response = hoemRes.data.documentVos || []
  55. response.map(item => {
  56. item.birthDay = item.birthday.split(' ')[0]
  57. })
  58. that.setData({
  59. useNumber: hoemRes.data.useNumber,
  60. documentVos: response
  61. })
  62. }).catch(e => {
  63. wx.hideLoading()
  64. wx.showModal({
  65. content: e,
  66. confirmColor: '#333',
  67. showCancel: false
  68. })
  69. })
  70. },
  71. // 打开地图选择位置。
  72. openMap () {
  73. wx.chooseLocation()
  74. },
  75. /**
  76. * 处理套餐 购买 or 预约
  77. * useNumber: 0-购买 1-预约
  78. * **/
  79. handlePackage () {
  80. var type = this.data.useNumber > 0 ? 1 : 0
  81. switch (type) {
  82. case 0:
  83. wx.navigateTo({
  84. url: '/pages/buy/buy?from=index',
  85. })
  86. break;
  87. case 1:
  88. this.appointmentAuth()
  89. break;
  90. }
  91. },
  92. // 预约前判断是否存在一位检测人
  93. appointmentAuth () {
  94. if (this.data.documentVos.length == 0) {
  95. wx.showModal({
  96. content: '预约用户前需要先添加检测人员信息',
  97. cancelColor: '#666',
  98. confirmColor: '#333',
  99. success (res) {
  100. if (res.confirm) {
  101. wx.navigateTo({
  102. url: '/pages/createFile/createFile?from=index'
  103. })
  104. }
  105. }
  106. })
  107. } else {
  108. wx.navigateTo({
  109. url: '/pages/appointment/appointment?from=index',
  110. })
  111. }
  112. },
  113. // 点击全部档案
  114. handleAllFile () {
  115. wx.navigateTo({
  116. url: '/pages/myFile/myFile',
  117. })
  118. },
  119. // 点击查看报告
  120. handleRepoetDetail (e) {
  121. var reportid = e.currentTarget.dataset.reportid
  122. wx.navigateTo({
  123. url: '/pages/reportDetail/reportDetail?reportid=' + reportid
  124. })
  125. },
  126. // 添加检测人
  127. handleAddCheck () {
  128. wx.navigateTo({
  129. url: '/pages/createFile/createFile?form=index',
  130. })
  131. },
  132. /* 车子的图片 做跳转交互,跳转做判断,0次则跳出去充值弹框,充值弹窗有两个选择 :若激活卡,则跳转至实体卡兑换页面;若充值,则跳转至体验卡购买页面 */
  133. handlActions () {
  134. if (this.data.useNumber == 0) {
  135. wx.showModal({
  136. title: '去充值',
  137. cancelColor: '#666',
  138. cancelText: '激活卡',
  139. confirmText: '去充值',
  140. confirmColor: '#333',
  141. success (res) {
  142. if (res.confirm) {
  143. wx.navigateTo({
  144. url: '/pages/buy/buy?from=index',
  145. })
  146. } else if (res.cancel) {
  147. wx.navigateTo({
  148. url: '/pages/exchange/exchange',
  149. })
  150. }
  151. }
  152. })
  153. } else {
  154. this.appointmentAuth()
  155. }
  156. },
  157. handleShowQRCode (e) {
  158. var that = this
  159. var id = e.currentTarget.dataset.id
  160. wx.showLoading({
  161. title: '生成中...'
  162. })
  163. createQRcode({ documentId: id }).then(res => {
  164. wx.hideLoading()
  165. that.setData({
  166. QRCodeBase64: that.data.baseStr + res.data,
  167. qrcodeDialog: true
  168. })
  169. }).catch(e => {
  170. wx.hideLoading()
  171. wx.showModal({
  172. content: e,
  173. confirmColor: '#333',
  174. showCancel: false
  175. })
  176. })
  177. },
  178. handleCloseQRCode (e) {
  179. this.setData({
  180. qrcodeDialog: false,
  181. QRCodeBase64: ''
  182. })
  183. }
  184. })