my.js 5.4 KB

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