完善店务员工工时与订单记录
This commit is contained in:
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user