diff --git a/JC-Salon-WeChat/app.json b/JC-Salon-WeChat/app.json index 2d288c15..f71b2324 100644 --- a/JC-Salon-WeChat/app.json +++ b/JC-Salon-WeChat/app.json @@ -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", diff --git a/JC-Salon-WeChat/components/entity-selector-sheet/index.js b/JC-Salon-WeChat/components/entity-selector-sheet/index.js new file mode 100644 index 00000000..45eecd27 --- /dev/null +++ b/JC-Salon-WeChat/components/entity-selector-sheet/index.js @@ -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') + } + } +}) diff --git a/JC-Salon-WeChat/components/entity-selector-sheet/index.json b/JC-Salon-WeChat/components/entity-selector-sheet/index.json new file mode 100644 index 00000000..467ce294 --- /dev/null +++ b/JC-Salon-WeChat/components/entity-selector-sheet/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/JC-Salon-WeChat/components/entity-selector-sheet/index.test.js b/JC-Salon-WeChat/components/entity-selector-sheet/index.test.js new file mode 100644 index 00000000..30eccce7 --- /dev/null +++ b/JC-Salon-WeChat/components/entity-selector-sheet/index.test.js @@ -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, /]*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) diff --git a/JC-Salon-WeChat/components/entity-selector-sheet/index.wxml b/JC-Salon-WeChat/components/entity-selector-sheet/index.wxml new file mode 100644 index 00000000..71d24b93 --- /dev/null +++ b/JC-Salon-WeChat/components/entity-selector-sheet/index.wxml @@ -0,0 +1,44 @@ + + + + + {{title}} + + + + + + + + + + + + 正在加载... + + + {{errorText}} + + + {{emptyText}} + + + + + + {{item.title}} + {{item.badge}} + + {{item.subtitle}} + {{item.meta}} + + {{selectedId == item.id ? '✓' : '›'}} + + + + + + + + + diff --git a/JC-Salon-WeChat/components/entity-selector-sheet/index.wxss b/JC-Salon-WeChat/components/entity-selector-sheet/index.wxss new file mode 100644 index 00000000..0328e0ee --- /dev/null +++ b/JC-Salon-WeChat/components/entity-selector-sheet/index.wxss @@ -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); } } diff --git a/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js b/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js new file mode 100644 index 00000000..128b531b --- /dev/null +++ b/JC-Salon-WeChat/pages/appointment-form/entity-selector.test.js @@ -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 +}) diff --git a/JC-Salon-WeChat/pages/appointment-form/index.js b/JC-Salon-WeChat/pages/appointment-form/index.js index f642a0f2..f99685f3 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.js +++ b/JC-Salon-WeChat/pages/appointment-form/index.js @@ -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)) diff --git a/JC-Salon-WeChat/pages/appointment-form/index.json b/JC-Salon-WeChat/pages/appointment-form/index.json index 9b43ad76..a2d4a1db 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.json +++ b/JC-Salon-WeChat/pages/appointment-form/index.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "新建预约" + "navigationBarTitleText": "新建预约", + "usingComponents": { + "entity-selector-sheet": "/components/entity-selector-sheet/index" + } } diff --git a/JC-Salon-WeChat/pages/appointment-form/index.wxml b/JC-Salon-WeChat/pages/appointment-form/index.wxml index 3515a539..b4a6c9ea 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JC-Salon-WeChat/pages/appointment-form/index.wxml @@ -1,27 +1,14 @@ - - - 客户姓名 - - - - 手机号 - - - - 正在搜索客户... - {{customerError}},可继续手动输入 - - - - {{item.displayName}} - {{item.displayPhone}} - - 选择 - - 暂无匹配客户,可继续手动输入 + + 客户 + + + {{form.customerName || '请选择客户'}} + {{form.phone || '搜索已有客户或手动录入'}} + 已有 + › @@ -44,9 +31,10 @@ 指定员工 - - {{selectedArtist.name || '请选择美甲师'}} - + + {{selectedArtist.name || '请选择员工'}} + › + 预约时间 @@ -79,6 +67,65 @@ {{conflictTip}} + + + + + + + + + 手动录入客户 + 录入后将直接带回本次预约 + + × + + + + 客户姓名 + + + + 手机号 + + + + + + + diff --git a/JC-Salon-WeChat/pages/appointment-form/index.wxss b/JC-Salon-WeChat/pages/appointment-form/index.wxss index 2cb4734a..0e1aeb09 100644 --- a/JC-Salon-WeChat/pages/appointment-form/index.wxss +++ b/JC-Salon-WeChat/pages/appointment-form/index.wxss @@ -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; diff --git a/JC-Salon-WeChat/pages/artist-transfer/entity-selector.test.js b/JC-Salon-WeChat/pages/artist-transfer/entity-selector.test.js new file mode 100644 index 00000000..e84a82a6 --- /dev/null +++ b/JC-Salon-WeChat/pages/artist-transfer/entity-selector.test.js @@ -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) diff --git a/JC-Salon-WeChat/pages/artist-transfer/index.js b/JC-Salon-WeChat/pages/artist-transfer/index.js index b1ec5e0f..f34e80ac 100644 --- a/JC-Salon-WeChat/pages/artist-transfer/index.js +++ b/JC-Salon-WeChat/pages/artist-transfer/index.js @@ -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) { diff --git a/JC-Salon-WeChat/pages/artist-transfer/index.json b/JC-Salon-WeChat/pages/artist-transfer/index.json index 7ef75910..a29d5ac5 100644 --- a/JC-Salon-WeChat/pages/artist-transfer/index.json +++ b/JC-Salon-WeChat/pages/artist-transfer/index.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "改派员工" + "navigationBarTitleText": "改派员工", + "usingComponents": { + "entity-selector-sheet": "/components/entity-selector-sheet/index" + } } diff --git a/JC-Salon-WeChat/pages/artist-transfer/index.wxml b/JC-Salon-WeChat/pages/artist-transfer/index.wxml index 5c56893e..1a812e92 100644 --- a/JC-Salon-WeChat/pages/artist-transfer/index.wxml +++ b/JC-Salon-WeChat/pages/artist-transfer/index.wxml @@ -1,25 +1,15 @@ - - - {{loadError}} - - - 暂无可选美甲师 - - - - - - {{item.name}} - {{item.statusText}} - + + + 改派员工 + + + {{selectedArtist.name || '请选择员工'}} + {{loadError}} - {{item.availableText}} + › - - - 新日期 @@ -34,7 +24,25 @@ - + + + diff --git a/JC-Salon-WeChat/pages/artist-transfer/index.wxss b/JC-Salon-WeChat/pages/artist-transfer/index.wxss index 0fe4bd23..fcddb6b6 100644 --- a/JC-Salon-WeChat/pages/artist-transfer/index.wxss +++ b/JC-Salon-WeChat/pages/artist-transfer/index.wxss @@ -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; } diff --git a/JC-Salon-WeChat/pages/employee-create/index.js b/JC-Salon-WeChat/pages/employee-create/index.js new file mode 100644 index 00000000..ebc69d9b --- /dev/null +++ b/JC-Salon-WeChat/pages/employee-create/index.js @@ -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 }) + } + } +}) diff --git a/JC-Salon-WeChat/pages/employee-create/index.json b/JC-Salon-WeChat/pages/employee-create/index.json new file mode 100644 index 00000000..ad893fc0 --- /dev/null +++ b/JC-Salon-WeChat/pages/employee-create/index.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "新增员工" +} diff --git a/JC-Salon-WeChat/pages/employee-create/index.test.js b/JC-Salon-WeChat/pages/employee-create/index.test.js new file mode 100644 index 00000000..c7640d7a --- /dev/null +++ b/JC-Salon-WeChat/pages/employee-create/index.test.js @@ -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 +}) diff --git a/JC-Salon-WeChat/pages/employee-create/index.wxml b/JC-Salon-WeChat/pages/employee-create/index.wxml new file mode 100644 index 00000000..64649f74 --- /dev/null +++ b/JC-Salon-WeChat/pages/employee-create/index.wxml @@ -0,0 +1,44 @@ + + + 录入员工账号 + {{pickerMode ? '保存后自动选择该员工' : '保存后即可用于预约指定和员工管理'}} + + + + + + + 员工头像 + 点击选择图片,可稍后补充 + + {{avatarUploading ? '上传中' : '更换'}} + + + + + + 姓名 + + + + 手机号 + + + + 登录账号 + + + + 初始密码 + + + + 微信号 + + + + + + + + diff --git a/JC-Salon-WeChat/pages/employee-create/index.wxss b/JC-Salon-WeChat/pages/employee-create/index.wxss new file mode 100644 index 00000000..b000e360 --- /dev/null +++ b/JC-Salon-WeChat/pages/employee-create/index.wxss @@ -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; +} diff --git a/JC-Salon-WeChat/pages/employees/index.js b/JC-Salon-WeChat/pages/employees/index.js index e4add4f8..2849368d 100644 --- a/JC-Salon-WeChat/pages/employees/index.js +++ b/JC-Salon-WeChat/pages/employees/index.js @@ -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 }) - } } }) diff --git a/JC-Salon-WeChat/pages/employees/index.wxml b/JC-Salon-WeChat/pages/employees/index.wxml index 469ebcd1..9842d82c 100644 --- a/JC-Salon-WeChat/pages/employees/index.wxml +++ b/JC-Salon-WeChat/pages/employees/index.wxml @@ -57,45 +57,4 @@ - - - - - 新增美甲师 - - × - - - - - - 头像 - - - - - - 姓名 - - - - 手机号 - - - - 登录账号 - - - - 初始密码 - - - - 微信号 - - - - - - diff --git a/JC-Salon-WeChat/pages/employees/index.wxss b/JC-Salon-WeChat/pages/employees/index.wxss index 045fcdbd..b1bdc254 100644 --- a/JC-Salon-WeChat/pages/employees/index.wxss +++ b/JC-Salon-WeChat/pages/employees/index.wxss @@ -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); - } -} diff --git a/JC-Salon-WeChat/pages/register/index.js b/JC-Salon-WeChat/pages/register/index.js index 927df158..b8e61d26 100644 --- a/JC-Salon-WeChat/pages/register/index.js +++ b/JC-Salon-WeChat/pages/register/index.js @@ -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 }) }, diff --git a/JC-Salon-WeChat/pages/register/index.json b/JC-Salon-WeChat/pages/register/index.json index 99b89cf6..5406aec2 100644 --- a/JC-Salon-WeChat/pages/register/index.json +++ b/JC-Salon-WeChat/pages/register/index.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "注册" + "navigationBarTitleText": "注册", + "usingComponents": { + "entity-selector-sheet": "/components/entity-selector-sheet/index" + } } diff --git a/JC-Salon-WeChat/pages/register/index.wxml b/JC-Salon-WeChat/pages/register/index.wxml index c68bc478..55f171ff 100644 --- a/JC-Salon-WeChat/pages/register/index.wxml +++ b/JC-Salon-WeChat/pages/register/index.wxml @@ -3,7 +3,8 @@ 123 !申请入口已失效请返回登录页重新点击微信快捷登录,获取新的申请凭证。 选择工作身份无需手机号和密码,审核人会根据你的身份处理申请店店长创建并负责一家 Salon 门店{{role === 'manager' ? '✓' : '○'}}员店员加入已有门店协同工作{{role === 'staff' ? '✓' : '○'}} - {{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}店铺名称店铺地址选择店铺{{selectedShopName || '请选择要加入的店铺'}}审核通过前不会获得门店业务权限返回上一步 + {{role === 'manager' ? '完善店铺资料' : '选择要加入的店铺'}}{{role === 'manager' ? '提交后由平台管理员审核' : '提交后由对应店长审核'}}店铺名称店铺地址选择店铺{{selectedShopName || '请选择要加入的店铺'}}›审核通过前不会获得门店业务权限返回上一步 ✓申请已提交{{role === 'manager' ? '平台管理员审核通过后,即可使用快捷登录。' : '店长审核通过后,即可使用快捷登录。'}}当前状态:等待审核 + OpenID 仅用于识别你的微信身份,不会在页面中展示。 diff --git a/JC-Salon-WeChat/pages/register/index.wxss b/JC-Salon-WeChat/pages/register/index.wxss index c9dba461..bf2f828d 100644 --- a/JC-Salon-WeChat/pages/register/index.wxss +++ b/JC-Salon-WeChat/pages/register/index.wxss @@ -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; diff --git a/JC-Salon-WeChat/pages/register/shop-selector.test.js b/JC-Salon-WeChat/pages/register/shop-selector.test.js new file mode 100644 index 00000000..1f17e122 --- /dev/null +++ b/JC-Salon-WeChat/pages/register/shop-selector.test.js @@ -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) diff --git a/docs/superpowers/specs/2026-10-12-salon业务引用字段底部选择页-design.md b/docs/superpowers/specs/2026-10-12-salon业务引用字段底部选择页-design.md new file mode 100644 index 00000000..dc52ed9e --- /dev/null +++ b/docs/superpowers/specs/2026-10-12-salon业务引用字段底部选择页-design.md @@ -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 结果属于同名符号跨项目误关联,因此不修改该函数,新增独立选择器映射函数规避影响。 diff --git a/docs/项目变更记录.md b/docs/项目变更记录.md index d8974a18..9bbf62d1 100644 --- a/docs/项目变更记录.md +++ b/docs/项目变更记录.md @@ -1,5 +1,14 @@ # 项目变更记录 +## 2026-10-12 Salon 小程序业务引用字段底部选择页 + +- 新增统一的业务引用选择组件,客户、员工和门店使用约 88% 屏高的底部选择页,统一搜索、加载、错误、空状态和滚动防穿透行为。 +- 新增预约将姓名与手机号合并为客户卡片,支持选择已有客户或切换手动录入;指定员工改为可搜索选择,并支持快速新增后自动回填。 +- 改派页面收敛为员工选择字段,店员注册改为按名称或地址搜索门店;日期、时间和固定枚举继续使用微信原生 picker。 +- 员工新增从列表弹窗迁移为独立页面,删除旧弹窗状态、方法和样式,创建结果通过事件通道通知来源页面。 +- 问题根因是业务引用字段分别使用内嵌下拉、原生 picker 和平铺列表,导致交互、错误状态及滚动处理不一致;本次通过标准化展示模型和页面内业务回填解决。 +- GitNexus 索引已刷新;其对通用名称 `normalizeCustomer` 的 CRITICAL 结果误关联了跨项目同名符号,因此保留原函数并新增独立映射函数规避风险。 + ## 2026-10-10 Salon 微信资料双按钮 - 将个人信息页“使用微信资料”折叠入口改为左右两个等宽按钮:左侧使用微信头像,右侧使用微信昵称。