//index.js //获取应用实例 studentRegistration const app = require('../../utils/util.js'); const tools = require('../../utils/tools.js'); Page({ data: { nameIsTrue: false, //名字是否填写 cultureIsTrue: false, //文化是否填写 graduationIsTrue: false, //毕业学校 majorIsTrue: false, //所有专业 postIsTrue: false, //现任职务 renzhishijianIsTrue: false, phoneIsTrue: false, //电话 peixunshijianTrue: false, // 培训时间 nameMessage: '', zaizhiTime: [], //在线时间 peixunTime: '', //培训时间 headmasterText: [], // names: [], timeIndex: '', chooseValue: [], // 选择的答案序列 radio: '1', renzhiDate: '', postshow: [], 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; }, questionList: [ // { // "QuestType": "6", // "Id": 11, // name: 'ccccc', // QuestStem: '时间选择', // QuestAnswer: '' // }, // { // "QuestType": "5", // "Id": 11, // name: 'dddd', // QuestStem: '姓名输入', // QuestAnswer: '' // }, // { // "QuestType": "6", // "Id": 11, // name: 'username111', // QuestStem: '时间2', // QuestAnswer: '' // }, // { // "QuestType": "5", // "Id": 11, // name: 'address', // QuestStem: '姓名输入', // QuestAnswer: '' // }, // { // "QuestType": "0", // "QuestChoice": [{ // value: 'USA', // name: '美国' // }, // { // value: 'CHN', // name: '中国', // checked: 'true' // }, // { // value: 'BRA', // name: '巴西' // }, // { // value: 'JPN', // name: '日本' // }, // { // value: 'ENG', // name: '英国' // }, // { // value: 'FRA', // name: '法国' // }, // ], // "Id": 36, // name: 'sex', // QuestStem: '性别单选' // }, // { // "QuestType": "0", // "QuestChoice": [{ // value: '男', // name: '男', // checked: false, // }, // { // value: '女', // name: '女', // checked: false, // }, // ], // "Id": 36, // name: 'sex111', // QuestStem: '性别单选2222' // }, // { // "QuestType": "1", // "QuestAnswer": "equals ()||\nhashCode()||", // "QuestChoice": [{ // value: 'USA', // name: '美国' // }, // { // value: 'CHN', // name: '中国', // checked: false // }, // { // value: 'FRA', // name: '法国' // } // ], // "Id": 38, // name: 'alls', // QuestStem: '多选' // }, // { // "QuestType": "2", // "QuestStem": "1+1=2", // "QuestAnswer": "是", // "QuestChoice": [{ // value: 'USA', // name: '是' // }, // { // value: 'CHN', // name: '中国', // checked: false // }, // ], // "Id": 42, // name: 'lllll', // QuestStem: '判断1' // }, // { // "QuestType": "2", // "QuestStem": "1+1=2", // "QuestAnswer": "是", // "QuestChoice": [{ // value: 'USA', // name: '是' // }, // { // value: 'CHN', // name: '中国', // checked: false // }, // ], // "Id": 42, // name: 'lllll', // QuestStem: '判断2' // }, // { // "QuestType": "2", // "QuestStem": "1+1=2", // "QuestAnswer": "是", // "QuestChoice": [{ // value: 'USA', // name: '是' // }, // { // value: 'CHN', // name: '中国', // checked: false // }, // ], // "Id": 42, // name: 'lllll', // QuestStem: '判断3' // }, // { // "QuestType": "3", // "QuestStem": "世纪大厦的萨科技的哈市(解答)", // "QuestAnswer": "", // "QuestChoice": "", // "Id": 39, // name: 'textarea', // }, ], answersId: '', // 提交答案用到 sessionKey: '', paperId: '', answersId: '', id: '', status: '' }, onChange(event) { this.setData({ radio: event.detail, }); }, radioChange(e) { console.log(e); const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice for (let i = 0, len = items.length; i < len; ++i) { items[i].checked = items[i].value === e.detail.value } let json = {}; json.currentAnswer = e.detail.value; json.id = e.currentTarget.dataset.idx; json.questType = e.currentTarget.dataset.questtypes; this.data.chooseValue[e.currentTarget.dataset.index] = json; this.setData({ questionList: this.data.questionList }) wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList); wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue); console.log(this.data.questionList); }, checkboxChange(e) { const items = this.data.questionList[e.currentTarget.dataset.index].QuestChoice const values = e.detail.value for (let i = 0, lenI = items.length; i < lenI; ++i) { items[i].checked = false for (let j = 0, lenJ = values.length; j < lenJ; ++j) { if (items[i].value === values[j]) { items[i].checked = true break } } } let json = {}; let aa = e.detail.value.join("||") json.currentAnswer = aa; json.id = e.currentTarget.dataset.idx; json.questType = e.currentTarget.dataset.questtypes; this.data.chooseValue[e.currentTarget.dataset.index] = json; this.setData({ questionList: this.data.questionList }) wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList); wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue); }, bindTextAreaBlur(e) { console.log(e, "hhhhh"); console.log(e.detail.value); let json = {}; json.currentAnswer = e.detail.value; json.id = e.currentTarget.dataset.idx; json.questType = e.currentTarget.dataset.questtypes; this.data.chooseValue[e.currentTarget.dataset.index] = json; this.data.questionList[e.currentTarget.dataset.index].QuestAnswer = e.detail.value; this.setData({ questionList: this.data.questionList }) wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList); wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue); }, share() { this.setData({ show: true }); }, onClose() { this.setData({ ['postshow[' + this.data.timeIndex + ']']: false, }); }, onClose1() { console.log("11111111111111"); this.setData({ postshow1: false }); }, onInput(event) { console.log(event, "8888888"); console.log("点击了"); this.setData({ currentDate: event.detail, }); }, onInput1(event) { console.log("000"); this.setData({ currentDate1: event.detail, }); }, formatDate(date) { date = new Date(date); return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`; }, share1(e) { console.log(e); console.log(e.currentTarget.dataset.index); console.log(e.currentTarget.dataset.names, "8520852085208520"); console.log(this.data.postshow[e.currentTarget.dataset.index]); this.data.postshow[e.currentTarget.dataset.index] = true; this.data.names[e.currentTarget.dataset.index] = e.currentTarget.dataset.names; this.setData({ postshow: this.data.postshow, timeIndex: e.currentTarget.dataset.index }) console.log(this.data.postshow, "打印下锕啊啊啊啊锕锕锕"); }, share() { this.setData({ postshow1: true }); }, formatDate(date) { date = new Date(date); return `${date.getFullYear()-1}/${date.getMonth() + 1}/${date.getDate()}`; }, onConfirm(event) { console.log(event, "1111111"); let timeValue = this.timeFormat(new Date(event.detail), "yyyy-MM-dd"); let json = {}; json.currentAnswer = timeValue; json.id = event.currentTarget.dataset.idx; json.questType = event.currentTarget.dataset.questtypes; let aa = this.data.chooseValue[event.currentTarget.dataset.index] = json; this.data.questionList[event.currentTarget.dataset.index].QuestAnswer = timeValue; this.setData({ questionList: this.data.questionList, ['chooseValue[' + event.currentTarget.dataset.index + ']']: aa, ['postshow[' + this.data.timeIndex + ']']: false, ['headmasterText[' + this.data.timeIndex + ']']: '', }); wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList); wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue); console.log(this.data.chooseValue, "确定后的值锕"); console.log(this.data.questionList, "789789798789"); }, onConfirm1(event) { console.log(event, "0000"); 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 }) }, // submitForm() { // //let arr1 = this.data.chooseValue.filter(d => d); // //console.log(arr1,"打印下提交"); // console.log(this.data.chooseValue, "打印下提交"); // let isTrue = false; // this.data.chooseValue.forEach(item => { // console.log(item, "123123"); // if (item.currentAnswer) { // isTrue = true; // } else { // wx.showModal({ // showCancel: false, // content: item.QuestStem + "不能为空", // success(res) {} // }) // } // }) // if (isTrue) { // console.log("提交了"); // wx.request({ // url: app.globalData.publicUrl + '/wx/paper/commit', // method: "post", // data: { // sessionKey: this.data.sessionKey, // currentAnswerTemp: this.data.chooseValue, // answersId: wx.getStorageSync('answersId') // }, // success: (res) => { // console.log(res); // } // }) // } // }, submitForm() { wx.showLoading({ mask: true, title: '加载中', }) console.log(this.data.chooseValue, "打印下提交"); wx.request({ url: app.globalData.publicUrl + '/wx/paper/commit', method: "post", data: { sessionKey: this.data.sessionKey, currentAnswerTemp: this.data.chooseValue, answersId: wx.getStorageSync('answersId') }, success: (res) => { wx.hideLoading(); console.log(res); if(res.data.msg == "请勿重复提交"){ wx.showModal({ showCancel: false, content: res.data.msg, success(res) {} }) }else{ wx.showModal({ showCancel: false, content: '评价成功', success() { wx.navigateBack({ delta: 1 }) } }) } } }) // let isTrue = false; // this.data.chooseValue.forEach(item => { // console.log(item, "123123"); // if (item.currentAnswer) { // isTrue = true; // } else { // wx.showModal({ // showCancel: false, // content: item.QuestStem + "不能为空", // success(res) {} // }) // } // }) // if (isTrue) { // console.log("提交了"); // wx.request({ // url: app.globalData.publicUrl + '/wx/paper/commit', // method: "post", // data: { // sessionKey: this.data.sessionKey, // currentAnswerTemp: this.data.chooseValue, // answersId: wx.getStorageSync('answersId') // }, // success: (res) => { // console.log(res); // if(res.data.msg == "请勿重复提交"){ // wx.showModal({ // showCancel: false, // content: res.data.msg, // success(res) {} // }) // }else{ // wx.navigateTo({ // url: '/pages/myClass/myClass', // }) // } // } // }) // } }, 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 (options) { //const sessionKey = 'BqQROCKCxn7R2NXdQLud9Q=='; console.log("onloading....................."); const sessionKey = await tools.checkSessionAndLogin(); console.log(sessionKey,"对接下"); wx.setStorageSync('answersId', options.answersId); this.setData({ sessionKey: sessionKey, paperId: options.paperId, answersId: options.answersId, id: options.id, }) if (wx.getStorageSync('questionList' + wx.getStorageSync('answersId'))) { console.log("缓村了锕"); const questionList = wx.getStorageSync('questionList' + wx.getStorageSync('answersId')); this.setData({ questionList: questionList, answersId: wx.getStorageSync('answersId' + wx.getStorageSync('answersId')), chooseValue: wx.getStorageSync('chooseValue' + wx.getStorageSync('answersId')), }) console.log(this.data.questionList, "show 缓存的数据"); } else { console.log("无缓存"); this.allShi(this.data.id, this.data.paperId, this.data.sessionKey); } }, allShi(id, paperId, sessionKey) { wx.request({ url: app.globalData.publicUrl + '/wx/paper/detail', method: "post", data: { sessionKey: sessionKey, id: id, paperId: paperId }, success: (res) => { let jsonArr = JSON.parse(res.data.paperContent).map(item => { let json = {}; json.QuestType = item.QuestType; json.Id = item.Id; json.QuestAnswer = item.QuestAnswer; json.QuestStem = item.QuestStem; if (item.QuestType == '1' || item.QuestType == '0') { let arr = item.QuestChoice.split('||'); let arrJson = arr.map(item => { let json1 = {}; json1.name = item; json1.value = item; json1.checked = false; return json1 }); json.QuestChoice = arrJson; } return json; }) // 答案锕 let chooceArr = jsonArr.map(item => { let json = {}; json.currentAnswer = ''; json.questType = ''; json.id = item.Id; json.QuestStem = item.QuestStem; return json }) this.setData({ questionList: jsonArr, chooseValue: chooceArr }) console.log(this.data.questionList, "00000"); wx.setStorageSync('questionList' + wx.getStorageSync('answersId'), this.data.questionList); wx.setStorageSync('chooseValue' + wx.getStorageSync('answersId'), this.data.chooseValue); } }) }, })