diff --git a/JC-Salon-WeChat/pages/profile/index.js b/JC-Salon-WeChat/pages/profile/index.js index bb0799ab..0f48b262 100644 --- a/JC-Salon-WeChat/pages/profile/index.js +++ b/JC-Salon-WeChat/pages/profile/index.js @@ -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() { diff --git a/JC-Salon-WeChat/pages/profile/index.wxml b/JC-Salon-WeChat/pages/profile/index.wxml index dca10981..37fda680 100644 --- a/JC-Salon-WeChat/pages/profile/index.wxml +++ b/JC-Salon-WeChat/pages/profile/index.wxml @@ -10,6 +10,41 @@ {{roleText}} + + + 店铺今日概览 + {{overview.date}} + + 正在加载今日数据... + + + {{overview.todayAppointments}} + 今日预约 + + + {{overview.pendingAppointments}} + 待确认预约 + + + {{overview.upcomingAppointments}} + 即将开始 + + + {{overview.availableEmployees}} + 今日可预约员工 + + + {{overview.scheduleExceptions}} + 请假/调班待处理 + + + + {{overview.shopStatus}} + 店铺当前状态 + + + + {{item.title}} diff --git a/JC-Salon-WeChat/pages/profile/index.wxss b/JC-Salon-WeChat/pages/profile/index.wxss index cef72e14..6572fc15 100644 --- a/JC-Salon-WeChat/pages/profile/index.wxss +++ b/JC-Salon-WeChat/pages/profile/index.wxss @@ -61,6 +61,92 @@ line-height: 1.2; } +.overview-card { + margin-top: 20rpx; + padding: 24rpx; +} + +.overview-head { + display: flex; + align-items: baseline; + justify-content: space-between; + margin-bottom: 20rpx; +} + +.overview-title { + color: #302c27; + font-size: 28rpx; + font-weight: 900; +} + +.overview-date, +.overview-loading { + color: #91897f; + font-size: 22rpx; +} + +.overview-loading { + padding: 28rpx 0; + text-align: center; +} + +.overview-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 12rpx; +} + +.overview-item { + display: flex; + min-height: 112rpx; + align-items: center; + justify-content: center; + flex-direction: column; + border-radius: 16rpx; + background: #f8f3ec; +} + +.overview-item--warning { + background: #fff3e7; +} + +.overview-item--status { + gap: 5rpx; +} + +.overview-value { + color: #2f6f62; + font-size: 38rpx; + font-weight: 900; + line-height: 1; +} + +.overview-label, +.overview-status { + margin-top: 10rpx; + color: #756b62; + font-size: 21rpx; + text-align: center; +} + +.overview-status { + margin-top: 0; + color: #2f6f62; + font-size: 27rpx; + font-weight: 800; +} + +.status-dot { + width: 18rpx; + height: 18rpx; + border-radius: 50%; + background: #c4bdb5; +} + +.status-dot.is-open { + background: #55a27f; +} + .menu-list { overflow: hidden; }