index.js 4.4 KB

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