版权声明:正在学习中,有错误欢迎指出。感谢比❤❤~ https://blog.csdn.net/gx17864373822/article/details/82425273
index.js
formSubmit: function(e) {
var that = this
var areaid = that.data.index
// console.log(that.data.index,'用户选择的区域下标')
// console.log(that.data.selectData,'所有区域')
var mobile = /^1\d{10}$/;
var isMobile = mobile.exec(e.detail.value.phone)
console.log(e.detail.value.phone, "输入手机号")
if (e.detail.value.name == '') {
wx.showModal({
title: '姓名不能为空',
content: '',
})
return;
}
if (e.detail.value.phone == '') {
wx.showModal({
title: '手机号不能为空',
content: '',
})
return;
}
if (e.detail.value.phone.length != 11){
wx.showModal({
title: '手机号输入位数有误!',
content: '',
})
return;
}
else if (!isMobile){
wx.showModal({
title: '手机号输入有误,请重新检查填写!',
content: '',
})
return;
}
// 用户报名
setTimeout(
wx.request({
url: app.globalData.url + "/api/apply",
method: "POST",
data: {
name: e.detail.value.name, // 用户姓名
phone: e.detail.value.phone, // 用户电话
id: app.globalData.userInfo.id, // 用户id
salesmanid: that.data.salesman.id, // 业务员id
type: that.data.salesman.type, // 报名类型 1:卡片消息 2:二维码
activityid: that.data.activityid, // 活动id
areaid: that.data.selectData[areaid]['id'], // 区域id
},
success: function(res) {
// console.log(res, '报名后返回的信息')
if (res.data.code == 1) {
wx.showToast({
title: '报名成功',
icon: 'success',
duration: 3000
}),
wx.request({
url: app.globalData.url + "/api/template",
method: "POST",
data: {
id: app.globalData.userInfo.id,
formId: e.detail.formId,
},
success: function(res) {
// console.log(res, "发送模板消息");
}
})
} else if (res.data.code == 0) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 3000
})
} else {
wx.showToast({
title: '报名失败,请稍后重试!',
icon: 'none',
duration: 3000
})
}
}
}), 5000)
},