my.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. await this.getAccountNmberFn()
  95. await this.appointmentListFn()
  96. await this.getAppGetConfigImg()
  97. },
  98. getAppGetConfigImg() {
  99. const that = this
  100. wx.showNavigationBarLoading()
  101. // 类型 【1.关于我的 2.用户协议 3.我的 4.实体卡兑换说明 】
  102. return new Promise((reslove,rej) => {
  103. appGetConfigImg({
  104. 'imgType': '3'
  105. }).then(configRes => {
  106. wx.hideNavigationBarLoading()
  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. wx.showNavigationBarLoading()
  154. return new Promise((resolve, reject) => {
  155. appointmentList({
  156. status: 1,
  157. currentPage: 1
  158. }).then(res => {
  159. wx.hideNavigationBarLoading()
  160. if (res.data.vos.length !== 0) {
  161. app.globalData.hasAppointment = true
  162. } else {
  163. app.globalData.hasAppointment = false
  164. }
  165. resolve(res)
  166. }).catch(e => {
  167. wx.hideNavigationBarLoading()
  168. })
  169. })
  170. },
  171. // 获取用户剩余检测机会
  172. getAccountNmberFn () {
  173. var that = this
  174. wx.showNavigationBarLoading()
  175. return new Promise((resolve, reject) => {
  176. getAccountNmber({}).then(res => {
  177. wx.hideNavigationBarLoading()
  178. that.setData({
  179. count: res.data,
  180. isFirstGetCount: false
  181. })
  182. app.globalData.useNumber = res.data
  183. resolve(res)
  184. }).catch(e => {
  185. wx.hideNavigationBarLoading()
  186. })
  187. })
  188. },
  189. // 路由跳转
  190. handleNavTo (e) {
  191. var url = e.currentTarget.dataset.url
  192. this.authNavTo(url)
  193. },
  194. // 去充值
  195. handleCharge () {
  196. this.authNavTo('/pages/buy/buy?from=my')
  197. },
  198. // 立即预约
  199. handleAppoint () {
  200. if (app.globalData.hasAppointment) {
  201. wx.showModal({
  202. content: '您预约的健康筛查还未体验,请先体验',
  203. cancelColor: '#666',
  204. cancelText: '取消',
  205. confirmText: '我的预约',
  206. confirmColor: '#333',
  207. success (res) {
  208. if (res.confirm) {
  209. wx.navigateTo({
  210. url: '/pages/myAppointment/myAppointment',
  211. })
  212. }
  213. }
  214. })
  215. } else {
  216. this.getDocumentList()
  217. }
  218. },
  219. /**
  220. * 路由拦截
  221. * **/
  222. authNavTo (url) {
  223. if (url.indexOf('/report') !== -1) {
  224. app.globalData.selectedInex = 1
  225. wx.setStorageSync('selectedInex', 1)
  226. wx.switchTab({
  227. url: url,
  228. })
  229. } else {
  230. wx.navigateTo({
  231. url: url,
  232. })
  233. }
  234. }
  235. })