my.js 5.4 KB

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