完善店员申请关联与预约页面
This commit is contained in:
@@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user