//index.js //获取应用实例 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: '', }, 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); // this.data.questionList[this.data.index].checked = e.detail.value; // this.setData({ // questionList: this.data.questionList // }) // const items = this.data.items // for (let i = 0, len = items.length; i < len; ++i) { // items[i].checked = items[i].value === e.detail.value // } // this.setData({ // items // }) }, 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, "打印下锕啊啊啊啊锕锕锕"); // 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) { 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, "打印下提交"); this.data.chooseValue.forEach(item => { console.log(item,"123123"); if (item.currentAnswer) { } else { console.log(item.QuestStem); wx.showModal({ showCancel: false, content: item.QuestStem + "不能为空", success(res) {} }) } }) // wx.request({ // url: app.globalData.publicUrl + '/wx/paper/commit', // method: "post", // data: { // sessionKey: this.data.sessionKey, // currentAnswerTemp: arr1, // answersId: wx.getStorageSync('answersId') // }, // success: (res) => { // console.log(res); // } // }) }, formSubmit(e) { console.log(e.detail.value, "000000000000000"); let arr1 = this.data.zaizhiTime.filter(d => d); let arr = this.data.names.filter(d => d); var activeSubjectsArr = []; for (var i = 0; i < arr.length; i++) { var activeSubjectsObject = {}; for (var j = 0; j < arr1.length; j++) { if (i == j) { activeSubjectsObject[arr[i]] = arr1[j]; activeSubjectsArr.push(activeSubjectsObject); } } } console.log(activeSubjectsArr, "7777777"); let count = 0; let data = {}; for (let a in e.detail.value) { count += 1; if (count = 1) { data[a] = e.detail.value[a] } } activeSubjectsArr.forEach(item => { Object.assign(data, item) }) console.log(data, "888888888888888888888888"); // Object.keys(data).forEach(function (key) { // if (!data[key]) { // wx.showModal({ // showCancel: false, // content: key + "不能为空" // }) // return; // } // }); // 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.zaizhiTime) { // this.setData({ // renzhishijianIsTrue: true // }) // } else { // this.setData({ // renzhishijianIsTrue: false // }) // } // if (!this.data.peixunTime) { // this.setData({ // peixunshijianTrue: true // }) // } else { // this.setData({ // peixunshijianTrue: false // }) // } // console.log(this.data.zaizhiTime, "在职时间000"); // console.log(this.data.peixunTime, "培训时间000"); // console.log(sex, "性别的"); // e.detail.value.zaizhiTime = this.data.zaizhiTime; // e.detail.value.peixunTime = this.data.peixunTime; // e.detail.value.sex = sex; // console.log(e.detail.value, "我是合并后的锕"); }, 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 () {}, onLoad: function (options) { //const sessionKey = await tools.checkSessionAndLogin(); const sessionKey = 'yoa0rZTt2bAiTVDsiRjysw=='; console.log("onloading....................."); let chooceArr = this.data.questionList.map(item => { let json = {}; json.currentAnswer = ''; json.questType = ''; json.id = item.Id; json.QuestStem = item.QuestStem; return json }) console.log(chooceArr); this.setData({ chooseValue: chooceArr }) wx.setStorageSync('answersId', options.paperId); 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.QuestChoice) { // let arr = item.QuestChoice.split('||'); // json.QuestChoice = arr; // } 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; }) // for(let i = 0 ; i { 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); } }) }, })