91 lines
2.6 KiB
JavaScript
91 lines
2.6 KiB
JavaScript
// pages/home/index.js
|
|
const API = require('../../utils/api.js')
|
|
|
|
Page({
|
|
data: {
|
|
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' },
|
|
{ icon: '/images/icon_stats.png', name: '数据统计', url: '/pages/stats/index' },
|
|
{ icon: '/images/icon_setting.png', name: '系统设置', url: '/pages/setting/index' }
|
|
],
|
|
todayOrders: [],
|
|
statusMap: {
|
|
pending: '待确认',
|
|
confirmed: '已确认',
|
|
in_progress: '进行中',
|
|
completed: '已完成',
|
|
cancelled: '已取消'
|
|
}
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
return {
|
|
title: '暖橙陪诊后台', // 转发标题
|
|
path: '/pages/home/index',
|
|
}
|
|
},
|
|
|
|
onShareTimeline: function () {
|
|
return {
|
|
title: '暖橙陪诊后台',
|
|
}
|
|
},
|
|
|
|
onLoad(options) {
|
|
this.getTodayOrders();
|
|
this.getStats();
|
|
},
|
|
|
|
onShow() {
|
|
this.getTodayOrders();
|
|
this.getStats();
|
|
},
|
|
|
|
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'] })
|
|
]);
|
|
this.setData({
|
|
todayCount: 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);
|
|
}
|
|
return item;
|
|
});
|
|
this.setData({ todayOrders: records });
|
|
}
|
|
},
|
|
|
|
navigateTo(e) {
|
|
const url = e.currentTarget.dataset.url
|
|
wx.navigateTo({ url })
|
|
},
|
|
|
|
viewAllOrders() {
|
|
wx.navigateTo({
|
|
url: '/pages/order/index'
|
|
})
|
|
}
|
|
})
|