profile.js 6.3 KB

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