You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.3 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// components/recordBill/index.js
const app = getApp();
Component({
data:{
// jobDetail:{}
},
/**
* 组件的属性列表
*/
properties: {
jobDetail: {
type: Object,
value: {},
},
show: {
type: Boolean,
value: false
},
drawerType: {
type: String,
value: ''
}
},
// observers:{
// 'jobDetail': function(newValue){
// console.log(newValue)
// this.setData({
// jobDetail:newValue
// })
// }
// },
/**
* 组件的初始数据
*/
data: {
idCardObj:{},
loading:false
},
ready () {
// console.log(this.data.jobDetail);
// this.setData({
// jobDetail:this.data.jobDetail
// })
},
/**
* 组件的方法列表
*/
methods: {
/**
* 阻止滑动穿透
*
*
*/
modalMove () {
return false;
},
hideModal () {
this.setData({
show: false
})
// this.triggerEvent("hidedrawer", eventDetail);
},
submitModal(e){
var that = this;
console.log('form发生了submit事件携带数据为', e.detail.value)
var formData = {};
var applyData = e.detail.value;
var nameReg = /^[\u4E00-\u9FA5]{2,10}(·[\u4E00-\u9FA5]{2,10}){0,2}$/;
if(nameReg.test(applyData.userName)){
// wx.showToast({
// icon: "none",
// title: '姓名正确',
// });
formData['userName'] = applyData.userName;
}else{
wx.showToast({
icon: "none",
title: '姓名不正确',
});
return
}
that.getIdCardInfo(applyData.idCard);
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证
if(reg.test(applyData.idCard)){
// wx.showToast({
// icon: "none",
// title: '身份证号码正确',
// });
formData['idCard'] = applyData.idCard;
formData['sex'] = that.data.idCardObj.sexCode;
formData['age'] = that.data.idCardObj.age;
// console.log(this.getIdCardInfo(applyData.idCard));
}else{
wx.showToast({
icon: "none",
title: '身份证号码不正确',
});
return
}
const telReg = /^1[3456789]\d{9}$/
if(telReg.test(applyData.tel)){
formData['tel'] = applyData.tel;
}else{
wx.showToast({
icon: "none",
title: '电话号码不正确',
});
return
}
that.setData({
loading:true
})
console.log(this.data.jobDetail);
formData['agencyUserId'] = '';
formData['jobId'] = this.data.jobDetail.id;
wx.request({
url: app.globalData.ip + "/assistant/apply/handler/add",
data: formData,
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
that.hideModal();
that.setData({
loading:false
})
wx.navigateTo({
url: '../../pages/returnMessage/index?type=success&msg=报名成功',
})
},
});
// wx.navigateTo({
// url: '../../pages/returnMessage/index?type=success&msg=报名成功',
// })
},
getIdCardInfo(idCard) {
var idCardObj = {};
//获取用户身份证号码
//获取性别
if (parseInt(idCard.substr(16, 1)) % 2 == 1) {
idCardObj.sexCode = '1' //男
} else {
idCardObj.sexCode = '2' //女
}
//获取出生年月日
var yearBirth = idCard.substring(6, 10);
var monthBirth = idCard.substring(10, 12);
var dayBirth = idCard.substring(12, 14);
var birthDate = yearBirth + "-" + monthBirth + "-" + dayBirth;
//获取当前年月日并计算年龄
var myDate = new Date();
var monthNow = myDate.getMonth() + 1;
var dayNow = myDate.getDay();
var age = myDate.getFullYear() - yearBirth;
if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
age--;
}
//得到年龄
idCardObj.birthDate = birthDate;
idCardObj.age = age;
this.setData({
idCardObj
})
//返回性别和年龄
// return idCardObj;
},
formReset(e) {
this.hideModal();
console.log('form发生了reset事件携带数据为', e.detail.value)
}
}
})