| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- // profile.js
- const mockData = require('../../utils/mockData.js')
- Page({
- data: {
- userInfo: mockData.userInfo,
- orderStats: {
- total: 0,
- delivering: 0,
- completed: 0
- },
- recentOrders: [],
- medicalStats: {
- total: 0,
- recent: 0
- },
- recentMedicalRecords: [],
- showFingerprintModal: false,
- showFaceModal: false
- },
- onLoad() {
- console.log('我的页面加载完成')
- this.loadUserData()
- },
- onShow() {
- // 每次页面显示时刷新数据
- this.loadUserData()
- },
- // 加载用户数据
- loadUserData() {
- // 从全局变量获取订单数据
- const app = getApp()
- const orders = app.getOrders()
-
- const orderStats = {
- total: orders.length,
- delivering: orders.filter(order => order.status === '配送中').length,
- completed: orders.filter(order => order.status === '已完成').length
- }
-
- const recentOrders = orders.slice(0, 3) // 显示最近3个订单
- // 加载病历记录
- const medicalRecords = app.getMedicalRecords()
- const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
- const recentMedicalRecords = medicalRecords.filter(item =>
- new Date(item.date) > thirtyDaysAgo
- ).slice(0, 3)
- const medicalStats = {
- total: medicalRecords.length,
- recent: recentMedicalRecords.length
- }
- this.setData({
- orderStats: orderStats,
- recentOrders: recentOrders,
- medicalStats: medicalStats,
- recentMedicalRecords: recentMedicalRecords
- })
- },
- // 切换指纹验证
- toggleFingerprint(e) {
- const enabled = e.detail.value
- if (enabled) {
- this.setData({
- showFingerprintModal: true
- })
- } else {
- this.disableFingerprint()
- }
- },
- // 关闭指纹验证模态框
- closeFingerprintModal() {
- this.setData({
- showFingerprintModal: false,
- 'userInfo.fingerprintRegistered': false
- })
- },
- // 确认指纹验证
- confirmFingerprint() {
- // 模拟指纹验证过程
- wx.showLoading({
- title: '验证中...',
- })
- setTimeout(() => {
- wx.hideLoading()
- this.setData({
- showFingerprintModal: false,
- 'userInfo.fingerprintRegistered': true
- })
-
- wx.showToast({
- title: '指纹验证成功',
- icon: 'success'
- })
- }, 2000)
- },
- // 禁用指纹验证
- disableFingerprint() {
- this.setData({
- 'userInfo.fingerprintRegistered': false
- })
- wx.showToast({
- title: '已关闭指纹验证',
- icon: 'success'
- })
- },
- // 切换人脸识别
- toggleFaceRecognition(e) {
- const enabled = e.detail.value
- if (enabled) {
- this.setData({
- showFaceModal: true
- })
- } else {
- this.disableFaceRecognition()
- }
- },
- // 关闭人脸识别模态框
- closeFaceModal() {
- this.setData({
- showFaceModal: false,
- 'userInfo.faceRegistered': false
- })
- },
- // 确认人脸识别
- confirmFaceRecognition() {
- // 模拟人脸识别过程
- wx.showLoading({
- title: '识别中...',
- })
- setTimeout(() => {
- wx.hideLoading()
- this.setData({
- showFaceModal: false,
- 'userInfo.faceRegistered': true
- })
-
- wx.showToast({
- title: '人脸识别成功',
- icon: 'success'
- })
- }, 3000)
- },
- // 禁用人脸识别
- disableFaceRecognition() {
- this.setData({
- 'userInfo.faceRegistered': false
- })
- wx.showToast({
- title: '已关闭人脸识别',
- icon: 'success'
- })
- },
- // 切换病历共享
- toggleMedicalRecords(e) {
- const enabled = e.detail.value
- this.setData({
- 'userInfo.medicalRecordsShared': enabled
- })
-
- if (enabled) {
- wx.showModal({
- title: '病历共享授权',
- content: '您确认要授权医院查看您的病历信息吗?',
- success: (res) => {
- if (!res.confirm) {
- this.setData({
- 'userInfo.medicalRecordsShared': false
- })
- }
- }
- })
- } else {
- wx.showToast({
- title: '已关闭病历共享',
- icon: 'success'
- })
- }
- },
- // 查看病历记录
- viewMedicalRecords() {
- wx.navigateTo({
- url: '/pages/medical-records/medical-records'
- })
- },
- // 查看订单
- viewOrders(e) {
- const status = e.currentTarget.dataset.status
- const app = getApp()
- const orders = app.getOrdersByStatus(status)
-
- if (orders.length === 0) {
- wx.showToast({
- title: `暂无${status}订单`,
- icon: 'none'
- })
- return
- }
- // 构建订单列表内容
- let content = `${status}订单列表:\n\n`
- orders.forEach((order, index) => {
- content += `${index + 1}. ${order.hospital}\n`
- content += ` 药品:${order.medicines.join('、')}\n`
- content += ` 价格:¥${order.totalPrice}\n`
- content += ` 状态:${order.status}\n`
- content += ` 日期:${order.date}\n\n`
- })
- wx.showModal({
- title: '订单列表',
- content: content,
- showCancel: false
- })
- },
- // 查看订单详情
- viewOrderDetail(e) {
- const order = e.currentTarget.dataset.order
- wx.navigateTo({
- url: `/pages/order-detail/order-detail?id=${order.id}`
- })
- },
- // 查看病历详情
- viewMedicalRecordDetail(e) {
- const record = e.currentTarget.dataset.record
- wx.navigateTo({
- url: `/pages/medical-record-detail/medical-record-detail?id=${record.id}`
- })
- },
- // 导航到设置页面
- navigateToSetting(e) {
- const type = e.currentTarget.dataset.type
- const titles = {
- 'privacy': '隐私设置',
- 'about': '关于我们',
- 'help': '帮助中心'
- }
-
- wx.showModal({
- title: titles[type],
- content: `这里将显示${titles[type]}的相关内容`,
- showCancel: false
- })
- },
- // 联系客服
- contactSupport() {
- wx.showModal({
- title: '联系客服',
- content: '客服电话:400-123-4567\n工作时间:9:00-18:00',
- showCancel: false
- })
- },
- // 退出登录
- logout() {
- wx.showModal({
- title: '确认退出',
- content: '您确定要退出登录吗?',
- success: (res) => {
- if (res.confirm) {
- // 模拟退出登录
- wx.showToast({
- title: '已退出登录',
- icon: 'success',
- success: () => {
- setTimeout(() => {
- // 这里可以跳转到登录页面或重新加载用户数据
- this.loadUserData()
- }, 1500)
- }
- })
- }
- }
- })
- }
- })
|