Initial commit of the WeChat mini program, Express backend, and admin console. Co-authored-by: Cursor <cursoragent@cursor.com>
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
const api = require('../../utils/api')
|
|
const authUtil = require('../../utils/auth')
|
|
const activityUtil = require('../../utils/activity')
|
|
|
|
Page({
|
|
data: {
|
|
name: '',
|
|
phone: '',
|
|
company: '',
|
|
submitting: false
|
|
},
|
|
|
|
onLoad(query) {
|
|
this.activityId = (query && query.id) || ''
|
|
api
|
|
.profile()
|
|
.then((profile) => {
|
|
if (!profile) return
|
|
this.setData({
|
|
name: this.data.name || profile.name || '',
|
|
phone: this.data.phone || profile.phone || '',
|
|
company: this.data.company || profile.company || ''
|
|
})
|
|
})
|
|
.catch(() => {})
|
|
},
|
|
|
|
onName(event) {
|
|
this.setData({ name: event.detail.value })
|
|
},
|
|
|
|
onPhone(event) {
|
|
this.setData({ phone: event.detail.value })
|
|
},
|
|
|
|
onCompany(event) {
|
|
this.setData({ company: event.detail.value })
|
|
},
|
|
|
|
submit() {
|
|
if (this.data.submitting) return
|
|
const name = this.data.name.trim()
|
|
const phone = this.data.phone.trim()
|
|
const company = this.data.company.trim()
|
|
if (!name || !phone) {
|
|
wx.showToast({ title: '请填写姓名和手机号', icon: 'none' })
|
|
return
|
|
}
|
|
if (!/^1\d{10}$/.test(phone)) {
|
|
wx.showToast({ title: '请填写正确的手机号', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ submitting: true })
|
|
api
|
|
.signup({
|
|
activityId: this.activityId,
|
|
name: name,
|
|
phone: phone,
|
|
company: company,
|
|
sourceSharer: authUtil.sourceSharer()
|
|
})
|
|
.then(() => {
|
|
wx.showToast({ title: '报名成功', icon: 'success' })
|
|
setTimeout(() => wx.navigateBack(), 600)
|
|
})
|
|
.catch((error) => {
|
|
this.setData({ submitting: false })
|
|
activityUtil.toast(error)
|
|
})
|
|
}
|
|
})
|