const app = getApp() Page({ data: { pageTop: 0, background: 'transparent', Id: '', UserName: '', Relation: '', BirthMonth: '', ProvinceId: '', CityId: '', Telephone: '', Remark: '', ProvinceName: '', CityName: '', Argument: false, }, onLoad() { app.waitLogin({ type: 0 }).then(() => { app.mpBehavior({ PageName: 'PG_PREAPPLY' }) app.getUserInfo().then((userInfo) => { if (userInfo.ApplyIntentionId) { this.getDetail(userInfo.ApplyIntentionId) this.setData({ Argument: true, }) } }) }) }, getDetail(Id: string) { wx.ajax({ method: 'GET', url: '?r=wtx/user-apply-intention/view', data: { Id, }, }).then((res) => { this.setData({ Id: res.Id, UserName: res.UserName, Relation: res.Relation, BirthMonth: res.BirthMonth, ProvinceId: res.ProvinceId, CityId: res.CityId, Telephone: res.Telephone, Remark: res.Remark, ProvinceName: res.ProvinceName, CityName: res.CityName, }) }) }, handleRelation(e) { const { value } = e.currentTarget.dataset this.setData({ Relation: value, }) }, handleAreaChange(e) { const value = e.detail this.setData({ ProvinceId: value[0].value, CityId: value[1] ? value[1].value : '', ProvinceName: value[0].label, CityName: value[1] ? value[1].label : '', }) }, handlePhoneNumber(e) { if (!e.detail.encryptedData) { return } wx.ajax({ method: 'POST', url: '?r=wtx/user/wx-telephone', data: { iv: e.detail.iv, encryptedData: e.detail.encryptedData, }, }).then((res) => { this.setData({ Telephone: res.Telephone, }) }) }, handleToggleArgument() { this.setData({ Argument: !this.data.Argument, }) }, handleSubmit() { app.mpBehavior({ PageName: 'BTN_PREAPPLY_SUBMIT' }) const { Id, UserName, Relation, BirthMonth, ProvinceId, CityId, Telephone, Remark, Argument } = this.data let toast = '' if (!Telephone) { toast = '请先获取手机号' } if (!ProvinceId) { toast = '请选择所在地区' } if (!BirthMonth) { toast = '请选择您的出生月份' } if (!UserName) { toast = '请输入您的姓名' } if (!Relation) { toast = '请选择您的身份' } if (toast) { wx.showToast({ title: toast, icon: 'none', }) return } const url = Id ? '?r=wtx/user-apply-intention/edit' : '?r=wtx/user-apply-intention/add' wx.ajax({ method: 'POST', url, data: { Id, UserName, Relation, BirthMonth, ProvinceId, CityId, Telephone, Remark, }, loading: true, loadingText: '提交中...', }).then(() => { wx.navigateTo({ url: '/pages/applyFromResult/index', }) }) }, handleBack() { wx.navigateBack() }, }) export {}