功能:重建指尖管理师规划系统
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const productsApi = require('../../api/products')
|
||||
const mock = require('../../utils/mock')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
customerName: '',
|
||||
phone: '',
|
||||
appointmentDate: dateUtil.formatDate(new Date()),
|
||||
appointmentTime: '13:00',
|
||||
productId: '',
|
||||
durationMinutes: '',
|
||||
artistId: '',
|
||||
remark: ''
|
||||
},
|
||||
products: [],
|
||||
artists: mock.artists,
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free',
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
'form.appointmentDate': options.date || dateUtil.formatDate(new Date()),
|
||||
'form.artistId': options.artistId || ''
|
||||
})
|
||||
this.loadOptions()
|
||||
},
|
||||
|
||||
async loadOptions() {
|
||||
const fallbackProducts = [
|
||||
{ id: 1, title: '纯色美甲', approximateDuration: '90分钟' },
|
||||
{ id: 2, title: '猫眼延长', approximateDuration: '120分钟' },
|
||||
{ id: 3, title: '手部护理', approximateDuration: '60分钟' }
|
||||
]
|
||||
try {
|
||||
const productsData = await productsApi.list({ page: 1, size: 100 })
|
||||
const products = productsData.list || productsData || fallbackProducts
|
||||
this.setData({ products })
|
||||
} catch (error) {
|
||||
this.setData({ products: fallbackProducts })
|
||||
}
|
||||
if (this.data.form.artistId) {
|
||||
const selectedArtist = this.data.artists.find(item => String(item.id) === String(this.data.form.artistId)) || {}
|
||||
this.setData({ selectedArtist })
|
||||
}
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
this.setData({
|
||||
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
onDateChange(event) {
|
||||
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
onTimeChange(event) {
|
||||
this.setData({ 'form.appointmentTime': event.detail.value })
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
onProductChange(event) {
|
||||
const selectedProduct = this.data.products[Number(event.detail.value)] || {}
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
'form.productId': selectedProduct.id,
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || 60)
|
||||
})
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
onArtistChange(event) {
|
||||
const selectedArtist = this.data.artists[Number(event.detail.value)] || {}
|
||||
this.setData({
|
||||
selectedArtist,
|
||||
'form.artistId': selectedArtist.id
|
||||
})
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
async checkAvailability() {
|
||||
const form = this.data.form
|
||||
if (!form.appointmentDate || !form.appointmentTime || !form.artistId) {
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
const durationMinutes = Number(form.durationMinutes || 0) || 60
|
||||
const startMinute = dateUtil.minutesOfDay(form.appointmentTime)
|
||||
const endMinute = startMinute + durationMinutes
|
||||
if (startMinute < dateUtil.minutesOfDay('10:00') || endMinute > dateUtil.minutesOfDay('22:00')) {
|
||||
const tip = '该时间超出营业时间 10:00-22:00'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
try {
|
||||
let calendar
|
||||
try {
|
||||
calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
endDate: form.appointmentDate,
|
||||
artistId: form.artistId
|
||||
})
|
||||
} catch (error) {
|
||||
calendar = mock.buildCalendar(form.appointmentDate)
|
||||
}
|
||||
const conflicts = (calendar.appointments || []).filter(item => {
|
||||
if (String(item.artistId) !== String(form.artistId) || item.date !== form.appointmentDate) return false
|
||||
if (item.status === 3 || item.statusText === '已取消') return false
|
||||
const itemStart = Number(item.startMinute || dateUtil.minutesOfDay((item.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(item.durationMinutes || 60)
|
||||
return startMinute < itemEnd && endMinute > itemStart
|
||||
})
|
||||
if (conflicts.length > 0) {
|
||||
const first = conflicts[0]
|
||||
const itemStart = Number(first.startMinute || dateUtil.minutesOfDay((first.startTime || '').slice(11, 16)))
|
||||
const itemEnd = itemStart + Number(first.durationMinutes || 60)
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${dateUtil.timeFromMinutes(itemStart)}-${dateUtil.timeFromMinutes(itemEnd)} 已有预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${form.appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
} catch (error) {
|
||||
const tip = '暂未获取到排班,请保存时以系统校验为准'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'warn' })
|
||||
return { ok: true, tip }
|
||||
}
|
||||
},
|
||||
|
||||
async submit() {
|
||||
const form = this.data.form
|
||||
if (!form.customerName || !form.phone || !form.productId || !form.artistId) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const availability = await this.checkAvailability()
|
||||
if (!availability.ok) {
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const result = await planningApi.createAppointment({
|
||||
...form,
|
||||
productId: Number(form.productId),
|
||||
artistId: Number(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined
|
||||
})
|
||||
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "新建预约"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card">
|
||||
<view class="field">
|
||||
<text class="field-label">客户姓名</text>
|
||||
<input value="{{form.customerName}}" data-field="customerName" bindinput="onInput" placeholder="请输入客户姓名" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" placeholder="请输入手机号" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">预约日期</text>
|
||||
<picker mode="date" value="{{form.appointmentDate}}" bindchange="onDateChange">
|
||||
<view class="field-value">{{form.appointmentDate}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">预约时间</text>
|
||||
<picker mode="time" value="{{form.appointmentTime}}" start="10:00" end="22:00" bindchange="onTimeChange">
|
||||
<view class="field-value">{{form.appointmentTime}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">项目内容</text>
|
||||
<picker range="{{products}}" range-key="title" bindchange="onProductChange">
|
||||
<view class="field-value">{{selectedProduct.title || '请选择项目'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">预计时长</text>
|
||||
<input value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" type="number" placeholder="默认读取项目时长" />
|
||||
<text class="unit">分钟</text>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">指定员工</text>
|
||||
<picker range="{{artists}}" range-key="name" bindchange="onArtistChange">
|
||||
<view class="field-value">{{selectedArtist.name || '请选择美甲师'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field textarea-field">
|
||||
<text class="field-label">备注</text>
|
||||
<textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="客户偏好、款式说明" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="capacity-tip card">
|
||||
<text class="tip-title">容量校验</text>
|
||||
<text class="tip-text">保存时会校验营业时间、美甲师休息和同时间段容量,冲突会直接拦截。</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{conflictTip}}" class="availability-tip card {{conflictLevel}}">
|
||||
<text class="tip-title">时段检查</text>
|
||||
<text class="tip-text">{{conflictTip}}</text>
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<button class="primary-btn" loading="{{loading}}" bindtap="submit">保存预约</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,60 @@
|
||||
.unit {
|
||||
color: #9a9288;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.textarea-field {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.capacity-tip {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
margin-top: 20rpx;
|
||||
padding: 22rpx;
|
||||
}
|
||||
|
||||
.tip-title {
|
||||
color: #4e4942;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
color: #90877e;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.availability-tip {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
margin-top: 16rpx;
|
||||
padding: 22rpx;
|
||||
}
|
||||
|
||||
.availability-tip.free {
|
||||
background: #f3faf5;
|
||||
}
|
||||
|
||||
.availability-tip.warn {
|
||||
background: #fff8e8;
|
||||
}
|
||||
|
||||
.availability-tip.danger {
|
||||
background: #fff2f2;
|
||||
}
|
||||
|
||||
.availability-tip.free .tip-title {
|
||||
color: #4f7d62;
|
||||
}
|
||||
|
||||
.availability-tip.warn .tip-title {
|
||||
color: #a2763d;
|
||||
}
|
||||
|
||||
.availability-tip.danger .tip-title {
|
||||
color: #c36a6a;
|
||||
}
|
||||
Reference in New Issue
Block a user