index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/index/index.js
  2. import { homePage } from '../../api/index'
  3. import { userEntityRecharge } from '../../api/charge'
  4. import { createQRcode } from "../../api/document";
  5. const app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. locationStr: '定位地址…',
  12. useNumber: 0, // 剩余预约次数
  13. documentVos: [], // 档案信息
  14. cardNo: '',
  15. cardSecret: '',
  16. scanTimer: null,
  17. baseStr: 'data:image/jpg;base64,',
  18. QRCodeBase64: '',
  19. qrcodeDialog: false
  20. },
  21. onShow () {
  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. wx.showLoading({
  45. title: '加载中...',
  46. mask: true
  47. })
  48. homePage({}).then(hoemRes => {
  49. wx.hideLoading()
  50. if (pullDownRefresh) {
  51. wx.stopPullDownRefresh()
  52. }
  53. var response = hoemRes.data.documentVos
  54. response.map(item => {
  55. item.birthDay = item.birthday.split(' ')[0]
  56. })
  57. this.setData({
  58. useNumber: hoemRes.data.useNumber,
  59. documentVos: response
  60. })
  61. }).catch(e => {
  62. wx.hideLoading()
  63. wx.showModal({
  64. content: e,
  65. confirmColor: '#333',
  66. showCancel: false
  67. })
  68. })
  69. },
  70. // 打开地图选择位置。
  71. openMap () {
  72. wx.chooseLocation()
  73. },
  74. /**
  75. * 处理套餐 购买 or 预约
  76. * useNumber: 0-购买 1-预约
  77. * **/
  78. handlePackage () {
  79. var type = this.data.useNumber > 0 ? 1 : 0
  80. switch (type) {
  81. case 0:
  82. wx.navigateTo({
  83. url: '/pages/buy/buy',
  84. })
  85. break;
  86. case 1:
  87. wx.navigateTo({
  88. url: '/pages/appointment/appointment',
  89. })
  90. break;
  91. }
  92. },
  93. // 点击全部档案
  94. handleAllFile () {
  95. wx.navigateTo({
  96. url: '/pages/myFile/myFile',
  97. })
  98. },
  99. // 添加检测人
  100. handleAddCheck () {
  101. wx.navigateTo({
  102. url: '/pages/createFile/createFile?form=index',
  103. })
  104. },
  105. /* 车子的图片 做跳转交互,跳转做判断,0次则跳出去充值弹框,充值弹窗有两个选择 :若激活卡,则跳转至实体卡兑换页面;若充值,则跳转至体验卡购买页面 */
  106. handlActions () {
  107. if (this.data.useNumber == 0) {
  108. wx.showModal({
  109. title: '去充值',
  110. cancelColor: '#666',
  111. cancelText: '激活卡',
  112. confirmText: '去充值',
  113. confirmColor: '#333',
  114. success (res) {
  115. if (res.confirm) {
  116. wx.navigateTo({
  117. url: '/pages/buy/buy?form=index',
  118. })
  119. } else if (res.cancel) {
  120. wx.navigateTo({
  121. url: '/pages/exchange/exchange',
  122. })
  123. }
  124. }
  125. })
  126. } else {
  127. wx.navigateTo({
  128. url: '/pages/appointment/appointment'
  129. })
  130. }
  131. },
  132. handleShowQRCode (e) {
  133. var that = this
  134. var id = e.currentTarget.dataset.id
  135. wx.showLoading({
  136. title: '生成中...'
  137. })
  138. createQRcode({ documentId: id }).then(res => {
  139. wx.hideLoading()
  140. that.setData({
  141. QRCodeBase64: that.data.baseStr + res.data,
  142. qrcodeDialog: true
  143. })
  144. }).catch(e => {
  145. wx.hideLoading()
  146. wx.showModal({
  147. content: e,
  148. confirmColor: '#333',
  149. showCancel: false
  150. })
  151. })
  152. },
  153. handleCloseQRCode (e) {
  154. this.setData({
  155. qrcodeDialog: false,
  156. QRCodeBase64: ''
  157. })
  158. }
  159. })