my.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/my/my.js
  2. import { getAccountNmber } from '../../api/appointment'
  3. import { documentList } from "../../api/document"
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. appHeadImg: '',
  11. appUserName: '',
  12. count: 0,
  13. isFirstGetCount: true, // 是否为第一次获取检测机会的次数
  14. gridList: [
  15. {
  16. id: 0,
  17. title: '我的地址',
  18. url: '/pages/address/address?form=my&back=0',
  19. imgUrl: '../../imaes/dizhi@2x.png'
  20. },
  21. {
  22. id: 1,
  23. title: '我的档案',
  24. url: '/pages/myFile/myFile?form=my',
  25. imgUrl: '../../imaes/dangan@2x.png'
  26. },
  27. {
  28. id: 2,
  29. title: '我的预约',
  30. url: '/pages/myAppointment/myAppointment?form=my',
  31. imgUrl: '../../imaes/yuyue@2x.png'
  32. },
  33. {
  34. id: 7,
  35. title: '实体卡兑换',
  36. url: '/pages/exchange/exchange?form=my',
  37. imgUrl: '../../imaes/chongzhi.png'
  38. },
  39. {
  40. id: 3,
  41. title: '我的记录',
  42. url: '/pages/myRecord/myRecord?form=my',
  43. imgUrl: '../../imaes/jilu@2x.png'
  44. },
  45. {
  46. id: 4,
  47. title: '我的报告',
  48. url: '/pages/report/report?form=my',
  49. imgUrl: '../../imaes/baogao2@2x.png'
  50. },
  51. /* {
  52. id: 5,
  53. title: '开通区域',
  54. url: '/pages/openArea/openArea?form=my',
  55. imgUrl: '../../imaes/quyu@2x.png'
  56. }, */
  57. {
  58. id: 7,
  59. title: '设置',
  60. url: '/pages/set/set?form=my',
  61. imgUrl: '../../imaes/shezhi@2x.png'
  62. },
  63. /* {
  64. id: 7,
  65. title: '测试页面',
  66. url: '/pages/aatest/test',
  67. imgUrl: '../../imaes/shezhi@2x.png'
  68. } */
  69. ]
  70. },
  71. onShow () {
  72. if (!this.data.isFirstGetCount) {
  73. this.getAccountNmberFn()
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. * 调用login接口,判断是否需要绑定手机号和头像昵称
  79. */
  80. onLoad(options) {
  81. app.globalData.selectedInex = 2
  82. var headImg = wx.getStorageSync('headImg')
  83. var userName = wx.getStorageSync('userName')
  84. this.setData({
  85. appHeadImg: headImg,
  86. appUserName: userName
  87. })
  88. this.getAccountNmberFn()
  89. },
  90. // 获取用户档案信息
  91. getDocumentList () {
  92. var that = this
  93. wx.showLoading({
  94. title: '加载中...',
  95. mask: true
  96. })
  97. documentList({
  98. currentPage: 1
  99. }).then(res => {
  100. wx.hideLoading()
  101. const response = res.data.vos || []
  102. if (response.length == 0) {
  103. wx.showModal({
  104. content: '预约用户前需要先添加检测人员信息',
  105. cancelColor: '#666',
  106. confirmColor: '#333',
  107. success (res) {
  108. if (res.confirm) {
  109. wx.navigateTo({
  110. url: '/pages/createFile/createFile?from=index'
  111. })
  112. }
  113. }
  114. })
  115. } else {
  116. that.authNavTo('/pages/appointment/appointment')
  117. }
  118. }).catch(e => {
  119. wx.hideLoading()
  120. wx.showModal({
  121. content: e,
  122. confirmColor: '#333',
  123. showCancel: false
  124. })
  125. })
  126. },
  127. // 获取用户剩余检测机会
  128. getAccountNmberFn () {
  129. var that = this
  130. wx.showNavigationBarLoading()
  131. getAccountNmber({}).then(res => {
  132. wx.hideNavigationBarLoading()
  133. that.setData({
  134. count: res.data,
  135. isFirstGetCount: false
  136. })
  137. })
  138. },
  139. // 路由跳转
  140. handleNavTo (e) {
  141. var url = e.currentTarget.dataset.url
  142. this.authNavTo(url)
  143. },
  144. // 去充值
  145. handleCharge () {
  146. this.authNavTo('/pages/buy/buy?from=my')
  147. },
  148. // 立即预约
  149. handleAppoint () {
  150. this.getDocumentList()
  151. },
  152. /**
  153. * 路由拦截
  154. * **/
  155. authNavTo (url) {
  156. if (url.indexOf('/report') !== -1) {
  157. app.globalData.selectedInex = 1
  158. wx.switchTab({
  159. url: url,
  160. })
  161. } else {
  162. wx.navigateTo({
  163. url: url,
  164. })
  165. }
  166. }
  167. })