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.

993 lines
24 KiB
JavaScript

2 years ago
// pages/newEnroll/index.js
const app = getApp();
var dateTimePicker = require("../../../utils/dateTimePicker.js");
var dateUtil = require("../../../utils/dateUtil.js");
import { isNotEmptyCheck, nationArray } from "../../../utils/commonUtil";
const mydate = new Date();
Page({
/**
* 页面的初始数据
*/
data: {
userId:'',
ageArray:[],
ageIndex:-1,
files: [],
urls:[],
userInfo: {
name: "",
address: "",
age: "",
nationality: "",
sex: "",
num: "",
tel: "",
idCardImageUrl: "",
},
showUpload: true,
name: "",
sex: [
{
id: 1,
value: "男",
},
{
id: 2,
value: "女",
},
],
imgSrc: "",
loading: false,
idInfo: {},
index: -1,
agentArray: [],
// jobIndex: -1,
jobArray: [
// {
// id: 1,
// name: "GG",
// },
],
storeIndex: -1,
storeArray: [
// {
// id: 1,
// name: "GG",
// },
],
dateTimeArray1: null,
dateTime1: null,
startYear: 2022,
endYear: 2024,
currentTime: dateUtil.formatDateYMD(mydate.toLocaleDateString()) + " " + "12:00",
searchListShow: false,
searchKeys: "",
searchKeysA: "",
inputShowed: false,
inputVal: "",
inputShowedA: false,
inputValA: "",
storeId: "",
agentId: "",
agentName: "",
storeJobId: "",
policy: "",
currentImg: "",
nationIndex: -1, // 民族的索引
managerRoleClassify: false, // 管理员权限
nationArray,
currentUser: {},
jobName: "",
switch1Checked: true,
newAddImg:[],
},
switch1Change:function(e){
console.log('radio发生change事件携带value值为', e.detail.value)
console.log(e.detail.value)
var check = this.data.switch1Checked;
if (check) {
this.data.switch1Checked = false;
console.log("已取消选中");
wx.showToast({
title: '请先阅读并同意《服务协议》及《隐私政策》',
icon: 'none',
duration: 2000
})
} else {
this.data.switch1Checked = true;
console.log("已选中");
}
this.setData({
switch1Checked: this.data.switch1Checked,
});
// if(!e.detail.value){
// }
},
shrink(){
wx.navigateBack({
delta: -1,
})
},
bindPickerChangeAge(e){
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
ageIndex: e.detail.value,
["userInfo.age"]: parseInt(e.detail.value) + 16,
})
},
chooseMedia(){
var that = this;
wx.chooseMedia({
count: 9,
mediaType: ['image'],
sizeType: ['original','compressed'],
sourceType: ['album', 'camera'],
success (res) {
// tempFilePath可以作为 img 标签的 src 属性显示图片
wx.showLoading({
title: '上传中...',
})
console.log(res);
var currData = {};
const tempFilePaths = res.tempFiles;
tempFilePaths.forEach((item,index)=>{
wx.uploadFile({
url: app.globalData.ip + "/imgs/uploadImage",
method: "post",
// data:currData,
// name: "uploadFile",
filePath: tempFilePaths[index].tempFilePath,
name: "uploadFile",
header: app.globalData.headers,
success: function (res) {
console.log(that.data.files);
console.log(JSON.parse(res.data).data);
that.data.files.push({url:JSON.parse(res.data).data,id:-999})
that.data.newAddImg.push(JSON.parse(res.data).data)
that.setData({
files:that.data.files,
newAddImg:that.data.newAddImg
})
// currData.data = JSON.parse(res.data);
that.pushImg();
// console.log(that.data.files);
// that.updateImgs(currData.type,currData.fkId,currData.data.data);
},
fail: function (res) {
console.log(res);
},
});
wx.hideLoading();
})
}
})
},
delImgs(e){
var that = this;
var url = e.currentTarget.dataset.url;
var id = e.currentTarget.dataset.id;
wx.showModal({
title: '提示',
content: '确定要删除该图片?',
confirmColor:'#ff4400',
success (res) {
if (res.confirm) {
that.data.files.forEach((item,index)=>{
if(id == item.id){
that.data.files.splice(index,1);
that.data.newAddImg.splice(index,1);
}
})
that.pushImg();
that.setData({
files:that.data.files,
newAddImg:that.data.newAddImg
})
if(id != -999){
wx.request({
url: app.globalData.ip + "/imgs/del/"+id,
header: app.globalData.headers,
// data:currData,
method: "get",
success: function (res) {
console.log(res.data);
},
fail: function (res) {
console.log(res);
},
});
}
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
pushImg(){
var that = this;
console.log(that.data.files);
that.data.urls = [];
// that.data.files.forEach(item=>{
// that.data.urls.push(item.url)
// })
let curr = [];
that.data.files.forEach(item=>{
curr.push({url:item.url,id:item.id})
})
that.setData({
urls:curr
})
},
showImgs(e){
var that = this;
console.log(that.data.urls);
let curr = [];
that.data.urls.forEach(item=>{
curr.push(item.url)
})
wx.previewImage({
current: e.mark.url, // 当前显示图片的 http 链接
urls: curr // 需要预览的图片 http 链接列表
})
},
radioChange: function (e) {
const sex = this.data.sex;
let currentSex = "";
for (let i = 0, len = sex.length; i < len; ++i) {
sex[i].checked = sex[i].id == e.detail.value;
if (sex[i].checked) {
currentSex = sex[i].value;
}
}
this.setData({
["userInfo.sex"]: currentSex,
sex,
});
console.log(e.detail.value);
},
chooseIdCard() {
var that = this;
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["album", "camera"],
success(res) {
console.log(res);
// debugger;
that.uploadIdcardImg(res);
},
});
},
uploadIdcardImg(imgPath) {
let that = this;
// tempFilePath可以作为img标签的src属性显示图片
console.log(imgPath.tempFilePaths[0]);
const tempFilePaths = imgPath.tempFilePaths;
wx.showLoading({
title: "识别中...",
});
wx.uploadFile({
// url: app.globalData.ip + '/commons/idCardOcrRecognize',
url: app.globalData.ip + "/commons/idCardOcrRecognizeAndUploadToAliyunOss",
filePath: imgPath.tempFilePaths[0],
name: "uploadFile",
header: app.globalData.headers,
success: function (res) {
console.log(JSON.parse(res.data));
var idcard = JSON.parse(res.data);
if (idcard.status == 200) {
that.setData({
ageIndex:parseInt(idcard.data.age) - 16,
userInfo: idcard.data,
showUpload: false,
currentImg: idcard.data.idCardImageUrl,
});
that.setStorage();
console.log(that.data.userInfo);
that.data.nationArray.forEach((item, index) => {
if (item.name.includes(that.data.userInfo.nationality)) {
that.setData({
nationIndex: index,
});
}
});
if (that.data.userInfo.sex == "男") {
that.data.sex[0].checked = true;
} else {
that.data.sex[1].checked = true;
}
// that.data.files.push({'url':tempFilePaths[0]})
// console.log(that.data.files);
that.setData({
// files: that.data.files,
sex: that.data.sex,
imgSrc: tempFilePaths[0],
});
that.pushImg();
} else {
wx.showToast({
duration: 2000,
title: "身份证未识别",
icon: "none",
mask: true,
});
// console.log(1);
//app.showTips(that, res.data.msg);
}
wx.hideLoading();
},
fail: function (res) {
console.log(res);
},
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
// console.log(JSON.parse(options.info));
// 获取缓存的报名人信息
let info = wx.getStorageSync("townsManInfo");
console.log(info);
if (app.isNotEmptyCheck(info)) {
// 统一给代理岗位相关的字段赋值
if(app.isNotEmptyCheck(info.userId)){
that.getImgs(info.userId);
}
that.setData({
userInfo: info,
userId:info.userId,
currentImg: info.currentImg,
});
if(app.isNotEmptyCheck(info.imgs)){
that.setData({
files:info.imgs,
urls:info.imgs,
});
}
// this.setData({
// userInfo: info,
// currentImg: info.currentImg,
// currentTime: info.currentTime,
// });
console.log(info);
if (info.sex == "男" || info.sex == "1") {
this.data.sex[0].checked = true;
} else if (info.sex == "女" || info.sex == "2") {
this.data.sex[1].checked = true;
}
that.data.nationArray.forEach((item, index) => {
if (item.name.indexOf(info.nationality) > -1 && info.nationality != "") {
console.log("isin");
that.setData({
nationIndex: index,
});
}
});
console.log(info.age);
if(info.age){
this.setData({
ageIndex:parseInt(info.age) - 16,
});
}
console.log(that.data.nationIndex);
this.setData({
sex: this.data.sex,
});
}
// this.getPolicyByStoreJobId(that.data.storeJobId);
that.setData({
managerRoleClassify: app.globalData.loginUserInfo.managerRoleClassify,
});
if (app.isNotEmptyCheck(options.info)) {
// 如果随路由传过来的信息有更新,赋值新的数据
this.setData({
storeJobId: JSON.parse(options.info).id,
jobName: JSON.parse(options.info).jobName,
inputVal: JSON.parse(options.info).storeName || JSON.parse(options.info).aliasName,
storeId: JSON.parse(options.info).storeId,
});
// this.getPolicyByStoreJobId(this.data.storeJobId);
}
if (app.isNotEmptyCheck(options.agencyInfo)) {
that.setData({
agentName: JSON.parse(options.agencyInfo).agencyName,
agentId: JSON.parse(options.agencyInfo).id,
});
}
if (app.isNotEmptyCheck(options.imgUrl)) {
let imgUrl = JSON.parse(options.imgUrl);
that.uploadIdcardImg(imgUrl);
}
},
toJobAndAgencySelect(e) {
console.log(e);
console.log(this.data.userInfo);
this.setStorage().then(() => {
console.log('--------','isIntonavigation');
wx.navigateTo({
url: `../recordChoice/index?type=${e.currentTarget.dataset.type}`,
});
});
},
showImg() {
wx.previewImage({
current: this.data.currentImg, // 当前显示图片的 http 链接
urls: [this.data.currentImg], // 需要预览的图片 http 链接列表
});
},
deleteImg() {
var that = this;
wx.showModal({
title: "提示",
content: "确定要删除图片吗?",
confirmColor: "#ff4400",
success(res) {
if (res.confirm) {
that.setData({
imgSrc: "",
showUpload: true,
});
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// let src = wx.getStorageSync("src");
// console.log(src);
},
bothwayBind(e) {
console.log(e);
let type = `userInfo.${e.currentTarget.dataset.type}`;
this.setData({
[type]: e.detail.value,
});
},
beforeFormSubmit: function (e) {
var that = this;
console.log(e);
that.setData({
loading: true,
});
if (app.isEmptyCheck(e.detail.value.userName)) {
wx.showToast({
duration: 2000,
title: "请输入姓名",
icon: "none",
mask: true,
});
that.setData({
loading: false,
});
} else if (app.isEmptyCheck(e.detail.value.sex)) {
wx.showToast({
duration: 2000,
title: "请选择性别",
icon: "none",
mask: true,
});
that.setData({
loading: false,
});
} else if (that.data.ageIndex == -1) {
wx.showToast({
duration: 2000,
title: "请选择年龄",
icon: "none",
mask: true,
});
that.setData({
loading: false,
});
} else {
setTimeout(() => {
that.formSubmit(e);
}, 1);
}
},
setStorage() {
let that = this;
wx.removeStorageSync('townsManInfo')
return new Promise((resolve, reject) => {
console.log(that.data.storeJobId);
let data = { ...that.data.userInfo, currentImg: that.data.currentImg };
console.log(data);
wx.setStorage({
key: "townsManInfo",
data,
});
console.log(wx.getStorageSync("townsManInfo"));
resolve();
});
},
formSubmit: function (e) {
var that = this;
console.log(e);
that.setData({
loading: true,
});
// wx.showLoading({
// title: "提交中...",
// mask: true,
// });
// if (that.data.index == -1) {
// wx.showToast({
// duration: 2000,
// title: '请选择代理',
// icon: 'none',
// mask: true
// })
// that.setData({
// loading: false
// })
// } else
// if (that.data.jobIndex == -1) {
// wx.showToast({
// duration: 2000,
// title: "请选择岗位",
// icon: "none",
// mask: true,
// });
// that.setData({
// loading: false,
// });
// } else {
console.log(that.data.userInfo);
new Promise(function (resolve, reject) {
var paramData = that.data.userInfo;
paramData["userName"] = e.detail.value.userName;
paramData["sex"] = e.detail.value.sex;
paramData["age"] = that.data.userInfo.age;
paramData["nation"] = that.data.userInfo.nationality;
paramData["idCard"] = e.detail.value.idCard;
paramData["num"] = e.detail.value.idCard;
paramData["tel"] = e.detail.value.tel;
paramData["idCardImageUrl"] = that.data.currentImg;
paramData ["address"] = e.detail.value.address;
paramData ["userId"] = that.data.userId;
// let urlss = [];
// if(app.isNotEmptyCheck(that.data.files)){
// that.data.files.forEach(item=>{
// urlss.push(item.url)
// })
// }
paramData["imgs"] = that.data.newAddImg.toString();
resolve(paramData);
}).then(function (paramData) {
console.log(paramData);
wx.removeStorageSync('townsManInfo')
new Promise((resolve, reject) => {
console.log(that.data.storeJobId);
let data = { ...paramData ,currentImg: that.data.currentImg,imgs:that.data.files };
console.log(data);
wx.setStorage({
key: "townsManInfo",
data,
});
console.log(wx.getStorageSync("townsManInfo"));
resolve();
}).then(() => {
console.log(paramData['userId']);
if(app.isNotEmptyCheck(that.data.userId)){
wx.request({
url: app.globalData.ip + "/user/updateInfo",
header: app.globalData.headers,
data: paramData,
method: "POST",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
wx.hideLoading();
wx.showToast({
duration: 2000,
title: "提交中",
icon: "success",
mask: true,
});
setTimeout(()=>{
wx.navigateBack({
delta: -1,
})
},2000)
}else{
wx.showToast({
title: res.data.msg,
icon:'none'
})
}
},
});
}else{
wx.hideLoading();
wx.showToast({
duration: 2000,
title: "提交中",
icon: "success",
mask: true,
});
setTimeout(()=>{
wx.navigateBack({
delta: -1,
})
},2000)
}
// wx.navigateBack({
// delta: -1,
// })
});
wx.hideLoading({
success: (res) => {},
})
});
// }
},
inputTyping: function (e) {
this.setData({
inputVal: e.detail.value,
});
if (e.detail.value.length > 0) {
this.setData({
searchListShow: true,
});
this.getStoreList(e.detail.value);
} else {
this.setData({
searchListShow: false,
});
}
},
getStoreList: function (searchKeys) {
console.log(searchKeys);
var that = this;
that.data.searchKeys = searchKeys;
// 60秒后重新获取验证码
wx.request({
url: app.globalData.ip + "/store/getAllStoreAliasName",
data: {
keys: searchKeys,
},
header: app.globalData.headers,
method: "GET",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
storeArray: res.data.data,
});
}
},
fail: function (res) {},
});
},
setValue: function (e) {
let str = e.currentTarget.dataset.name;
let storeId = e.currentTarget.dataset.id;
console.log(storeId);
this.setData({
inputVal: str,
storeId: storeId,
searchListShow: false,
});
this.getJobList(storeId);
},
getJobList: function (storeId) {
var that = this;
return new Promise((resolve, reject) => {
wx.request({
url: app.globalData.ip + "/store/job/getJobNameByStoreId",
data: {
storeId: storeId,
},
header: app.globalData.headers,
method: "GET",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
jobArray: res.data.data,
});
resolve();
}
},
fail: function (res) {},
});
});
},
// bindPickerChangeJob: function (e) {
// var that = this;
// console.log("picker发送选择改变携带值为", e.detail.value);
// var storeJobId = that.data.jobArray[e.detail.value].id;
// console.log(storeJobId);
// that.getPolicyByStoreJobId(storeJobId);
// this.setData({
// jobIndex: e.detail.value,
// });
// },
bindPickerChangeNation(e) {
let that = this;
console.log("picker发送选择改变携带值为", e.detail.value);
var nationName = that.data.nationArray[e.detail.value].name;
this.setData({
nationIndex: e.detail.value,
["userInfo.nationality"]: nationName,
});
},
getPolicyByStoreJobId: function (storeJobId) {
var that = this;
wx.request({
url: app.globalData.ip + "/store/job/getPolicyByStoreJobId",
data: {
storeJobId: storeJobId,
},
header: app.globalData.headers,
method: "GET",
success: function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
policy: res.data.data,
});
}
},
fail: function (res) {
console.log(res);
},
});
},
changeDateTime(e) {
var dateTimeArray = this.data.dateTimeArray,
dateTime = e.detail.value;
this.setData({
// dateTime: e.detail.value,
currentTime: dateTimeArray[0][dateTime[0]].replace("年", "") + "-" + dateTimeArray[1][dateTime[1]].replace("月", "") + "-" + dateTimeArray[2][dateTime[2]].replace("日", "") + " " + dateTimeArray[3][dateTime[3]],
});
console.log(this.data.dateTimeArray);
},
changeDateTimeColumn(e) {
var arr = this.data.dateTime,
dateArr = this.data.dateTimeArray;
arr[e.detail.column] = e.detail.value;
console.log("aaaaaa");
console.log(dateArr[0][arr[0]], dateArr[1][arr[1]]);
dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
for (let index = 0; index < dateArr[2].length; index++) {
dateArr[2][index] = dateArr[2][index] + "日";
}
// .replace("年",'').replace("月",'').replace("日",'')
this.setData({
dateTimeArray: dateArr,
dateTime: arr,
});
},
// getAgencyList: function (searchKeys) {
// var that = this;
// that.data.searchKeysA = searchKeys;
// // 60秒后重新获取验证码
// wx.request({
// url: app.globalData.ip + "/agency/getByPmdUserId",
// data: {
// agencyName: searchKeys,
// // pmdUserId: 101125
// },
// header: app.globalData.headers,
// method: "GET",
// success: function (res) {
// console.log(res);
// if (res.data.status == 200) {
// that.setData({
// agentArray: res.data.data,
// });
// }
// },
// fail: function (res) {},
// });
// },
/**
* 生命周期函数--监听页面显示
*/
getImgs(userId){
var that = this;
wx.request({
url: app.globalData.ip + "/imgs/list/"+userId+"?type=20",
header: app.globalData.headers,
method: "GET",
success: function (res) {
console.log(res);
// if (res.data.status == 200) {
let currFils = [];
let regs = /\.(jpg|jpeg|png)(\?.*)?$/;
// res.data.data.storeImage.forEach((item) => {
// item.isImg = regs.test(item.url.toLowerCase());
// if(app.isEmptyCheck(item.recordState)){
// item.recordState = 1
// }
// });
if(app.isNotEmptyCheck(res.data.data.userImgs)){
res.data.data.userImgs.forEach(item=>{
if(regs.test(item.url.toLowerCase())){
currFils.push({url:item.url,id:item.id})
}
})
}
that.setData({
files: currFils,
urls: currFils,
});
// }
},
fail: function (res) {
console.log(res);
},
});
},
onShow: function () {
let that = this;
that.pushImg();
for(let i = 16;i < 70;i++){
that.data.ageArray.push(i)
}
// let that = this;
// let info = wx.getStorageSync("townsManInfo");
// if (app.isNotEmptyCheck(info)) {
// this.setData({
// userInfo: info,
// currentImg: info.currentImg,
// currentTime: info.currentTime,
// });
// console.log(info);
// if (info.sex == "男") {
// this.data.sex[0].checked = true;
// } else if (info.sex == "女") {
// this.data.sex[1].checked = true;
// }
// that.data.nationArray.forEach((item, index) => {
// if (item.name.indexOf(info.nationality) > -1 && info.nationality != "") {
// console.log("isin");
// that.setData({
// nationIndex: index,
// });
// }
// });
// console.log(that.data.nationIndex);
// this.setData({
// sex: this.data.sex,
// });
// }
// this.pickerTap();
var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, this.data.currentTime);
console.log(obj);
console.log(obj.dateTimeArray);
for (let index = 0; index < obj.dateTimeArray[0].length; index++) {
obj.dateTimeArray[0][index] = obj.dateTimeArray[0][index] + "年";
}
for (let index = 0; index < obj.dateTimeArray[1].length; index++) {
obj.dateTimeArray[1][index] = obj.dateTimeArray[1][index] + "月";
}
for (let index = 0; index < obj.dateTimeArray[2].length; index++) {
obj.dateTimeArray[2][index] = obj.dateTimeArray[2][index] + "日";
}
this.setData({
dateTimeArray: obj.dateTimeArray,
dateTime: obj.dateTime,
ageArray:that.data.ageArray
});
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function (e) {
console.log("isHide");
console.log(e);
// this.setData({
// userInfo: {
// name: "",
// address: "",
// age: "",
// nationality: "",
// sex: "",
// num: "",
// idCardImageUrl: "",
// },
// });
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
// wx.removeStorageSync("townsManInfo");
// wx.switchTab({
// url: "../firstBill/index",
// });
// console.log(wx.getStorageSync("townsManInfo"));
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage1: function () {},
});