tmp
This commit is contained in:
+39
-17
@@ -4,18 +4,20 @@ const API = require('../../utils/api.js')
|
||||
Page({
|
||||
data: {
|
||||
today: '',
|
||||
greeting: '',
|
||||
todayText: '',
|
||||
pendingCount: 0,
|
||||
completedCount: 0,
|
||||
recentOrders: [],
|
||||
// 快捷入口:前3个为快捷操作(橙色系),后4个为功能入口(绿色系)
|
||||
// 快捷入口:type=quick 为快捷操作(橙色系),type=function 为功能入口(绿色系),分行显示
|
||||
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' }
|
||||
{ type: 'quick', icon: 'add-circle', name: '增加预约', url: '/pages/order/orderEdit', color: '#ff8f4d' },
|
||||
{ type: 'quick', icon: 'file-add', name: '增加档案', url: '/pages/healthprofile/profileInfo', color: '#ff8f4d' },
|
||||
{ type: 'quick', icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#ff8f4d' },
|
||||
{ type: 'function', icon: 'bill', name: '预约订单', url: '/pages/order/index', color: '#1abc9c' },
|
||||
{ type: 'function', icon: 'heart', name: '健康档案', url: '/pages/healthprofile/index', color: '#1abc9c' },
|
||||
{ type: 'function', icon: 'user', name: '注册用户', url: '/pages/customer/index', color: '#1abc9c' },
|
||||
{ type: 'function', icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#1abc9c' }
|
||||
],
|
||||
online: true,
|
||||
profile: {
|
||||
@@ -23,7 +25,7 @@ Page({
|
||||
level: '初级陪诊师',
|
||||
avatar: ''
|
||||
},
|
||||
todayIncome: 168,
|
||||
todayIncome: 0,
|
||||
todayOrderCount: 0,
|
||||
pendingOrder: {
|
||||
count: 1,
|
||||
@@ -63,7 +65,10 @@ Page({
|
||||
this.loadUser()
|
||||
const now = new Date();
|
||||
const today = now.toISOString().substring(0, 10);
|
||||
this.setData({ today });
|
||||
const hour = now.getHours();
|
||||
const greeting = hour < 6 ? '夜深了' : hour < 9 ? '早上好' : hour < 12 ? '上午好' : hour < 14 ? '中午好' : hour < 18 ? '下午好' : '晚上好';
|
||||
const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][now.getDay()];
|
||||
this.setData({ today, greeting, todayText: `${now.getMonth() + 1}月${now.getDate()}日 ${week}` });
|
||||
this.getRecentOrders();
|
||||
this.getStats();
|
||||
},
|
||||
@@ -104,16 +109,33 @@ Page({
|
||||
},
|
||||
|
||||
async getStats() {
|
||||
const today = new Date().toISOString().substring(0, 10);
|
||||
const [todayRes, pendingRes, completedRes] = await Promise.all([
|
||||
API.escort.getAllRecords({ appointmentDate: today }),
|
||||
API.escort.getAllRecords({ status: 'pending,confirmed' }),
|
||||
const now = new Date();
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
// 本地日期(toISOString 是 UTC,早晨会差一天)
|
||||
const todayStr = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
||||
const isSameDay = (d, ref) =>
|
||||
d.getFullYear() === ref.getFullYear() && d.getMonth() === ref.getMonth() && d.getDate() === ref.getDate();
|
||||
const feeOf = (item) => Number(item.payment && item.payment.totalFee) || 0;
|
||||
|
||||
const [todayRes, completedRes] = await Promise.all([
|
||||
API.escort.getAllRecords({ appointmentDate: todayStr }),
|
||||
API.escort.getAllRecords({ status: 'completed' })
|
||||
]);
|
||||
|
||||
// 今日收益:当日已完成订单的费用合计
|
||||
let todayIncome = 0;
|
||||
if (completedRes.code === 0) {
|
||||
(completedRes.data.records || []).forEach(item => {
|
||||
const d = item.schedule && item.schedule.date ? new Date(item.schedule.date) : null;
|
||||
if (d && !isNaN(d.getTime()) && isSameDay(d, now)) {
|
||||
todayIncome += feeOf(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.setData({
|
||||
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,
|
||||
todayIncome,
|
||||
todayOrderCount: todayRes.code === 0 ? (todayRes.data.records || []).length : 0
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user