重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
const scheduleApi = require('../../api/artist-schedule')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
const format = require('../../utils/format')
|
||||
const { markDirty } = require('../../utils/page-state')
|
||||
|
||||
function todayText(offset) {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + (offset || 0))
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${month}-${day}`
|
||||
}
|
||||
|
||||
function safeList(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
list: [],
|
||||
startDate: todayText(0),
|
||||
endDate: todayText(6),
|
||||
artistId: '',
|
||||
canEdit: false,
|
||||
form: {
|
||||
artistId: '',
|
||||
workDate: todayText(0),
|
||||
startTime: '10:00',
|
||||
endTime: '18:00',
|
||||
slotMinutes: '60',
|
||||
capacity: '1',
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入排班管理')) {
|
||||
return
|
||||
}
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canEdit: permission.hasPermission(permissionCodes, 'schedule:edit')
|
||||
})
|
||||
this.loadSchedules()
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.loadSchedules().finally(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
|
||||
buildQuery() {
|
||||
const query = {}
|
||||
;['artistId', 'startDate', 'endDate'].forEach(key => {
|
||||
const value = String(this.data[key] || '').trim()
|
||||
if (value) {
|
||||
query[key] = value
|
||||
}
|
||||
})
|
||||
return query
|
||||
},
|
||||
|
||||
async loadSchedules() {
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const list = await scheduleApi.listSchedules(this.buildQuery())
|
||||
this.setData({
|
||||
list: safeList(list).map(item => this.formatSchedule(item))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '排班加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
formatSchedule(item) {
|
||||
const startTime = String(item.startTime || '').slice(0, 5)
|
||||
const endTime = String(item.endTime || '').slice(0, 5)
|
||||
return {
|
||||
...item,
|
||||
displayDate: format.formatDate(item.workDate),
|
||||
displayTime: `${startTime || '--'} - ${endTime || '--'}`,
|
||||
statusText: Number(item.status) === 0 ? '停用' : '可预约'
|
||||
}
|
||||
},
|
||||
|
||||
handleArtistInput(event) {
|
||||
this.setData({ artistId: event.detail.value })
|
||||
},
|
||||
|
||||
handleStartDateChange(event) {
|
||||
this.setData({ startDate: event.detail.value })
|
||||
this.loadSchedules()
|
||||
},
|
||||
|
||||
handleEndDateChange(event) {
|
||||
this.setData({ endDate: event.detail.value })
|
||||
this.loadSchedules()
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadSchedules()
|
||||
},
|
||||
|
||||
handleFormInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
if (!field) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleFormDateChange(event) {
|
||||
this.setData({
|
||||
'form.workDate': event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleFormStartTimeChange(event) {
|
||||
this.setData({
|
||||
'form.startTime': event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleFormEndTimeChange(event) {
|
||||
this.setData({
|
||||
'form.endTime': event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
async handleSaveSchedule() {
|
||||
if (!this.data.canEdit) {
|
||||
wx.showToast({
|
||||
title: '当前账号没有编辑排班权限',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const form = this.data.form
|
||||
const artistId = String(form.artistId || '').trim()
|
||||
if (!artistId) {
|
||||
wx.showToast({
|
||||
title: '请填写美甲师 ID',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await scheduleApi.saveSchedule({
|
||||
artistId,
|
||||
workDate: form.workDate,
|
||||
startTime: form.startTime,
|
||||
endTime: form.endTime,
|
||||
slotMinutes: Number(form.slotMinutes) || 60,
|
||||
capacity: Number(form.capacity) || 1,
|
||||
status: 1,
|
||||
remark: String(form.remark || '').trim()
|
||||
})
|
||||
markDirty('admin-workbench')
|
||||
wx.showToast({
|
||||
title: '排班已保存',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadSchedules()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '排班保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/manage/index')
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
|
||||
},
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<navigation-bar title="排班管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">Schedule</text>
|
||||
<text class="hero-title">门店排班</text>
|
||||
<text class="hero-desc">按日期和美甲师查看可约班次,支持店长和管理员快速补录当天班次。</text>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">筛选</text>
|
||||
<input class="field-input compact-field" placeholder="美甲师 ID,可留空" placeholder-class="placeholder" value="{{artistId}}" bindinput="handleArtistInput" confirm-type="search" bindconfirm="handleSearch"></input>
|
||||
<view class="filter-row">
|
||||
<picker mode="date" value="{{startDate}}" bindchange="handleStartDateChange">
|
||||
<view class="field-picker">{{startDate || '开始日期'}}</view>
|
||||
</picker>
|
||||
<picker mode="date" value="{{endDate}}" bindchange="handleEndDateChange">
|
||||
<view class="field-picker">{{endDate || '结束日期'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<button class="secondary-btn compact-btn" loading="{{loading}}" bindtap="handleSearch">查询排班</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{canEdit}}" class="surface-card">
|
||||
<text class="section-title">快速补班</text>
|
||||
<view class="form-grid">
|
||||
<input class="field-input" placeholder="美甲师 ID" placeholder-class="placeholder" value="{{form.artistId}}" data-field="artistId" bindinput="handleFormInput"></input>
|
||||
<picker mode="date" value="{{form.workDate}}" bindchange="handleFormDateChange">
|
||||
<view class="field-picker">{{form.workDate}}</view>
|
||||
</picker>
|
||||
<picker mode="time" value="{{form.startTime}}" bindchange="handleFormStartTimeChange">
|
||||
<view class="field-picker">{{form.startTime}}</view>
|
||||
</picker>
|
||||
<picker mode="time" value="{{form.endTime}}" bindchange="handleFormEndTimeChange">
|
||||
<view class="field-picker">{{form.endTime}}</view>
|
||||
</picker>
|
||||
<input class="field-input" type="number" placeholder="时段分钟" placeholder-class="placeholder" value="{{form.slotMinutes}}" data-field="slotMinutes" bindinput="handleFormInput"></input>
|
||||
<input class="field-input" type="number" placeholder="容量" placeholder-class="placeholder" value="{{form.capacity}}" data-field="capacity" bindinput="handleFormInput"></input>
|
||||
</view>
|
||||
<textarea class="field-textarea compact-textarea" placeholder="备注,可留空" placeholder-class="placeholder" value="{{form.remark}}" data-field="remark" bindinput="handleFormInput"></textarea>
|
||||
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveSchedule">保存排班</button>
|
||||
</view>
|
||||
|
||||
<block wx:for="{{list}}" wx:key="id">
|
||||
<view class="list-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.displayDate}} · 美甲师 {{item.artistId}}</text>
|
||||
<text class="list-subtitle">{{item.displayTime}} · {{item.slotMinutes || 60}} 分钟/档 · 容量 {{item.capacity || 1}}</text>
|
||||
</view>
|
||||
<text class="{{item.status === 0 ? 'soft-badge' : 'success-badge'}}">{{item.statusText}}</text>
|
||||
</view>
|
||||
<view wx:if="{{item.remark}}" class="hint-card">{{item.remark}}</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{!list.length && !loading}}" class="empty-state">
|
||||
<text class="empty-title">暂无排班</text>
|
||||
<text class="empty-desc">当前日期范围没有可展示班次。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,27 @@
|
||||
@import "../../app.wxss";
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.compact-field,
|
||||
.compact-btn,
|
||||
.compact-textarea {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.filter-row picker,
|
||||
.form-grid picker {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 14rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.compact-textarea {
|
||||
min-height: 140rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user