profile.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. const app = getApp()
  183. const orders = app.getOrdersByStatus(status)
  184. if (orders.length === 0) {
  185. wx.showToast({
  186. title: `暂无${status}订单`,
  187. icon: 'none'
  188. })
  189. return
  190. }
  191. // 构建订单列表内容
  192. let content = `${status}订单列表:\n\n`
  193. orders.forEach((order, index) => {
  194. content += `${index + 1}. ${order.hospital}\n`
  195. content += ` 药品:${order.medicines.join('、')}\n`
  196. content += ` 价格:¥${order.totalPrice}\n`
  197. content += ` 状态:${order.status}\n`
  198. content += ` 日期:${order.date}\n\n`
  199. })
  200. wx.showModal({
  201. title: '订单列表',
  202. content: content,
  203. showCancel: false
  204. })
  205. },
  206. // 查看订单详情
  207. viewOrderDetail(e) {
  208. const order = e.currentTarget.dataset.order
  209. wx.navigateTo({
  210. url: `/pages/order-detail/order-detail?id=${order.id}`
  211. })
  212. },
  213. // 查看病历详情
  214. viewMedicalRecordDetail(e) {
  215. const record = e.currentTarget.dataset.record
  216. wx.navigateTo({
  217. url: `/pages/medical-record-detail/medical-record-detail?id=${record.id}`
  218. })
  219. },
  220. // 导航到设置页面
  221. navigateToSetting(e) {
  222. const type = e.currentTarget.dataset.type
  223. const titles = {
  224. 'privacy': '隐私设置',
  225. 'about': '关于我们',
  226. 'help': '帮助中心'
  227. }
  228. wx.showModal({
  229. title: titles[type],
  230. content: `这里将显示${titles[type]}的相关内容`,
  231. showCancel: false
  232. })
  233. },
  234. // 联系客服
  235. contactSupport() {
  236. wx.showModal({
  237. title: '联系客服',
  238. content: '客服电话:400-123-4567\n工作时间:9:00-18:00',
  239. showCancel: false
  240. })
  241. },
  242. // 退出登录
  243. logout() {
  244. wx.showModal({
  245. title: '确认退出',
  246. content: '您确定要退出登录吗?',
  247. success: (res) => {
  248. if (res.confirm) {
  249. // 模拟退出登录
  250. wx.showToast({
  251. title: '已退出登录',
  252. icon: 'success',
  253. success: () => {
  254. setTimeout(() => {
  255. // 这里可以跳转到登录页面或重新加载用户数据
  256. this.loadUserData()
  257. }, 1500)
  258. }
  259. })
  260. }
  261. }
  262. })
  263. }
  264. })