diff --git a/index.html b/index.html index ebb56fc..281ea98 100644 --- a/index.html +++ b/index.html @@ -63,8 +63,8 @@ -
- +
+
@@ -302,11 +302,12 @@ html += `
`; html += ``; } else if (data.type === 5) { + data.answer = '1'; html += `
`; html += `

${data.question}

`; - html += ``; for (let j = 0; j < data.optionList.length; j++) { - html += ``; + html += ``; } html += ``; html += `
`; @@ -338,25 +339,40 @@ var tar = event.target || event.srcElement; let id = tar.getAttribute("data-id"); - console.log("event", event, "tar", tar, "id", id) - let arr = this.tempData; arr.forEach(function(item, index) { - if (item.type === 1 || item.type === 2 || item.type === 3 || item.type === 6) { + if (item.type === 1 || item.type === 2 || item.type === 3 || item.type === 5 || item.type === 6) { if (item.questionId == id) { item.answer = tar.value; } + } else if (item.type === 4) { + if (item.questionId == id) { + item.optionList.forEach(v => { + if (v.submitValue === tar.value) { + v.choose = v.choose === 1 ? 0 : 1; + } + }) + + item.answer = ''; + item.optionList.forEach(v => { + if (v.choose === 1) { + item.answer += ',' + v.submitValue; + } + }) + } } else if (item.type === 7) { tar.addEventListener('change', function(event) { var files = event.target.files; - var formData = new FormData(); - formData.append('param', files[0]); - that.upload(formData, index); + + if (files && files.length > 0) { + var formData = new FormData(); + formData.append('param', files[0]); + that.upload(formData, index); + } + }, false); } }); - - console.log(arr); }, // 预览 @@ -368,20 +384,41 @@ let that = this; console.log("that.tempData",that.tempData) let questionList = [], arr = that.tempData; + + if (!arr.length) { + alert("请选择红头文件模板"); + return false; + } + + arr.forEach(item => { + if (!item.answer) { + alert("请填写" + item.question); + return false; + } + }) + arr.forEach(function(item, index) { - console.log(item, index); - if (item.type === 1 || item.type === 2) { - item.answer = that.dom.querySelector('.ques-' + item.questionId).value; - let obj = {}; + let obj = { questionId: '', answerList: [] }; + + if (item.type === 1 || item.type === 2 || item.type === 3 || item.type === 6 || item.type === 7) { obj.questionId = item.questionId; - obj.answerList = item.answer; - } else if (item.type === 3) { - item.answer = that.dom.querySelector('.ques-' + item.questionId).value; - let obj = {}; + obj.answerList.push(item.answer); + } else if (item.type === 4) { obj.questionId = item.questionId; - obj.answerList = item.answer; + item.optionList.forEach(v => { + if (v.choose === 1) { + obj.answerList.push(v.submitValue); + } + }) + } else if (item.type === 5) { + obj.questionId = item.questionId; + obj.answerList.push(item.answer ? item.answer : 1); } + + questionList.push(obj); }) + + console.log('questionList', questionList) }, // 文件上传 @@ -405,7 +442,6 @@ let fileName = that.dom.querySelector('.file-name'); fileName.innerHTML = data.name; that.tempData[index].answer = data.path; - console.log("that.tempData", that.tempData) } else { console.log('msg: ', msg); }