tmp
This commit is contained in:
+102
-28
@@ -4,16 +4,39 @@ const API = require('../../utils/api.js')
|
||||
Page({
|
||||
data: {
|
||||
today: '',
|
||||
todayCount: 0,
|
||||
pendingCount: 0,
|
||||
completedCount: 0,
|
||||
menuList: [
|
||||
{ icon: '/images/icon_order.png', name: '订单管理', url: '/pages/order/index' },
|
||||
{ icon: '/images/icon_patient.png', name: '患者管理', url: '/pages/patient/index' },
|
||||
{ icon: '/images/icon_escort.png', name: '陪诊员管理', url: '/pages/escort/index' },
|
||||
{ icon: '/images/icon_schedule.png', name: '排班管理', url: '/pages/schedule/index' }
|
||||
recentOrders: [],
|
||||
// 快捷入口:前3个为快捷操作(橙色系),后4个为功能入口(绿色系)
|
||||
quickEntries: [
|
||||
{ icon: 'add-circle', name: '增加预约', url: '/pages/order/orderEdit', color: '#ff8f4d' },
|
||||
{ icon: 'file-add', name: '增加档案', url: '/pages/healthprofile/profileInfo', color: '#ff8f4d' },
|
||||
{ icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#ff8f4d' },
|
||||
{ icon: 'bill', name: '预约订单', url: '/pages/order/index', color: '#1abc9c' },
|
||||
{ icon: 'heart', name: '健康档案', url: '/pages/healthprofile/index', color: '#1abc9c' },
|
||||
{ icon: 'user', name: '注册用户', url: '/pages/customer/index', color: '#1abc9c' },
|
||||
{ icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#1abc9c' }
|
||||
],
|
||||
todayOrders: [],
|
||||
online: true,
|
||||
profile: {
|
||||
name: '王姐陪诊师',
|
||||
level: '初级陪诊师',
|
||||
avatar: ''
|
||||
},
|
||||
todayIncome: 168,
|
||||
todayOrderCount: 0,
|
||||
pendingOrder: {
|
||||
count: 1,
|
||||
hospital: '中医院',
|
||||
time: '10:00',
|
||||
price: 88
|
||||
},
|
||||
ongoingOrder: {
|
||||
count: 1,
|
||||
hospital: '康复医院',
|
||||
time: '15:30',
|
||||
price: 128
|
||||
},
|
||||
statusMap: {
|
||||
pending: '待确认',
|
||||
confirmed: '已确认',
|
||||
@@ -37,56 +60,107 @@ Page({
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.loadUser()
|
||||
const now = new Date();
|
||||
const today = now.toISOString().substring(0, 10);
|
||||
this.setData({ today });
|
||||
this.getTodayOrders();
|
||||
this.getRecentOrders();
|
||||
this.getStats();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.getTodayOrders();
|
||||
this.loadUser()
|
||||
this.getRecentOrders();
|
||||
this.getStats();
|
||||
},
|
||||
|
||||
loadUser() {
|
||||
const app = getApp()
|
||||
const user = app.globalData && app.globalData.user
|
||||
if (user) {
|
||||
this.setData({
|
||||
'profile.name': user.nickname || this.data.profile.name,
|
||||
'profile.level': user.level || this.data.profile.level,
|
||||
'profile.avatar': user.avatar || ''
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
toggleOnline() {
|
||||
this.setData({
|
||||
online: !this.data.online
|
||||
})
|
||||
},
|
||||
|
||||
onOrderCardTap(e) {
|
||||
const { type } = e.currentTarget.dataset
|
||||
const title = type === 'pending' ? '待接单' : '进行中'
|
||||
wx.showToast({
|
||||
title: `${title} 订单列表`,
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
|
||||
async getStats() {
|
||||
const today = new Date().toISOString().substring(0, 10);
|
||||
const [todayRes, pendingRes, completedRes] = await Promise.all([
|
||||
API.escort.getMyRecords({ appointmentDate: today }),
|
||||
API.escort.getMyRecords({ status: ['pending', 'confirmed'] }),
|
||||
API.escort.getMyRecords({ status: ['completed'] })
|
||||
API.escort.getAllRecords({ appointmentDate: today }),
|
||||
API.escort.getAllRecords({ status: 'pending,confirmed' }),
|
||||
API.escort.getAllRecords({ status: 'completed' })
|
||||
]);
|
||||
this.setData({
|
||||
todayCount: todayRes.code === 0 ? (todayRes.data.records || []).length : 0,
|
||||
todayOrderCount: todayRes.code === 0 ? (todayRes.data.records || []).length : 0,
|
||||
pendingCount: pendingRes.code === 0 ? (pendingRes.data.records || []).length : 0,
|
||||
completedCount: completedRes.code === 0 ? (completedRes.data.records || []).length : 0,
|
||||
});
|
||||
},
|
||||
|
||||
async getTodayOrders() {
|
||||
const res = await API.escort.getMyRecords({
|
||||
appointmentDate: new Date().toISOString().substring(0, 10),
|
||||
});
|
||||
if (res.code == 0) {
|
||||
const records = (res.data.records || []).map(item => {
|
||||
if (item.schedule && item.schedule.date) {
|
||||
const d = new Date(item.schedule.date);
|
||||
item.schedule.date = d.toISOString().substring(0, 10) + ' ' + d.toTimeString().substring(0, 5);
|
||||
}
|
||||
/**
|
||||
* 加载近7日订单(含6天前至今及未来订单,按预约时间倒序,最多10条)
|
||||
*/
|
||||
async getRecentOrders() {
|
||||
const res = await API.escort.getAllRecords({ page: 1, pageSize: 50 });
|
||||
if (res.code !== 0) return;
|
||||
|
||||
const start = new Date();
|
||||
start.setDate(start.getDate() - 6);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
const records = (res.data.records || [])
|
||||
.filter(item => item.schedule && item.schedule.date && new Date(item.schedule.date) >= start)
|
||||
.slice(0, 10)
|
||||
.map(item => {
|
||||
const d = new Date(item.schedule.date);
|
||||
item.schedule.date = `${d.getMonth() + 1}月${d.getDate()}日 ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
return item;
|
||||
});
|
||||
this.setData({ todayOrders: records });
|
||||
}
|
||||
this.setData({ recentOrders: records });
|
||||
},
|
||||
|
||||
navigateTo(e) {
|
||||
const url = e.currentTarget.dataset.url
|
||||
wx.navigateTo({ url })
|
||||
onEntryTap(e) {
|
||||
const { index } = e.currentTarget.dataset
|
||||
const item = this.data.quickEntries[index]
|
||||
if (item.isTab) {
|
||||
wx.switchTab({ url: item.url })
|
||||
} else {
|
||||
wx.navigateTo({ url: item.url })
|
||||
}
|
||||
},
|
||||
|
||||
viewAllOrders() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/order/index'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击近7日订单卡片,进入订单详情
|
||||
*/
|
||||
onOrderTap(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
if (!id) return
|
||||
wx.navigateTo({
|
||||
url: `/pages/order/orderDetail?id=${id}`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user