my.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/my/my.js
  2. import { getAccountNmber, appointmentList } from '../../api/appointment'
  3. import { documentList } from "../../api/document"
  4. import { appGetConfigImg } from '../../api/index'
  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. imageList: []
  72. },
  73. onShow () {
  74. if (!this.data.isFirstGetCount) {
  75. this.initMyPage()
  76. }
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. * 调用login接口,判断是否需要绑定手机号和头像昵称
  81. */
  82. onLoad(options) {
  83. app.globalData.selectedInex = 2
  84. wx.setStorageSync('selectedInex', 2)
  85. var headImg = wx.getStorageSync('headImg')
  86. var userName = wx.getStorageSync('userName')
  87. this.setData({
  88. appHeadImg: headImg,
  89. appUserName: userName
  90. })
  91. this.initMyPage()
  92. },
  93. async initMyPage () {
  94. wx.showNavigationBarLoading()
  95. await this.getAccountNmberFn()
  96. await this.appointmentListFn()
  97. await this.getAppGetConfigImg()
  98. wx.hideNavigationBarLoading()
  99. },
  100. getAppGetConfigImg() {
  101. const that = this
  102. // 类型 【1.关于我的 2.用户协议 3.我的 4.实体卡兑换说明 】
  103. return new Promise((reslove,rej) => {
  104. appGetConfigImg({
  105. 'imgType': '3'
  106. }).then(configRes => {
  107. that.setData({
  108. imageList: configRes.data || []
  109. })
  110. reslove(configRes)
  111. })
  112. })
  113. },
  114. // 获取用户档案信息
  115. getDocumentList () {
  116. var that = this
  117. wx.showLoading({
  118. title: '加载中...',
  119. mask: true
  120. })
  121. documentList({
  122. currentPage: 1
  123. }).then(res => {
  124. wx.hideLoading()
  125. const response = res.data.vos || []
  126. if (response.length == 0) {
  127. wx.showModal({
  128. content: '预约用户前需要先添加检测人员信息',
  129. cancelColor: '#666',
  130. confirmColor: '#333',
  131. success (res) {
  132. if (res.confirm) {
  133. wx.navigateTo({
  134. url: '/pages/createFile/createFile?from=index'
  135. })
  136. }
  137. }
  138. })
  139. } else {
  140. that.authNavTo('/pages/appointment/appointment')
  141. }
  142. }).catch(e => {
  143. wx.hideLoading()
  144. wx.showModal({
  145. content: e,
  146. confirmColor: '#333',
  147. showCancel: false
  148. })
  149. })
  150. },
  151. // 获取用户预约信息
  152. appointmentListFn () {
  153. return new Promise((resolve, reject) => {
  154. appointmentList({
  155. status: 1,
  156. currentPage: 1
  157. }).then(res => {
  158. if (res.data.vos.length !== 0) {
  159. app.globalData.hasAppointment = true
  160. } else {
  161. app.globalData.hasAppointment = false
  162. }
  163. resolve(res)
  164. })
  165. })
  166. },
  167. // 获取用户剩余检测机会
  168. getAccountNmberFn () {
  169. var that = this
  170. return new Promise((resolve, reject) => {
  171. getAccountNmber({}).then(res => {
  172. that.setData({
  173. count: res.data,
  174. isFirstGetCount: false
  175. })
  176. app.globalData.useNumber = res.data
  177. resolve(res)
  178. })
  179. })
  180. },
  181. // 路由跳转
  182. handleNavTo (e) {
  183. var url = e.currentTarget.dataset.url
  184. this.authNavTo(url)
  185. },
  186. // 去充值
  187. handleCharge () {
  188. this.authNavTo('/pages/buy/buy?from=my')
  189. },
  190. // 立即预约
  191. handleAppoint () {
  192. if (app.globalData.hasAppointment) {
  193. wx.showModal({
  194. content: '您预约的健康筛查还未体验,请先体验',
  195. cancelColor: '#666',
  196. cancelText: '取消',
  197. confirmText: '我的预约',
  198. confirmColor: '#333',
  199. success (res) {
  200. if (res.confirm) {
  201. wx.navigateTo({
  202. url: '/pages/myAppointment/myAppointment',
  203. })
  204. }
  205. }
  206. })
  207. } else {
  208. this.getDocumentList()
  209. }
  210. },
  211. /**
  212. * 路由拦截
  213. * **/
  214. authNavTo (url) {
  215. if (url.indexOf('/report') !== -1) {
  216. app.globalData.selectedInex = 1
  217. wx.setStorageSync('selectedInex', 1)
  218. wx.switchTab({
  219. url: url,
  220. })
  221. } else {
  222. wx.navigateTo({
  223. url: url,
  224. })
  225. }
  226. }
  227. })