index.js 5.6 KB

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