YZProjectCloud/yanzhu-ui-app/miniprogram/pages/project_subdepts/add/index.js

843 lines
26 KiB
JavaScript
Raw Blame History

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.

import config from '../../../config'
import {
getToken
} from '../../../utils/auth'
import {
findDictCache,
findCardOcrFront
} from '../../../api/publics'
import {
registerSubDeptsGL,
findProSubDeptsInfoById
} from '../../../api/project'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
limit: 1,
maxDate: new Date(2088, 1, 1).getTime(),
form: {
subDeptType: "3",
subDeptName: "",
subDeptCode: "",
businessLicensePath: "",
subDeptInfos: {
legalPersonCardImgPos: "",
legalPersonCardImgInv: "",
legalPerson: "",
legalPersonCard: ""
},
contractInfos: "",
useDates: "",
startWorkDates: "",
endWorkDates: "",
leaderCardImgPos: "",
leaderCardImgInv: "",
leaderUserPicture: "",
subDeptLeaderPowerPath: "",
subDeptLeaderName: "",
subDeptLeaderCode: "",
subDeptLeaderPhone: "",
nation: "",
nativePlace: "",
address: "",
emergencyContact: "",
contactPhone: "",
leaderDegreeGrade: ""
},
eduCationalType: [],
subDeptTypeList: [],
active: 0,
flowNodes: [{
text: '信息登记'
}, {
text: '信息审核'
}, {
text: '单位入场'
}],
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();
},
/**
* 获取字典缓存数据
*/
getDictCache() {
// 初始化单位类型
findDictCache("sub_dept_type").then(res => {
if (res.code == 200) {
let list = [];
res.data.forEach(item => {
if (item.dictValue != "1") {
list.push({
"id": item.dictValue,
"text": item.dictLabel
});
}
});
this.setData({
subDeptTypeList: list
});
}
});
// 初始化学历类型
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) {
findProSubDeptsInfoById(id).then(deptRes => {
if (deptRes.code == 200 && deptRes.data) {
if (deptRes.data.proProjectInfoSubdeptsUsers) {
deptRes.data.leaderDegreeGrade = deptRes.data.proProjectInfoSubdeptsUsers.degreeGrade;
deptRes.data.eduFilePath = deptRes.data.proProjectInfoSubdeptsUsers.eduFilePath;
deptRes.data.subStep = deptRes.data.proProjectInfoSubdeptsUsers.subStep;
if (deptRes.data.proProjectInfoSubdeptsUsers.userPicture) {
deptRes.data.leaderUserPicture = (this.data.imgBase + deptRes.data.proProjectInfoSubdeptsUsers.userPicture).split(',');
}
if (deptRes.data.proProjectInfoSubdeptsUsers.subDeptPowerPath) {
deptRes.data.subDeptLeaderPowerPath = (this.data.imgBase + deptRes.data.proProjectInfoSubdeptsUsers.subDeptPowerPath).split(',');
}
if (deptRes.data.proProjectInfoSubdeptsUsers.userInfos) {
let userInfosJSON = JSON.parse(deptRes.data.proProjectInfoSubdeptsUsers.userInfos);
if (userInfosJSON.cardImgPos) {
deptRes.data.leaderCardImgPos = (this.data.imgBase + userInfosJSON.cardImgPos).split(',');
}
if (userInfosJSON.cardImgInv) {
deptRes.data.leaderCardImgInv = (this.data.imgBase + userInfosJSON.cardImgInv).split(',');
}
deptRes.data.proProjectInfoSubdeptsUsers.userInfos = userInfosJSON;
deptRes.data.nativePlace = userInfosJSON.nativePlace;
deptRes.data.nation = userInfosJSON.nation;
deptRes.data.address = userInfosJSON.address;
deptRes.data.emergencyContact = userInfosJSON.emergencyContact;
deptRes.data.contactPhone = userInfosJSON.contactPhone;
}
}
if (deptRes.data.businessLicensePath) {
deptRes.data.businessLicensePath = (this.data.imgBase + deptRes.data.businessLicensePath).split(',');
}
if (deptRes.data.subDeptInfos) {
let subDeptInfosJSON = JSON.parse(deptRes.data.subDeptInfos);
deptRes.data.subDeptInfos = subDeptInfosJSON;
if (deptRes.data.subDeptInfos.legalPersonCardImgPos) {
deptRes.data.subDeptInfos.legalPersonCardImgPos = (this.data.imgBase + deptRes.data.subDeptInfos.legalPersonCardImgPos).split(',');
}
if (deptRes.data.subDeptInfos.legalPersonCardImgInv) {
deptRes.data.subDeptInfos.legalPersonCardImgInv = (this.data.imgBase + deptRes.data.subDeptInfos.legalPersonCardImgInv).split(',');
}
}
this.setData({
active: 100,
form: deptRes.data
});
}
});
},
//取消页面
cancelSaveView() {
this.returnToPage()
},
/**
* 委托代理提交参建单位信息
*/
submitSubDeptValues() {
let {
form
} = this.data;
let subDeptInfos = form.subDeptInfos;
if (!subDeptInfos) {
subDeptInfos = {};
}
//数据效验
if (!form.projectId) {
app.toast("数据异常,请刷新页面重试!")
return false;
}
//数据效验
if (!form.subDeptType) {
app.toast("请选择单位类型!");
return false;
}
if (!form.subDeptName) {
app.toast("请填写单位名称!");
return false;
}
if (!form.subDeptCode) {
app.toast("请填写单位社会信用代码!");
return false;
}
if (!form.useDates) {
app.toast("请选择进入场地时间!");
return false;
}
if (form.subDeptType == "4" || form.subDeptType == "5") {
if (!form.businessLicensePath || form.businessLicensePath.length == 0) {
app.toast("请上传营业执照副本!");
return false;
}
if (!subDeptInfos.legalPersonCardImgPos || subDeptInfos.legalPersonCardImgPos.length == 0) {
app.toast("请上传法人身份证正面照!");
return false;
}
if (!subDeptInfos.legalPersonCardImgInv || subDeptInfos.legalPersonCardImgInv.length == 0) {
app.toast("请上传法人身份证反面照!");
return false;
}
if (!subDeptInfos.legalPerson) {
app.toast("请填写法人姓名!");
return false;
}
if (!subDeptInfos.legalPersonCard) {
app.toast("请填写法人身份证号!");
return false;
}
if (!form.contractInfos) {
app.toast("请填写合同约定的承包范围!");
return false;
}
if (!form.startWorkDates) {
app.toast("请选择计划开工时间!");
return false;
}
if (!form.endWorkDates) {
app.toast("请选择计划完工时间!");
return false;
}
if (!form.leaderCardImgPos || form.leaderCardImgPos.length == 0) {
app.toast("请上传委托人身份证正面照!");
return false;
}
if (!form.leaderCardImgInv || form.leaderCardImgInv.length == 0) {
app.toast("请上传委托人身份证反面照!");
return false;
}
if (!form.leaderUserPicture || form.leaderUserPicture.length == 0) {
app.toast("请上传委托人半身近照!");
return false;
}
if (!form.subDeptLeaderPowerPath || form.subDeptLeaderPowerPath.length == 0) {
app.toast("请上传委托人单位委托书!");
return false;
}
if (!form.subDeptLeaderName) {
app.toast("请填写委托人姓名!");
return false;
}
if (!form.subDeptLeaderCode) {
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.subDeptLeaderCode)) {
app.toast("身份证号码不正确!");
return false;
}
}
if (!form.subDeptLeaderPhone) {
app.toast("请填写委托人联系电话!");
return false;
}else{
const phonePattern = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
if (!phonePattern.test(form.subDeptLeaderPhone)) {
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.leaderDegreeGrade) {
app.toast("请选择委托人学历信息!");
return false;
}
}
let that = this;
//弹出确认
wx.showModal({
title: '提示',
content: '是否确认保存参建单位信息?',
success: function (sm) {
if (sm.confirm) {
that.submitSubDeptForm();
}
}
})
},
/**
* 委托代理提交参建单位表单
*/
submitSubDeptForm() {
let _form = {
...this.data.form
};
let subDeptInfos = {
..._form.subDeptInfos
};
this.setData({
loadShow: true
})
let uploadFiles = [];
if (_form.businessLicensePath && _form.businessLicensePath.length > 0) {
uploadFiles.push({
type: 'businessLicensePath',
path: _form.businessLicensePath[0]
});
}
if (subDeptInfos.legalPersonCardImgPos && subDeptInfos.legalPersonCardImgPos.length > 0) {
uploadFiles.push({
type: 'legalPersonCardImgPos',
path: subDeptInfos.legalPersonCardImgPos[0]
});
}
if (subDeptInfos.legalPersonCardImgInv && subDeptInfos.legalPersonCardImgInv.length > 0) {
uploadFiles.push({
type: 'legalPersonCardImgInv',
path: subDeptInfos.legalPersonCardImgInv[0]
});
}
if (_form.leaderCardImgPos && _form.leaderCardImgPos.length > 0) {
uploadFiles.push({
type: 'leaderCardImgPos',
path: _form.leaderCardImgPos[0]
});
}
if (_form.leaderCardImgInv && _form.leaderCardImgInv.length > 0) {
uploadFiles.push({
type: 'leaderCardImgInv',
path: _form.leaderCardImgInv[0]
});
}
if (_form.leaderUserPicture && _form.leaderUserPicture.length > 0) {
uploadFiles.push({
type: 'leaderUserPicture',
path: _form.leaderUserPicture[0]
});
}
if (_form.subDeptLeaderPowerPath && _form.subDeptLeaderPowerPath.length > 0) {
uploadFiles.push({
type: 'subDeptLeaderPowerPath',
path: _form.subDeptLeaderPowerPath[0]
});
}
let that = this;
let uploads = [];
if (uploadFiles.length > 0) {
uploadFiles.forEach(async (item) => {
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 == "businessLicensePath") {
_form.businessLicensePath = obj.data.data.url;
}
if (item.type == "legalPersonCardImgPos") {
subDeptInfos.legalPersonCardImgPos = obj.data.data.url;
}
if (item.type == "legalPersonCardImgInv") {
subDeptInfos.legalPersonCardImgInv = obj.data.data.url;
}
if (item.type == "leaderCardImgPos") {
_form.leaderCardImgPos = obj.data.data.url;
}
if (item.type == "leaderCardImgInv") {
_form.leaderCardImgInv = obj.data.data.url;
}
if (item.type == "leaderUserPicture") {
_form.leaderUserPicture = obj.data.data.url;
}
if (item.type == "subDeptLeaderPowerPath") {
_form.subDeptLeaderPowerPath = obj.data.data.url;
}
uploads.push(obj.data.data.url);
//验证图片上传完毕
if (uploads.length == uploadFiles.length) {
_form.subDeptInfos = JSON.stringify(subDeptInfos);
let leaderUserInfos = {};
leaderUserInfos.nation = _form.nation;
leaderUserInfos.nativePlace = _form.nativePlace;
leaderUserInfos.address = _form.address;
leaderUserInfos.emergencyContact = _form.emergencyContact;
leaderUserInfos.contactPhone = _form.contactPhone;
leaderUserInfos.cardImgPos = _form.leaderCardImgPos;
leaderUserInfos.cardImgInv = _form.leaderCardImgInv;
_form.leaderUserInfos = JSON.stringify(leaderUserInfos);
if (_form.proProjectInfoSubdeptsUsers && _form.proProjectInfoSubdeptsUsers.userInfos) {
_form.proProjectInfoSubdeptsUsers.userInfos = JSON.stringify(_form.proProjectInfoSubdeptsUsers.userInfos);
}
registerSubDeptsGL(_form).then(res => {
this.setData({
loadShow: false
});
if (res.code == 200) {
app.toast("保存数据成功!")
setTimeout(() => {
wx.redirectTo({
url: `../list/index`,
})
}, 200)
}
});
}
});
} else {
_form.subDeptInfos = JSON.stringify(subDeptInfos);
let leaderUserInfos = {};
leaderUserInfos.nation = _form.nation;
leaderUserInfos.nativePlace = _form.nativePlace;
leaderUserInfos.address = _form.address;
leaderUserInfos.emergencyContact = _form.emergencyContact;
leaderUserInfos.contactPhone = _form.contactPhone;
leaderUserInfos.cardImgPos = _form.leaderCardImgPos;
leaderUserInfos.cardImgInv = _form.leaderCardImgInv;
_form.leaderUserInfos = JSON.stringify(leaderUserInfos);
registerSubDeptsGL(_form).then(res => {
this.setData({
loadShow: false
});
if (res.code == 200) {
app.toast("新增数据成功!")
setTimeout(() => {
wx.redirectTo({
url: `../list/index`,
})
}, 200)
}
});
}
},
//选择单位类型
onSubDeptType(e) {
this.setData({
"form.subDeptType": e.detail.id
})
},
//填写单位名称
onSubDeptName(e) {
this.setData({
"form.subDeptName": e.detail.value
})
},
//填写信用代码
onSubDeptCode(e) {
this.setData({
"form.subDeptCode": e.detail.value
})
},
/**
* 营业执照副本
* @param {*} options
*/
fileUpload0(options) {
let file = options.detail;
this.setData({
"form.businessLicensePath": file
});
},
/**
* 法人身份证正面
* @param {*} options
*/
fileUpload1(options) {
let file = options.detail;
this.setData({
"form.subDeptInfos.legalPersonCardImgPos": file
});
file.forEach(async (item, idx) => {
let obj = await this.syncUploadImage(item);
findCardOcrFront(obj.data.data.url).then(res => {
if (res.code == 200) {
this.setData({
"form.subDeptInfos.legalPerson": res.data.name,
"form.subDeptInfos.legalPersonCard": res.data.cardId
})
if (!res.data.name || !res.data.cardId) {
this.setData({
"form.subDeptInfos.legalPersonCardImgPos": []
});
app.toast("身份证正面照识别失败!请重新上传");
}
}
});
})
},
/**
* 法人身份证反面
* @param {*} options
*/
fileUpload2(options) {
let file = options.detail;
this.setData({
"form.subDeptInfos.legalPersonCardImgInv": file
});
},
/** 单位法人姓名 */
inputInfoslegalPerson(e) {
this.setData({
"form.subDeptInfos.legalPerson": e.detail.value
})
},
/** 单位法人身份证号 */
inputInfoslegalPersonCard(e) {
this.setData({
"form.subDeptInfos.legalPersonCard": e.detail.value
})
},
/** 合同约定的承包范围 */
inputContractInfos(e) {
this.setData({
"form.contractInfos": e.detail.value
})
},
/** 进入场地时间 */
onInputTime0(e) {
this.setData({
"form.useDates": e.detail
})
},
/** 计划开工时间 */
onInputTime1(e) {
this.setData({
"form.startWorkDates": e.detail
})
},
/** 计划完工时间 */
onInputTime2(e) {
this.setData({
"form.endWorkDates": e.detail
})
},
/**
* 委托人身份证反面
* @param {*} options
*/
fileUpload3(options) {
let file = options.detail;
this.setData({
"form.leaderCardImgPos": file
});
file.forEach(async (item, idx) => {
let obj = await this.syncUploadImage(item);
findCardOcrFront(obj.data.data.url).then(res => {
if (res.code == 200) {
this.setData({
"form.subDeptLeaderName": res.data.name,
"form.subDeptLeaderCode": 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.leaderCardImgPos": []
});
app.toast("身份证正面照识别失败!请重新上传");
}
}
});
})
},
/**
* 委托人身份证反面
* @param {*} options
*/
fileUpload4(options) {
let file = options.detail;
this.setData({
"form.leaderCardImgInv": file
});
},
/**
* 委托人半身照
* @param {*} options
*/
fileUpload5(options) {
let file = options.detail;
this.setData({
"form.leaderUserPicture": file
});
},
/**
* 委托人委托书
* @param {*} options
*/
fileUpload6(options) {
let file = options.detail;
this.setData({
"form.subDeptLeaderPowerPath": file
});
},
/**
* 输入负责人姓名
* @param {*} e
*/
inputLeaderName(e) {
this.setData({
"form.subDeptLeaderName": e.detail.value
})
},
/**
* 输入负责人身份证号
* @param {*} e
*/
inputLeaderCode(e) {
this.setData({
"form.subDeptLeaderCode": e.detail.value
})
},
/**
* 输入负责人联系电话
* @param {*} e
*/
subDeptLeaderPhone(e) {
this.setData({
"form.subDeptLeaderPhone": 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
*/
onLeaderDegreeGrade(e) {
this.setData({
"form.leaderDegreeGrade": e.detail.id
})
},
/**
* 这里考虑上传图片异步问题,封装为同步
*/
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() {
}
})