192 lines
7.1 KiB
JavaScript
192 lines
7.1 KiB
JavaScript
const authApi = require('../../api/auth')
|
|
|
|
Page({
|
|
data: {
|
|
step: 1,
|
|
role: 'manager',
|
|
form: { shopName: '', shopAddress: '', shopId: '', shopLongitude: '', shopLatitude: '', applicantNickname: '', applicantAvatarFileId: '', applicantAvatarUrl: '' },
|
|
registrationTicket: '',
|
|
applicationId: '',
|
|
shopOptions: [],
|
|
shopSelectorItems: [],
|
|
shopSheetVisible: false,
|
|
shopKeyword: '',
|
|
shopLoading: false,
|
|
shopError: '',
|
|
selectedShopName: '',
|
|
loading: false,
|
|
avatarUploading: false,
|
|
ticketInvalid: false,
|
|
registrationStatus: null,
|
|
registrationStatusText: '',
|
|
contentStatusText: '',
|
|
contentStatusReason: ''
|
|
},
|
|
|
|
async onLoad(options) {
|
|
const registrationTicket = options && options.registrationTicket ? options.registrationTicket : ''
|
|
this.setData({
|
|
registrationTicket,
|
|
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,
|
|
shopSelectorItems: this.filterShops(shopOptions, this.data.shopKeyword)
|
|
})
|
|
} catch (error) {
|
|
this.setData({ shopOptions: [], shopSelectorItems: [], shopError: error.message || '门店列表加载失败' })
|
|
} finally {
|
|
this.setData({ shopLoading: false })
|
|
}
|
|
},
|
|
|
|
onInput(event) {
|
|
const field = event.currentTarget.dataset.field
|
|
const value = event.detail.value
|
|
const next = { [`form.${field}`]: value }
|
|
if (field === 'shopAddress') {
|
|
next['form.shopLongitude'] = ''
|
|
next['form.shopLatitude'] = ''
|
|
}
|
|
this.setData(next)
|
|
},
|
|
|
|
chooseShopLocation() {
|
|
wx.chooseLocation({
|
|
success: result => {
|
|
if (!result || (!result.address && !result.name)) return
|
|
this.setData({
|
|
'form.shopAddress': result.address || result.name || '',
|
|
'form.shopLongitude': result.longitude || '',
|
|
'form.shopLatitude': result.latitude || ''
|
|
})
|
|
},
|
|
fail: error => {
|
|
if (!String(error && error.errMsg || '').includes('cancel')) wx.showToast({ title: '地图选点失败,可继续手动填写地址', icon: 'none' })
|
|
}
|
|
})
|
|
},
|
|
|
|
async chooseApplicantAvatar(event) {
|
|
try {
|
|
const filePath = event && event.detail ? event.detail.avatarUrl : ''
|
|
if (!filePath) return
|
|
this.setData({ avatarUploading: true })
|
|
const result = await authApi.uploadRegistrationAvatar(this.data.registrationTicket, filePath)
|
|
this.setData({ 'form.applicantAvatarFileId': result.fileId || result.id, 'form.applicantAvatarUrl': filePath })
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '头像上传失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ avatarUploading: false })
|
|
}
|
|
},
|
|
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 shop = event.detail.item
|
|
if (shop) this.setData({ selectedShopName: shop.name, 'form.shopId': shop.id, shopSheetVisible: false })
|
|
},
|
|
|
|
goBackStep() { this.setData({ step: 1 }) },
|
|
|
|
mapRegistrationStatus(result) {
|
|
const statusText = {
|
|
APPROVED: '已通过',
|
|
REJECTED: '已驳回',
|
|
PENDING_ADMIN: '待平台审核',
|
|
PENDING_MANAGER: '待店长审核'
|
|
}[String(result && result.status || '').toUpperCase()] || '状态未知'
|
|
const moderationStatus = String(result && result.contentModerationStatus || '').toUpperCase()
|
|
const contentStatusText = {
|
|
APPROVED: '资料内容审核已通过',
|
|
REJECTED: '资料内容审核未通过',
|
|
PENDING: '资料内容正在审核,审核完成前不会展示',
|
|
RETRY: '资料内容待重新审核,审核完成前不会展示',
|
|
MISSING: '资料尚未进入审核,请联系门店负责人确认'
|
|
}[moderationStatus] || ''
|
|
return {
|
|
registrationStatus: result || null,
|
|
registrationStatusText: statusText,
|
|
contentStatusText,
|
|
contentStatusReason: result && result.contentModerationReason || ''
|
|
}
|
|
},
|
|
|
|
async submit() {
|
|
const form = this.data.form
|
|
if (!this.data.registrationTicket) {
|
|
wx.showToast({ title: '注册票据已失效,请返回重新快捷登录', icon: 'none' })
|
|
return
|
|
}
|
|
if (this.data.role === 'manager' && !String(form.shopName || '').trim()) {
|
|
wx.showToast({ title: '请输入店铺名称', icon: 'none' }); return
|
|
}
|
|
if (this.data.role === 'staff' && !form.shopId) {
|
|
wx.showToast({ title: '请选择要加入的店铺', icon: 'none' }); return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const result = await authApi.register({
|
|
registrationTicket: this.data.registrationTicket,
|
|
applicationId: this.data.applicationId || undefined,
|
|
shopName: String(form.shopName || '').trim(),
|
|
shopAddress: String(form.shopAddress || '').trim(),
|
|
shopLongitude: form.shopLongitude ? Number(form.shopLongitude) : undefined,
|
|
shopLatitude: form.shopLatitude ? Number(form.shopLatitude) : undefined,
|
|
shopId: form.shopId || undefined,
|
|
roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF',
|
|
applicantNickname: this.data.role === 'staff' ? String(form.applicantNickname || '').trim() || undefined : undefined,
|
|
applicantAvatarFileId: this.data.role === 'staff' ? form.applicantAvatarFileId || undefined : undefined,
|
|
agreementAccepted: true
|
|
})
|
|
this.setData({ step: 3, registrationTicket: '', ...this.mapRegistrationStatus(result) })
|
|
} catch (error) {
|
|
const message = String(error.message || '提交失败')
|
|
if (/注册票据|注册凭证|一次性.*(失效|消费)|票据.*(失效|过期|已使用)/.test(message)) {
|
|
this.setData({ ticketInvalid: true })
|
|
return
|
|
}
|
|
wx.showToast({ title: message, icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
back() { wx.reLaunch({ url: '/pages/login/index' }) }
|
|
})
|