profile.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // profile.js
  2. const mockData = require('../../utils/mockData.js')
  3. Page({
  4. data: {
  5. userInfo: mockData.userInfo,
  6. orderStats: {
  7. total: 0,
  8. delivering: 0,
  9. completed: 0
  10. },
  11. recentOrders: [],
  12. medicalStats: {
  13. total: 0,
  14. recent: 0
  15. },
  16. recentMedicalRecords: [],
  17. showFingerprintModal: false,
  18. showFaceModal: false
  19. },
  20. onLoad() {
  21. console.log('我的页面加载完成')
  22. this.loadUserData()
  23. },
  24. onShow() {
  25. // 每次页面显示时刷新数据
  26. this.loadUserData()
  27. },
  28. // 加载用户数据
  29. loadUserData() {
  30. // 从全局变量获取订单数据
  31. const app = getApp()
  32. const orders = app.getOrders()
  33. const orderStats = {
  34. total: orders.length,
  35. delivering: orders.filter(order => order.status === '配送中').length,
  36. completed: orders.filter(order => order.status === '已完成').length
  37. }
  38. const recentOrders = orders.slice(0, 3) // 显示最近3个订单
  39. // 加载病历记录
  40. const medicalRecords = app.getMedicalRecords()
  41. const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
  42. const recentMedicalRecords = medicalRecords.filter(item =>
  43. new Date(item.date) > thirtyDaysAgo
  44. ).slice(0, 3)
  45. const medicalStats = {
  46. total: medicalRecords.length,
  47. recent: recentMedicalRecords.length
  48. }
  49. this.setData({
  50. orderStats: orderStats,
  51. recentOrders: recentOrders,
  52. medicalStats: medicalStats,
  53. recentMedicalRecords: recentMedicalRecords
  54. })
  55. },
  56. // 切换指纹验证
  57. toggleFingerprint(e) {
  58. const enabled = e.detail.value
  59. if (enabled) {
  60. this.setData({
  61. showFingerprintModal: true
  62. })
  63. } else {
  64. this.disableFingerprint()
  65. }
  66. },
  67. // 关闭指纹验证模态框
  68. closeFingerprintModal() {
  69. this.setData({
  70. showFingerprintModal: false,
  71. 'userInfo.fingerprintRegistered': false
  72. })
  73. },
  74. // 确认指纹验证
  75. confirmFingerprint() {
  76. // 模拟指纹验证过程
  77. wx.showLoading({
  78. title: '验证中...',
  79. })
  80. setTimeout(() => {
  81. wx.hideLoading()
  82. this.setData({
  83. showFingerprintModal: false,
  84. 'userInfo.fingerprintRegistered': true
  85. })
  86. wx.showToast({
  87. title: '指纹验证成功',
  88. icon: 'success'
  89. })
  90. }, 2000)
  91. },
  92. // 禁用指纹验证
  93. disableFingerprint() {
  94. this.setData({
  95. 'userInfo.fingerprintRegistered': false
  96. })
  97. wx.showToast({
  98. title: '已关闭指纹验证',
  99. icon: 'success'
  100. })
  101. },
  102. // 切换人脸识别
  103. toggleFaceRecognition(e) {
  104. const enabled = e.detail.value
  105. if (enabled) {
  106. this.setData({
  107. showFaceModal: true
  108. })
  109. } else {
  110. this.disableFaceRecognition()
  111. }
  112. },
  113. // 关闭人脸识别模态框
  114. closeFaceModal() {
  115. this.setData({
  116. showFaceModal: false,
  117. 'userInfo.faceRegistered': false
  118. })
  119. },
  120. // 确认人脸识别
  121. confirmFaceRecognition() {
  122. // 模拟人脸识别过程
  123. wx.showLoading({
  124. title: '识别中...',
  125. })
  126. setTimeout(() => {
  127. wx.hideLoading()
  128. this.setData({
  129. showFaceModal: false,
  130. 'userInfo.faceRegistered': true
  131. })
  132. wx.showToast({
  133. title: '人脸识别成功',
  134. icon: 'success'
  135. })
  136. }, 3000)
  137. },
  138. // 禁用人脸识别
  139. disableFaceRecognition() {
  140. this.setData({
  141. 'userInfo.faceRegistered': false
  142. })
  143. wx.showToast({
  144. title: '已关闭人脸识别',
  145. icon: 'success'
  146. })
  147. },
  148. // 切换病历共享
  149. toggleMedicalRecords(e) {
  150. const enabled = e.detail.value
  151. this.setData({
  152. 'userInfo.medicalRecordsShared': enabled
  153. })
  154. if (enabled) {
  155. wx.showModal({
  156. title: '病历共享授权',
  157. content: '您确认要授权医院查看您的病历信息吗?',
  158. success: (res) => {
  159. if (!res.confirm) {
  160. this.setData({
  161. 'userInfo.medicalRecordsShared': false
  162. })
  163. }
  164. }
  165. })
  166. } else {
  167. wx.showToast({
  168. title: '已关闭病历共享',
  169. icon: 'success'
  170. })
  171. }
  172. },
  173. // 查看病历记录
  174. viewMedicalRecords() {
  175. wx.navigateTo({
  176. url: '/pages/medical-records/medical-records'
  177. })
  178. },
  179. // 查看订单
  180. viewOrders(e) {
  181. const status = e.currentTarget.dataset.status
  182. let tabStatus = 'all'
  183. if (status === '配送中') {
  184. tabStatus = 'delivering'
  185. } else if (status === '已完成') {
  186. tabStatus = 'completed'
  187. }
  188. wx.navigateTo({
  189. url: `/pages/order-list/order-list?status=${tabStatus}`
  190. })
  191. },
  192. // 查看订单详情
  193. viewOrderDetail(e) {
  194. const order = e.currentTarget.dataset.order
  195. wx.navigateTo({
  196. url: `/pages/order-detail/order-detail?id=${order.id}`
  197. })
  198. },
  199. // 查看病历详情
  200. viewMedicalRecordDetail(e) {
  201. const record = e.currentTarget.dataset.record
  202. wx.navigateTo({
  203. url: `/pages/medical-record-detail/medical-record-detail?id=${record.id}`
  204. })
  205. },
  206. // 导航到设置页面
  207. navigateToSetting(e) {
  208. const type = e.currentTarget.dataset.type
  209. const titles = {
  210. 'privacy': '隐私设置',
  211. 'about': '关于我们',
  212. 'help': '帮助中心'
  213. }
  214. wx.showModal({
  215. title: titles[type],
  216. content: `这里将显示${titles[type]}的相关内容`,
  217. showCancel: false
  218. })
  219. },
  220. // 联系客服
  221. contactSupport() {
  222. wx.showModal({
  223. title: '联系客服',
  224. content: '客服电话:400-123-4567\n工作时间:9:00-18:00',
  225. showCancel: false
  226. })
  227. },
  228. // 退出登录
  229. logout() {
  230. wx.showModal({
  231. title: '确认退出',
  232. content: '您确定要退出登录吗?',
  233. success: (res) => {
  234. if (res.confirm) {
  235. // 模拟退出登录
  236. wx.showToast({
  237. title: '已退出登录',
  238. icon: 'success',
  239. success: () => {
  240. setTimeout(() => {
  241. // 这里可以跳转到登录页面或重新加载用户数据
  242. this.loadUserData()
  243. }, 1500)
  244. }
  245. })
  246. }
  247. }
  248. })
  249. }
  250. })