完善店员申请关联与预约页面
自动发布开发环境 Nacos 配置 / publish (push) Successful in 21s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 8s

This commit is contained in:
2026-11-03 23:29:40 +08:00
parent 1fc46f3835
commit 4b4c1ddef5
18 changed files with 442 additions and 64 deletions
+57 -3
View File
@@ -7,6 +7,7 @@ Page({
data: {
pickerMode: false,
appointmentContext: { date: '', time: '', durationMinutes: '' },
applicationId: '',
employeeColors: EMPLOYEE_COLORS,
onboardingVisible: false,
createdEmployee: null,
@@ -35,7 +36,9 @@ Page({
date: options.date || '',
time: options.time || '',
durationMinutes: options.durationMinutes || ''
}
},
applicationId: options.applicationId || '',
applicationNo: options.applicationNo || ''
})
},
@@ -81,6 +84,12 @@ Page({
},
async submit() {
if (this.data.creating || this.data.avatarUploading) return
if (this.data.createdEmployee) {
if (this.data.applicationId && !this.data.applicationApproved) return this.associateCreatedEmployee()
this.setData({ onboardingVisible: true })
return
}
const form = this.data.form
const nickname = String(form.nickname || '').trim()
const phone = String(form.phone || '').trim()
@@ -106,7 +115,11 @@ Page({
})
const id = result && typeof result === 'object' ? (result.id || result.userId) : result
const employee = { id, name: nickname, title: nickname, avatar: form.avatar || '' }
this.setData({ createdEmployee: employee })
this.setData({ createdEmployee: employee, applicationApproved: false })
if (this.data.applicationId) {
await this.associateCreatedEmployee()
return
}
await this.offerPendingAssociation()
} catch (error) {
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
@@ -115,6 +128,33 @@ Page({
}
},
async associateCreatedEmployee() {
const employee = this.data.createdEmployee
if (!employee || !employee.id || !this.data.applicationId || this.data.associatingApplication) return
this.setData({ associatingApplication: true })
try {
await employeesApi.approveApplication(this.data.applicationId, {
targetArtistUserId: employee.id,
useApplicantNickname: false,
useApplicantAvatar: false
})
this.setData({ applicationApproved: true, associatingApplication: false, onboardingVisible: true })
wx.showToast({ title: '已关联并通过审核', icon: 'success' })
} catch (error) {
this.setData({ associatingApplication: false })
wx.showModal({
title: '关联审核未完成',
content: error.message || '美甲师档案已创建,可重试关联申请。',
confirmText: '重试',
cancelText: '稍后处理',
success: result => {
if (result.confirm) this.associateCreatedEmployee()
else this.setData({ onboardingVisible: true })
}
})
}
},
async offerPendingAssociation() {
try {
const data = await employeesApi.unassociatedApplications()
@@ -180,6 +220,7 @@ Page({
},
setupFirstSchedule() {
if (this.data.applicationId && !this.data.applicationApproved) return
const employee = this.data.createdEmployee
if (!employee || !employee.id) return
const context = this.data.appointmentContext
@@ -202,7 +243,7 @@ Page({
},
skipFirstSchedule() {
if (this.data.savingDefaultSchedule || !this.data.createdEmployee) return
if (this.data.savingDefaultSchedule || !this.data.createdEmployee || (this.data.applicationId && !this.data.applicationApproved)) return
this.setData({ savingDefaultSchedule: true })
employeesApi.saveScheduleRule({
artistId: this.data.createdEmployee.id,
@@ -231,6 +272,10 @@ Page({
},
finishCreated(autoSelect, scheduleSaved) {
if (this.data.applicationId && !this.data.applicationApproved) {
this.setData({ onboardingVisible: true })
return
}
const employee = this.data.createdEmployee
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
if (eventChannel && eventChannel.emit) {
@@ -239,5 +284,14 @@ Page({
this.setData({ onboardingVisible: false })
wx.showToast({ title: scheduleSaved ? '排班已保存' : '美甲师已新增', icon: 'success' })
setTimeout(() => wx.navigateBack(), 300)
},
leaveAssociationForLater() {
const employee = this.data.createdEmployee
const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel()
if (eventChannel && eventChannel.emit && employee) {
eventChannel.emit('employeeCreated', { ...employee, autoSelect: this.data.pickerMode, scheduleSaved: false })
}
wx.navigateBack()
}
})
@@ -3,10 +3,12 @@ const employeesApi = require('../../api/employees')
let navigatedBack = false
let navigatedTo = ''
let modalConfirm = false
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
showModal: options => options.success({ confirm: modalConfirm }),
navigateBack: () => { navigatedBack = true },
navigateTo: options => { navigatedTo = options.url }
}
@@ -102,6 +104,35 @@ async function run() {
page.data.appointmentContext = { date: '2026-10-12', time: '14:00', durationMinutes: '60' }
page.setupFirstSchedule()
assert.strictEqual(navigatedTo.includes('/pages/schedule-setting/index?id=88&onboarding=1&source=appointment'), true)
let employeeCreateCount = 0
let approvalAttempts = 0
let approvalPayload
page.data.form = { nickname: '申请档案员工', phone: '13800138001', wechatId: '', color: '#8FB89A', avatar: '', avatarUrl: '' }
page.data.createdEmployee = null
page.data.applicationId = '42'
page.data.applicationApproved = false
page.data.onboardingVisible = false
employeesApi.createUser = async () => { employeeCreateCount += 1; return { userId: 90 } }
employeesApi.approveApplication = async (applicationId, payload) => {
approvalAttempts += 1
approvalPayload = { applicationId, ...payload }
if (approvalAttempts === 1) throw new Error('暂时无法审核')
}
await page.submit()
assert.strictEqual(employeeCreateCount, 1)
assert.deepStrictEqual(approvalPayload, {
applicationId: '42',
targetArtistUserId: 90,
useApplicantNickname: false,
useApplicantAvatar: false
})
assert.strictEqual(page.data.createdEmployee.id, 90)
assert.strictEqual(page.data.onboardingVisible, true)
await page.associateCreatedEmployee()
assert.strictEqual(employeeCreateCount, 1)
assert.strictEqual(approvalAttempts, 2)
assert.strictEqual(page.data.applicationApproved, true)
}
run().catch(error => {
@@ -1,7 +1,7 @@
<view class="page no-tab employee-create-page">
<view class="create-intro">
<text class="create-title">新增美甲师档案</text>
<text class="create-subtitle">{{pickerMode ? '保存后自动选择该美甲师' : '保存后即可用于预约指定和美甲师管理'}}</text>
<text class="create-subtitle">{{applicationId ? '保存后将自动关联当前申请并通过审核' : (pickerMode ? '保存后自动选择该美甲师' : '保存后即可用于预约指定和美甲师管理')}}</text>
</view>
<view class="card avatar-card" bindtap="chooseAvatar">
@@ -42,17 +42,24 @@
</view>
<view class="fixed-bottom">
<button class="primary-btn" loading="{{creating}}" disabled="{{avatarUploading || creating}}" bindtap="submit">保存美甲师</button>
<button class="primary-btn" loading="{{creating || associatingApplication}}" disabled="{{avatarUploading || creating || associatingApplication || (applicationId && applicationApproved)}}" bindtap="submit">{{applicationId && !createdEmployee ? '创建并通过审核' : (applicationId && createdEmployee && !applicationApproved ? '重试关联并通过' : '保存美甲师')}}</button>
</view>
<view wx:if="{{onboardingVisible}}" class="onboarding-mask" catchtouchmove="stopTouchMove">
<view class="onboarding-card">
<view class="onboarding-icon">✓</view>
<text class="onboarding-title">美甲师已创建</text>
<text class="onboarding-desc">{{pickerMode ? '设置常规排班后,可继续把当前预约分配给该美甲师。' : '为新美甲师设置首个常规排班,之后即可正常承接预约。'}}</text>
<text class="onboarding-default-note">不立即设置时,将默认全年无休、全天排班(00:00-23:59);实际预约仍受门店营业时间限制,之后可在排班设置中调整。</text>
<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 class="onboarding-icon {{applicationId && !applicationApproved ? 'association-failed' : ''}}">{{applicationId && !applicationApproved ? '!' : '✓'}}</view>
<text class="onboarding-title">{{applicationId && !applicationApproved ? '美甲师档案已创建' : (applicationId ? '申请已关联并通过' : '美甲师已创建')}}</text>
<text class="onboarding-desc">{{applicationId && !applicationApproved ? '员工档案已保留,申请仍待处理。关联失败不会重复创建员工,可直接重试。' : (pickerMode ? '设置常规排班后,可继续把当前预约分配给该美甲师。' : '为新美甲师设置首个常规排班,之后即可正常承接预约。')}}</text>
<view wx:if="{{applicationId && !applicationApproved}}" class="association-retry-box">
<text>申请编号 {{applicationNo || applicationId}}</text>
<button class="primary-btn onboarding-primary" loading="{{associatingApplication}}" disabled="{{associatingApplication}}" bindtap="associateCreatedEmployee">重试关联并通过审核</button>
<button class="onboarding-skip" disabled="{{associatingApplication}}" bindtap="leaveAssociationForLater">稍后处理</button>
</view>
<block wx:else>
<text class="onboarding-default-note">不立即设置时,将默认全年无休、全天排班(00:00-23:59);实际预约仍受门店营业时间限制,之后可在排班设置中调整。</text>
<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>
</block>
</view>
</view>
<entity-selector-sheet visible="{{associationSheetVisible}}" title="关联待审核申请" keyword="{{associationKeyword}}" placeholder="搜索申请昵称、手机号或编号" items="{{associationItems}}" selected-id="{{associationSelectedId}}" loading="{{associationLoading}}" empty-text="暂无可关联申请" action-text="暂不关联,继续" bind:search="onAssociationSearch" bind:select="selectAssociation" bind:action="skipAssociation" bind:close="skipAssociation" />
@@ -148,8 +148,15 @@
font-weight: 900;
}
.onboarding-icon.association-failed {
background: #fff0ed;
color: #ad5148;
}
.onboarding-title { margin-top: 22rpx; color: #17211f; font-size: 32rpx; font-weight: 900; }
.onboarding-desc { margin-top: 12rpx; color: #837b72; font-size: 23rpx; line-height: 1.7; text-align: center; }
.onboarding-default-note { margin-top: 14rpx; padding: 14rpx 16rpx; border-radius: 12rpx; background: #eff7f2; color: #39705d; font-size: 21rpx; line-height: 1.55; text-align: left; }
.onboarding-primary { width: 100%; margin-top: 30rpx; }
.onboarding-skip { margin-top: 12rpx; background: transparent; color: #7e776f; font-size: 23rpx; }
.association-retry-box { width: 100%; margin-top: 20rpx; padding: 18rpx; box-sizing: border-box; border-radius: 12rpx; background: #fff5f3; color: #8f4d46; font-size: 22rpx; text-align: center; }
.association-retry-box .onboarding-primary { margin-top: 18rpx; }