From b0a1281069142d6eb11d17953ec9511338a4a318 Mon Sep 17 00:00:00 2001 From: xuesinan <1404152492@qq.com> Date: Tue, 28 Dec 2021 17:18:32 +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 | 86 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 281ea98..39cf103 100644 --- a/index.html +++ b/index.html @@ -37,7 +37,7 @@ --> -
+
@@ -99,9 +99,12 @@ fileId: '', // 上传文件ID filePath: '', // 上传文件路径 curStatus: 0, // 当前状态 0 未提交 1 已提交待审核 - curIndex: 0, // 当前选择的模板 + // curIndex: 0, // 当前选择的模板 tempList: [{name: '模板1', organizer: '国家体育总局社会体育指导中心', title: ''}, {name: '模板2', organizer: '', title: ''}, {name: '模板3', organizer: '', title: ''}], - tempData: {}, + tempData: {}, // 当前选择的模板数据 + currTempData: {}, // 当前计划的模板数据 + templateId: '', // 当前选择的模板ID + currTemplateId: '', // 当前计划的模板ID init() { this.dom = document.querySelector("div[data-root=p1472866674721169408]"); @@ -129,8 +132,7 @@ that.token = data.token; // 查询培训计划 that.getTrainPlan() - // 查询所有模板 - that.getAllTemp(); + } else { console.log('msg: ', msg); } @@ -158,10 +160,16 @@ .then(function(res) { const { success, code, data, msg } = res; if (success && code === 200) { - + that.templateId = data.templateId; + that.currTemplateId = data.templateId; + that.tempData = data.trainingInfos; + that.currTempData = data.trainingInfos; } else { console.log('msg: ', msg); } + + // 查询所有模板 + that.getAllTemp(); }); }, @@ -212,8 +220,15 @@ temps[i].classList.add("border-gray-200"); } temps[index].classList.add("border-blue-400"); - this.curIndex = index; - this.getTempData(obj.id); + + this.templateId = obj.id; + if (this.currTemplateId === obj.id) { + this.tempData = this.currTempData; + this.renderTempData(); // 渲染模板数据 + } else { + // this.curIndex = index; + this.getTempData(obj.id); + } }, // 根据模板id获取模板数据 @@ -251,36 +266,43 @@ // 渲染模板 renderTemp() { let that = this; - // this.tempList - let html = ''; for (let j = 0; j < that.tempList.length; j++) { + let d = that.tempList[j]; + html += `
- +
`; } that.dom.querySelector('.temp-list').innerHTML = html; + + for (let j = 0; j < that.tempList.length; j++) { + if (that.tempList[j].id === that.currTemplateId) { + that.selTemp(j); + } + } }, // 渲染模板数据 renderTempData() { let that = this; let html = ''; + for (let i = 0; i < that.tempData.length; i++) { let data = that.tempData[i]; if (data.type === 1) { html += `

${data.question}

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

${data.question}

- +
`; } else if (data.type === 3) { html += `
`; @@ -288,7 +310,7 @@ html += `
`; for (let j = 0; j < data.optionList.length; j++) { - html += ``; + html += ``; } html += `
`; html += `
`; @@ -297,7 +319,7 @@ html += `

${data.question}

`; html += `
`; for (let j = 0; j < data.optionList.length; j++) { - html += ``; + html += ``; } html += `
`; html += `
`; @@ -305,9 +327,9 @@ data.answer = '1'; html += `
`; html += `

${data.question}

`; - html += ``; for (let j = 0; j < data.optionList.length; j++) { - html += ``; + html += ``; } html += ``; html += `
`; @@ -315,12 +337,12 @@ html += `

${data.question}

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

文件上传

+

${data.answer ? data.answer : '文件上传'}

@@ -419,6 +441,32 @@ }) console.log('questionList', questionList) + + 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, + questionList, + templateId: that.templateId + } + }), + }) + .then(function(response) { + return response.json(); + }) + .then(function(res) { + const { success, code, data, msg } = res; + if (success && code === 200) { + that.getTrainPlan(); // 重新调用查询培训计划方法,查询提交后的红头文件 + } else { + console.log('msg: ', msg); + } + }); }, // 文件上传