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

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() {
+35
View File
@@ -10,6 +10,41 @@
<text class="role-badge">{{roleText}}</text>
</view>
<view class="card overview-card">
<view class="overview-head">
<text class="overview-title">店铺今日概览</text>
<text class="overview-date">{{overview.date}}</text>
</view>
<view wx:if="{{overviewLoading}}" class="overview-loading">正在加载今日数据...</view>
<view wx:else class="overview-grid">
<view class="overview-item" data-action="todayAppointments" bindtap="goOverviewAction">
<text class="overview-value">{{overview.todayAppointments}}</text>
<text class="overview-label">今日预约</text>
</view>
<view class="overview-item overview-item--warning" data-action="pendingAppointments" bindtap="goOverviewAction">
<text class="overview-value">{{overview.pendingAppointments}}</text>
<text class="overview-label">待确认预约</text>
</view>
<view class="overview-item" data-action="upcomingAppointments" bindtap="goOverviewAction">
<text class="overview-value">{{overview.upcomingAppointments}}</text>
<text class="overview-label">即将开始</text>
</view>
<view class="overview-item">
<text class="overview-value">{{overview.availableEmployees}}</text>
<text class="overview-label">今日可预约员工</text>
</view>
<view class="overview-item overview-item--warning" data-action="scheduleExceptions" bindtap="goOverviewAction">
<text class="overview-value">{{overview.scheduleExceptions}}</text>
<text class="overview-label">请假/调班待处理</text>
</view>
<view class="overview-item overview-item--status">
<view class="status-dot {{overview.shopOpen ? 'is-open' : 'is-closed'}}"></view>
<text class="overview-status">{{overview.shopStatus}}</text>
<text class="overview-label">店铺当前状态</text>
</view>
</view>
</view>
<view class="section menu-list card">
<view wx:for="{{menus}}" wx:key="title" class="menu-row" data-url="{{item.url}}" data-action="{{item.action}}" bindtap="go">
<text>{{item.title}}</text>
+86
View File
@@ -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;
}