优化:统一小程序业务引用选择交互

This commit is contained in:
2026-10-12 22:24:24 +08:00
parent fa1fed006e
commit 3b98e4746a
31 changed files with 1378 additions and 504 deletions
+1
View File
@@ -10,6 +10,7 @@
"pages/customers/index",
"pages/customer-detail/index",
"pages/employees/index",
"pages/employee-create/index",
"pages/employee-detail/index",
"pages/schedule-setting/index",
"pages/leave-management/index",
@@ -0,0 +1,41 @@
Component({
properties: {
visible: { type: Boolean, value: false },
title: { type: String, value: '请选择' },
keyword: { type: String, value: '' },
placeholder: { type: String, value: '搜索' },
items: { type: Array, value: [] },
selectedId: { type: null, value: '' },
loading: { type: Boolean, value: false },
errorText: { type: String, value: '' },
emptyText: { type: String, value: '暂无可选内容' },
actionText: { type: String, value: '' },
showSearch: { type: Boolean, value: true }
},
methods: {
close() {
this.triggerEvent('close')
},
stopEvent() {
},
onSearch(event) {
this.triggerEvent('search', { value: event.detail.value })
},
selectItem(event) {
const item = this.data.items[Number(event.currentTarget.dataset.index)]
if (item) this.triggerEvent('select', { item })
},
retry() {
this.triggerEvent('retry')
},
action() {
this.triggerEvent('action')
}
}
})
@@ -0,0 +1,3 @@
{
"component": true
}
@@ -0,0 +1,36 @@
const assert = require('assert')
const fs = require('fs')
const path = require('path')
let definition
global.Component = value => { definition = value }
require('./index')
const events = []
const component = {
data: {
items: [{ id: 7, title: '小周' }]
},
triggerEvent(name, detail) {
events.push({ name, detail })
}
}
Object.assign(component, definition.methods)
component.onSearch({ detail: { value: '周' } })
component.selectItem({ currentTarget: { dataset: { index: 0 } } })
component.retry()
component.action()
component.close()
assert.deepStrictEqual(events.map(item => item.name), ['search', 'select', 'retry', 'action', 'close'])
assert.strictEqual(events[0].detail.value, '周')
assert.strictEqual(events[1].detail.item.id, 7)
const wxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
const wxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
assert.match(wxml, /class="selector-mask"[^>]*catchtouchmove="stopEvent"/)
assert.match(wxml, /<scroll-view class="selector-scroll" scroll-y/)
assert.doesNotMatch(wxml, /selector-scroll[^>]*catchtouchmove/)
assert.match(wxss, /\.selector-sheet\s*\{[^}]*height:\s*88vh;[^}]*flex-direction:\s*column;[^}]*overflow:\s*hidden;/s)
assert.match(wxss, /\.selector-scroll\s*\{[^}]*min-height:\s*0;[^}]*flex:\s*1;/s)
@@ -0,0 +1,44 @@
<view wx:if="{{visible}}" class="selector-mask" bindtap="close" catchtouchmove="stopEvent">
<view class="selector-sheet" catchtap="stopEvent">
<view class="selector-handle"></view>
<view class="selector-head">
<text class="selector-title">{{title}}</text>
<button class="selector-close" bindtap="close" aria-label="关闭"></button>
</view>
<view wx:if="{{showSearch}}" class="selector-search-wrap">
<text class="selector-search-icon"></text>
<input class="selector-search" value="{{keyword}}" bindinput="onSearch" placeholder="{{placeholder}}" confirm-type="search" />
</view>
<scroll-view class="selector-scroll" scroll-y enhanced show-scrollbar="{{false}}">
<view wx:if="{{loading}}" class="selector-state">
<view class="selector-loading-dot"></view>
<text>正在加载...</text>
</view>
<view wx:elif="{{errorText}}" class="selector-state selector-error">
<text>{{errorText}}</text>
<button class="selector-retry" bindtap="retry">重新加载</button>
</view>
<view wx:elif="{{items.length === 0}}" class="selector-state">{{emptyText}}</view>
<view wx:else class="selector-list">
<view wx:for="{{items}}" wx:key="id" class="selector-item {{selectedId == item.id ? 'selected' : ''}}" data-index="{{index}}" bindtap="selectItem">
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill"></image>
<view class="selector-copy {{item.avatar ? '' : 'without-avatar'}}">
<view class="selector-title-row">
<text class="selector-item-title">{{item.title}}</text>
<text wx:if="{{item.badge}}" class="selector-badge">{{item.badge}}</text>
</view>
<text wx:if="{{item.subtitle}}" class="selector-subtitle">{{item.subtitle}}</text>
<text wx:if="{{item.meta}}" class="selector-meta">{{item.meta}}</text>
</view>
<view class="selector-check">{{selectedId == item.id ? '✓' : '›'}}</view>
</view>
</view>
</scroll-view>
<view wx:if="{{actionText}}" class="selector-footer">
<button class="selector-action" bindtap="action">{{actionText}}</button>
</view>
</view>
</view>
@@ -0,0 +1,289 @@
.selector-mask,
.selector-sheet,
.selector-head,
.selector-search-wrap,
.selector-scroll,
.selector-list,
.selector-item,
.selector-copy,
.selector-footer,
.selector-close,
.selector-retry,
.selector-action,
.selector-search {
box-sizing: border-box;
}
.selector-close,
.selector-retry,
.selector-action {
margin: 0;
padding: 0;
}
.selector-close::after,
.selector-retry::after,
.selector-action::after {
border: 0;
}
.selector-mask {
position: fixed;
inset: 0;
z-index: 120;
display: flex;
align-items: flex-end;
background: rgba(25, 22, 18, 0.5);
animation: selectorMaskIn 180ms ease both;
}
.selector-sheet {
display: flex;
width: 100%;
height: 88vh;
max-height: 88vh;
flex-direction: column;
overflow: hidden;
border-radius: 34rpx 34rpx 0 0;
background: #fffdf8;
box-shadow: 0 -20rpx 48rpx rgba(44, 35, 27, 0.18);
animation: selectorSheetUp 220ms ease both;
}
.selector-handle {
width: 72rpx;
height: 7rpx;
margin: 14rpx auto 2rpx;
border-radius: 999rpx;
background: #ddd6cd;
}
.selector-head {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 92rpx;
padding: 0 28rpx;
}
.selector-title {
color: #29241f;
font-size: 34rpx;
font-weight: 900;
letter-spacing: 1rpx;
}
.selector-close {
position: relative;
width: 52rpx;
min-width: 52rpx;
height: 52rpx;
min-height: 52rpx;
margin: 0;
padding: 0;
border: 1rpx solid #e6dfd6;
border-radius: 50%;
background: #f8f4ee;
}
.selector-close::before,
.selector-close::after {
content: "";
position: absolute;
top: 24rpx;
left: 14rpx;
width: 22rpx;
height: 3rpx;
border-radius: 999rpx;
background: #665e56;
}
.selector-close::before { transform: rotate(45deg); }
.selector-close::after { transform: rotate(-45deg); }
.selector-search-wrap {
display: flex;
align-items: center;
min-height: 80rpx;
margin: 0 28rpx 18rpx;
padding: 0 22rpx;
border: 1rpx solid #e7e0d7;
border-radius: 22rpx;
background: #f7f3ed;
}
.selector-search-icon {
position: relative;
width: 26rpx;
height: 26rpx;
margin-right: 18rpx;
border: 3rpx solid #8e877f;
border-radius: 50%;
}
.selector-search-icon::after {
content: "";
position: absolute;
right: -9rpx;
bottom: -6rpx;
width: 12rpx;
height: 3rpx;
border-radius: 999rpx;
background: #8e877f;
transform: rotate(45deg);
}
.selector-search {
height: 78rpx;
flex: 1;
color: #29241f;
font-size: 27rpx;
}
.selector-scroll {
height: 0;
min-height: 0;
flex: 1;
}
.selector-list {
padding: 0 28rpx 24rpx;
}
.selector-item {
display: flex;
align-items: center;
min-height: 112rpx;
margin-bottom: 14rpx;
padding: 20rpx;
border: 1rpx solid #ece5dc;
border-radius: 24rpx;
background: #fff;
transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.selector-item:active { transform: scale(0.99); }
.selector-item.selected { border-color: #8eafa3; background: #f0f6f3; }
.selector-avatar {
width: 76rpx;
height: 76rpx;
flex: 0 0 auto;
border-radius: 50%;
background: #eee9e2;
}
.selector-copy {
min-width: 0;
flex: 1;
margin-left: 18rpx;
}
.selector-copy.without-avatar { margin-left: 2rpx; }
.selector-title-row {
display: flex;
align-items: center;
gap: 12rpx;
}
.selector-item-title {
overflow: hidden;
color: #2b2621;
font-size: 28rpx;
font-weight: 800;
text-overflow: ellipsis;
white-space: nowrap;
}
.selector-badge {
flex: 0 0 auto;
padding: 5rpx 12rpx;
border-radius: 999rpx;
background: #e7f0ec;
color: #55786d;
font-size: 19rpx;
font-weight: 800;
}
.selector-subtitle,
.selector-meta {
display: block;
margin-top: 7rpx;
overflow: hidden;
color: #7f7870;
font-size: 23rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.selector-meta { color: #a19990; font-size: 21rpx; }
.selector-check {
width: 52rpx;
color: #8c857d;
font-size: 32rpx;
font-weight: 800;
text-align: right;
}
.selector-item.selected .selector-check { color: #2f6f62; }
.selector-state {
display: flex;
min-height: 360rpx;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx 48rpx;
color: #9a9289;
font-size: 25rpx;
line-height: 1.6;
text-align: center;
}
.selector-error { color: #a8554e; }
.selector-retry {
min-width: 180rpx;
height: 64rpx;
margin-top: 22rpx;
padding: 0 28rpx;
border: 1rpx solid #d8d1c8;
border-radius: 999rpx;
background: #fff;
color: #514b44;
font-size: 23rpx;
font-weight: 800;
line-height: 64rpx;
}
.selector-loading-dot {
width: 20rpx;
height: 20rpx;
margin-bottom: 20rpx;
border-radius: 50%;
background: #6f8f83;
box-shadow: -30rpx 0 #c9d8d2, 30rpx 0 #9eb9af;
}
.selector-footer {
padding: 16rpx 28rpx calc(18rpx + env(safe-area-inset-bottom));
border-top: 1rpx solid #eee7de;
background: #fffdf8;
}
.selector-action {
width: 100%;
height: 78rpx;
border: 1rpx solid #cbdad4;
border-radius: 22rpx;
background: #edf4f1;
color: #2f6f62;
font-size: 26rpx;
font-weight: 900;
line-height: 78rpx;
}
@keyframes selectorMaskIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes selectorSheetUp { from { transform: translateY(48rpx); } to { transform: translateY(0); } }
@@ -0,0 +1,63 @@
const assert = require('assert')
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
setStorageSync: () => {},
removeStorageSync: () => {},
showToast: () => {},
navigateTo: () => {}
}
global.getApp = () => ({ globalData: { userInfo: { type: 2, id: 1, shopId: 2 } } })
let definition
global.Page = value => { definition = value }
require('./index')
function createPage() {
return {
...definition,
data: JSON.parse(JSON.stringify(definition.data)),
setData(values) {
Object.entries(values).forEach(([key, value]) => {
const parts = key.split('.')
let target = this.data
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
target[parts[parts.length - 1]] = value
})
}
}
}
async function run() {
const page = createPage()
page.selectCustomer({ detail: { item: { id: 18, name: '小周', phone: '13800138000' } } })
assert.strictEqual(page.data.form.customerUserId, 18)
assert.strictEqual(page.data.form.customerName, '小周')
assert.strictEqual(page.data.form.phone, '13800138000')
assert.strictEqual(page.data.customerSheetVisible, false)
page.data.form.customerUserId = 18
page.data.manualCustomerForm = { name: '新客户', phone: '13900139000' }
page.useManualCustomer()
assert.strictEqual(page.data.form.customerUserId, '')
assert.strictEqual(page.data.form.customerName, '新客户')
assert.strictEqual(page.data.form.phone, '13900139000')
page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }]
page.onArtistSearch({ detail: { value: '李' } })
assert.deepStrictEqual(page.data.artistSelectorItems.map(item => item.id), [2])
page.refreshAvailableTimes = async () => {}
page.checkAvailability = () => {}
page.selectArtist({ detail: { item: { id: 2, name: '小李' } } })
assert.strictEqual(page.data.form.artistId, 2)
assert.strictEqual(page.data.selectedArtist.name, '小李')
assert.strictEqual(page.data.artistSheetVisible, false)
}
run().catch(error => {
console.error(error)
process.exitCode = 1
})
+156 -33
View File
@@ -231,6 +231,25 @@ function normalizeCustomer(customer) {
}
}
function buildCustomerSelectorItem(customer) {
return {
...customer,
title: customer.displayName,
subtitle: customer.displayPhone,
badge: '已有客户'
}
}
function buildArtistSelectorItem(artist) {
return {
...artist,
title: artist.name || '未命名员工',
subtitle: artist.statusText || '可用于指定预约',
meta: artist.workStartTime && artist.workEndTime ? `${artist.workStartTime.slice(0, 5)}-${artist.workEndTime.slice(0, 5)}` : '',
avatar: artist.avatar || artist.avatarUrl || '/assets/images/default-user-avatar.png'
}
}
Page({
data: {
form: {
@@ -253,12 +272,19 @@ Page({
remark: ''
},
customerOptions: [],
customerDropdownVisible: false,
customerSheetVisible: false,
customerKeyword: '',
customerLoading: false,
customerError: '',
manualCustomerVisible: false,
manualCustomerForm: { name: '', phone: '' },
products: [],
filteredProducts: [],
artists: [],
artistSelectorItems: [],
artistSheetVisible: false,
artistKeyword: '',
artistError: '',
selectedProduct: {},
selectedArtist: {},
productModalVisible: false,
@@ -298,7 +324,6 @@ Page({
return
}
this.loadOptions()
this.searchCustomers()
},
async loadOptions() {
@@ -319,21 +344,37 @@ Page({
this.checkAvailability()
},
async loadArtists() {
async loadArtists(preferredArtistId, fallbackEmployee) {
try {
const calendar = await planningApi.calendar({
startDate: this.data.form.appointmentDate,
endDate: this.data.form.appointmentDate
})
const artists = getCalendarArtists(calendar)
const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {}
this.setData({ artists, selectedArtist })
let artists = getCalendarArtists(calendar)
const requestedId = preferredArtistId || this.data.form.artistId
if (fallbackEmployee && requestedId && !findArtist(artists, requestedId).id) {
artists = artists.concat({
id: requestedId,
name: fallbackEmployee.name || fallbackEmployee.title,
avatar: fallbackEmployee.avatar || ''
})
}
const selectedArtist = requestedId ? findArtist(artists, requestedId) : {}
this.setData({
artists,
artistSelectorItems: this.filterArtistItems(artists, this.data.artistKeyword),
selectedArtist,
artistError: '',
'form.artistId': selectedArtist.id || ''
})
this.refreshProductCards()
} catch (error) {
this.setData({
artists: [],
artistSelectorItems: [],
selectedArtist: {},
'form.artistId': '',
artistError: error.message || '员工列表加载失败',
conflictTip: error.message || '美甲师列表加载失败',
conflictLevel: 'danger'
})
@@ -345,44 +386,40 @@ Page({
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)
}
if (field === 'durationMinutes') {
this.refreshAvailableTimes()
this.checkAvailability()
}
},
onCustomerFocus(event) {
const field = event.currentTarget.dataset.field
this.setData({ customerDropdownVisible: true })
this.searchCustomers(field)
openCustomerSheet() {
this.setData({ customerSheetVisible: true })
this.searchCustomers(this.data.customerKeyword)
},
scheduleCustomerSearch(field) {
closeCustomerSheet() {
this.setData({ customerSheetVisible: false })
},
onCustomerSearch(event) {
const keyword = event.detail.value
this.setData({ customerKeyword: keyword })
clearTimeout(this._customerTimer)
this._customerTimer = setTimeout(() => this.searchCustomers(field), 250)
this._customerTimer = setTimeout(() => this.searchCustomers(keyword), 250)
},
async searchCustomers(preferredField) {
async searchCustomers(keywordValue) {
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()
const keyword = String(keywordValue === undefined ? this.data.customerKeyword : keywordValue || '').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),
customerOptions: list.map(normalizeCustomer).map(buildCustomerSelectorItem),
customerError: ''
})
} catch (error) {
@@ -395,8 +432,12 @@ Page({
}
},
retryCustomerSearch() {
this.searchCustomers(this.data.customerKeyword)
},
selectCustomer(event) {
const customer = this.data.customerOptions.find(item => String(item.id) === String(event.currentTarget.dataset.id))
const customer = event.detail.item
if (!customer) {
return
}
@@ -404,14 +445,48 @@ Page({
'form.customerUserId': customer.id,
'form.customerName': customer.name,
'form.phone': customer.phone,
customerDropdownVisible: false
customerSheetVisible: false,
customerKeyword: ''
})
},
hideCustomerDropdown() {
setTimeout(() => {
this.setData({ customerDropdownVisible: false })
}, 180)
openManualCustomer() {
this.setData({
customerSheetVisible: false,
manualCustomerVisible: true,
manualCustomerForm: {
name: this.data.form.customerName || '',
phone: this.data.form.phone || ''
}
})
},
closeManualCustomer() {
this.setData({ manualCustomerVisible: false })
},
onManualCustomerInput(event) {
this.setData({ [`manualCustomerForm.${event.currentTarget.dataset.field}`]: event.detail.value })
},
useManualCustomer() {
const name = String(this.data.manualCustomerForm.name || '').trim()
const phone = String(this.data.manualCustomerForm.phone || '').trim()
if (!name) {
wx.showToast({ title: '请输入客户姓名', icon: 'none' })
return
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
this.setData({
'form.customerUserId': '',
'form.customerName': name,
'form.phone': phone,
manualCustomerVisible: false,
customerKeyword: ''
})
},
onUnload() {
@@ -534,17 +609,65 @@ Page({
})
},
onArtistChange(event) {
const selectedArtist = this.data.artists[Number(event.detail.value)] || {}
filterArtistItems(artists, keywordValue) {
const keyword = String(keywordValue || '').trim().toLowerCase()
return (artists || [])
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
.map(buildArtistSelectorItem)
},
openArtistSheet() {
this.setData({
artistSheetVisible: true,
artistSelectorItems: this.filterArtistItems(this.data.artists, this.data.artistKeyword)
})
},
closeArtistSheet() {
this.setData({ artistSheetVisible: false })
},
retryArtists() {
this.loadArtists()
},
onArtistSearch(event) {
const artistKeyword = event.detail.value
this.setData({
artistKeyword,
artistSelectorItems: this.filterArtistItems(this.data.artists, artistKeyword)
})
},
selectArtist(event) {
const selectedArtist = event.detail.item || {}
this.setData({
selectedArtist,
'form.artistId': selectedArtist.id,
'form.appointmentTime': ''
'form.appointmentTime': '',
artistSheetVisible: false
})
this.refreshAvailableTimes()
this.checkAvailability()
},
addEmployeeFromSelector() {
this.setData({ artistSheetVisible: false })
wx.navigateTo({
url: '/pages/employee-create/index?picker=1',
success: result => {
result.eventChannel.on('employeeCreated', employee => this.handleEmployeeCreated(employee))
}
})
},
async handleEmployeeCreated(employee) {
await this.loadArtists(employee.id, employee)
this.setData({ 'form.appointmentTime': '' })
await this.refreshAvailableTimes()
this.checkAvailability()
},
canOpenTimeSheet() {
const form = this.data.form
return Boolean(form.appointmentDate && form.artistId && normalizeDuration(form.durationMinutes))
@@ -1,3 +1,6 @@
{
"navigationBarTitleText": "新建预约"
"navigationBarTitleText": "新建预约",
"usingComponents": {
"entity-selector-sheet": "/components/entity-selector-sheet/index"
}
}
@@ -1,27 +1,14 @@
<view class="page no-tab">
<view class="card form-card">
<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" maxlength="11" type="number" 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 class="field customer-field" bindtap="openCustomerSheet">
<text class="field-label required">客户</text>
<view class="reference-card {{form.customerName ? 'filled' : ''}}">
<view class="reference-copy">
<text class="reference-title">{{form.customerName || '请选择客户'}}</text>
<text class="reference-subtitle">{{form.phone || '搜索已有客户或手动录入'}}</text>
</view>
<text wx:if="{{form.customerUserId}}" class="reference-badge">已有</text>
<text class="reference-arrow">›</text>
</view>
</view>
<view class="field">
@@ -44,9 +31,10 @@
</view>
<view class="field">
<text class="field-label required">指定员工</text>
<picker range="{{artists}}" range-key="name" bindchange="onArtistChange">
<view class="field-value">{{selectedArtist.name || '请选择美甲师'}}</view>
</picker>
<view class="field-value reference-value" bindtap="openArtistSheet">
<text>{{selectedArtist.name || '请选择员工'}}</text>
<text class="reference-arrow">›</text>
</view>
</view>
<view class="field">
<text class="field-label required">预约时间</text>
@@ -79,6 +67,65 @@
<text class="tip-text">{{conflictTip}}</text>
</view>
<entity-selector-sheet
visible="{{customerSheetVisible}}"
title="选择客户"
keyword="{{customerKeyword}}"
placeholder="搜索客户姓名或手机号"
items="{{customerOptions}}"
selected-id="{{form.customerUserId}}"
loading="{{customerLoading}}"
error-text="{{customerError}}"
empty-text="暂无匹配客户,可手动录入"
action-text="手动录入客户"
bind:search="onCustomerSearch"
bind:select="selectCustomer"
bind:retry="retryCustomerSearch"
bind:action="openManualCustomer"
bind:close="closeCustomerSheet"
/>
<entity-selector-sheet
visible="{{artistSheetVisible}}"
title="选择员工"
keyword="{{artistKeyword}}"
placeholder="搜索员工姓名"
items="{{artistSelectorItems}}"
selected-id="{{form.artistId}}"
loading="{{false}}"
error-text="{{artistError}}"
empty-text="暂无匹配员工"
action-text="快速新增员工"
bind:search="onArtistSearch"
bind:select="selectArtist"
bind:retry="retryArtists"
bind:action="addEmployeeFromSelector"
bind:close="closeArtistSheet"
/>
<view wx:if="{{manualCustomerVisible}}" class="modal-mask" bindtap="closeManualCustomer" catchtouchmove="stopTouchMove">
<view class="manual-customer-sheet" catchtap="stopTap">
<view class="modal-head">
<view>
<text class="modal-title">手动录入客户</text>
<text class="modal-subtitle">录入后将直接带回本次预约</text>
</view>
<view class="modal-close" bindtap="closeManualCustomer">×</view>
</view>
<view class="manual-customer-form">
<view class="manual-customer-field">
<text class="required-label">客户姓名</text>
<input value="{{manualCustomerForm.name}}" data-field="name" bindinput="onManualCustomerInput" placeholder="请输入客户姓名" />
</view>
<view class="manual-customer-field">
<text class="required-label">手机号</text>
<input value="{{manualCustomerForm.phone}}" data-field="phone" bindinput="onManualCustomerInput" type="number" maxlength="11" placeholder="请输入手机号" />
</view>
</view>
<button class="primary-btn manual-customer-submit" bindtap="useManualCustomer">使用该客户</button>
</view>
</view>
<view wx:if="{{productModalVisible}}" class="modal-mask" bindtap="closeProductModal" catchtouchmove="stopTouchMove">
<view class="product-modal" catchtap="stopTap">
<view class="modal-head">
@@ -3,75 +3,81 @@
font-size: 24rpx;
}
.customer-select {
position: relative;
.customer-field {
align-items: stretch;
padding: 18rpx 0;
}
.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 {
.customer-field > .field-label {
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;
.reference-card,
.reference-value {
display: flex;
min-width: 0;
flex: 1;
align-items: center;
gap: 12rpx;
}
.customer-copy {
.reference-card {
min-height: 78rpx;
padding: 13rpx 16rpx;
border: 1rpx solid #e7e0d7;
border-radius: 18rpx;
background: #f8f4ee;
}
.reference-copy {
display: flex;
min-width: 0;
flex: 1;
flex-direction: column;
gap: 6rpx;
}
.customer-name {
min-width: 0;
.reference-title,
.reference-subtitle {
display: block;
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;
.reference-title {
color: #817a72;
font-size: 27rpx;
font-weight: 800;
}
.muted-option {
justify-content: center;
color: #9a9288;
font-size: 24rpx;
.reference-card.filled .reference-title { color: #29241f; }
.reference-subtitle {
margin-top: 6rpx;
color: #9a9289;
font-size: 21rpx;
}
.reference-badge {
flex: 0 0 auto;
padding: 5rpx 11rpx;
border-radius: 999rpx;
background: #e7f0ec;
color: #55786d;
font-size: 19rpx;
font-weight: 800;
}
.reference-value {
justify-content: space-between;
}
.reference-arrow {
flex: 0 0 auto;
color: #a99f95;
font-size: 38rpx;
line-height: 1;
}
.product-value {
@@ -221,6 +227,49 @@
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
}
.manual-customer-sheet {
display: flex;
width: 100%;
height: 88vh;
max-height: 88vh;
flex-direction: column;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 34rpx 34rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
}
.manual-customer-form {
flex: 1;
padding-top: 12rpx;
}
.manual-customer-field {
margin-bottom: 20rpx;
padding: 20rpx 22rpx;
border: 1rpx solid #e7e0d7;
border-radius: 20rpx;
background: #fff;
}
.manual-customer-field text {
display: block;
margin-bottom: 10rpx;
color: #625c55;
font-size: 24rpx;
font-weight: 800;
}
.manual-customer-field input {
height: 64rpx;
color: #29241f;
font-size: 28rpx;
}
.manual-customer-submit {
flex: 0 0 auto;
}
.time-modal {
width: 100%;
max-height: 82vh;
@@ -0,0 +1,29 @@
const assert = require('assert')
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
navigateTo: () => {},
navigateBack: () => {}
}
let definition
global.Page = value => { definition = value }
require('./index')
const page = {
...definition,
data: JSON.parse(JSON.stringify(definition.data)),
setData(values) { Object.assign(this.data, values) }
}
page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }]
page.onArtistSearch({ detail: { value: '周' } })
assert.deepStrictEqual(page.data.artistItems.map(item => item.id), [1])
assert.strictEqual(page.data.artistItems[0].avatar, '/assets/images/default-user-avatar.png')
page.selectArtist({ detail: { item: page.data.artistItems[0] } })
assert.strictEqual(page.data.selectedArtistId, 1)
assert.strictEqual(page.data.selectedArtist.name, '小周')
assert.strictEqual(page.data.artistSheetVisible, false)
+59 -5
View File
@@ -6,7 +6,11 @@ Page({
data: {
id: '',
artists: [],
artistItems: [],
selectedArtistId: '',
selectedArtist: {},
artistSheetVisible: false,
artistKeyword: '',
date: dateUtil.formatDate(new Date()),
time: '13:00',
loadError: '',
@@ -20,38 +24,88 @@ Page({
this.loadArtists()
},
async loadArtists() {
async loadArtists(preferredArtistId, fallbackEmployee) {
try {
const calendar = await planningApi.calendar({
startDate: this.data.date,
endDate: this.data.date
})
const artists = Array.isArray(calendar.artists) ? calendar.artists : []
let artists = Array.isArray(calendar.artists) ? calendar.artists : []
if (fallbackEmployee && preferredArtistId && !artists.some(item => String(item.id) === String(preferredArtistId))) {
artists = artists.concat({ id: preferredArtistId, name: fallbackEmployee.name || fallbackEmployee.title, avatar: fallbackEmployee.avatar || '' })
}
const selectedArtistId = preferredArtistId || this.data.selectedArtistId
const selectedArtist = artists.find(item => String(item.id) === String(selectedArtistId)) || {}
this.setData({
artists: artists.map(item => ({
...item,
availableStatus: 'free',
availableText: '可选择'
})),
selectedArtistId: '',
artistItems: this.filterArtistItems(artists, this.data.artistKeyword),
selectedArtistId: selectedArtist.id || '',
selectedArtist,
loadError: ''
})
} catch (error) {
this.setData({
artists: [],
artistItems: [],
selectedArtistId: '',
selectedArtist: {},
loadError: error.message || '美甲师列表加载失败'
})
}
},
filterArtistItems(artists, keywordValue) {
const keyword = String(keywordValue || '').trim().toLowerCase()
return (artists || [])
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
.map(item => ({
...item,
title: item.name || '未命名员工',
subtitle: item.statusText || '可用于改派',
meta: item.workStartTime && item.workEndTime ? `${item.workStartTime.slice(0, 5)}-${item.workEndTime.slice(0, 5)}` : '',
avatar: item.avatar || item.avatarUrl || '/assets/images/default-user-avatar.png'
}))
},
openArtistSheet() {
this.setData({ artistSheetVisible: true, artistItems: this.filterArtistItems(this.data.artists, this.data.artistKeyword) })
},
closeArtistSheet() {
this.setData({ artistSheetVisible: false })
},
onArtistSearch(event) {
const artistKeyword = event.detail.value
this.setData({ artistKeyword, artistItems: this.filterArtistItems(this.data.artists, artistKeyword) })
},
selectArtist(event) {
this.setData({ selectedArtistId: event.currentTarget.dataset.id })
const selectedArtist = event.detail.item || {}
this.setData({ selectedArtistId: selectedArtist.id, selectedArtist, artistSheetVisible: false })
},
retryArtists() {
this.loadArtists()
},
addEmployeeFromSelector() {
this.setData({ artistSheetVisible: false })
wx.navigateTo({
url: '/pages/employee-create/index?picker=1',
success: result => {
result.eventChannel.on('employeeCreated', employee => this.loadArtists(employee.id, employee))
}
})
},
async onDateChange(event) {
this.setData({ date: event.detail.value })
await this.loadArtists()
await this.loadArtists(this.data.selectedArtistId)
},
onTimeChange(event) {
@@ -1,3 +1,6 @@
{
"navigationBarTitleText": "改派员工"
"navigationBarTitleText": "改派员工",
"usingComponents": {
"entity-selector-sheet": "/components/entity-selector-sheet/index"
}
}
@@ -1,25 +1,15 @@
<view class="page no-tab">
<view class="list">
<view wx:if="{{loadError}}" class="empty card">
<text>{{loadError}}</text>
<button class="secondary-btn retry-btn" bindtap="loadArtists">重试</button>
</view>
<view wx:elif="{{artists.length === 0}}" class="empty card">暂无可选美甲师</view>
<view wx:for="{{artists}}" wx:key="id" class="card transfer-card {{selectedArtistId == item.id ? 'active' : ''}}" data-id="{{item.id}}" bindtap="selectArtist">
<view class="row between">
<view class="row">
<view class="chip-dot large" style="background: {{item.color}};"></view>
<view>
<text class="artist-name">{{item.name}}</text>
<text class="artist-status">{{item.statusText}}</text>
</view>
<view class="card form-card section">
<view class="field">
<text class="field-label required">改派员工</text>
<view class="field-value transfer-reference" bindtap="openArtistSheet">
<view>
<text>{{selectedArtist.name || '请选择员工'}}</text>
<text wx:if="{{loadError}}" class="transfer-error">{{loadError}}</text>
</view>
<text class="tag {{item.availableStatus}}">{{item.availableText}}</text>
<text class="transfer-arrow">›</text>
</view>
</view>
</view>
<view wx:if="{{!loadError}}" class="card form-card section">
<view class="field">
<text class="field-label required">新日期</text>
<picker mode="date" value="{{date}}" bindchange="onDateChange">
@@ -34,7 +24,25 @@
</view>
</view>
<view wx:if="{{!loadError}}" class="fixed-bottom">
<entity-selector-sheet
visible="{{artistSheetVisible}}"
title="选择改派员工"
keyword="{{artistKeyword}}"
placeholder="搜索员工姓名"
items="{{artistItems}}"
selected-id="{{selectedArtistId}}"
loading="{{false}}"
error-text="{{loadError}}"
empty-text="暂无可选员工"
action-text="快速新增员工"
bind:search="onArtistSearch"
bind:select="selectArtist"
bind:retry="retryArtists"
bind:action="addEmployeeFromSelector"
bind:close="closeArtistSheet"
/>
<view class="fixed-bottom">
<button class="primary-btn" loading="{{loading}}" bindtap="submit">确认改派</button>
</view>
</view>
@@ -1,52 +1,29 @@
.transfer-card {
padding: 24rpx;
.transfer-reference {
display: flex;
min-width: 0;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.retry-btn {
width: 180rpx;
min-width: 180rpx;
max-width: 180rpx;
margin: 24rpx auto 0;
.transfer-reference > view {
display: flex;
min-width: 0;
flex: 1;
flex-direction: column;
}
.transfer-card.active {
outline: 3rpx solid #8fb89a;
}
.chip-dot.large {
width: 24rpx;
height: 24rpx;
margin-right: 16rpx;
}
.artist-name,
.artist-status {
display: block;
}
.artist-name {
color: #25211d;
font-size: 30rpx;
font-weight: 800;
}
.artist-status {
.transfer-error {
margin-top: 6rpx;
color: #948c83;
font-size: 22rpx;
overflow: hidden;
color: #a8554e;
font-size: 21rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.tag.free {
background: #e5eee9;
color: #55786d;
}
.tag.busy {
background: #fbedd7;
color: #a5722a;
}
.tag.full {
background: #f8e2e6;
color: #b06070;
.transfer-arrow {
flex: 0 0 auto;
color: #a99f95;
font-size: 38rpx;
}
@@ -0,0 +1,96 @@
const employeesApi = require('../../api/employees')
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
Page({
data: {
pickerMode: false,
form: {
nickname: '',
phone: '',
account: '',
password: DEFAULT_EMPLOYEE_PASSWORD,
wechatId: '',
avatar: '',
avatarUrl: ''
},
avatarUploading: false,
creating: false
},
onLoad(options) {
this.setData({ pickerMode: options && options.picker === '1' })
},
onInput(event) {
const field = event.currentTarget.dataset.field
const value = event.detail.value
const updates = { [`form.${field}`]: value }
if (field === 'phone' && !this.data.form.account) updates['form.account'] = value
this.setData(updates)
},
async chooseAvatar() {
if (this.data.avatarUploading || this.data.creating) return
try {
const filePath = await chooseImageFilePath()
if (!filePath) return
this.setData({ avatarUploading: true })
const uploadResult = await uploadObjectFile(filePath)
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
this.setData({
'form.avatar': avatarUrl,
'form.avatarUrl': avatarUrl
})
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ avatarUploading: false })
}
},
removeAvatar() {
this.setData({ 'form.avatar': '', 'form.avatarUrl': '' })
},
async submit() {
const form = this.data.form
const nickname = String(form.nickname || '').trim()
const phone = String(form.phone || '').trim()
const account = String(form.account || '').trim()
const password = String(form.password || '').trim()
const wechatId = String(form.wechatId || '').trim()
if (!nickname || !phone || !account || !password || !wechatId) {
wx.showToast({ title: '请补全员工信息', icon: 'none' })
return
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
this.setData({ creating: true })
try {
const result = await employeesApi.createUser({
nickname,
phone,
contactPhone: phone,
account,
password,
wechatId,
avatar: form.avatar || undefined,
type: 3
})
const id = result && typeof result === 'object' ? (result.id || result.userId) : result
const employee = { id, name: nickname, title: nickname, avatar: form.avatar || '' }
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
if (eventChannel && eventChannel.emit) eventChannel.emit('employeeCreated', employee)
wx.showToast({ title: '员工已新增', icon: 'success' })
setTimeout(() => wx.navigateBack(), 450)
} catch (error) {
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
} finally {
this.setData({ creating: false })
}
}
})
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "新增员工"
}
@@ -0,0 +1,52 @@
const assert = require('assert')
const employeesApi = require('../../api/employees')
let navigatedBack = false
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
navigateBack: () => { navigatedBack = true }
}
global.setTimeout = callback => { callback(); return 1 }
let definition
global.Page = value => { definition = value }
require('./index')
let emitted
const page = {
...definition,
data: JSON.parse(JSON.stringify(definition.data)),
getOpenerEventChannel: () => ({ emit: (name, value) => { emitted = { name, value } } }),
setData(values) {
Object.entries(values).forEach(([key, value]) => {
const parts = key.split('.')
let target = this.data
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
target[parts[parts.length - 1]] = value
})
}
}
async function run() {
page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13800138000' } })
assert.strictEqual(page.data.form.account, '13800138000')
Object.assign(page.data.form, {
nickname: '小周',
phone: '13800138000',
account: '13800138000',
password: 'Fingertip@123',
wechatId: 'wx_zhou'
})
employeesApi.createUser = async () => 88
await page.submit()
assert.strictEqual(emitted.name, 'employeeCreated')
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '' })
assert.strictEqual(navigatedBack, true)
}
run().catch(error => {
console.error(error)
process.exitCode = 1
})
@@ -0,0 +1,44 @@
<view class="page no-tab employee-create-page">
<view class="create-intro">
<text class="create-title">录入员工账号</text>
<text class="create-subtitle">{{pickerMode ? '保存后自动选择该员工' : '保存后即可用于预约指定和员工管理'}}</text>
</view>
<view class="card avatar-card" bindtap="chooseAvatar">
<image wx:if="{{form.avatarUrl}}" class="avatar-preview" src="{{form.avatarUrl}}" mode="aspectFill"></image>
<image wx:else class="avatar-preview" src="/assets/images/default-user-avatar.png" mode="aspectFit"></image>
<view class="avatar-copy">
<text class="avatar-title">员工头像</text>
<text class="avatar-tip">点击选择图片,可稍后补充</text>
</view>
<text class="avatar-action">{{avatarUploading ? '上传中' : '更换'}}</text>
</view>
<button wx:if="{{form.avatarUrl}}" class="remove-avatar" catchtap="removeAvatar">移除当前头像</button>
<view class="card form-card create-form">
<view class="field">
<text class="field-label required">姓名</text>
<input value="{{form.nickname}}" data-field="nickname" bindinput="onInput" placeholder="请输入员工姓名" />
</view>
<view class="field">
<text class="field-label required">手机号</text>
<input value="{{form.phone}}" data-field="phone" bindinput="onInput" type="number" maxlength="11" placeholder="请输入手机号" />
</view>
<view class="field">
<text class="field-label required">登录账号</text>
<input value="{{form.account}}" data-field="account" bindinput="onInput" placeholder="默认跟随手机号" />
</view>
<view class="field">
<text class="field-label required">初始密码</text>
<input value="{{form.password}}" data-field="password" bindinput="onInput" password placeholder="请输入初始密码" />
</view>
<view class="field">
<text class="field-label required">微信号</text>
<input value="{{form.wechatId}}" data-field="wechatId" bindinput="onInput" placeholder="请输入微信号" />
</view>
</view>
<view class="fixed-bottom">
<button class="primary-btn" loading="{{creating}}" disabled="{{avatarUploading || creating}}" bindtap="submit">保存员工</button>
</view>
</view>
@@ -0,0 +1,81 @@
.employee-create-page {
padding-top: 28rpx;
}
.create-intro {
margin: 0 6rpx 24rpx;
}
.create-title,
.create-subtitle,
.avatar-title,
.avatar-tip {
display: block;
}
.create-title {
color: #29241f;
font-size: 38rpx;
font-weight: 900;
}
.create-subtitle {
margin-top: 10rpx;
color: #8b837b;
font-size: 23rpx;
}
.avatar-card {
display: flex;
align-items: center;
padding: 24rpx;
}
.avatar-preview {
width: 96rpx;
height: 96rpx;
flex: 0 0 auto;
border-radius: 50%;
background: #eee9e2;
}
.avatar-copy {
min-width: 0;
flex: 1;
margin-left: 20rpx;
}
.avatar-title {
color: #302a25;
font-size: 28rpx;
font-weight: 900;
}
.avatar-tip {
margin-top: 8rpx;
color: #948c83;
font-size: 22rpx;
}
.avatar-action {
color: #2f6f62;
font-size: 24rpx;
font-weight: 800;
}
.remove-avatar {
width: auto;
min-height: 58rpx;
margin: 8rpx 8rpx 10rpx auto;
padding: 0 12rpx;
color: #a8554e;
font-size: 22rpx;
}
.create-form {
margin-top: 22rpx;
}
.create-form .field-label {
width: 176rpx;
}
+5 -118
View File
@@ -1,10 +1,8 @@
const employeesApi = require('../../api/employees')
const planningApi = require('../../api/planning')
const dateUtil = require('../../utils/date')
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
const EMPLOYEE_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
function buildScheduleSummary(item) {
const mode = item.scheduleModeSummary || item.scheduleMode || '未设置'
@@ -33,19 +31,7 @@ Page({
reviewPendingCount: 0,
reviewLoading: false,
reviewError: '',
reviewingId: '',
createModalVisible: false,
creating: false,
createForm: {
nickname: '',
phone: '',
account: '',
password: DEFAULT_EMPLOYEE_PASSWORD,
wechatId: '',
avatar: '',
avatarUrl: ''
},
avatarUploading: false
reviewingId: ''
},
onLoad() {
@@ -188,110 +174,11 @@ Page({
},
addEmployee() {
this.setData({ createModalVisible: true })
},
closeCreateModal() {
if (this.data.creating) {
return
}
this.setData({ createModalVisible: false })
},
stopTap() {
},
onCreateInput(event) {
const field = event.currentTarget.dataset.field
const value = event.detail.value
const updates = {
[`createForm.${field}`]: value
}
if (field === 'phone' && !this.data.createForm.account) {
updates['createForm.account'] = value
}
this.setData(updates)
},
resetCreateForm() {
this.setData({
createForm: {
nickname: '',
phone: '',
account: '',
password: DEFAULT_EMPLOYEE_PASSWORD,
wechatId: '',
avatar: '',
avatarUrl: ''
wx.navigateTo({
url: '/pages/employee-create/index',
success: result => {
result.eventChannel.on('employeeCreated', () => this.loadEmployees())
}
})
},
async chooseEmployeeAvatar() {
if (this.data.avatarUploading || this.data.creating) {
return
}
try {
const filePath = await chooseImageFilePath()
if (!filePath) {
return
}
this.setData({ avatarUploading: true })
const uploadResult = await uploadObjectFile(filePath)
const avatarUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
this.setData({
'createForm.avatar': avatarUrl,
'createForm.avatarUrl': avatarUrl
})
} catch (error) {
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
} finally {
this.setData({ avatarUploading: false })
}
},
removeEmployeeAvatar() {
this.setData({
'createForm.avatar': '',
'createForm.avatarUrl': ''
})
},
async submitEmployee() {
const form = this.data.createForm
const nickname = String(form.nickname || '').trim()
const phone = String(form.phone || '').trim()
const account = String(form.account || '').trim()
const password = String(form.password || '').trim()
const wechatId = String(form.wechatId || '').trim()
if (!nickname || !phone || !account || !password || !wechatId) {
wx.showToast({ title: '请补全美甲师信息', icon: 'none' })
return
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
this.setData({ creating: true })
try {
await employeesApi.createUser({
nickname,
phone,
contactPhone: phone,
account,
password,
wechatId,
avatar: form.avatar || undefined,
type: 3
})
wx.showToast({ title: '美甲师已新增', icon: 'success' })
this.resetCreateForm()
this.setData({ createModalVisible: false })
await this.loadEmployees()
} catch (error) {
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
} finally {
this.setData({ creating: false })
}
}
})
@@ -57,45 +57,4 @@
</view>
</view>
<view wx:if="{{createModalVisible}}" class="modal-mask" bindtap="closeCreateModal">
<view class="employee-modal" catchtap="stopTap">
<view class="modal-head">
<view>
<text class="modal-title">新增美甲师</text>
</view>
<view class="modal-close" bindtap="closeCreateModal">×</view>
</view>
<view class="avatar-upload">
<view wx:if="{{createForm.avatarUrl}}" class="avatar-preview image-avatar">
<image src="{{createForm.avatarUrl}}" mode="aspectFill"></image>
</view>
<view wx:else class="avatar-preview">头像</view>
<button class="secondary-btn avatar-btn" loading="{{avatarUploading}}" bindtap="chooseEmployeeAvatar">上传头像</button>
<button wx:if="{{createForm.avatarUrl}}" class="text-btn avatar-remove" bindtap="removeEmployeeAvatar">移除</button>
</view>
<view class="form-grid">
<view class="modal-field">
<text class="required-label">姓名</text>
<input value="{{createForm.nickname}}" data-field="nickname" bindinput="onCreateInput" placeholder="请输入姓名" />
</view>
<view class="modal-field">
<text class="required-label">手机号</text>
<input value="{{createForm.phone}}" data-field="phone" bindinput="onCreateInput" type="number" maxlength="11" placeholder="请输入手机号" />
</view>
<view class="modal-field">
<text class="required-label">登录账号</text>
<input value="{{createForm.account}}" data-field="account" bindinput="onCreateInput" placeholder="请输入账号" />
</view>
<view class="modal-field">
<text class="required-label">初始密码</text>
<input value="{{createForm.password}}" data-field="password" bindinput="onCreateInput" password placeholder="请输入密码" />
</view>
<view class="modal-field">
<text class="required-label">微信号</text>
<input value="{{createForm.wechatId}}" data-field="wechatId" bindinput="onCreateInput" placeholder="请输入微信号" />
</view>
</view>
<button class="primary-btn modal-submit" loading="{{creating}}" bindtap="submitEmployee">保存美甲师</button>
</view>
</view>
</view>
-159
View File
@@ -264,148 +264,6 @@
margin: 24rpx auto 0;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: flex-end;
justify-content: center;
background: rgba(18, 15, 12, 0.48);
animation: maskIn 180ms ease both;
}
.employee-modal {
width: 100%;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 28rpx 28rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
animation: modalUp 220ms ease both;
}
.modal-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
margin-bottom: 20rpx;
}
.modal-title {
display: block;
}
.modal-title {
color: #27211d;
font-size: 34rpx;
font-weight: 900;
}
.modal-close {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 48rpx;
min-width: 48rpx;
height: 48rpx;
border-radius: 50%;
border: 1rpx solid #e4d8ca;
background: #fffaf4;
color: transparent;
font-size: 0;
line-height: 0;
}
.modal-close::before,
.modal-close::after {
content: "";
position: absolute;
width: 22rpx;
height: 3rpx;
border-radius: 999rpx;
background: #61554c;
}
.modal-close::before {
transform: rotate(45deg);
}
.modal-close::after {
transform: rotate(-45deg);
}
.avatar-upload {
display: flex;
align-items: center;
gap: 16rpx;
margin-bottom: 18rpx;
padding: 18rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.avatar-preview {
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 92rpx;
height: 92rpx;
overflow: hidden;
border-radius: 50%;
background: #6f8f83;
color: #fff;
font-size: 24rpx;
font-weight: 900;
}
.avatar-preview image {
width: 100%;
height: 100%;
}
.avatar-btn {
flex: 1;
min-width: 0;
max-width: none;
}
.avatar-remove {
flex: 0 0 auto;
}
.form-grid {
display: grid;
grid-template-columns: 1fr;
gap: 16rpx;
}
.modal-field {
padding: 16rpx 18rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.modal-field text {
display: block;
margin-bottom: 8rpx;
color: #6c5f54;
font-size: 24rpx;
font-weight: 800;
}
.modal-field input {
height: 58rpx;
color: #2c2722;
font-size: 28rpx;
}
.modal-submit {
margin-top: 22rpx;
}
@keyframes cardIn {
from {
opacity: 0;
@@ -417,20 +275,3 @@
}
}
@keyframes maskIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes modalUp {
from {
transform: translateY(40rpx);
}
to {
transform: translateY(0);
}
}
+43 -10
View File
@@ -8,7 +8,11 @@ Page({
registrationTicket: '',
applicationId: '',
shopOptions: [],
shopIndex: 0,
shopSelectorItems: [],
shopSheetVisible: false,
shopKeyword: '',
shopLoading: false,
shopError: '',
selectedShopName: '',
loading: false,
ticketInvalid: false
@@ -21,17 +25,26 @@ Page({
applicationId: options && options.applicationId ? options.applicationId : '',
ticketInvalid: !registrationTicket
})
await this.loadShops()
},
async loadShops() {
this.setData({ shopLoading: true, shopError: '' })
try {
const shops = await authApi.getAvailableRegistrationShops()
const shopOptions = (Array.isArray(shops) ? shops : []).map(item => ({
id: item.id,
name: item.shopName || item.name,
address: item.address || ''
}))
this.setData({
shopOptions: (Array.isArray(shops) ? shops : []).map(item => ({
id: item.id,
name: item.shopName || item.name,
address: item.address || ''
}))
shopOptions,
shopSelectorItems: this.filterShops(shopOptions, this.data.shopKeyword)
})
} catch (error) {
this.setData({ shopOptions: [] })
this.setData({ shopOptions: [], shopSelectorItems: [], shopError: error.message || '门店列表加载失败' })
} finally {
this.setData({ shopLoading: false })
}
},
@@ -39,10 +52,30 @@ Page({
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
continueFromRole() { if (!this.data.ticketInvalid) this.setData({ step: 2 }) },
filterShops(shops, keywordValue) {
const keyword = String(keywordValue || '').trim().toLowerCase()
return (shops || [])
.filter(item => !keyword || [item.name, item.address].some(value => String(value || '').toLowerCase().includes(keyword)))
.map(item => ({ ...item, title: item.name || '未命名门店', subtitle: item.address || '暂无地址' }))
},
openShopSheet() {
this.setData({ shopSheetVisible: true, shopSelectorItems: this.filterShops(this.data.shopOptions, this.data.shopKeyword) })
if (this.data.shopError) this.loadShops()
},
closeShopSheet() {
this.setData({ shopSheetVisible: false })
},
onShopSearch(event) {
const shopKeyword = event.detail.value
this.setData({ shopKeyword, shopSelectorItems: this.filterShops(this.data.shopOptions, shopKeyword) })
},
selectShop(event) {
const index = Number(event.detail.value)
const shop = this.data.shopOptions[index]
if (shop) this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
const shop = event.detail.item
if (shop) this.setData({ selectedShopName: shop.name, 'form.shopId': shop.id, shopSheetVisible: false })
},
goBackStep() { this.setData({ step: 1 }) },
+4 -1
View File
@@ -1,3 +1,6 @@
{
"navigationBarTitleText": "注册"
"navigationBarTitleText": "注册",
"usingComponents": {
"entity-selector-sheet": "/components/entity-selector-sheet/index"
}
}
+2 -1
View File
@@ -3,7 +3,8 @@
<view class="progress-row"><view class="progress-step {{step >= 1 ? 'active' : ''}}"><text>1</text><label>选择身份</label></view><view class="progress-line {{step >= 2 ? 'active' : ''}}"></view><view class="progress-step {{step >= 2 ? 'active' : ''}}"><text>2</text><label>门店资料</label></view><view class="progress-line {{step >= 3 ? 'active' : ''}}"></view><view class="progress-step {{step >= 3 ? 'active' : ''}}"><text>3</text><label>等待审核</label></view></view>
<view wx:if="{{ticketInvalid}}" class="card result-card"><view class="result-icon">!</view><view class="section-title">申请入口已失效</view><view class="section-desc">请返回登录页重新点击微信快捷登录,获取新的申请凭证。</view><button class="primary-btn" bindtap="back">返回登录</button></view>
<view wx:elif="{{step === 1}}" class="card form-card"><view class="section-title">选择工作身份</view><view class="section-desc">无需手机号和密码,审核人会根据你的身份处理申请</view><view class="role-list"><view class="role-option {{role === 'manager' ? 'selected' : ''}}" data-role="manager" bindtap="selectRole"><view class="role-icon">店</view><view class="role-copy"><text class="role-title">店长</text><text class="role-desc">创建并负责一家 Salon 门店</text></view><text class="role-mark">{{role === 'manager' ? '✓' : '○'}}</text></view><view class="role-option {{role === 'staff' ? 'selected' : ''}}" data-role="staff" bindtap="selectRole"><view class="role-icon">员</view><view class="role-copy"><text class="role-title">店员</text><text class="role-desc">加入已有门店协同工作</text></view><text class="role-mark">{{role === 'staff' ? '✓' : '○'}}</text></view></view><button class="primary-btn" bindtap="continueFromRole">继续</button></view>
<view wx:elif="{{step === 2}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><picker range="{{shopOptions}}" range-key="name" value="{{shopIndex}}" bindchange="selectShop"><view class="picker-value {{selectedShopName ? 'filled' : ''}}">{{selectedShopName || '请选择要加入的店铺'}}</view></picker></view><view wx:if="{{role === 'staff'}}" class="notice">审核通过前不会获得门店业务权限</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
<view wx:elif="{{step === 2}}" class="card form-card"><view class="section-title">{{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}</view><view class="section-desc">{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}</view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view><view wx:if="{{role === 'manager'}}" class="field"><text class="field-label">店铺地址</text><input value="{{form.shopAddress}}" data-field="shopAddress" bindinput="onInput" placeholder="请输入门店地址" /></view><view wx:if="{{role === 'staff'}}" class="field"><text class="field-label">选择店铺</text><view class="picker-value {{selectedShopName ? 'filled' : ''}}" bindtap="openShopSheet"><text>{{selectedShopName || '请选择要加入的店铺'}}</text><text class="picker-arrow">›</text></view></view><view wx:if="{{role === 'staff'}}" class="notice">审核通过前不会获得门店业务权限</view><button class="primary-btn" loading="{{loading}}" bindtap="submit">提交审核</button><view class="back-entry" bindtap="goBackStep">返回上一步</view></view>
<view wx:elif="{{step === 3}}" class="card result-card"><view class="result-icon">✓</view><view class="section-title">申请已提交</view><view class="section-desc">{{role === 'manager' ? '平台管理员审核通过后,即可使用快捷登录。' : '店长审核通过后,即可使用快捷登录。'}}</view><view class="result-status">当前状态:<text>等待审核</text></view><button class="primary-btn" bindtap="back">返回登录</button></view>
<entity-selector-sheet visible="{{shopSheetVisible}}" title="选择门店" keyword="{{shopKeyword}}" placeholder="搜索门店名称或地址" items="{{shopSelectorItems}}" selected-id="{{form.shopId}}" loading="{{shopLoading}}" error-text="{{shopError}}" empty-text="暂无匹配门店" bind:search="onShopSearch" bind:select="selectShop" bind:retry="loadShops" bind:close="closeShopSheet" />
<view class="safe-note">OpenID 仅用于识别你的微信身份,不会在页面中展示。</view>
</view>
@@ -114,11 +114,18 @@
.picker-value {
display: flex;
align-items: center;
justify-content: space-between;
color: #a0ada4;
}
.picker-value.filled { color: #2e4a3d; }
.picker-arrow {
color: #8fa096;
font-size: 36rpx;
line-height: 1;
}
.code-row {
display: flex;
align-items: center;
@@ -0,0 +1,35 @@
const assert = require('assert')
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
reLaunch: () => {}
}
let definition
global.Page = value => { definition = value }
require('./index')
const page = {
...definition,
data: JSON.parse(JSON.stringify(definition.data)),
setData(values) {
Object.entries(values).forEach(([key, value]) => {
const parts = key.split('.')
let target = this.data
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
target[parts[parts.length - 1]] = value
})
}
}
const shops = [
{ id: 1, name: '甲屿一店', address: '滨江路' },
{ id: 2, name: '甲屿二店', address: '湖滨路' }
]
assert.deepStrictEqual(page.filterShops(shops, '湖滨').map(item => item.id), [2])
page.selectShop({ detail: { item: { ...shops[1], title: shops[1].name } } })
assert.strictEqual(page.data.form.shopId, 2)
assert.strictEqual(page.data.selectedShopName, '甲屿二店')
assert.strictEqual(page.data.shopSheetVisible, false)
@@ -0,0 +1,53 @@
# Salon 小程序业务引用字段底部选择页设计
## 背景与问题
新增预约中的客户搜索以内嵌下拉列表呈现,员工和注册门店仍使用原生 picker,改派页面则直接铺开全部员工卡片。相同的“引用已有业务数据”操作分散在多个页面,搜索、加载失败、空状态和滚动处理不一致;员工新增还嵌在员工列表弹窗中,无法从预约选择流程快速创建并回填。
## 设计目标
- 客户、员工和门店统一使用约 88% 屏高的底部选择页。
- 标题、搜索和底部操作固定,列表区域独立滚动,遮罩阻止主页面滚动穿透。
- 选择结果自动回填原表单;请求失败只影响弹层,不清空已有表单。
- 日期、时间和固定枚举继续使用微信原生 picker。
- 作品保留现有富内容弹层,但高度、滚动和防穿透规则与公共选择页一致。
## 组件边界
`entity-selector-sheet` 只负责通用展示和交互状态,接收标准化的 `id`、`title`、`subtitle`、`meta`、`avatar`、`badge` 数据,并向页面发送 `search`、`select`、`retry`、`action`、`close` 事件。数据请求、过滤、业务校验和表单回填仍由页面负责,避免公共组件耦合客户、员工或门店接口。
## 页面交互
### 新增预约
- 客户姓名和手机号合并为客户卡片。客户弹层默认搜索已有客户,底部“手动录入客户”切换到同高度的姓名、手机号表单。
- 选择已有客户时保留 `customerUserId`;手动录入时清空该 ID,继续复用后端现有客户解析能力。
- 指定员工改用员工选择弹层,按姓名本地搜索,并提供“快速新增员工”。
- 快速新增成功后通过事件通道回传员工 ID 和展示信息,刷新员工数据并自动选中。
### 改派与注册
- 改派页面将平铺员工卡片收敛为员工选择字段,复用员工搜索和快速新增能力。
- 店员注册将门店 picker 改为门店选择弹层,按名称或地址搜索,只允许选择已有门店。
### 员工创建
- 员工页原新增弹窗迁移到独立 `employee-create` 页面。
- 普通入口创建成功后刷新员工列表;选择器入口创建成功后额外自动回填原业务表单。
## 异常与状态
- 加载中、空列表和请求错误均在弹层列表区域展示;错误状态提供重新加载。
- 搜索结果为空时仍保留客户手动录入或员工快速新增入口。
- 关闭弹层只清理可见状态,不修改已经填写的预约、改派或注册数据。
- 员工无真实头像时使用项目内黑白默认人物头像,不使用昵称首字。
## 验证
- 覆盖公共组件事件、独立滚动和防穿透结构。
- 覆盖已有客户与手动客户回填、员工搜索与选择、门店名称/地址搜索、员工创建事件回传。
- 运行 Salon 小程序全部 Node 测试、JavaScript/JSON 静态检查、Git 差异检查和 GitNexus 变更检测。
## 约束
本次仅修改 `JC-Salon-WeChat` 和项目文档,不修改后端、SQL、Nacos、后台管理或 ArtList。GitNexus 对 `normalizeCustomer` 的 CRITICAL 结果属于同名符号跨项目误关联,因此不修改该函数,新增独立选择器映射函数规避影响。
+9
View File
@@ -1,5 +1,14 @@
# 项目变更记录
## 2026-10-12 Salon 小程序业务引用字段底部选择页
- 新增统一的业务引用选择组件,客户、员工和门店使用约 88% 屏高的底部选择页,统一搜索、加载、错误、空状态和滚动防穿透行为。
- 新增预约将姓名与手机号合并为客户卡片,支持选择已有客户或切换手动录入;指定员工改为可搜索选择,并支持快速新增后自动回填。
- 改派页面收敛为员工选择字段,店员注册改为按名称或地址搜索门店;日期、时间和固定枚举继续使用微信原生 picker。
- 员工新增从列表弹窗迁移为独立页面,删除旧弹窗状态、方法和样式,创建结果通过事件通道通知来源页面。
- 问题根因是业务引用字段分别使用内嵌下拉、原生 picker 和平铺列表,导致交互、错误状态及滚动处理不一致;本次通过标准化展示模型和页面内业务回填解决。
- GitNexus 索引已刷新;其对通用名称 `normalizeCustomer` 的 CRITICAL 结果误关联了跨项目同名符号,因此保留原函数并新增独立映射函数规避风险。
## 2026-10-10 Salon 微信资料双按钮
- 将个人信息页“使用微信资料”折叠入口改为左右两个等宽按钮:左侧使用微信头像,右侧使用微信昵称。