jhwxapp/miniprogram/pages/tempRegistration/index.js

860 lines
23 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.

// pages/tempRegistration/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
laborTeamIdList: [],
workTypeList: [],
//身份证正面信息
id_card_name: '',
id_card_no: '',
id_card_address: '',
birth: '',
sex: '',
nation: '',
//身份证反面信息
sign_of_origin: '',
sign_of_date: '',
end_of_date: '',
//身份证正面地址
id_card_front: '',
//身份证反面地址
id_card_back: '',
//考勤半身照
half_body_photo: '',
loadShow: false,
//用户openId
openId: '',
//归属劳务公司(实名制劳务公司)
laborCompanyName: '',
laborCompanyId: '',
//归属劳务公司实名制班组id
laborTeamName: '',
laborTeamId: '',
//归属工种
workTypeId: '',
workTypeName: '',
//预计干活多少天
expectedWorkDays: '',
//项目id
projectId: '',
//项目名称
projectName: '',
//project
projectObject:{},
//人员类型
personTypeList:[
{
id:"1",
text:"管理人员",
},
{
id:"2",
text:"劳务人员"
}
],
personType:'1',
firstLevelList:[],
firstLevel:'',
laborList:[
{
id:"8",
text:"特殊工种",
list:[
"电工","电焊工","架子工","建筑起重思索信号工","建筑起重机械司机","建筑起重机械安装拆卸工","高处作业吊篮安装拆卸工","建筑起重机械安装质量检测工","建筑施工现场内机动车司机","其他工种"
]
},
{
id:"9",
text:"普通工种",
list:[
"钢筋工","木工","混凝土工","泥瓦工","抹灰工","防水工","机修工","腻子工","水电工","安装工","装修工","普工","其他工种"
]
}
],
manageList:[
{
id:'1',
text:"管理人员",
list:[
"项目经理","常务副经理","项目副经理","项目书记","项目副书记","项目总工","安全总监","工会主席"
]
},
{
id:'2',
text:"工程部",
list:[
"项目经理","正部长","副部长","技术员","试验员","资料员","测量员","施工员"
]
},
{
id:'3',
text:"工经部",
list:[
"部长","预算员"
]
},
{
id:'4',
text:"物机部",
list:[
"正部长","副部长","材料员","机械员"
]
},
{
id:'5',
text:"财务部",
list:[
"部长","会计","出纳"
]
},
{
id:'6',
text:"办公室",
list:[
"办公室主任","劳务员","信息员"
]
},
{
id:'7',
text:"安质部",
list:[
"部长","安全员","质检员"
]
},
],
//管理单位
managementUnitList:[
{
id:'1',
text:"建设单位",
},
{
id:'2',
text:"监理单位",
},
{
id:'3',
text:"总承包单位",
},
],
managementUnit:'',
//文化程度
educationLevelList:[],
educationLevel:'',
//紧急联系人
emergencyName:'',
//紧急联系人电话
emergencyPhone:'',
//用工形式列表
employmentTypeList:[],
employmentType:''
},
//选择人员类型
onPersonType(e) {
this.setData({
personType:e.detail.id
})
if(e.detail.id == 1) {
this.setData({
firstLevelList:this.data.manageList,
firstLevel:this.data.manageList[0].id,
expectedWorkDays:'',
managementUnit:'1'
})
this.getWorkTypeId(this.data.manageList[0].list)
} else {
this.setData({
firstLevelList:this.data.laborList,
firstLevel:this.data.laborList[0].id
})
this.getWorkTypeId(this.data.laborList[0].list)
}
},
//管理单位
onManagementUnit(e) {
if(e.detail.id == 1) {
this.setData({
managementUnit:e.detail.id,
educationLevel:'',
emergencyName:'',
emergencyPhone:'',
expectedWorkDays:''
})
} else {
this.setData({
managementUnit:e.detail.id
})
}
},
//选择归属劳务公司班组id
onSelectLabourCompanyName(e) {
this.setData({
laborCompanyId: e.detail.id,
laborCompanyName: e.detail.text,
laborTeamIdList:e.detail.teamList,
laborTeamId:e.detail.teamList[0].id == undefined ?"":e.detail.teamList[0].id,
laborTeamName: e.detail.teamList[0].text == undefined ?"":e.detail.teamList[0].text
})
},
//选择归属劳务公司班组id
onSelectLabourTeamName(e) {
this.setData({
laborTeamId: e.detail.id,
laborTeamName: e.detail.text
})
},
onSelectFirstLevel(e) {
this.setData({
firstLevel:e.detail.id
})
var list = e.detail.list
//获取二级工种
this.getWorkTypeId(list)
},
//选择归属工种
onSelectworkType(e) {
this.setData({
workTypeId: e.detail.id,
workTypeName: e.detail.text
})
},
//预计干活天数
onExpectedWorkDays(e) {
this.setData({
expectedWorkDays: e.detail.value
})
},
onClickShow() {
this.setData({
loadShow: true
});
},
onClickHide() {
this.setData({
loadShow: false
});
},
/**
* 用工形式
*/
getEmploymentType() {
var that = this
wx.request({
url: app.globalData.szhUrl + '/system/dict/data/listData',
method: "post",
data: {
dictType: "employment_type"
},
header: {
'content-type': 'application/x-www-form-urlencoded' //修改此处即可
},
success(res) {
var list = []
if (res.data.code == 0) {
if (res.data.rows.length > 0) {
var data = res.data.rows;
data.forEach(item => {
var obj = {}
obj.id = item.dictValue
obj.text = item.dictLabel
list.push(obj)
});
that.setData({
employmentTypeList: list,
employmentType:list[0].id
})
} else {
that.setData({
employmentTypeList: [],
employmentType:''
})
}
} else {
that.setData({
employmentTypeList: [],
employmentType:''
})
}
}
})
},
onSelectEmploymentType(e) {
if(e.detail.id == 1) {
this.setData({
employmentType: e.detail.id,
})
} else {
this.setData({
employmentType: e.detail.id,
expectedWorkDays:3
})
}
},
/**
* 获取人员文化程度
*/
getEducatuinLevelList() {
var that = this
wx.request({
url: app.globalData.szhUrl + '/system/dict/data/listData',
method: "post",
data: {
dictType: "education_level"
},
header: {
'content-type': 'application/x-www-form-urlencoded' //修改此处即可
},
success(res) {
var list = []
if (res.data.code == 0) {
if (res.data.rows.length > 0) {
var data = res.data.rows;
data.forEach(item => {
var obj = {}
obj.id = item.dictValue
obj.text = item.dictLabel
list.push(obj)
});
that.setData({
educationLevelList: list,
educationLevel:list[0].id
})
} else {
that.setData({
educationLevelList: [],
educationLevel:''
})
}
} else {
that.setData({
educationLevelList: [],
educationLevel:''
})
}
}
})
},
/**
* 文化程度变化
*/
onSelectEducationLevel(e) {
this.setData({
educationLevel: e.detail.id,
})
},
/**
* 紧急联系人
*/
onEmergencyName(e) {
this.setData({
emergencyName: e.detail.value
})
},
/**
* 紧急联系人联系方式
*/
onEmergencyPhone(e) {
this.setData({
emergencyPhone: e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
app.getOPenId()
const {q} = options;
console.log(q)
if (q) {
let urlStr = decodeURIComponent(q);
let subStrUrl = urlStr.substr(urlStr.indexOf("?"), urlStr.length - 1)
let params = this.getRequest(subStrUrl)
this.setData({
projectId: params.projectId
})
// 获取当前项目对应劳务实名制的projectId
if(params.projectId != "" && params.projectId != undefined) {
this.getProjectInfo(params.projectId)
}
}
// this.setData({
// projectId: 147
// })
// this.getProjectInfo(147)
if(this.data.personType == 1) {
this.setData({
firstLevelList:this.data.manageList,
firstLevel:this.data.manageList[0].id,
managementUnit:'1'
})
this.getWorkTypeId(this.data.manageList[0].list)
} else {
this.setData({
firstLevel:this.data.laborList,
firstLevel:this.data.laborList[0].id,
managementUnit:'1'
})
this.getWorkTypeId(this.data.laborList[0].list)
}
this.getEducatuinLevelList()
this.getEmploymentType()
// this.getLaborCompanyId();
},
/**
* 获取当前项目对应关系
*/
getProjectInfo(projectId) {
var that = this;
wx.request({
url: app.globalData.szhUrl + '/system/registration/getProjectInfo',
data: {
"projectId": projectId
},
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
method: "POST",
success: (res) => {
if(res.data.code == 0) {
if(res.data.data.length > 0) {
var list = res.data.data;
that.setData({
projectObject:list[0],
projectName:list[0].projectName
})
that.onClickShow();
//获取用户openId
that.getUserOpenId();
//获取归属劳务公司列表
that.getLaborCompanyId();
}
}
}
})
},
/**
* 获取请求地址信息
*/
getRequest(url) {
var theRequest = new Object();
var strs;
if (url.indexOf("?") != -1) {
let str = url.substr(1);
strs = str.split("&");
for (let i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
},
/**
* 获取用户openId
*/
getUserOpenId() {
wx.login({
success: res => {
wx.request({
url: app.globalData.reqUrl + '/weixin/userLogin/getOpenId',
data: {
"code": res.code,
"appId": app.globalData.appId,
},
success: (res) => {
this.setData({
openId: res.data.openid,
})
}
})
this.onClickHide()
}
})
},
/**
* 获取工种类型
*/
getWorkTypeId: function (selectList) {
let list = [];
wx.request({
url: app.globalData.smzUrl + '/mkl/basic/getWorkTypeList?appid=1c3d51aaf0c54a15b2c727ace5ccbe8d&sign=E5153931BE2113A48EF2E759811F375E',
data: {},
method: "GET",
success: (res) => {
if (res.data.code == 0) {
if (res.data.data.length > 0) {
for (let i = 0; i < res.data.data.length; i++) {
if(selectList.includes(res.data.data[i].workType)) {
var obj = {};
obj.id = res.data.data[i].id;
obj.text = res.data.data[i].workType;
list.push(obj);
}
}
}
}
this.setData({
workTypeList: list,
workTypeId:list[0].id,
workTypeName:list[0].text
})
this.onClickHide();
}
})
},
/**
* 获取劳务公司类型
*/
getLaborCompanyId: function () {
var that = this
let list = [];
wx.request({
url:app.globalData.smzUrl + '/mkl/tools/getToken?appid=1c3d51aaf0c54a15b2c727ace5ccbe8d&projectId='+that.data.projectObject.smz,
//url:app.globalData.smzUrl + '/mkl/tools/getToken?appid=1c3d51aaf0c54a15b2c727ace5ccbe8d&projectId=169',
data:{},
method:"GET",
header:{
appsecret:'AB05BFC6CC7D406BA45B1E08219E41D1'
},
success:(res=>{
if(res.data.code == 0) {
var sign = res.data.sign
wx.request({
url: app.globalData.smzUrl + '/mkl/basic/getUnitList?appid=1c3d51aaf0c54a15b2c727ace5ccbe8d&sign='+sign+'&projectId=' + that.data.projectObject.smz,
// url: app.globalData.smzUrl + '/mkl/basic/getUnitList?appid=1c3d51aaf0c54a15b2c727ace5ccbe8d&sign='+sign+'&projectId=169' ,
data: {},
method: "GET",
success: (res) => {
if (res.statusCode == 200) {
if (res.data.data.length > 0) {
for (let i = 0; i < res.data.data.length; i++) {
var obj = {};
obj.id = res.data.data[i].unitTypeid;
obj.text = res.data.data[i].enterpriseName;
var tempList = []
if(res.data.data[i].teamList.length > 0) {
res.data.data[i].teamList.forEach(item=>{
var teamObj = {}
teamObj.id = item.id
teamObj.text = item.teamName
tempList.push(teamObj)
})
}
obj.teamList = tempList
list.push(obj);
}
}
}
console.log(list)
this.setData({
laborCompanyIdList: list,
laborCompanyId:list[0].id,
laborCompanyName:list[0].text,
laborTeamIdList:list[0].teamList,
laborTeamId:list[0].teamList[0].id,
laborTeamName:list[0].teamList[0].text
})
this.onClickHide();
}
})
}
})
})
},
/**
*
* 身份证正面上传
*
*/
onImagesIdCardFront(e) {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
//图片上传地址
url: app.globalData.reqUrl + '/weixin/security/fileUpload',
filePath: e.detail[0],
name: 'file',
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
formData: {
user: 'test'
},
success: res => {
let data = JSON.parse(res.data);
this.setData({
id_card_front: data.url
});
let that = this;
wx.request({
url: app.globalData.szhUrl + '/weixin/tempRegistration/ocrIdCard',
data: {
path: data.url,
type: 'front'
},
method: "POST",
success: function (res1) {
that.setData({
id_card_name: res1.data.words_result.姓名.words,
id_card_no: res1.data.words_result.公民身份号码.words,
id_card_address: res1.data.words_result.住址.words,
birth: res1.data.words_result.出生.words,
sex: res1.data.words_result.性别.words,
nation: res1.data.words_result.民族.words,
});
}
})
},
});
},
//身份证反面上传
onImagesArr(e) {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
//图片上传地址
url: app.globalData.reqUrl + '/weixin/security/fileUpload',
filePath: e.detail[0],
name: 'file',
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
formData: {
user: 'test'
},
success: res => {
let data = JSON.parse(res.data);
this.setData({
id_card_back: data.url
});
let that = this;
wx.request({
url: app.globalData.szhUrl + '/weixin/tempRegistration/ocrIdCard',
data: {
path: data.url,
type: 'back'
},
method: "POST",
success: function (res1) {
that.setData({
sign_of_origin: res1.data.words_result.签发机关.words,
sign_of_date: res1.data.words_result.签发日期.words,
end_of_date: res1.data.words_result.失效日期.words,
});
}
})
},
});
},
//考勤半身照上传
onHalfBodyImg(e) {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
//图片上传地址
url: app.globalData.reqUrl + '/weixin/security/fileUpload',
filePath: e.detail[0],
name: 'file',
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
formData: {
user: 'test'
},
success: res => {
let data = JSON.parse(res.data);
this.setData({
half_body_photo: data.url
});
},
});
},
add: function () {
if(this.data.personType == 1) {
//管理人员
if (this.data.managementUnit == '' || this.data.managementUnit == undefined) {
app.toast("请选择管理单位");
return;
}
}
//判断值是否为空
if (this.data.laborCompanyId == '' || this.data.laborCompanyId == undefined) {
app.toast("请选择归属劳务公司");
return;
} else if (this.data.laborTeamId == '' || this.data.laborTeamId == undefined) {
app.toast("请选择归属劳务班组");
return;
} else if (this.data.firstLevel == '' || this.data.firstLevel == undefined) {
app.toast("请选择一级工种");
return;
} else if (this.data.workTypeId == '' || this.data.workTypeId == undefined) {
app.toast("请选择二级工种");
return;
} else if (this.data.employmentType == '' || this.data.employmentType == undefined) {
app.toast("请选择用工形式");
return;
} else if (this.data.id_card_front == '' || this.data.id_card_front == undefined) {
app.toast("请上传身份证正面照片");
return;
} else if (this.data.id_card_back == '' || this.data.id_card_back == undefined) {
app.toast("请上传身份证反面照片");
return;
} else if (this.data.id_card_no == '' || this.data.id_card_no == undefined) {
app.toast("请填写身份证号码");
return;
} else if (this.data.half_body_photo == '' || this.data.half_body_photo == undefined) {
app.toast("请上传考勤半身照片");
return;
}
//身份证校验
wx.request({
header: {
'content-type': 'application/x-www-form-urlencoded'
},
url: app.globalData.szhUrl + '/system/registration/checkUser',
data: {
idCardNo: this.data.id_card_no,
projectId:this.data.projectId
},
method: "POST",
success: res => {
if (res.data.code == 0) {
wx.setStorageSync('userOpenId', this.data.openId)
wx.setStorageSync('idCardNo', this.data.id_card_no)
wx.request({
header: {
'content-type': 'application/x-www-form-urlencoded'
},
url: app.globalData.szhUrl + '/system/registration/add',
data: {
projectId:this.data.projectId,
openId: this.data.openId,
laborCompanyId:this.data.laborCompanyId,
laborCompanyName:this.data.laborCompanyName,
laborTeamId: this.data.laborTeamId,
laborTeamName: this.data.laborTeamName,
workTypeId: this.data.workTypeId,
workTypeName: this.data.workTypeName,
expectedWorkDays: this.data.expectedWorkDays,
idCardFront: this.data.id_card_front,
idCardBack: this.data.id_card_back,
idCardName: this.data.id_card_name,
idCardNo: this.data.id_card_no,
birth: this.data.birth,
sex: this.data.sex,
nation: this.data.nation,
halfBodyPhoto: this.data.half_body_photo,
idCardAddress: this.data.id_card_address,
signOfOrigin: this.data.sign_of_origin,
signOfDate: this.data.sign_of_date,
endOfDate: this.data.end_of_date,
personType:this.data.personType,
firstLevel:this.data.firstLevel,
educationLevel:this.data.educationLevel,
emergencyName:this.data.emergencyName,
emergencyPhone:this.data.emergencyPhone,
employmentType:this.data.employmentType
},
method: "POST",
success: res=> {
if (res.data.code == 0) {
app.toast("添加成功!")
if(this.data.personType == 1) {
//在需要退出小程序的地方调用添加下面代码即可(js文件中)
wx.exitMiniProgram({
success: (res) => {}
})
} else {
wx.redirectTo({
url: '../newAddPage/safetyBriefingLearning/index?projectId='+this.data.projectId+"&firstWorkType="+this.data.firstLevel+"&secondWorkType="+this.data.workTypeId
,complete:function(res){
console.log(res)
},fail: err => {
console.log(err)
}
});
}
} else {
app.toast("添加失败");
return;
}
}
})
} else {
if(res.data.code == 500 && res.data.msg == "人员信息已存在,无需重复录入!") {
var that = this
//人员二次进场,修改数据状态
wx.request({
header: {
'content-type': 'application/x-www-form-urlencoded'
},
url: app.globalData.szhUrl + '/mkl/api/changTempoaryPersonState',
data: {
projectId:that.data.projectId,
idCardNo: that.data.id_card_no,
auditState:0
},
method: "POST",
success: function (result) {
if (result.data.code == 0) {
app.toast("温馨提醒:人员信息已成功提交,审核通过后可通过人脸识别闸机进场!");
}
}
})
} else {
wx.redirectTo({
url: '../newAddPage/safetyBriefingLearning/index?projectId='+that.data.projectId
})
}
}
}
})
},
/**
* 重置
*/
resetForm() {
wx.reLaunch({
url: '../tempRegistration/index'
})
},
/**
* 身份证号码输入
*/
onidCardIdNo(e) {
if (e.detail.value != "") {
this.setData({
id_card_no: e.detail.value
})
}
}
})