Files
JayuCloud/JC-Salon-WeChat/pages/register/index.js
T

83 lines
2.7 KiB
JavaScript
Raw Normal View History

2026-06-04 16:39:06 +08:00
const authApi = require('../../api/auth')
2026-09-07 11:09:34 +08:00
2026-06-04 16:39:06 +08:00
Page({
data: {
2026-09-07 11:09:34 +08:00
step: 1,
role: 'manager',
form: { shopName: '', shopAddress: '', shopId: '' },
registrationTicket: '',
applicationId: '',
2026-09-07 11:09:34 +08:00
shopOptions: [],
shopIndex: 0,
selectedShopName: '',
2026-06-04 16:39:06 +08:00
loading: false,
ticketInvalid: false
2026-06-04 16:39:06 +08:00
},
2026-09-07 12:14:02 +08:00
async onLoad(options) {
const registrationTicket = options && options.registrationTicket ? options.registrationTicket : ''
this.setData({
registrationTicket,
applicationId: options && options.applicationId ? options.applicationId : '',
ticketInvalid: !registrationTicket
})
2026-09-07 12:09:42 +08:00
try {
const shops = await authApi.getAvailableRegistrationShops()
this.setData({
shopOptions: (Array.isArray(shops) ? shops : []).map(item => ({
id: item.id,
name: item.shopName || item.name,
address: item.address || ''
}))
})
2026-09-07 12:09:42 +08:00
} catch (error) {
this.setData({ shopOptions: [] })
}
},
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
2026-09-07 11:09:34 +08:00
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
continueFromRole() { if (!this.data.ticketInvalid) this.setData({ step: 2 }) },
2026-09-07 11:09:34 +08:00
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 })
2026-06-04 16:39:06 +08:00
},
goBackStep() { this.setData({ step: 1 }) },
2026-09-11 15:35:41 +08:00
2026-06-04 16:39:06 +08:00
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
}
2026-06-04 16:39:06 +08:00
this.setData({ loading: true })
try {
await authApi.register({
registrationTicket: this.data.registrationTicket,
applicationId: this.data.applicationId || undefined,
shopName: String(form.shopName || '').trim(),
shopAddress: String(form.shopAddress || '').trim(),
shopId: form.shopId || undefined,
roleType: this.data.role === 'manager' ? 'MANAGER' : 'STAFF',
agreementAccepted: true
})
this.setData({ step: 3, registrationTicket: '' })
} catch (error) {
wx.showToast({ title: error.message || '提交失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
2026-09-07 11:09:34 +08:00
},
back() { wx.reLaunch({ url: '/pages/login/index' }) }
2026-06-04 16:39:06 +08:00
})