From 49ac2fd3699933cf9f1594d036dca32b89913546 Mon Sep 17 00:00:00 2001 From: xuesinan <1404152492@qq.com> Date: Mon, 1 Nov 2021 11:49:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 139 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/index.html b/index.html index 11dea05..8d3e6f7 100644 --- a/index.html +++ b/index.html @@ -105,6 +105,13 @@ -->
+ +

选择模板

@@ -232,6 +239,8 @@ curIndex: 0, // 当前选择的模板 tempList: [{name: '模板1', organizer: '国家体育总局社会体育指导中心', title: ''}, {name: '模板2', organizer: '', title: ''}, {name: '模板3', organizer: '', title: ''}], tempData: {}, + checkArr: [], + templateId: 0, // 选中的模板id init() { this.dom = document.querySelector("div[data-root=p1449927427387301888]"); @@ -258,9 +267,9 @@ if (success && code === 200) { that.token = data.token; // 查询培训计划 - that.getTrainPlan() + that.getTrainPlan(); // 查询所有模板 - that.getAllTemp(); + // that.getAllTemp(); } else { console.log('msg: ', msg); } @@ -288,29 +297,17 @@ .then(function(res) { const { success, code, data, msg } = res; if (success && code === 200) { - // if (!data) { - // that.showOrHide(1, -1, 0, 0); - // } else { - // that.dom.querySelector('.train-name').value = data.name; - // that.dom.querySelector('.train-desc').value = data.description; - // let start = that.format(data.startTime); - // that.dom.querySelector('.train-start-time').value = that.format(data.startTime); - // that.dom.querySelector('.train-end-time').value = that.format(data.endTime); - // that.fileId = data.fileId; - // that.filePath = data.path; - // that.dom.querySelector('.file-name').innerHTML = data.name; - // console.log(data.startTime, start) - - // if (data && data.checkStatus === 0) { - // that.showOrHide(1, 0, 1, 0); - // } else if (data && data.checkStatus === 2) { - // that.showOrHide(1, 2, 1, 1); - // that.dom.querySelector('.reason').innerHTML = data.rejectCause; - // } else { - // that.showOrHide(2, 0, 0, 0); - // } - // } - // that.tempData = data; + that.getAllTemp(); + if (data) { + if (data.checkStatus === 0) { + that.dom.querySelector('.status-box').style.display = 'flex'; + } + + that.templateId = data.templateId; + that.tempData = data.trainingInfos; + that.renderTempData(); + } + } else { console.log('msg: ', msg); } @@ -365,6 +362,7 @@ } temps[index].classList.add("border-blue-400"); this.curIndex = index; + this.templateId = obj.id; this.getTempData(obj.id); }, @@ -403,12 +401,14 @@ // 渲染模板 renderTemp() { let that = this; - // this.tempList let html = ''; - for (let j = 0; j < that.tempList.length; j++) { - html += `
+ if (that.tempList[j].id == that.templateId) { + that.dom.querySelector('.sel-temp-name').innerHTML = that.tempList[j].name; + } + + html += `
`; } @@ -426,13 +426,13 @@ html += `

${data.question}

- +
`; } else if (data.type === 2) { html += `

${data.question}

- +
`; } else if (data.type === 3) { html += `
`; @@ -456,9 +456,10 @@ } else if (data.type === 5) { html += `
`; html += `

${data.question}

`; - html += ``; + html += ``; for (let j = 0; j < data.optionList.length; j++) { - html += ``; + html += ``; } html += ``; html += `
`; @@ -466,7 +467,7 @@ html += `

${data.question}

- +
`; } else if (data.type === 7) { @@ -490,14 +491,26 @@ 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; + item.answer = [tar.value]; } + } else if (item.type === 4) { + if (tar.checked) { + that.checkArr.push(tar.value); + } else { + let currIndex = 0; + for (let i = 0; i < that.checkArr.length; i++) { + if (that.checkArr[i] == tar.value) { + currIndex = i; + } + } + that.checkArr.splice(currIndex, 1); + } + + item.answer = that.checkArr; } else if (item.type === 7) { tar.addEventListener('change', function(event) { var files = event.target.files; @@ -507,8 +520,6 @@ }, false); } }); - - console.log(arr); }, // 预览 @@ -517,24 +528,41 @@ }, submit() { - // this.tempData let that = this; - console.log("that.tempData",that.tempData) - let questionList = [], arr = that.tempData; + let questionList = []; + let arr = this.tempData; 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 = {}; - 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.questionId = item.questionId; - obj.answerList = item.answer; - } + let obj = {}; + obj.questionId = item.questionId; + obj.answerList = item.answer; + questionList.push(obj); }) + + fetch(`https://test.tall.wiki/gateway/sports/training/save`, { + headers: new Headers({ + 'Authorization': 'Bearer ' + that.token, + 'Content-Type': 'application/json; charset=utf-8' + }), + method: 'POST', + body: JSON.stringify({ + param: { + projectId: that.projectId, + templateId: that.templateId, + questionList: questionList + } + }) + }) + .then(function(response) { + return response.json(); + }) + .then(function(res) { + const { success, code, data, msg } = res; + if (success && code === 200) { + + } else { + console.log('msg: ', msg); + } + }); }, // 文件上传 @@ -557,8 +585,7 @@ that.filePath = data.path; let fileName = that.dom.querySelector('.file-name'); fileName.innerHTML = data.name; - that.tempData[index].answer = data.path; - console.log("that.tempData", that.tempData) + that.tempData[index].answer = [data.path]; } else { console.log('msg: ', msg); }