完善店务预约状态与详情流程
This commit is contained in:
@@ -7,6 +7,7 @@ const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
const { chooseImageFilePaths, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
|
||||
|
||||
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
|
||||
const PLANNING_RETURN_TARGET_STORAGE_KEY = 'planningReturnTarget'
|
||||
const TIME_SLOT_MINUTES = 15
|
||||
const DAY_MINUTES = 24 * 60
|
||||
const DAY_END_COVER_MINUTE = 23 * 60 + 59
|
||||
@@ -146,6 +147,41 @@ function removeDraftForm() {
|
||||
}
|
||||
}
|
||||
|
||||
function writePlanningReturnTarget(target) {
|
||||
try {
|
||||
wx.setStorageSync(PLANNING_RETURN_TARGET_STORAGE_KEY, target)
|
||||
} catch (error) {
|
||||
throw new Error(`写入规划页返回目标失败:${error.message || error}`)
|
||||
}
|
||||
}
|
||||
|
||||
function confirmAppointmentSubmit() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title: '确认提交预约',
|
||||
content: '提交成功后将返回规划月视图。',
|
||||
confirmText: '提交',
|
||||
cancelText: '再检查',
|
||||
success: result => resolve(!!result.confirm),
|
||||
fail: error => reject(new Error(`打开预约确认弹窗失败:${error.errMsg || error.message || error}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function confirmFormAction(title, content, confirmText, confirmColor) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
title,
|
||||
content,
|
||||
cancelText: '取消',
|
||||
confirmText,
|
||||
confirmColor,
|
||||
success: result => resolve(!!result.confirm),
|
||||
fail: error => reject(new Error(`打开确认弹窗失败:${error.errMsg || error.message || error}`))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeDuration(value) {
|
||||
const duration = Number(value)
|
||||
return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0
|
||||
@@ -440,12 +476,16 @@ function normalizeProduct(product, artists) {
|
||||
.map(id => findArtist(artists, id).name)
|
||||
.filter(Boolean)
|
||||
const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '')
|
||||
const productPrice = formatProductPrice(product.price)
|
||||
const productPriceText = productPrice === '0'
|
||||
? '未定'
|
||||
: productPrice ? `¥${productPrice}` : '价格待定'
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
tagList: parseProductTags(product).slice(0, 4),
|
||||
artistText: artistNames.length > 0 ? artistNames.join('、') : '全部美甲师',
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
priceText: productPriceText,
|
||||
durationText
|
||||
}
|
||||
}
|
||||
@@ -553,8 +593,11 @@ function normalizeConfirmedPrice(value) {
|
||||
return String(price)
|
||||
}
|
||||
|
||||
function collectManualProductImages(fileIds, imageUrls) {
|
||||
return splitManualImageValues(`${fileIds || ''},${imageUrls || ''}`)
|
||||
function resolveAppointmentPriceText(form) {
|
||||
if (form.manualProductPriceUndetermined) {
|
||||
return '0'
|
||||
}
|
||||
return normalizeConfirmedPrice(form.manualProductPrice)
|
||||
}
|
||||
|
||||
function normalizeCustomer(customer) {
|
||||
@@ -606,6 +649,7 @@ Page({
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductPrice: '',
|
||||
manualProductPriceUndetermined: false,
|
||||
manualProductDescription: '',
|
||||
manualProductTags: '',
|
||||
manualProductPrecautions: '',
|
||||
@@ -740,6 +784,9 @@ Page({
|
||||
const patch = {
|
||||
[`form.${field}`]: value
|
||||
}
|
||||
if (field === 'manualProductPrice' && value) {
|
||||
patch['form.manualProductPriceUndetermined'] = false
|
||||
}
|
||||
if (field === 'customerName' || field === 'phone') {
|
||||
patch['form.customerUserId'] = ''
|
||||
patch.customerDropdownVisible = true
|
||||
@@ -762,6 +809,17 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onPriceUndeterminedChange(event) {
|
||||
const checked = !!event.detail.value
|
||||
const patch = {
|
||||
'form.manualProductPriceUndetermined': checked
|
||||
}
|
||||
if (checked) {
|
||||
patch['form.manualProductPrice'] = ''
|
||||
}
|
||||
this.setData(patch)
|
||||
},
|
||||
|
||||
onCustomerFocus(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -919,13 +977,15 @@ Page({
|
||||
selectProduct(event) {
|
||||
const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {}
|
||||
const price = formatProductPrice(selectedProduct.price)
|
||||
const priceUndetermined = price === '' || price === '0'
|
||||
const productTag = resolveTagValue(this.data.tagOptions, parseProductTags(selectedProduct).join(','))
|
||||
const imageUrls = Array.isArray(selectedProduct.imageUrls) ? selectedProduct.imageUrls : []
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': selectedProduct.title || '',
|
||||
'form.manualProductPrice': price,
|
||||
'form.manualProductPrice': priceUndetermined ? '' : price,
|
||||
'form.manualProductPriceUndetermined': priceUndetermined,
|
||||
'form.manualProductDescription': selectedProduct.description || '',
|
||||
'form.manualProductTags': productTag,
|
||||
'form.manualProductPrecautions': selectedProduct.precautions || '',
|
||||
@@ -953,8 +1013,8 @@ Page({
|
||||
|
||||
useManualProduct() {
|
||||
const title = String(this.data.form.manualProductTitle || '').trim()
|
||||
const priceText = normalizeConfirmedPrice(this.data.form.manualProductPrice)
|
||||
const imageValues = collectManualProductImages(this.data.form.manualProductImageFileIds, this.data.form.manualProductImageUrl)
|
||||
const priceUndetermined = !!this.data.form.manualProductPriceUndetermined
|
||||
const priceText = resolveAppointmentPriceText(this.data.form)
|
||||
if (!title) {
|
||||
wx.showToast({ title: '请填写作品名称', icon: 'none' })
|
||||
return
|
||||
@@ -963,15 +1023,11 @@ Page({
|
||||
wx.showToast({ title: '请填写正确的作品价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (imageValues.length === 0) {
|
||||
wx.showToast({ title: '请上传作品图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedProduct: {},
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': title,
|
||||
'form.manualProductPrice': priceText,
|
||||
'form.manualProductPrice': priceUndetermined ? '' : priceText,
|
||||
manualProductPanelVisible: false
|
||||
})
|
||||
this.closeProductModal()
|
||||
@@ -1225,7 +1281,7 @@ Page({
|
||||
return
|
||||
}
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim()
|
||||
const customerName = String(form.customerName || '').trim()
|
||||
const phone = String(form.phone || '').trim()
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
@@ -1233,17 +1289,12 @@ Page({
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const appointmentPriceText = normalizeConfirmedPrice(form.manualProductPrice)
|
||||
const appointmentPriceText = resolveAppointmentPriceText(form)
|
||||
if (!appointmentPriceText) {
|
||||
wx.showToast({ title: '请填写本次价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const appointmentPrice = Number(appointmentPriceText)
|
||||
const manualProductImages = collectManualProductImages(form.manualProductImageFileIds, form.manualProductImageUrl)
|
||||
if (!form.productId && manualProductImages.length === 0) {
|
||||
wx.showToast({ title: '请上传作品图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!durationMinutes) {
|
||||
wx.showToast({ title: '请填写预约时长', icon: 'none' })
|
||||
return
|
||||
@@ -1253,6 +1304,16 @@ Page({
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
let confirmed
|
||||
try {
|
||||
confirmed = await confirmAppointmentSubmit()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '确认提交失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const payload = {
|
||||
@@ -1267,6 +1328,7 @@ Page({
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
delete payload.manualProductPriceUndetermined
|
||||
if (form.productId) {
|
||||
payload.productId = String(form.productId)
|
||||
payload.manualProductTitle = undefined
|
||||
@@ -1282,8 +1344,16 @@ Page({
|
||||
}
|
||||
const result = await planningApi.createAppointment(payload)
|
||||
removeDraftForm()
|
||||
writePlanningReturnTarget({
|
||||
source: 'appointment-create',
|
||||
date: form.appointmentDate,
|
||||
orderItemId: result.orderItemId || result.id || ''
|
||||
})
|
||||
markPlanningRefresh()
|
||||
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||
wx.switchTab({
|
||||
url: '/pages/planning/index',
|
||||
fail: error => wx.showToast({ title: `跳转规划页失败:${error.errMsg || error.message || error}`, icon: 'none' })
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -1301,7 +1371,17 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
clearDraft() {
|
||||
async clearDraft() {
|
||||
let confirmed
|
||||
try {
|
||||
confirmed = await confirmFormAction('清空草稿', '确认清空当前本机预约草稿?', '清空', '#d98d8d')
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '确认清空失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
removeDraftForm()
|
||||
this.setData({ draftSavedAtText: '' })
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
<text class="field-label required">客户姓名</text>
|
||||
<input value="{{form.customerName}}" data-field="customerName" bindinput="onInput" bindfocus="onCustomerFocus" bindblur="hideCustomerDropdown" placeholder="搜索或输入客户姓名" focus="{{customerNameFocused}}" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" bindfocus="onCustomerFocus" bindblur="hideCustomerDropdown" placeholder="可选,填写后匹配客户" />
|
||||
</view>
|
||||
<view wx:if="{{customerDropdownVisible}}" class="customer-dropdown">
|
||||
<view wx:if="{{customerLoading}}" class="customer-option muted-option">正在搜索客户...</view>
|
||||
<view wx:elif="{{customerError}}" class="customer-option muted-option">{{customerError}},可继续手动输入</view>
|
||||
@@ -36,10 +32,18 @@
|
||||
<text>{{form.customerName ? (form.manualProductTitle || selectedProduct.title || '请选择作品') : '请先填写客户姓名'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{form.productId || form.manualProductTitle}}" class="field">
|
||||
<text class="field-label required">本次价格</text>
|
||||
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" type="digit" placeholder="可按本次预约修改" />
|
||||
<text class="unit">元</text>
|
||||
<view wx:if="{{form.productId || form.manualProductTitle}}" class="field price-field">
|
||||
<text class="field-label">本次价格</text>
|
||||
<view class="price-control">
|
||||
<view class="price-input {{form.manualProductPriceUndetermined ? 'disabled' : ''}}">
|
||||
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" disabled="{{form.manualProductPriceUndetermined}}" type="digit" placeholder="{{form.manualProductPriceUndetermined ? '未定' : '可按本次预约修改'}}" />
|
||||
<text>{{form.manualProductPriceUndetermined ? '未定' : '元'}}</text>
|
||||
</view>
|
||||
<view class="price-toggle">
|
||||
<text>价格未定</text>
|
||||
<switch checked="{{form.manualProductPriceUndetermined}}" color="#6f8f83" bindchange="onPriceUndeterminedChange" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预计时长</text>
|
||||
@@ -110,16 +114,20 @@
|
||||
<input value="{{form.manualProductTitle}}" data-field="manualProductTitle" bindinput="onInput" placeholder="作品名称" />
|
||||
</view>
|
||||
<view class="manual-field manual-price-field">
|
||||
<text class="manual-field-label required-label">价格</text>
|
||||
<view class="manual-price-input">
|
||||
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" type="digit" placeholder="价格" />
|
||||
<text>元</text>
|
||||
<text class="manual-field-label">价格</text>
|
||||
<view class="manual-price-input {{form.manualProductPriceUndetermined ? 'disabled' : ''}}">
|
||||
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" disabled="{{form.manualProductPriceUndetermined}}" type="digit" placeholder="{{form.manualProductPriceUndetermined ? '未定' : '价格'}}" />
|
||||
<text>{{form.manualProductPriceUndetermined ? '未定' : '元'}}</text>
|
||||
</view>
|
||||
<view class="manual-price-toggle">
|
||||
<text>价格未定</text>
|
||||
<switch checked="{{form.manualProductPriceUndetermined}}" color="#6f8f83" bindchange="onPriceUndeterminedChange" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="manual-image-section">
|
||||
<view class="manual-image-head">
|
||||
<text class="manual-image-title required-label">作品图片</text>
|
||||
<text class="manual-image-title">作品图片</text>
|
||||
</view>
|
||||
<view class="manual-image-list">
|
||||
<view wx:for="{{manualProductImageUrls}}" wx:for-item="imageUrl" wx:key="*this" class="manual-image-item">
|
||||
@@ -155,10 +163,8 @@
|
||||
<view wx:if="{{productModalVisible}}" class="modal-mask template-mask" catchtap="stopTap">
|
||||
<view class="product-modal template-modal" catchtap="stopTap">
|
||||
<view class="modal-head">
|
||||
<view>
|
||||
<text class="modal-title">使用已有作品模板</text>
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeProductModal">×</view>
|
||||
<view><text class="modal-title">选择已有作品</text></view>
|
||||
</view>
|
||||
<input class="product-search" value="{{productKeyword}}" bindinput="onProductSearch" placeholder="搜索作品、标签、美甲师" />
|
||||
<scroll-view class="product-list" scroll-y>
|
||||
|
||||
@@ -35,6 +35,67 @@
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.price-field {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.price-control {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.price-input,
|
||||
.manual-price-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 72rpx;
|
||||
padding-right: 16rpx;
|
||||
border: 1rpx solid #eadfd2;
|
||||
border-radius: 18rpx;
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
.price-input.disabled,
|
||||
.manual-price-input.disabled {
|
||||
background: #f5f0ea;
|
||||
color: #9a9288;
|
||||
}
|
||||
|
||||
.form-card .price-input input {
|
||||
min-height: 70rpx;
|
||||
padding: 0 18rpx;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.price-input text,
|
||||
.manual-price-input text {
|
||||
flex: 0 0 auto;
|
||||
color: #9a9288;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.price-toggle,
|
||||
.manual-price-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8rpx;
|
||||
color: #6d6258;
|
||||
font-size: 24rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.price-toggle switch,
|
||||
.manual-price-toggle switch {
|
||||
transform: scale(0.72);
|
||||
transform-origin: right center;
|
||||
}
|
||||
|
||||
.customer-select {
|
||||
position: relative;
|
||||
}
|
||||
@@ -45,7 +106,7 @@
|
||||
|
||||
.customer-dropdown {
|
||||
position: absolute;
|
||||
top: 214rpx;
|
||||
top: 102rpx;
|
||||
right: 0;
|
||||
left: 180rpx;
|
||||
z-index: 30;
|
||||
@@ -927,7 +988,7 @@
|
||||
|
||||
.manual-field-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 200rpx;
|
||||
grid-template-columns: minmax(0, 1fr) 248rpx;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
@@ -958,27 +1019,13 @@
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.manual-price-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 70rpx;
|
||||
padding-right: 16rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #fffaf4;
|
||||
}
|
||||
|
||||
.manual-price-input input {
|
||||
flex: 1;
|
||||
width: auto;
|
||||
min-width: 0;
|
||||
padding-right: 8rpx;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.manual-price-input text {
|
||||
flex: 0 0 auto;
|
||||
color: #9a9288;
|
||||
font-size: 22rpx;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.manual-field picker {
|
||||
|
||||
Reference in New Issue
Block a user