774 lines
22 KiB
JavaScript
774 lines
22 KiB
JavaScript
import config from '../../../config'
|
||
import {
|
||
getToken
|
||
} from '../../../utils/auth'
|
||
import {
|
||
findDictCache,
|
||
findCardOcrFront
|
||
} from '../../../api/publics'
|
||
import {
|
||
subdeptsList,
|
||
findSubGroupsList,
|
||
registerSubUsersGL,
|
||
findProSubUsersInfoById
|
||
} from '../../../api/project'
|
||
const app = getApp()
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
limit: 1,
|
||
maxDate: new Date(2088, 1, 1).getTime(),
|
||
form: {},
|
||
active: 0,
|
||
flowNodes: [{
|
||
text: '信息登记'
|
||
}, {
|
||
text: '信息审核'
|
||
}, {
|
||
text: '人员入场'
|
||
}],
|
||
subDeptList: [],
|
||
subGroupList: [],
|
||
userPostList: [],
|
||
eduCationalType: [],
|
||
loadShow: false,
|
||
imgBase: config.baseImgUrl,
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
if (!getToken()) {
|
||
wx.redirectTo({
|
||
url: '../../../login/login',
|
||
})
|
||
}
|
||
if (options && options.id) {
|
||
//查询数据回填...
|
||
this.initData(options.id);
|
||
}
|
||
this.setData({
|
||
"form.projectId": app.globalData.useProjectId,
|
||
"form.projectName": app.globalData.useProjectName
|
||
});
|
||
this.getDictCache();
|
||
this.getAllSubDepts();
|
||
},
|
||
|
||
/**
|
||
* 获取单位
|
||
*/
|
||
getAllSubDepts() {
|
||
let params = "pageNum=1&pageSize=1000&useStatus=0&activeTags=finished&projectId=" + app.globalData.useProjectId;
|
||
subdeptsList(params).then(res => {
|
||
let list = [];
|
||
res.rows.forEach(item => {
|
||
list.push({
|
||
"id": item.id,
|
||
"text": item.subDeptName,
|
||
"type": item.subDeptType,
|
||
"typeName": item.subDeptTypeName,
|
||
"code": item.subDeptCode,
|
||
});
|
||
});
|
||
this.setData({
|
||
subDeptList: list
|
||
});
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 获取班组
|
||
*/
|
||
getAllSubGroups(subDeptId) {
|
||
let params = "pageNum=1&pageSize=1000&useStatus=0&activeTags=finished&projectId=" + app.globalData.useProjectId + "&subDeptId=" + subDeptId;
|
||
findSubGroupsList(params).then(res => {
|
||
let list = [];
|
||
res.rows.forEach(item => {
|
||
list.push({
|
||
"id": item.id,
|
||
"text": item.groupName,
|
||
"groupCode": item.groupCode,
|
||
"craftType": item.craftType,
|
||
"craftTypeName": item.craftTypeName,
|
||
"craftPost": item.craftPost,
|
||
"craftPostName": item.craftPostName,
|
||
});
|
||
});
|
||
this.setData({
|
||
subGroupList: list
|
||
});
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 获取字典缓存数据
|
||
*/
|
||
getDictCache() {
|
||
// 初始化学历类型
|
||
findDictCache("educational_type").then(res => {
|
||
if (res.code == 200) {
|
||
let eduCationalType = [];
|
||
res.data.forEach(item => {
|
||
eduCationalType.push({
|
||
"id": item.dictValue,
|
||
"text": item.dictLabel
|
||
});
|
||
})
|
||
this.setData({
|
||
eduCationalType
|
||
});
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 初始化数据
|
||
* @param {*} id
|
||
*/
|
||
initData(id) {
|
||
findProSubUsersInfoById(id).then(userRes => {
|
||
if (userRes.code == 200 && userRes.data != null) {
|
||
if (userRes.data.userInfos) {
|
||
let userInfosJSON = JSON.parse(userRes.data.userInfos);
|
||
userRes.data.nativePlace = userInfosJSON.nativePlace;
|
||
userRes.data.nation = userInfosJSON.nation;
|
||
userRes.data.address = userInfosJSON.address;
|
||
userRes.data.emergencyContact = userInfosJSON.emergencyContact;
|
||
userRes.data.contactPhone = userInfosJSON.contactPhone;
|
||
userRes.data.bankName = userInfosJSON.bankName;
|
||
userRes.data.bankOffice = userInfosJSON.bankOffice;
|
||
userRes.data.bankCardNo = userInfosJSON.bankCardNo;
|
||
userRes.data.cardImgPos = userInfosJSON.cardImgPos;
|
||
userRes.data.cardImgInv = userInfosJSON.cardImgInv;
|
||
}
|
||
if (userRes.data.cardImgPos) {
|
||
userRes.data.cardImgPos = (this.data.imgBase + userRes.data.cardImgPos).split(',');
|
||
}
|
||
if (userRes.data.cardImgInv) {
|
||
userRes.data.cardImgInv = (this.data.imgBase + userRes.data.cardImgInv).split(',');
|
||
}
|
||
if (userRes.data.userPicture) {
|
||
userRes.data.userPicture = (this.data.imgBase + userRes.data.userPicture).split(',');
|
||
}
|
||
if (userRes.data.subDeptPowerPath) {
|
||
userRes.data.subDeptPowerPath = (this.data.imgBase + userRes.data.subDeptPowerPath).split(',');
|
||
}
|
||
userRes.data._userPost = userRes.data.craftPost;
|
||
this.setData({
|
||
active: 100,
|
||
form: userRes.data
|
||
});
|
||
this.initUserPostList(userRes.data.craftType,userRes.data.id);
|
||
}
|
||
});
|
||
},
|
||
|
||
//取消页面
|
||
cancelSaveView() {
|
||
this.returnToPage()
|
||
},
|
||
|
||
/**
|
||
* 委托代理提交参建单位信息
|
||
*/
|
||
submitSubUsers() {
|
||
let {
|
||
form
|
||
} = this.data;
|
||
//数据效验
|
||
if (!form.projectId) {
|
||
app.toast("数据异常,请刷新页面重试!")
|
||
return false;
|
||
}
|
||
//数据效验
|
||
if (!form.subDeptId || !form.subDeptType || !form.subDeptName) {
|
||
app.toast("请选择参建单位!");
|
||
return false;
|
||
}
|
||
if (!form.subDeptGroup || !form.subDeptGroupName) {
|
||
app.toast("请选择所属班组!");
|
||
return false;
|
||
}
|
||
if (!form._userPost) {
|
||
app.toast("请选择工种岗位!");
|
||
return false;
|
||
}
|
||
if (!form.cardImgPos || form.cardImgPos.length == 0) {
|
||
app.toast("请上传身份证正面照!");
|
||
return false;
|
||
}
|
||
if (!form.cardImgInv || form.cardImgInv.length == 0) {
|
||
app.toast("请上传身份证反面照!");
|
||
return false;
|
||
}
|
||
if (!form.userPicture || form.userPicture.length == 0) {
|
||
app.toast("请上传进场半身近照!");
|
||
return false;
|
||
}
|
||
if (form._userPost == '2' || form._userPost == '6') {
|
||
if (!form.subDeptPowerPath || form.subDeptPowerPath.length == 0) {
|
||
app.toast("请上传委托人单位委托书!");
|
||
return false;
|
||
}
|
||
}
|
||
if (!form.userName) {
|
||
app.toast("请填写人员姓名!");
|
||
return false;
|
||
}
|
||
if (!form.cardCode) {
|
||
app.toast("请填写身份证号!");
|
||
return false;
|
||
} else {
|
||
const cardCodePattern = /^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/;
|
||
if (!cardCodePattern.test(form.cardCode)) {
|
||
app.toast("身份证号码不正确!");
|
||
return false;
|
||
}
|
||
}
|
||
if (!form.userPhone) {
|
||
app.toast("请填写联系电话!");
|
||
return false;
|
||
} else {
|
||
const phonePattern = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
|
||
if (!phonePattern.test(form.userPhone)) {
|
||
app.toast("人员联系电话不正确!");
|
||
return false;
|
||
}
|
||
}
|
||
if (!form.nativePlace) {
|
||
app.toast("请填写籍贯!");
|
||
return false;
|
||
}
|
||
if (!form.nation) {
|
||
app.toast("请填写民族!");
|
||
return false;
|
||
}
|
||
if (!form.address) {
|
||
app.toast("请填写地址!");
|
||
return false;
|
||
}
|
||
if (!form.emergencyContact) {
|
||
app.toast("请填写紧急联系人!");
|
||
return false;
|
||
}
|
||
if (!form.contactPhone) {
|
||
app.toast("请填写紧急联系人电话!");
|
||
return false;
|
||
} else {
|
||
const phonePattern = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
|
||
if (!phonePattern.test(form.contactPhone)) {
|
||
app.toast("紧急联系人电话不正确!");
|
||
return false;
|
||
}
|
||
}
|
||
if (!form.degreeGrade) {
|
||
app.toast("请选择文化程度!");
|
||
return false;
|
||
}
|
||
if (false) {
|
||
if (!form.bankName) {
|
||
app.toast("请填写开户银行名称!");
|
||
return false;
|
||
}
|
||
if (!form.bankOffice) {
|
||
app.toast("请填写开户银行网点!");
|
||
return false;
|
||
}
|
||
if (!form.bankCardNo) {
|
||
app.toast("请填写工资银行卡号!");
|
||
return false;
|
||
}
|
||
}
|
||
let that = this;
|
||
//弹出确认
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: '是否确认保存班组人员信息?',
|
||
success: function (sm) {
|
||
if (sm.confirm) {
|
||
that.submitSubUserForm();
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 委托代理提交参建单位表单
|
||
*/
|
||
submitSubUserForm() {
|
||
let _form = {
|
||
...this.data.form
|
||
};
|
||
this.setData({
|
||
loadShow: true
|
||
})
|
||
let uploadFiles = [];
|
||
if (_form.cardImgPos && _form.cardImgPos.length > 0) {
|
||
uploadFiles.push({
|
||
type: 'cardImgPos',
|
||
path: _form.cardImgPos[0]
|
||
});
|
||
}
|
||
if (_form.cardImgInv && _form.cardImgInv.length > 0) {
|
||
uploadFiles.push({
|
||
type: 'cardImgInv',
|
||
path: _form.cardImgInv[0]
|
||
});
|
||
}
|
||
if (_form.userPicture && _form.userPicture.length > 0) {
|
||
uploadFiles.push({
|
||
type: 'userPicture',
|
||
path: _form.userPicture[0]
|
||
});
|
||
}
|
||
if (_form.subDeptPowerPath && _form.subDeptPowerPath.length > 0) {
|
||
uploadFiles.push({
|
||
type: 'subDeptPowerPath',
|
||
path: _form.subDeptPowerPath[0]
|
||
});
|
||
}
|
||
let that = this;
|
||
let uploads = [];
|
||
uploadFiles.forEach(async (item, idx) => {
|
||
let obj;
|
||
if (item.path.indexOf(this.data.imgBase) > -1) {
|
||
obj = {
|
||
data: {
|
||
data: {
|
||
url: item.path.replace(this.data.imgBase, "")
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
|
||
obj = await that.syncUploadImage(item.path);
|
||
}
|
||
if (item.type == "cardImgPos") {
|
||
_form.cardImgPos = obj.data.data.url;
|
||
}
|
||
if (item.type == "cardImgInv") {
|
||
_form.cardImgInv = obj.data.data.url;
|
||
}
|
||
if (item.type == "userPicture") {
|
||
_form.userPicture = obj.data.data.url;
|
||
}
|
||
if (item.type == "subDeptPowerPath") {
|
||
_form.subDeptPowerPath = obj.data.data.url;
|
||
}
|
||
uploads.push(obj.data.data.url);
|
||
//验证图片上传完毕
|
||
if (uploads.length == uploadFiles.length) {
|
||
let userInfos = {};
|
||
userInfos.nation = _form.nation;
|
||
userInfos.nativePlace = _form.nativePlace;
|
||
userInfos.address = _form.address;
|
||
userInfos.emergencyContact = _form.emergencyContact;
|
||
userInfos.contactPhone = _form.contactPhone;
|
||
userInfos.bankName = _form.bankName;
|
||
userInfos.bankOffice = _form.bankOffice;
|
||
userInfos.bankCardNo = _form.bankCardNo;
|
||
userInfos.cardImgPos = _form.cardImgPos;
|
||
userInfos.cardImgInv = _form.cardImgInv;
|
||
_form.userInfos = JSON.stringify(userInfos);
|
||
_form.craftPost = _form._userPost;
|
||
registerSubUsersGL(_form).then(res => {
|
||
this.setData({
|
||
loadShow: false
|
||
});
|
||
if (res.code == 200) {
|
||
app.toast("保存数据成功!")
|
||
setTimeout(() => {
|
||
wx.redirectTo({
|
||
url: `../list/index`,
|
||
})
|
||
}, 200)
|
||
}
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
//选择参建单位
|
||
onSubDept(e) {
|
||
this.setData({
|
||
subGroupList: [],
|
||
userPostList: [],
|
||
});
|
||
this.getAllSubGroups(e.detail.id);
|
||
let _list = this.data.subDeptList;
|
||
_list.forEach(item => {
|
||
if (item.id == e.detail.id) {
|
||
this.setData({
|
||
"form.subDeptId": item.id,
|
||
"form.subDeptType": item.type,
|
||
"form.subDeptTypeName": item.typeName,
|
||
"form.subDeptName": item.text,
|
||
"form.subDeptCode": item.code,
|
||
"form.subDeptGroup": null,
|
||
"form.subDeptGroupName": null,
|
||
"form.craftType": null,
|
||
"form.craftTypeName": null,
|
||
"form.craftPost": null,
|
||
"form.craftPostName": null,
|
||
"form._userPost": null,
|
||
})
|
||
}
|
||
});
|
||
},
|
||
|
||
//选择所属班组
|
||
onSubGroup(e) {
|
||
this.setData({
|
||
userPostList: [],
|
||
});
|
||
let _list = this.data.subGroupList;
|
||
_list.forEach(item => {
|
||
if (item.id == e.detail.id) {
|
||
this.setData({
|
||
"form.subDeptGroup": item.id,
|
||
"form.subDeptGroupName": item.text,
|
||
"form.craftType": item.craftType,
|
||
"form.craftTypeName": item.craftTypeName,
|
||
"form.craftPost": item.craftPost,
|
||
"form.craftPostName": item.craftPostName,
|
||
"form._userPost": item.craftType=='1'?item.craftPost:null,
|
||
})
|
||
this.initUserPostList(item.craftType,this.data.form.id);
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 初始化用户岗位
|
||
*/
|
||
initUserPostList(type,optId) {
|
||
if (!type) {
|
||
type == "1";
|
||
}
|
||
findDictCache("pro_craft_post").then(res => {
|
||
if (res.code == 200) {
|
||
let list = [];
|
||
res.data.forEach(item => {
|
||
let _rms = item.remark.split(',');
|
||
if (item.cssClass == type && _rms.includes(this.data.form.subDeptType)) {
|
||
if (type == "3") {
|
||
if (item.dictValue != "3022") {
|
||
list.push({
|
||
"id": item.dictValue,
|
||
"text": item.dictLabel
|
||
});
|
||
}
|
||
} else {
|
||
list.push({
|
||
"id": item.dictValue,
|
||
"text": item.dictLabel
|
||
});
|
||
}
|
||
}
|
||
});
|
||
this.setData({
|
||
userPostList: list
|
||
});
|
||
if(!optId && type!="1"){
|
||
this.setData({
|
||
"form._userPost": list.length == 1 ? list[0].id : null
|
||
});
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 选择工种岗位
|
||
* @param {*} e
|
||
*/
|
||
onUserPost(e) {
|
||
this.setData({
|
||
"form._userPost": e.detail.id
|
||
})
|
||
console.log("form",this.data.form);
|
||
},
|
||
|
||
/**
|
||
* 个人身份证正面照
|
||
* @param {*} options
|
||
*/
|
||
fileUploadCardImgPos(options) {
|
||
let file = options.detail;
|
||
this.setData({
|
||
"form.cardImgPos": file
|
||
});
|
||
file.forEach(async (item, idx) => {
|
||
let obj = await this.syncUploadImage(item);
|
||
findCardOcrFront(obj.data.data.url).then(res => {
|
||
if (res.code == 200) {
|
||
if (res.data.nation.indexOf("族") < 0) {
|
||
res.data.nation = res.data.nation + "族";
|
||
}
|
||
this.setData({
|
||
"form.userName": res.data.name,
|
||
"form.cardCode": res.data.cardId,
|
||
"form.nation": res.data.nation,
|
||
"form.nativePlace": res.data.native,
|
||
"form.address": res.data.address
|
||
})
|
||
if (!res.data.name || !res.data.cardId) {
|
||
this.setData({
|
||
"form.cardImgPos": []
|
||
});
|
||
app.toast("身份证正面照识别失败!请重新上传");
|
||
}
|
||
}
|
||
});
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 个人身份证反面照
|
||
* @param {*} options
|
||
*/
|
||
fileUploadCardImgInv(options) {
|
||
let file = options.detail;
|
||
this.setData({
|
||
"form.cardImgInv": file
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 个人半身近照
|
||
* @param {*} options
|
||
*/
|
||
fileUploadUserPicture(options) {
|
||
let file = options.detail;
|
||
this.setData({
|
||
"form.userPicture": file
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 单位委托书
|
||
* @param {*} options
|
||
*/
|
||
fileUploadDeptPower(options) {
|
||
let file = options.detail;
|
||
this.setData({
|
||
"form.subDeptPowerPath": file
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 输入个人姓名
|
||
* @param {*} e
|
||
*/
|
||
inputUserName(e) {
|
||
this.setData({
|
||
"form.userName": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 输入个人身份证号
|
||
* @param {*} e
|
||
*/
|
||
inputUserCode(e) {
|
||
this.setData({
|
||
"form.cardCode": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 输入联系电话
|
||
* @param {*} e
|
||
*/
|
||
inputUserPhone(e) {
|
||
this.setData({
|
||
"form.userPhone": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 个人籍贯
|
||
* @param {*} e
|
||
*/
|
||
inputOriginNative(e) {
|
||
this.setData({
|
||
"form.nativePlace": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 个人民族
|
||
* @param {*} e
|
||
*/
|
||
inputOriginNation(e) {
|
||
this.setData({
|
||
"form.nation": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 个人籍贯地址
|
||
* @param {*} e
|
||
*/
|
||
inputOriginAddress(e) {
|
||
this.setData({
|
||
"form.address": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 紧急联系人
|
||
* @param {*} e
|
||
*/
|
||
inputUrgentUser(e) {
|
||
this.setData({
|
||
"form.emergencyContact": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 紧急联系人电话
|
||
* @param {*} e
|
||
*/
|
||
inputUrgentUserPhone(e) {
|
||
this.setData({
|
||
"form.contactPhone": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 个人文化程度
|
||
* @param {*} e
|
||
*/
|
||
onDegreeGrade(e) {
|
||
this.setData({
|
||
"form.degreeGrade": e.detail.id
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 开户行名称
|
||
* @param {*} e
|
||
*/
|
||
inputBankName(e) {
|
||
this.setData({
|
||
"form.bankName": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 开户行网点
|
||
* @param {*} e
|
||
*/
|
||
inputBankOffice(e) {
|
||
this.setData({
|
||
"form.bankOffice": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 开户行卡号
|
||
* @param {*} e
|
||
*/
|
||
inputBankCardNo(e) {
|
||
this.setData({
|
||
"form.bankCardNo": e.detail.value
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 这里考虑上传图片异步问题,封装为同步
|
||
*/
|
||
syncUploadImage(file) {
|
||
let _baseUrl = config.baseUrl;
|
||
return new Promise((resolve, reject) => {
|
||
wx.uploadFile({
|
||
url: _baseUrl + "/file/upload", // 上传的服务器接口地址
|
||
filePath: file,
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
||
'Authorization': 'Bearer ' + getToken()
|
||
},
|
||
name: "file", //上传的所需字段,后端提供
|
||
formData: {},
|
||
success: (res) => {
|
||
// 上传完成操作
|
||
const data = JSON.parse(res.data)
|
||
resolve({
|
||
data: data
|
||
})
|
||
},
|
||
fail: (err) => {
|
||
//上传失败:修改pedding为reject
|
||
console.log("访问接口失败", err);
|
||
wx.showToast({
|
||
title: "网络出错,上传失败",
|
||
icon: 'none',
|
||
duration: 1000
|
||
});
|
||
reject(err)
|
||
}
|
||
});
|
||
})
|
||
},
|
||
|
||
returnToPage: function () {
|
||
wx.redirectTo({
|
||
url: `../list/index`
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |