优化店务小程序规划视图与表单加载

This commit is contained in:
2026-07-23 15:57:39 +08:00
parent 7d6929bcf6
commit 3d10affea3
8 changed files with 273 additions and 78 deletions
+86 -23
View File
@@ -773,6 +773,8 @@ Page({
customerError: '',
products: [],
filteredProducts: [],
productsLoaded: false,
productsLoading: false,
artists: [],
selectedProduct: {},
selectedArtist: {},
@@ -784,6 +786,8 @@ Page({
productKeyword: '',
productError: '',
tagOptions: [],
tagsLoaded: false,
tagsLoading: false,
tagPickerIndex: 0,
tagError: '',
conflictTip: '',
@@ -818,7 +822,6 @@ Page({
return
}
this.loadOptions()
this.searchCustomers()
wx.nextTick(() => {
this.setData({ customerNameFocused: true })
})
@@ -841,34 +844,71 @@ Page({
async loadOptions() {
this.showPageMask('正在加载预约信息')
try {
try {
const productsData = await productsApi.list({ page: 1, size: 100 })
const products = productsData.list || productsData || []
this.setData({ products, productError: '' })
} catch (error) {
this.setData({
products: [],
filteredProducts: [],
productError: error.message || '作品列表加载失败'
})
}
await this.loadTags()
await this.loadArtists()
this.refreshProductCards()
await this.refreshAvailableTimes()
this.refreshAvailableTimes()
await this.checkAvailability(this.data.form.appointmentTime)
} finally {
this.hidePageMask()
}
},
ensureProductsLoaded() {
if (this.data.productsLoaded) {
return Promise.resolve()
}
if (this._productsLoadingPromise) {
return this._productsLoadingPromise
}
this._productsLoadingPromise = this.loadProducts().finally(() => {
this._productsLoadingPromise = null
})
return this._productsLoadingPromise
},
async loadProducts() {
this.setData({ productsLoading: true })
try {
const productsData = await productsApi.list({ page: 1, size: 100 })
const products = productsData.list || productsData || []
this.setData({
products,
productsLoaded: true,
productError: ''
})
} catch (error) {
this.setData({
products: [],
filteredProducts: [],
productsLoaded: false,
productError: error.message || '作品列表加载失败'
})
} finally {
this.setData({ productsLoading: false })
}
},
ensureTagsLoaded() {
if (this.data.tagsLoaded) {
return Promise.resolve()
}
if (this._tagsLoadingPromise) {
return this._tagsLoadingPromise
}
this._tagsLoadingPromise = this.loadTags().finally(() => {
this._tagsLoadingPromise = null
})
return this._tagsLoadingPromise
},
async loadTags() {
this.setData({ tagsLoading: true })
try {
const tagsData = await tagsApi.listAll()
const tagOptions = normalizeTagOptions(tagsData.list || tagsData || [])
const selectedTag = resolveTagValue(tagOptions, this.data.form.manualProductTags)
this.setData({
tagOptions,
tagsLoaded: true,
tagPickerIndex: resolveTagPickerIndex(tagOptions, selectedTag),
'form.manualProductTags': selectedTag,
tagError: ''
@@ -876,9 +916,12 @@ Page({
} catch (error) {
this.setData({
tagOptions: [],
tagsLoaded: false,
tagPickerIndex: 0,
tagError: error.message || '标签加载失败'
})
} finally {
this.setData({ tagsLoading: false })
}
},
@@ -968,6 +1011,14 @@ Page({
const form = this.data.form
const sourceValue = preferredField === 'phone' ? form.phone : form.customerName || form.phone
const keyword = String(sourceValue || '').trim()
if (!keyword) {
this.setData({
customerOptions: [],
customerError: '',
customerLoading: false
})
return
}
this.setData({ customerLoading: true })
try {
const data = await customersApi.list({ keyword, page: 1, size: 20 })
@@ -1047,15 +1098,21 @@ Page({
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
return
}
this.openManualProductPanel()
void this.openManualProductPanel()
},
openProductTemplateSheet() {
this.setData({ productKeyword: '' })
this.refreshProductCards()
this.setData({
productModalVisible: true
})
async openProductTemplateSheet() {
this.showPageMask('正在加载作品库')
try {
await Promise.all([this.ensureProductsLoaded(), this.ensureTagsLoaded()])
this.setData({ productKeyword: '' })
this.refreshProductCards()
this.setData({
productModalVisible: true
})
} finally {
this.hidePageMask()
}
},
closeProductModal() {
@@ -1064,12 +1121,18 @@ Page({
})
},
openManualProductPanel() {
async openManualProductPanel() {
const customerName = String(this.data.form.customerName || '').trim()
if (!customerName) {
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
return
}
this.showPageMask('正在加载作品设置')
try {
await this.ensureTagsLoaded()
} finally {
this.hidePageMask()
}
const imageUrls = this.data.manualProductImageUrls.length > 0
? this.data.manualProductImageUrls
: splitManualImageValues(this.data.form.manualProductImageUrl)
@@ -84,21 +84,23 @@
}
.price-field {
align-items: flex-start;
align-items: center;
}
.price-control {
display: flex;
min-width: 0;
flex: 1;
flex-direction: column;
gap: 12rpx;
align-items: center;
gap: 10rpx;
}
.price-input,
.manual-price-input {
display: flex;
align-items: center;
flex: 1 1 0;
min-width: 0;
min-height: 72rpx;
padding-right: 16rpx;
border: 1rpx solid #eadfd2;
@@ -113,6 +115,8 @@
}
.form-card .price-input input {
min-width: 0;
flex: 1;
min-height: 70rpx;
padding: 0 18rpx;
border: 0;
@@ -138,12 +142,23 @@
font-weight: 800;
}
.price-toggle {
flex: 0 0 auto;
gap: 4rpx;
font-size: 22rpx;
white-space: nowrap;
}
.price-toggle switch,
.manual-price-toggle switch {
transform: scale(0.72);
transform-origin: right center;
}
.price-toggle switch {
transform: scale(0.68);
}
.customer-select {
position: relative;
}
+54 -5
View File
@@ -266,6 +266,9 @@ Page({
pendingCount: 0,
canCreateAppointment: true,
loading: false,
loadingText: '',
pageMaskVisible: false,
pageMaskText: '',
calendarError: '',
emptyDateActionVisible: false,
pendingEmptyDate: '',
@@ -287,6 +290,7 @@ Page({
onShow() {
const app = getApp()
this.hidePageMask()
try {
const returnTarget = readPlanningReturnTarget()
if (returnTarget) {
@@ -413,6 +417,20 @@ Page({
stopTap() {},
showPageMask(text) {
this.setData({
pageMaskVisible: true,
pageMaskText: text
})
},
hidePageMask() {
this.setData({
pageMaskVisible: false,
pageMaskText: ''
})
},
selectEmptyDateSpecialType(event) {
const value = String(event.currentTarget.dataset.value || 'REST')
const option = resolveSpecialDateType(value)
@@ -469,7 +487,10 @@ Page({
const range = this.resolveRange()
const requestSeq = (this._calendarRequestSeq || 0) + 1
this._calendarRequestSeq = requestSeq
this.setData({ loading: true })
this.setData({
loading: true,
loadingText: '正在加载规划'
})
try {
const data = await planningApi.calendar({
startDate: range.start,
@@ -498,7 +519,10 @@ Page({
})
} finally {
if (requestSeq === this._calendarRequestSeq) {
this.setData({ loading: false })
this.setData({
loading: false,
loadingText: ''
})
}
}
},
@@ -610,6 +634,7 @@ Page({
: this.normalizeArtistCounts(summary.artistCounts || artistTemplate)
return {
...day,
isToday: day.date === todayText,
isPast: day.date < todayText,
totalCount: summary.totalCount || 0,
dayStatus: summary.dayStatus || 'free',
@@ -823,16 +848,27 @@ Page({
},
createAppointment() {
if (this.data.loading || this.data.pageMaskVisible) {
return
}
if (!this.data.canCreateAppointment) {
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
return
}
this.showPageMask('正在打开预约表单')
wx.navigateTo({
url: buildAppointmentFormUrl(this.data.currentDateText, this.data.selectedArtistId)
url: buildAppointmentFormUrl(this.data.currentDateText, this.data.selectedArtistId),
fail: error => {
this.hidePageMask()
wx.showToast({ title: `打开预约表单失败:${error.errMsg || error.message || error}`, icon: 'none' })
}
})
},
createAppointmentFromEmptyDate() {
if (this.data.loading || this.data.pageMaskVisible) {
return
}
if (!this.data.pendingEmptyDate) {
wx.showToast({ title: '请选择预约日期', icon: 'none' })
return
@@ -842,8 +878,13 @@ Page({
return
}
this.setData({ emptyDateActionVisible: false })
this.showPageMask('正在打开预约表单')
wx.navigateTo({
url: buildAppointmentFormUrl(this.data.pendingEmptyDate, this.data.selectedArtistId)
url: buildAppointmentFormUrl(this.data.pendingEmptyDate, this.data.selectedArtistId),
fail: error => {
this.hidePageMask()
wx.showToast({ title: `打开预约表单失败:${error.errMsg || error.message || error}`, icon: 'none' })
}
})
},
@@ -893,13 +934,21 @@ Page({
},
openAppointment(event) {
if (this.data.loading || this.data.pageMaskVisible) {
return
}
const id = resolveAppointmentEventId(event)
if (!id) {
wx.showToast({ title: '缺少预约详情ID', icon: 'none' })
return
}
this.showPageMask('正在打开预约详情')
wx.navigateTo({
url: `/pages/appointment-detail/index?id=${encodeURIComponent(id)}`
url: `/pages/appointment-detail/index?id=${encodeURIComponent(id)}`,
fail: error => {
this.hidePageMask()
wx.showToast({ title: `打开预约详情失败:${error.errMsg || error.message || error}`, icon: 'none' })
}
})
}
})
+7 -5
View File
@@ -84,10 +84,6 @@
<view wx:for="{{weekDays}}" wx:key="date" class="week-day-card card {{item.date === currentDateText ? 'active' : ''}} {{item.statusClass}}" data-date="{{item.date}}" bindtap="selectDate">
<text class="week-name">{{item.weekName}}</text>
<text class="week-date">{{item.day}}</text>
<text class="week-total">{{item.totalCount}}单</text>
<view class="week-bars {{item.totalCount === 0 ? 'empty' : ''}}">
<view wx:for="{{item.artistCounts}}" wx:for-item="count" wx:key="key" class="week-bar {{count.statusClass}}" style="background: {{count.color}}; width: {{count.width}}%;"></view>
</view>
</view>
</scroll-view>
<view class="card week-grid">
@@ -122,7 +118,7 @@
<text wx:for="{{weekLabels}}" wx:key="*this">{{item}}</text>
</view>
<view class="month-grid">
<view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.date === currentDateText ? 'selected' : ''}} {{emptyDateActionVisible && item.date === pendingEmptyDate ? 'action-target' : ''}} {{!item.isPast && item.shopRest ? 'is-rest' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
<view wx:for="{{monthDays}}" wx:key="date" class="month-cell {{item.isCurrentMonth ? '' : 'out-month'}} {{item.isToday ? 'today' : ''}} {{item.date === currentDateText ? 'selected' : ''}} {{emptyDateActionVisible && item.date === pendingEmptyDate ? 'action-target' : ''}} {{!item.isPast && item.shopRest ? 'is-rest' : ''}}" data-date="{{item.date}}" bindtap="selectDate">
<view class="month-cell-head">
<text class="month-day">{{item.day}}</text>
<text wx:if="{{!item.isPast && item.shopRest}}" class="day-mark rest">休</text>
@@ -199,4 +195,10 @@
</view>
</view>
</view>
<view wx:if="{{loading || pageMaskVisible}}" class="planning-loading-mask" catchtap="stopTap">
<view class="planning-loading-card" catchtap="stopTap">
<view class="planning-loading-spinner"></view>
<text>{{pageMaskText || loadingText || '正在加载规划'}}</text>
</view>
</view>
</view>
+79 -34
View File
@@ -423,58 +423,49 @@
.week-day-card {
position: relative;
display: inline-flex;
align-items: flex-start;
justify-content: center;
flex-direction: column;
box-sizing: border-box;
width: 148rpx;
min-height: 164rpx;
height: 142rpx;
min-height: 142rpx;
max-height: 142rpx;
margin-right: 12rpx;
padding: 16rpx;
}
.week-day-card.is-completed {
background: #f5fff7;
border-color: #c8ead1;
background: #fffdf8;
border-color: #eee8df;
}
.week-day-card.is-cancelled {
background: #fff5f6;
border-color: #e8c7cc;
background: #fffdf8;
border-color: #eee8df;
}
.week-day-card.is-completed::after,
.week-day-card.is-cancelled::after {
content: none;
}
.week-day-card.active {
outline: 3rpx solid #8fb89a;
}
.week-name,
.week-total {
.week-name {
color: #8f877e;
font-size: 22rpx;
}
.week-date {
margin: 8rpx 0;
margin-top: 10rpx;
color: #211e1a;
font-size: 38rpx;
font-weight: 800;
}
.week-bars {
display: flex;
flex-direction: column;
gap: 6rpx;
margin-top: 12rpx;
min-height: 22rpx;
}
.week-bars.empty {
min-height: 22rpx;
}
.week-bar {
position: relative;
height: 8rpx;
border-radius: 999rpx;
}
.week-grid {
margin-top: 18rpx;
padding: 20rpx;
@@ -528,8 +519,6 @@
font-weight: 700;
}
.week-bar.is-completed::after,
.week-bar.is-cancelled::after,
.week-count-bar.is-completed::after,
.week-count-bar.is-cancelled::after,
.month-order-block.is-completed::after,
@@ -548,8 +537,6 @@
pointer-events: none;
}
.week-bar.is-completed::before,
.week-bar.is-cancelled::before,
.week-count-bar.is-completed::before,
.week-count-bar.is-cancelled::before,
.month-order-block.is-completed::before,
@@ -568,14 +555,12 @@
pointer-events: none;
}
.week-bar.is-completed::before,
.week-count-bar.is-completed::before,
.month-order-block.is-completed::before,
.month-row-block.is-completed::before {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 100 100'%3E%3Cline x1='0' y1='0' x2='100' y2='100' stroke='%2345825b' stroke-opacity='.9' stroke-width='2' stroke-linecap='square' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
}
.week-bar.is-cancelled::before,
.week-count-bar.is-cancelled::before,
.month-order-block.is-cancelled::before,
.month-row-block.is-cancelled::before {
@@ -587,9 +572,9 @@
}
.month-toolbar {
display: flex;
display: grid;
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: center;
justify-content: space-between;
gap: 8rpx;
margin-bottom: 14rpx;
padding: 0 4rpx;
@@ -603,6 +588,7 @@
.month-mode-switch {
display: inline-flex;
justify-self: center;
gap: 6rpx;
padding: 6rpx;
border-radius: 999rpx;
@@ -633,6 +619,7 @@
.row-name-switch {
display: inline-flex;
align-items: center;
justify-self: end;
gap: 8rpx;
height: 44rpx;
padding: 0 10rpx;
@@ -728,6 +715,15 @@
background: #fff8f6;
}
.month-cell.today {
background: #fff3dc;
box-shadow: inset 0 0 0 3rpx #e1b76a;
}
.month-cell.today.selected {
background: #ffefd2;
}
.month-cell-head {
display: flex;
align-items: center;
@@ -1094,6 +1090,46 @@
line-height: 88rpx;
}
.planning-loading-mask {
position: fixed;
inset: 0;
z-index: 140;
display: flex;
align-items: center;
justify-content: center;
padding: 40rpx;
background: rgba(36, 30, 24, 0.34);
animation: pageFadeIn 160ms ease both;
}
.planning-loading-card {
display: flex;
min-width: 248rpx;
min-height: 168rpx;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 22rpx;
padding: 32rpx 36rpx;
border: 1rpx solid rgba(255, 255, 255, 0.78);
border-radius: 20rpx;
background: rgba(255, 253, 248, 0.96);
color: #3d352f;
font-size: 26rpx;
font-weight: 900;
box-shadow: 0 24rpx 54rpx rgba(41, 31, 23, 0.2);
animation: emptyDateSheetIn 180ms ease both;
}
.planning-loading-spinner {
width: 54rpx;
height: 54rpx;
border: 6rpx solid #dfe8e2;
border-top-color: #6f8f83;
border-radius: 50%;
animation: planningSpinnerRotate 0.78s linear infinite;
}
@keyframes pageFadeIn {
from {
opacity: 0;
@@ -1115,3 +1151,12 @@
transform: translateY(0);
}
}
@keyframes planningSpinnerRotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}