保存客户与美甲师表单改造检查点

This commit is contained in:
2026-10-29 17:02:57 +08:00
parent bb3d00c51e
commit b3a8c7e01c
24 changed files with 425 additions and 60 deletions
+7 -4
View File
@@ -9,6 +9,7 @@ Page({
creating: false,
createForm: {
nickname: '',
wechatId: '',
phone: ''
}
},
@@ -72,6 +73,7 @@ Page({
this.setData({
createForm: {
nickname: '',
wechatId: '',
phone: ''
}
})
@@ -80,18 +82,19 @@ Page({
async submitCustomer() {
const form = this.data.createForm
const nickname = String(form.nickname || '').trim()
const wechatId = String(form.wechatId || '').trim()
const phone = String(form.phone || '').trim()
if (!nickname || !phone) {
wx.showToast({ title: '请填写客户姓名和手机号', icon: 'none' })
if (!nickname) {
wx.showToast({ title: '请填写客户姓名', icon: 'none' })
return
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
if (phone && !/^1[3-9]\d{9}$/.test(phone)) {
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
return
}
this.setData({ creating: true })
try {
await customersApi.create({ nickname, phone })
await customersApi.create({ nickname, wechatId: wechatId || undefined, phone: phone || undefined })
wx.showToast({ title: '客户已新增', icon: 'success' })
this.resetCreateForm()
this.setData({ createModalVisible: false })
@@ -0,0 +1,49 @@
const assert = require('assert')
const customersApi = require('../../api/customers')
let definition
global.Page = value => { definition = value }
global.wx = {
showToast: () => {},
navigateTo: () => {}
}
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()
let submitted
let toast
global.wx.showToast = options => { toast = options.title }
customersApi.create = async value => { submitted = value }
customersApi.list = async () => ({ list: [] })
page.setData({ 'createForm.nickname': '小周', 'createForm.wechatId': 'wx_zhou' })
await page.submitCustomer()
assert.deepStrictEqual(submitted, { nickname: '小周', wechatId: 'wx_zhou', phone: undefined })
submitted = undefined
page.setData({ 'createForm.nickname': '', 'createForm.phone': '' })
await page.submitCustomer()
assert.strictEqual(submitted, undefined)
assert.strictEqual(toast, '请填写客户姓名')
}
run().catch(error => {
console.error(error)
process.exitCode = 1
})
+6 -2
View File
@@ -34,8 +34,12 @@
<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="请输入手机号" />
<text>微信号</text>
<input value="{{createForm.wechatId}}" data-field="wechatId" bindinput="onCreateInput" placeholder="选填" />
</view>
<view class="modal-field">
<text>手机号</text>
<input value="{{createForm.phone}}" data-field="phone" bindinput="onCreateInput" type="number" maxlength="11" placeholder="选填" />
</view>
</view>
<button class="primary-btn modal-submit" loading="{{creating}}" bindtap="submitCustomer">保存客户</button>
+37 -3
View File
@@ -2,11 +2,13 @@ const employeesApi = require('../../api/employees')
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
const DEFAULT_EMPLOYEE_PASSWORD = 'Fingertip@123'
const EMPLOYEE_COLORS = ['#7BA7C7', '#8FB89A', '#A894C7', '#D7A86E', '#D98DA5', '#79A6A3', '#B9A16B', '#9BA9C8']
Page({
data: {
pickerMode: false,
appointmentContext: { date: '', time: '', durationMinutes: '' },
employeeColors: EMPLOYEE_COLORS,
onboardingVisible: false,
createdEmployee: null,
form: {
@@ -15,6 +17,7 @@ Page({
account: '',
password: DEFAULT_EMPLOYEE_PASSWORD,
wechatId: '',
color: '#8FB89A',
avatar: '',
avatarUrl: ''
},
@@ -37,10 +40,15 @@ Page({
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
if (field === 'account') this._accountManuallyEdited = true
if (field === 'phone' && !this._accountManuallyEdited) updates['form.account'] = value
this.setData(updates)
},
selectColor(event) {
this.setData({ 'form.color': event.currentTarget.dataset.color })
},
async chooseAvatar() {
if (this.data.avatarUploading || this.data.creating) return
try {
@@ -74,7 +82,7 @@ Page({
const account = String(form.account || '').trim()
const password = String(form.password || '').trim()
const wechatId = String(form.wechatId || '').trim()
if (!nickname || !phone || !account || !password || !wechatId) {
if (!nickname || !phone || !account || !password) {
wx.showToast({ title: '请补全美甲师信息', icon: 'none' })
return
}
@@ -91,6 +99,7 @@ Page({
account,
password,
wechatId,
color: form.color,
avatar: form.avatar || undefined,
type: 3
})
@@ -127,7 +136,32 @@ Page({
},
skipFirstSchedule() {
this.finishCreated(!this.data.pickerMode, false)
if (this.data.savingDefaultSchedule || !this.data.createdEmployee) return
this.setData({ savingDefaultSchedule: true })
employeesApi.saveScheduleRule({
artistId: this.data.createdEmployee.id,
presetType: 'CUSTOM',
workDays: [1, 2, 3, 4, 5, 6, 7],
startTime: '00:00',
endTime: '23:59',
status: 1,
remark: '新建美甲师默认全天可预约,可在排班设置中调整'
}).then(() => {
this.finishCreated(!this.data.pickerMode, false)
}).catch(error => {
wx.showModal({
title: '默认排班设置失败',
content: error.message || '未设置排班前,该美甲师暂不可预约。请重试或返回排班设置。',
confirmText: '重试',
cancelText: '稍后设置',
success: result => {
if (result.confirm) this.skipFirstSchedule()
else this.setData({ savingDefaultSchedule: false })
}
})
}).finally(() => {
if (this.data.onboardingVisible) this.setData({ savingDefaultSchedule: false })
})
},
finishCreated(autoSelect, scheduleSaved) {
@@ -34,19 +34,33 @@ const page = {
async function run() {
page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13800138000' } })
assert.strictEqual(page.data.form.account, '13800138000')
page.onInput({ currentTarget: { dataset: { field: 'account' } }, detail: { value: 'staff_zhou' } })
page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13900139000' } })
assert.strictEqual(page.data.form.account, 'staff_zhou')
assert.strictEqual(page.data.form.color, '#8FB89A')
Object.assign(page.data.form, {
nickname: '小周',
phone: '13800138000',
account: '13800138000',
password: 'Fingertip@123',
wechatId: 'wx_zhou'
wechatId: ''
})
employeesApi.createUser = async () => 88
employeesApi.createUser = async payload => {
assert.strictEqual(payload.wechatId, '')
assert.strictEqual(payload.color, '#8FB89A')
return 88
}
await page.submit()
assert.strictEqual(page.data.onboardingVisible, true)
assert.strictEqual(emitted, undefined)
page.data.pickerMode = true
employeesApi.saveScheduleRule = async payload => {
assert.deepStrictEqual(payload.workDays, [1, 2, 3, 4, 5, 6, 7])
assert.strictEqual(payload.startTime, '00:00')
assert.strictEqual(payload.endTime, '23:59')
}
page.skipFirstSchedule()
await new Promise(resolve => setImmediate(resolve))
assert.strictEqual(emitted.name, 'employeeCreated')
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: false, scheduleSaved: false })
assert.strictEqual(navigatedBack, true)
@@ -33,8 +33,14 @@
<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="请输入微信号" />
<text class="field-label">微信号</text>
<input value="{{form.wechatId}}" data-field="wechatId" bindinput="onInput" placeholder="选填" />
</view>
<view class="field color-field">
<text class="field-label required">专属颜色</text>
<view class="color-options">
<view wx:for="{{employeeColors}}" wx:key="*this" class="color-option {{form.color === item ? 'selected' : ''}}" style="background: {{item}};" data-color="{{item}}" bindtap="selectColor"></view>
</view>
</view>
</view>
@@ -47,8 +53,8 @@
<view class="onboarding-icon">✓</view>
<text class="onboarding-title">美甲师已创建</text>
<text class="onboarding-desc">{{pickerMode ? '设置常规排班后,可继续把当前预约分配给该美甲师。' : '为新美甲师设置首个常规排班,之后即可正常承接预约。'}}</text>
<button class="primary-btn onboarding-primary" bindtap="setupFirstSchedule">{{pickerMode ? '设置排班并分配' : '立即设置排班'}}</button>
<button class="onboarding-skip" bindtap="skipFirstSchedule">{{pickerMode ? '暂不设置' : '稍后设置'}}</button>
<button class="primary-btn onboarding-primary" loading="{{savingDefaultSchedule}}" disabled="{{savingDefaultSchedule}}" bindtap="setupFirstSchedule">{{pickerMode ? '设置排班并分配' : '立即设置排班'}}</button>
<button class="onboarding-skip" loading="{{savingDefaultSchedule}}" disabled="{{savingDefaultSchedule}}" bindtap="skipFirstSchedule">{{pickerMode ? '暂不设置' : '稍后设置(默认全天可约)'}}</button>
</view>
</view>
</view>
@@ -80,6 +80,25 @@
width: 176rpx;
}
.color-options {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
padding: 10rpx 0;
}
.color-option {
width: 44rpx;
height: 44rpx;
border: 4rpx solid #fff;
border-radius: 50%;
box-shadow: 0 0 0 1rpx #d9e3dd;
}
.color-option.selected {
box-shadow: 0 0 0 4rpx #287a62;
}
.onboarding-mask {
position: fixed;
z-index: 50;
+9 -6
View File
@@ -466,16 +466,17 @@ Page({
},
buildDayView(calendar) {
const minuteScale = 4
const startMinute = dateUtil.minutesOfDay(calendar.businessStartTime || '10:00')
const endMinute = dateUtil.minutesOfDay(calendar.businessEndTime || '22:00')
const timelineHeight = Math.max(560, endMinute - startMinute)
const timelineHeight = Math.max(560, (endMinute - startMinute) * minuteScale)
const laneHeaderHeight = 54
const hours = []
for (let cursor = startMinute; cursor <= endMinute; cursor += 60) {
hours.push({
value: cursor,
label: dateUtil.timeFromMinutes(cursor),
top: cursor - startMinute + laneHeaderHeight
top: (cursor - startMinute) * minuteScale + laneHeaderHeight
})
}
const filteredArtists = this.data.selectedArtistId
@@ -491,8 +492,9 @@ Page({
const itemStart = resolveAppointmentStartMinute(item)
return {
...item,
top: Math.max(0, itemStart - startMinute) + laneHeaderHeight,
height: Math.max(64, item.durationMinutes || 60),
top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight,
height: Math.max(100, (item.durationMinutes || 60) * minuteScale),
compact: Number(item.durationMinutes || 60) <= 15,
timeText: resolveAppointmentTimeText(item)
}
})
@@ -505,8 +507,9 @@ Page({
const itemStart = resolveAppointmentStartMinute(item)
return {
...item,
top: Math.max(0, itemStart - startMinute) + laneHeaderHeight,
height: Math.max(64, item.durationMinutes || 60),
top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight,
height: Math.max(100, (item.durationMinutes || 60) * minuteScale),
compact: Number(item.durationMinutes || 60) <= 15,
timeText: resolveAppointmentTimeText(item)
}
})
@@ -87,6 +87,11 @@ async function run() {
assert.strictEqual(dayState.dayLanes[0].artistId, '__unassigned__')
assert.strictEqual(dayState.dayLanes[0].blocks.length, 1)
assert.strictEqual(dayState.unassignedCount, 1)
assert.strictEqual(dayState.timelineHeight, 2934)
assert.strictEqual(dayState.hours.find(item => item.label === '14:00').top, 1014)
assert.strictEqual(dayState.dayLanes[0].blocks[0].height, 240)
assert.match(planningWxss, /background-size:\s*100% 240rpx/)
assert.match(planningWxss, /\.control-card\s*\{[^}]*padding:\s*12rpx 16rpx;/)
const requestPage = createPage({ viewMode: 'day', currentDateText: '2026-10-11' })
let calendarRequests = 0
+1 -1
View File
@@ -95,7 +95,7 @@
<view class="chip-dot" style="background: {{item.color}};"></view>
<text>{{item.name}}</text>
</view>
<view wx:for="{{item.blocks}}" wx:for-item="block" wx:key="orderItemId" class="appointment-block {{block.status === 0 ? 'pending' : ''}}" style="top: {{block.top}}rpx; height: {{block.height}}rpx; border-left-color: {{item.color}};" data-id="{{block.orderItemId}}" bindtap="openAppointment">
<view wx:for="{{item.blocks}}" wx:for-item="block" wx:key="orderItemId" class="appointment-block {{block.status === 0 ? 'pending' : ''}} {{block.compact ? 'compact' : ''}}" style="top: {{block.top}}rpx; height: {{block.height}}rpx; border-left-color: {{item.color}};" data-id="{{block.orderItemId}}" bindtap="openAppointment">
<text class="block-title">{{block.customerName}}</text>
<text class="block-meta">{{block.timeText}} · {{block.productTitle}}</text>
<text class="block-status">{{block.statusText}}</text>
+35 -15
View File
@@ -72,7 +72,7 @@
}
.control-card {
padding: 18rpx;
padding: 12rpx 16rpx;
}
.calendar-error-card {
@@ -175,8 +175,8 @@
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8rpx;
margin-top: 18rpx;
padding: 8rpx;
margin-top: 10rpx;
padding: 6rpx;
border-radius: 12px;
background: #f1ece4;
}
@@ -185,7 +185,7 @@
display: flex;
align-items: center;
justify-content: center;
height: 58rpx;
height: 46rpx;
border-radius: 10px;
color: #7d756c;
font-size: 24rpx;
@@ -203,7 +203,7 @@
.artist-filter {
display: flex;
width: 100%;
margin-top: 16rpx;
margin-top: 10rpx;
white-space: nowrap;
}
@@ -291,13 +291,13 @@
.day-board {
height: 820rpx;
margin-top: 18rpx;
margin-top: 12rpx;
overflow: hidden;
}
.timeline-wrap {
position: relative;
min-height: 720rpx;
min-height: 774rpx;
}
.time-axis {
@@ -344,7 +344,7 @@
flex-shrink: 0;
border-right: 1rpx solid #e7ece9;
background-image: linear-gradient(to bottom, rgba(203, 220, 213, 0.45) 1rpx, transparent 1rpx);
background-size: 100% 60rpx;
background-size: 100% 240rpx;
}
.lane-head {
@@ -367,9 +367,9 @@
left: 12rpx;
display: flex;
flex-direction: column;
gap: 4rpx;
gap: 2rpx;
overflow: hidden;
padding: 12rpx 12rpx;
padding: 6rpx 10rpx;
border-left: 8rpx solid #7ba7c7;
border-radius: 10px;
background: #fff7ee;
@@ -389,28 +389,48 @@
.block-title {
color: #17211f;
font-size: 24rpx;
font-size: 22rpx;
font-weight: 800;
}
.block-meta,
.block-status {
color: #7e756b;
font-size: 20rpx;
font-size: 18rpx;
line-height: 1.25;
}
.block-actions {
display: flex;
gap: 10rpx;
margin-top: 6rpx;
margin-top: 2rpx;
color: #247b63;
font-size: 20rpx;
font-size: 18rpx;
font-weight: 800;
}
.block-actions text {
padding: 2rpx 6rpx;
padding: 0 5rpx;
}
.appointment-block.compact {
gap: 0;
padding: 2rpx 8rpx;
}
.appointment-block.compact .block-title {
font-size: 20rpx;
line-height: 1.05;
}
.appointment-block.compact .block-meta {
font-size: 16rpx;
line-height: 1.05;
}
.appointment-block.compact .block-status,
.appointment-block.compact .block-actions {
display: none;
}
.lane-empty {