-
+
@@ -227,6 +235,7 @@
curStatus: 0, // 当前状态 0 未提交 1 已提交待审核
curIndex: 0, // 当前选择的模板
tempList: [{name: '模板1', organizer: '国家体育总局社会体育指导中心', title: ''}, {name: '模板2', organizer: '', title: ''}, {name: '模板3', organizer: '', title: ''}],
+ tempData: {},
init() {
this.dom = document.querySelector("div[data-root=p1449927427387301888]");
@@ -305,6 +314,7 @@
// that.showOrHide(2, 0, 0, 0);
// }
// }
+ that.tempData = data;
} else {
console.log('msg: ', msg);
}
@@ -316,61 +326,156 @@
*/
getAllTemp() {
var that = this;
- // fetch(`https://test.tall.wiki/gateway/sports/training/template`, {
- // headers: new Headers({
- // 'Authorization': 'Bearer ' + that.token,
- // 'Content-Type': 'application/json; charset=utf-8'
- // }),
- // method: 'POST',
- // body: JSON.stringify({
- // param: {projectId: that.projectId}
- // })
- // })
- // .then(function(response) {
- // return response.json();
- // })
- // .then(function(res) {
- // const { success, code, data, msg } = res;
- // if (success && code === 200) {
- // for (let i = 0; i < data.length; i++) {
- // if (data[i].type === 0) {
- // that.tempList = data[i].templateList;
- // }
- // }
-
- // let html = '';
-
- // for (let j = 0; j < that.tempList.length; j++) {
- // html += `
- //

- //
`;
- // }
-
- // that.dom.querySelector('.temp-list').html = html;
-
- // html += `
- //

- //
`;
-
- // } else {
- // console.log('msg: ', msg);
- // }
- // });
+ fetch(`https://test.tall.wiki/gateway/sports/training/template`, {
+ headers: new Headers({
+ 'Authorization': 'Bearer ' + that.token,
+ 'Content-Type': 'application/json; charset=utf-8'
+ }),
+ method: 'POST',
+ body: JSON.stringify({
+ param: {projectId: that.projectId}
+ })
+ })
+ .then(function(response) {
+ return response.json();
+ })
+ .then(function(res) {
+ const { success, code, data, msg } = res;
+ if (success && code === 200) {
+ for (let i = 0; i < data.length; i++) {
+ if (data[i].type === 0) {
+ that.tempList = data[i].templateList;
+ }
+ }
+
+ that.renderTemp(); // 渲染模板
+ } else {
+ console.log('msg: ', msg);
+ }
+ });
},
/**
* 选择模板
*/
selTemp(index) {
+ let obj = this.tempList[index];
let tempName = document.querySelector('.sel-temp-name');
- tempName.innerHTML = this.tempList[index - 1].name;
+ tempName.innerHTML = obj.name;
let temps = document.querySelectorAll('.temp-item');
for (let i = 0; i < temps.length; i++) {
temps[i].classList.remove("border-blue-400");
temps[i].classList.add("border-gray-200");
}
- temps[index - 1].classList.add("border-blue-400");
- this.curIndex = index - 1;
+ temps[index].classList.add("border-blue-400");
+ this.curIndex = index;
+ this.getTempData(obj.id);
+ },
+
+ // 根据模板id获取模板数据
+ getTempData(id) {
+ var that = this;
+ fetch(`https://test.tall.wiki/gateway/sports/training/templateId`, {
+ headers: new Headers({
+ 'Authorization': 'Bearer ' + that.token,
+ 'Content-Type': 'application/json; charset=utf-8'
+ }),
+ method: 'POST',
+ body: JSON.stringify({
+ param: {id: id}
+ })
+ })
+ .then(function(response) {
+ return response.json();
+ })
+ .then(function(res) {
+ const { success, code, data, msg } = res;
+ if (success && code === 200) {
+ for (let i = 0; i < data.length; i++) {
+ if (data[i].type === 0) {
+ that.tempList = data[i].templateList;
+ }
+ }
+ that.tempData = data;
+ that.renderTempData(); // 渲染模板数据
+ } else {
+ console.log('msg: ', msg);
+ }
+ });
+ },
+
+ // 渲染模板
+ renderTemp() {
+ let that = this;
+ // this.tempList
+
+ let html = '';
+
+ for (let j = 0; j < that.tempList.length; j++) {
+ html += `
+

+
`;
+ }
+
+ that.dom.querySelector('.temp-list').innerHTML = html;
+ },
+
+ // 渲染模板数据
+ renderTempData() {
+ let html = '';
+ for (let i = 0; i < this.tempData.length; i++) {
+ let data = this.tempData[i];
+ if (data.type === 1) {
+ html += `
`;
+ } else if (data.type === 2) {
+ html += `
`;
+ } else if (data.type === 3) {
+ html += `
`;
+ html += `
${data.question}
`;
+
+ html += `
`;
+ for (let j = 0; j < data.optionList.length; j++) {
+ html += ``;
+ }
+ html += `
`;
+ html += `
`;
+ } else if (data.type === 4) {
+ html += `
+
${data.question}
+
+ <% for (let j = 0; j < data.optionList.length; j++) { %>
+
+ <% } %>
+
+
`;
+ } else if (data.type === 5) {
+ html += `
+
${data.question}
+
+
`;
+ } else if (data.type === 6) {
+ html += `
`;
+ }
+ }
+
+ this.dom.querySelector('.temp-box').innerHTML = html;
},
// 预览