const tools = require('../../utils/tools.js'); const app = require('../../utils/util.js'); Page({ data: { kaihutext: '请选择', kaihuList: [{ name: '高中' }, { name: '大专' }, { name: '本科' }, { name: '硕士' }, ], nameIsTrue: false, //名字是否填写 cultureIsTrue: false, //文化是否填写 graduationIsTrue: false, //毕业学校 majorIsTrue: false, //所有专业 postIsTrue: false, //现任职务 renzhishijianIsTrue: false, phoneIsTrue: false, //电话 peixunshijianTrue: false, // 培训时间 nameMessage: '', tenure: '', //在线时间 peixunTime: '', //培训时间 headmasterText: '请选择任职时间', // peixunText: '请选择培训时间', radio: '1', username: 'asdsadsad', info: {}, parameter: [{ id: 1, name: '男', value: '0', checked: false }, { id: 2, name: '女', checked: false, value: '1', }], renzhiDate: '', postshow: false, postshow1: false, errorIsTrue: false, currentDate: new Date().getTime(), currentDate1: new Date().getTime(), minDate: new Date().getTime, formatter(type, value) { if (type === 'year') { return `${value}年`; } else if (type === 'month') { return `${value}月`; } return value; }, }, onChange(event) { this.setData({ radio: event.detail, }); }, share() { this.setData({ show: true }); }, onClose() { this.setData({ postshow: false }); }, onClose1() { this.setData({ postshow1: false }); }, onInput(event) { this.setData({ currentDate: event.detail, }); }, onInput1(event) { this.setData({ currentDate1: event.detail, }); }, formatDate(date) { date = new Date(date); return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`; }, kaihuListChange: function (e) { console.log(e, "8888888888888") this.setData({ kaihuindex: e.detail.value, kaihutext: '', }) }, share1() { this.setData({ postshow: true }); }, share() { this.setData({ postshow1: true }); }, formatDate(date) { date = new Date(date); return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`; }, onConfirm(event) { let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd"); this.setData({ tenure: timeValue, postshow: false, headmasterText: '' }); }, onConfirm1(event) { let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd"); this.setData({ peixunTime: timeValue, postshow1: false, peixunText: '' }); }, parameterTap: function (e) { //e是获取e.currentTarget.dataset.id所以是必备的,跟前端的data-id获取的方式差不多 let that = this let this_checked = e.currentTarget.dataset.id let parameterList = this.data.parameter //获取Json数组 for (let i = 0; i < parameterList.length; i++) { if (parameterList[i].id == this_checked) { parameterList[i].checked = true; //当前点击的位置为true即选中 } else { parameterList[i].checked = false; //其他的位置为false } } that.setData({ parameter: parameterList }) }, formSubmit(e) { if (!e.detail.value.username) { this.setData({ nameIsTrue: true }) } else { this.setData({ nameIsTrue: false }) } let sex = ''; if (this.data.parameter[0].checked) { sex = this.data.parameter[0].name this.setData({ errorIsTrue: false }) } else if (this.data.parameter[1].checked) { sex = this.data.parameter[1].name this.setData({ errorIsTrue: false }) } else { this.setData({ errorIsTrue: true }) } if (!e.detail.value.work) { this.setData({ workIsTrue: true }) } else { this.setData({ workIsTrue: false }) } if (!e.detail.value.culture) { this.setData({ cultureIsTrue: true }) } else { this.setData({ cultureIsTrue: false }) } if (!e.detail.value.graduation) { this.setData({ graduationIsTrue: true }) } else { this.setData({ graduationIsTrue: false }) } if (!e.detail.value.major) { this.setData({ majorIsTrue: true }) } else { this.setData({ majorIsTrue: false }) } if (!e.detail.value.post) { this.setData({ postIsTrue: true }) } else { this.setData({ postIsTrue: false }) } if (!e.detail.value.phone) { this.setData({ phoneIsTrue: true }) } else { this.setData({ phoneIsTrue: false }) } if (!this.data.tenure) { this.setData({ renzhishijianIsTrue: true }) } else { this.setData({ renzhishijianIsTrue: false }) } if (!this.data.peixunTime) { this.setData({ peixunshijianTrue: true }) } else { this.setData({ peixunshijianTrue: false }) } e.detail.value.culture = this.data.kaihuList[this.data.kaihuindex].name; e.detail.value.tenure = this.data.tenure; e.detail.value.sessionKey = this.data.sessionKey; let aa = e.detail.value console.log(aa, "00000000") if (aa.culture && aa.mcajor && aa.school && aa.studentDuty && aa.tenure && aa.studentDept) { wx.request({ url: app.globalData.publicUrl + '/wx/student/upStudent', method: "post", data: { studentDept: aa.studentDept, culture: aa.culture, school: aa.school, studentDuty: aa.studentDuty, tenure: aa.tenure, studentPhone: aa.studentPhone, sessionKey: this.data.sessionKey, mcajor: aa.mcajor, }, success: () => { console.log("提交成功"); wx.showModal({ showCancel: false, content: '提交成功', success() { wx.navigateBack({ delta: 1 }) } }) }, fail: (res) => { console.log(res) wx.showModal({ showCancel: false, content: '提交失败', success() { wx.navigateBack({ delta: 1 }) } }) } }) } else { wx.showModal({ showCancel: false, content: '请补全信息', success() { } }) } }, timeFormat(date, fmt) { let o = { "M+": date.getMonth() + 1, //月份    "d+": date.getDate(), //日 "h+": date.getHours(), //小时    "m+": date.getMinutes(), //分    "s+": date.getSeconds(), //秒    "q+": Math.floor((date.getMonth() + 3) / 3), //季度    "S": date.getMilliseconds() //毫秒    }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); for (let k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }, onReady: function () {}, async onLoad() { const sessionKey = await tools.checkSessionAndLogin(); console.log(sessionKey, "000000"); this.setData({ sessionKey: sessionKey }) this.getBanner(sessionKey); }, getBanner(sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/student/selStudentSessionKeyEcho', method: "post", data: { sessionKey: sessionKey, }, success: (res) => { // console.log(rs) if (res.data.code == 0) { this.data.parameter.forEach(item => { if (item.value == res.data.data.studentSex) { item.checked = true; } }) this.setData({ info: res.data.data, parameter: this.data.parameter, studentDept: res.data.data.studentDept, studentDuty: res.data.data.studentDuty, kaihutext: res.data.data.culture, major: res.data.data.major, tenure: res.data.data.tenure, studentPhone: res.data.data.studentPhone, }) } } }) }, })