完善店务员工工时与订单记录

This commit is contained in:
2026-07-24 14:23:13 +08:00
parent 3a543f1d69
commit eff4e73427
20 changed files with 440 additions and 225 deletions
@@ -1,11 +1,99 @@
const employeesApi = require('../../api/employees')
const dateUtil = require('../../utils/date')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
function formatExceptionSummary(item) {
const date = String(item.workDate || '').slice(0, 10)
const remark = String(item.remark || '').trim()
return {
id: item.id || `${date}-${remark || 'leave'}`,
date,
text: remark || '全天请假'
}
}
Page({
data: {
days: Array.from({ length: 31 }).map((_, index) => ({ day: index + 1, rest: [12, 25].includes(index + 1) })),
records: [
{ date: '2026-06-12', text: '全天请假' },
{ date: '2026-06-25', text: '下午请假' }
]
artistId: '',
records: [],
leaveForm: {
workDate: dateUtil.formatDate(new Date()),
remark: ''
},
loading: false,
saving: false,
loadError: ''
},
add() { wx.showToast({ title: '请选择日期后保存', icon: 'none' }) },
back() { wx.navigateBack() }
onLoad(options) {
this.setData({ artistId: options.id || '' })
this.loadRecords()
},
async loadRecords() {
if (!this.data.artistId) {
this.setData({ records: [], loadError: '员工ID不能为空' })
return
}
this.setData({ loading: true, loadError: '' })
try {
const setting = await employeesApi.scheduleRule({ artistId: this.data.artistId })
const exceptions = Array.isArray(setting.exceptions) ? setting.exceptions : []
this.setData({
records: exceptions
.filter(item => item.exceptionType === 'REST')
.map(formatExceptionSummary)
})
} catch (error) {
this.setData({
records: [],
loadError: error.message || '工时记录加载失败'
})
} finally {
this.setData({ loading: false })
}
},
onLeaveDateChange(event) {
this.setData({ 'leaveForm.workDate': event.detail.value })
},
onLeaveRemarkInput(event) {
this.setData({ 'leaveForm.remark': event.detail.value })
},
async add() {
const form = this.data.leaveForm
if (!this.data.artistId) {
wx.showToast({ title: '员工ID不能为空', icon: 'none' })
return
}
if (!form.workDate) {
wx.showToast({ title: '请选择请假日期', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await employeesApi.saveScheduleException({
artistId: this.data.artistId,
workDate: form.workDate,
exceptionType: 'REST',
startTime: null,
endTime: null,
remark: String(form.remark || '').trim()
})
markPlanningRefresh()
wx.showToast({ title: '请假已新增', icon: 'success' })
this.setData({ 'leaveForm.remark': '' })
await this.loadRecords()
} catch (error) {
wx.showToast({ title: error.message || '新增请假失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
},
back() {
wx.navigateBack()
}
})
@@ -1,3 +1,3 @@
{
"navigationBarTitleText": "请假管理"
"navigationBarTitleText": "工时管理"
}
@@ -1,12 +1,31 @@
<view class="page no-tab">
<view class="card mini-calendar">
<view wx:for="{{days}}" wx:key="date" class="mini-day {{item.rest ? 'rest' : ''}}">{{item.day}}</view>
</view>
<view class="section">
<view class="section-title">请假记录</view>
<view class="list">
<view wx:for="{{records}}" wx:key="date" class="card list-card">{{item.date}} {{item.text}}</view>
<view class="card leave-form">
<view class="field">
<text class="field-label">请假日期</text>
<picker mode="date" value="{{leaveForm.workDate}}" bindchange="onLeaveDateChange">
<view class="field-value">{{leaveForm.workDate}}</view>
</picker>
</view>
<view class="field">
<text class="field-label">备注</text>
<input value="{{leaveForm.remark}}" bindinput="onLeaveRemarkInput" placeholder="可选,例如全天请假" />
</view>
</view>
<view class="fixed-bottom"><button class="primary-btn" bindtap="add">新增请假</button></view>
<view class="section">
<view class="section-title">工时记录</view>
<view class="list">
<view wx:if="{{loading}}" class="empty card">工时记录加载中...</view>
<view wx:elif="{{loadError}}" class="empty card error">
<text>{{loadError}}</text>
<button class="secondary-btn retry-btn" bindtap="loadRecords">重试</button>
</view>
<view wx:elif="{{records.length === 0}}" class="empty card">暂无请假记录</view>
<view wx:for="{{records}}" wx:key="id" class="card list-card leave-record">
<text class="leave-date">{{item.date}}</text>
<text class="leave-text">{{item.text}}</text>
</view>
</view>
</view>
<view class="fixed-bottom"><button class="primary-btn" loading="{{saving}}" bindtap="add">新增请假</button></view>
</view>
@@ -1,22 +1,49 @@
.mini-calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 10rpx;
padding: 18rpx;
.leave-form {
padding: 8rpx 24rpx;
}
.mini-day {
display: flex;
align-items: center;
justify-content: center;
height: 64rpx;
border-radius: 10rpx;
background: #f2ede7;
color: #5d564e;
.field input,
.field-value {
text-align: right;
}
.field-value {
min-height: 58rpx;
padding: 14rpx 20rpx;
border-radius: 999rpx;
background: #f4f0ea;
color: #4d473f;
font-size: 26rpx;
font-weight: 700;
}
.mini-day.rest {
background: #e7f0f6;
color: #6e9fbd;
.leave-record {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
}
.leave-date,
.leave-text {
display: block;
}
.leave-date {
color: #302c27;
font-size: 26rpx;
font-weight: 800;
}
.leave-text {
color: #7b7168;
text-align: right;
font-size: 24rpx;
}
.retry-btn {
width: 180rpx;
min-width: 180rpx;
max-width: 180rpx;
margin: 24rpx auto 0;
}