You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
397 lines
8.8 KiB
397 lines
8.8 KiB
import {
|
|
addFamilyMember,
|
|
updateFamilyMember,
|
|
getFamilyMember,
|
|
householderRelation
|
|
} from '../../utils/api.js'
|
|
import validate from "../../utils/validate/index.js";
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
submitBtnIsAllowed: false,
|
|
isShowDialog: false,
|
|
pageType: null, // add 新增 edit 编辑 look 查看
|
|
fmData: {
|
|
userName: '',
|
|
idCard: '',
|
|
gender: '',
|
|
birthday: '',
|
|
mobile: '',
|
|
nationValue: '',
|
|
nation: '',
|
|
householdRegisterName: "",
|
|
relation: "",
|
|
outLiveAddressName: "",
|
|
outLiveAddressDetail: "",
|
|
},
|
|
nationList: [],
|
|
houseRelationList: []
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
async onLoad (options) {
|
|
wx.showLoading({
|
|
title: "加载中",
|
|
mask: true,
|
|
});
|
|
let idCard = options.idCard
|
|
this.setData({
|
|
pageType:options.pageType
|
|
})
|
|
if(options.pageType !== 'add'){
|
|
await this.getMemberInfo(idCard)
|
|
}else{
|
|
this.setData({
|
|
'fmData.unitId':options.id
|
|
})
|
|
}
|
|
await this.householderRelationFun()
|
|
wx.hideLoading()
|
|
},
|
|
// 获取成员详情信息
|
|
async getMemberInfo(idCard){
|
|
const res = await getFamilyMember({idCard:idCard})
|
|
if(res.msg === 'success' && res.code === 0){
|
|
this.setData({
|
|
'fmData':res.data,
|
|
})
|
|
if (idCard) {
|
|
this.handleValidBlur('',idCard)
|
|
}
|
|
}
|
|
},
|
|
// 获取与户主关系
|
|
async householderRelationFun(){
|
|
const res = await householderRelation()
|
|
if(res.msg === 'success' && res.code === 0){
|
|
this.setData({
|
|
'houseRelationList':res.data,
|
|
})
|
|
}
|
|
},
|
|
nameSync(e){
|
|
this.setData({
|
|
'fmData.userName' : e.detail.value
|
|
})
|
|
},
|
|
idCardSync(e){
|
|
this.setData({
|
|
'fmData.idCard' : e.detail.value
|
|
})
|
|
},
|
|
mobileSync(e){
|
|
this.setData({
|
|
'fmData.mobile' : e.detail.value
|
|
})
|
|
},
|
|
nationSync(e){
|
|
this.setData({
|
|
'fmData.nation' : e.detail.value
|
|
})
|
|
},
|
|
nationSyncPicker(e){
|
|
this.setData({
|
|
'fmData.nationValue' : this.data.nationList[e.detail.value].dictValue,
|
|
'fmData.nation' : this.data.nationList[e.detail.value].dictName
|
|
})
|
|
},
|
|
houseSyncPicker(e){
|
|
this.setData({
|
|
'fmData.houseRelation' : this.data.houseRelationList[e.detail.value].dictValue,
|
|
'fmData.relation' : this.data.houseRelationList[e.detail.value].dictName
|
|
})
|
|
},
|
|
householdRegisterSync(e){
|
|
this.setData({
|
|
'fmData.householdRegisterName' : e.detail.value
|
|
})
|
|
},
|
|
outLiveAddressSync(e){
|
|
this.setData({
|
|
'fmData.outLiveAddressName' : e.detail.value
|
|
})
|
|
},
|
|
addressSync(e){
|
|
this.setData({
|
|
'fmData.outLiveAddressDetail' : e.detail.value
|
|
})
|
|
},
|
|
handleValidBlur (e,val) {
|
|
var fmData = this.data.fmData;
|
|
var right = this.identityCodeValid(val ? val : e.detail.value);
|
|
if (right) {
|
|
fmData.birthday = this.getBirthday(this.data.fmData.idCard);
|
|
fmData.gender = this.getGender(this.data.fmData.idCard);
|
|
this.setData({ fmData });
|
|
}else {
|
|
fmData.idCard = '';
|
|
this.setData({ fmData });
|
|
wx.showToast({
|
|
title: '身份证号不正确,请重新输入',
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
},
|
|
// 校验身份证是否正确
|
|
identityCodeValid (idcode) {
|
|
var weightFactor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
|
|
// 校验码
|
|
var checkCode = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
|
|
|
|
var code = idcode + ''
|
|
var last = idcode[17]// 最后一位
|
|
|
|
var seventeen = code.substring(0, 17)
|
|
|
|
// ISO 7064:1983.MOD 11-2
|
|
// 判断最后一位校验码是否正确
|
|
var arr = seventeen.split('')
|
|
var len = arr.length
|
|
var num = 0
|
|
for (var i = 0; i < len; i++) {
|
|
num = num + arr[i] * weightFactor[i]
|
|
}
|
|
|
|
// 获取余数
|
|
var resisue = num % 11
|
|
var lastNo = checkCode[resisue]
|
|
|
|
// 格式的正则
|
|
// 正则思路
|
|
/*
|
|
第一位不可能是0
|
|
第二位到第六位可以是0-9
|
|
第七位到第十位是年份,所以七八位为19或者20
|
|
十一位和十二位是月份,这两位是01-12之间的数值
|
|
十三位和十四位是日期,是从01-31之间的数值
|
|
十五,十六,十七都是数字0-9
|
|
十八位可能是数字0-9,也可能是X
|
|
*/
|
|
var idcardPatter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/
|
|
|
|
// 判断格式是否正确
|
|
var format = idcardPatter.test(idcode)
|
|
|
|
// 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
|
|
return !!(last === lastNo && format)
|
|
},
|
|
getBirthday: function (psidno) {
|
|
var birthdayno, birthdaytemp;
|
|
if (psidno.length === 18) {
|
|
birthdayno = psidno.substring(6, 14);
|
|
}
|
|
else if (psidno.length === 15) {
|
|
birthdaytemp = psidno.substring(6, 12);
|
|
birthdayno = '19' + birthdaytemp;
|
|
}
|
|
else {
|
|
return '';
|
|
}
|
|
var birthday = birthdayno.substring(0, 4) + '-' + birthdayno.substring(4, 6) + '-' + birthdayno.substring(6, 8);
|
|
return birthday;
|
|
},
|
|
getGender (psidno) {
|
|
var num = psidno.charAt(16);
|
|
if (num % 2 == 0) {
|
|
return '女';
|
|
}else {
|
|
return '男';
|
|
}
|
|
},
|
|
|
|
// 编辑按钮点击事件
|
|
editTap () {
|
|
if (this.data.fmData.idCard) {
|
|
this.handleValidBlur('',this.data.fmData.idCard)
|
|
}
|
|
this.setData({
|
|
pageType: 'edit'
|
|
})
|
|
},
|
|
// 取消编辑
|
|
closeEditTap () {
|
|
this.setData({
|
|
pageType: 'look'
|
|
})
|
|
},
|
|
|
|
|
|
// 注册
|
|
async submit() {
|
|
if (!this.computeSubmitBtnIsAllowed(false)) return;
|
|
|
|
const { fmData } = this.data;
|
|
if (fmData.gender === '男') {
|
|
fmData.gender = '1'
|
|
} else if (fmData.gender === '女') {
|
|
fmData.gender = '2'
|
|
}
|
|
this.setData({ fmData })
|
|
wx.showLoading({
|
|
title: "提交中",
|
|
mask: true,
|
|
});
|
|
const res = await addFamilyMember({...fmData})
|
|
wx.hideLoading();
|
|
|
|
if (res.msg === "success" && res.code === 0) {
|
|
wx.showToast({
|
|
title: "提交成功",
|
|
duration: 2000,
|
|
});
|
|
setTimeout(function () {
|
|
wx.navigateBack()
|
|
}, 1000)
|
|
|
|
// wxRedirectTo("../index", {});
|
|
}
|
|
},
|
|
|
|
// 修改提交
|
|
async editSubmit () {
|
|
if (!this.computeSubmitBtnIsAllowed(false)) return;
|
|
|
|
const { fmData } = this.data;
|
|
if (fmData.gender === '男') {
|
|
fmData.gender = '1'
|
|
} else if (fmData.gender === '女') {
|
|
fmData.gender = '2'
|
|
}
|
|
this.setData({ fmData })
|
|
wx.showLoading({
|
|
title: "提交中",
|
|
mask: true,
|
|
});
|
|
const res = await updateFamilyMember({...fmData})
|
|
wx.hideLoading();
|
|
|
|
if (res.msg === "success" && res.code === 0) {
|
|
wx.showToast({
|
|
title: "提交成功",
|
|
duration: 2000,
|
|
});
|
|
|
|
setTimeout(function () {
|
|
wx.navigateBack()
|
|
}, 1000)
|
|
}
|
|
},
|
|
|
|
|
|
// 更新data数据后需主动触发
|
|
$afterUpdateData() {
|
|
this.computeSubmitBtnIsAllowed();
|
|
},
|
|
|
|
|
|
// 校验
|
|
computeSubmitBtnIsAllowed(isQuiet = true) {
|
|
const { fmData } = this.data,
|
|
vlt = validate(fmData, {
|
|
// surname: [
|
|
// {
|
|
// rule: "required",
|
|
// message: "请先输入成员【姓】",
|
|
// },
|
|
// ],
|
|
|
|
userName: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入成员【姓名】",
|
|
},
|
|
],
|
|
|
|
idCard: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入成员【身份证号】",
|
|
},
|
|
],
|
|
|
|
mobile: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入成员【手机号】",
|
|
},
|
|
{
|
|
rule: "mobile",
|
|
message: "【手机号】格式不正确",
|
|
},
|
|
]
|
|
});
|
|
if (!vlt.valid) {
|
|
if (!isQuiet) {
|
|
wx.showToast({
|
|
title: vlt.error,
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
this.setData({
|
|
submitBtnIsAllowed: false,
|
|
});
|
|
return false;
|
|
} else {
|
|
this.setData({
|
|
submitBtnIsAllowed: true,
|
|
});
|
|
return true;
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
})
|