优化管理师登录与预约客户选择
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const planningApi = require('../../api/planning')
|
||||
const productsApi = require('../../api/products')
|
||||
const customersApi = require('../../api/customers')
|
||||
const dateUtil = require('../../utils/date')
|
||||
|
||||
function buildClientRequestId(prefix) {
|
||||
@@ -65,9 +66,22 @@ function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
|
||||
return scheduleStartMinute <= startMinute && scheduleEndMinute >= endMinute
|
||||
}
|
||||
|
||||
function normalizeCustomer(customer) {
|
||||
const name = customer.nickname || customer.name || customer.account || ''
|
||||
const phone = customer.contactPhone || customer.phone || ''
|
||||
return {
|
||||
id: customer.id,
|
||||
name,
|
||||
phone,
|
||||
displayName: name || phone || '客户',
|
||||
displayPhone: phone || '未填写手机号'
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
form: {
|
||||
customerUserId: '',
|
||||
customerName: '',
|
||||
phone: '',
|
||||
appointmentDate: dateUtil.formatDate(new Date()),
|
||||
@@ -79,6 +93,10 @@ Page({
|
||||
artistId: '',
|
||||
remark: ''
|
||||
},
|
||||
customerOptions: [],
|
||||
customerDropdownVisible: false,
|
||||
customerLoading: false,
|
||||
customerError: '',
|
||||
products: [],
|
||||
filteredProducts: [],
|
||||
artists: [],
|
||||
@@ -107,6 +125,7 @@ Page({
|
||||
return
|
||||
}
|
||||
this.loadOptions()
|
||||
this.searchCustomers()
|
||||
},
|
||||
|
||||
async loadOptions() {
|
||||
@@ -148,11 +167,81 @@ Page({
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const patch = {
|
||||
[`form.${field}`]: event.detail.value
|
||||
}
|
||||
if (field === 'customerName' || field === 'phone') {
|
||||
patch['form.customerUserId'] = ''
|
||||
patch.customerDropdownVisible = true
|
||||
}
|
||||
this.setData(patch)
|
||||
if (field === 'customerName' || field === 'phone') {
|
||||
this.scheduleCustomerSearch(field)
|
||||
}
|
||||
},
|
||||
|
||||
onCustomerFocus(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({ customerDropdownVisible: true })
|
||||
this.searchCustomers(field)
|
||||
},
|
||||
|
||||
scheduleCustomerSearch(field) {
|
||||
clearTimeout(this._customerTimer)
|
||||
this._customerTimer = setTimeout(() => this.searchCustomers(field), 250)
|
||||
},
|
||||
|
||||
async searchCustomers(preferredField) {
|
||||
if (!this.data.canCreateAppointment) {
|
||||
return
|
||||
}
|
||||
const form = this.data.form
|
||||
const sourceValue = preferredField === 'phone' ? form.phone : form.customerName || form.phone
|
||||
const keyword = String(sourceValue || '').trim()
|
||||
this.setData({ customerLoading: true })
|
||||
try {
|
||||
const data = await customersApi.list({ keyword, page: 1, size: 20 })
|
||||
const list = data.list || data || []
|
||||
this.setData({
|
||||
customerOptions: list.map(normalizeCustomer),
|
||||
customerError: ''
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
customerOptions: [],
|
||||
customerError: error.message || '客户列表加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ customerLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
selectCustomer(event) {
|
||||
const customer = this.data.customerOptions.find(item => String(item.id) === String(event.currentTarget.dataset.id))
|
||||
if (!customer) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
|
||||
'form.customerUserId': customer.id,
|
||||
'form.customerName': customer.name,
|
||||
'form.phone': customer.phone,
|
||||
customerDropdownVisible: false
|
||||
})
|
||||
},
|
||||
|
||||
hideCustomerDropdown() {
|
||||
setTimeout(() => {
|
||||
this.setData({ customerDropdownVisible: false })
|
||||
}, 180)
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this._customerTimer) {
|
||||
clearTimeout(this._customerTimer)
|
||||
}
|
||||
},
|
||||
|
||||
async onDateChange(event) {
|
||||
this.setData({ 'form.appointmentDate': event.detail.value })
|
||||
await this.loadArtists()
|
||||
@@ -303,6 +392,7 @@ Page({
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
|
||||
artistId: String(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card">
|
||||
<view class="field">
|
||||
<text class="field-label required">客户姓名</text>
|
||||
<input value="{{form.customerName}}" data-field="customerName" bindinput="onInput" placeholder="请输入客户姓名" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">手机号</text>
|
||||
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" placeholder="请输入手机号" />
|
||||
<view class="customer-select">
|
||||
<view class="field">
|
||||
<text class="field-label required">客户姓名</text>
|
||||
<input value="{{form.customerName}}" data-field="customerName" bindinput="onInput" bindfocus="onCustomerFocus" bindblur="hideCustomerDropdown" placeholder="搜索或输入客户姓名" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">手机号</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>
|
||||
<view wx:else>
|
||||
<view wx:for="{{customerOptions}}" wx:key="id" class="customer-option" data-id="{{item.id}}" bindtap="selectCustomer">
|
||||
<view class="customer-copy">
|
||||
<text class="customer-name">{{item.displayName}}</text>
|
||||
<text class="customer-phone">{{item.displayPhone}}</text>
|
||||
</view>
|
||||
<text class="customer-select-tag">选择</text>
|
||||
</view>
|
||||
<view wx:if="{{customerOptions.length === 0}}" class="customer-option muted-option">暂无匹配客户,可继续手动输入</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预约日期</text>
|
||||
|
||||
@@ -3,6 +3,77 @@
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.customer-select {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.customer-dropdown {
|
||||
position: absolute;
|
||||
top: 214rpx;
|
||||
right: 0;
|
||||
left: 180rpx;
|
||||
z-index: 30;
|
||||
max-height: 360rpx;
|
||||
overflow-y: auto;
|
||||
border: 1rpx solid #e5ded4;
|
||||
border-radius: 18rpx;
|
||||
background: #fffdf8;
|
||||
box-shadow: 0 18rpx 40rpx rgba(58, 48, 34, 0.14);
|
||||
}
|
||||
|
||||
.customer-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
min-height: 76rpx;
|
||||
padding: 0 20rpx;
|
||||
border-bottom: 1rpx solid #f0e9df;
|
||||
}
|
||||
|
||||
.customer-option:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.customer-copy {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: #2a2521;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
color: #8c8177;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.customer-select-tag {
|
||||
flex: 0 0 auto;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #e5eee9;
|
||||
color: #55786d;
|
||||
font-size: 22rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.muted-option {
|
||||
justify-content: center;
|
||||
color: #9a9288;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.product-value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user