my.js 5.0 KB

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