在小程序我的页面增加店铺今日概览

This commit is contained in:
2026-09-04 15:50:55 +08:00
parent 89c9deeeb2
commit 4209ee732c
3 changed files with 186 additions and 0 deletions
+65
View File
@@ -2,6 +2,10 @@ const { BRAND_CONFIG } = require('../../utils/config')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
const planningApi = require('../../api/planning')
const employeesApi = require('../../api/employees')
const shopApi = require('../../api/shop')
const dateUtil = require('../../utils/date')
function resolveRoleText(type) {
const role = Number(type)
@@ -27,6 +31,17 @@ Page({
wechatId: '',
signature: ''
},
overviewLoading: false,
overview: {
date: '',
todayAppointments: 0,
pendingAppointments: 0,
upcomingAppointments: 0,
availableEmployees: 0,
scheduleExceptions: 0,
shopOpen: true,
shopStatus: '营业中'
},
menus: [
{ title: '个人信息', action: 'editProfile' },
{ title: '店铺设置', url: '/pages/shop-settings/index' },
@@ -39,6 +54,56 @@ Page({
onShow() {
this.refreshFromSession()
this.loadProfile()
this.loadOverview()
},
async loadOverview() {
const today = dateUtil.formatDate(new Date())
this.setData({ overviewLoading: true })
try {
const [calendar, shop] = await Promise.all([
planningApi.calendar({ startDate: today, endDate: today }),
shopApi.settings()
])
const appointments = Array.isArray(calendar.appointments) ? calendar.appointments : []
const now = Date.now()
const upcomingAppointments = appointments.filter(item => {
const appointmentTime = new Date(String(item.appointmentTime || item.startTime || '').replace(/-/g, '/')).getTime()
return Number.isFinite(appointmentTime) && appointmentTime >= now
}).length
const artists = Array.isArray(calendar.artists) ? calendar.artists : []
const scheduleRules = await Promise.all(artists.map(artist => employeesApi.scheduleRule({ artistId: artist.id })))
const scheduleExceptions = scheduleRules.reduce((total, setting) => {
const exceptions = Array.isArray(setting && setting.exceptions) ? setting.exceptions : []
return total + exceptions.filter(item => item.workDate === today).length
}, 0)
const shopOpen = Number(shop && shop.status) !== 0
this.setData({
overview: {
date: `${today.slice(5, 7)}月${today.slice(8, 10)}日`,
todayAppointments: appointments.length,
pendingAppointments: appointments.filter(item => Number(item.status) === 0).length,
upcomingAppointments,
availableEmployees: artists.filter(item => Number(item.status) !== 0).length,
scheduleExceptions,
shopOpen,
shopStatus: shopOpen ? '营业中' : '已暂停'
}
})
} catch (error) {
wx.showToast({ title: error.message || '今日概览加载失败', icon: 'none' })
} finally {
this.setData({ overviewLoading: false })
}
},
goOverviewAction(event) {
const action = event.currentTarget.dataset.action
if (action === 'scheduleExceptions') {
wx.navigateTo({ url: '/pages/leave-management/index' })
return
}
wx.switchTab({ url: '/pages/planning/index' })
},
refreshFromSession() {