diff --git a/src/views/modules/course/examination/questionBank/add.vue b/src/views/modules/course/examination/questionBank/add.vue index 21714cc..f416f06 100644 --- a/src/views/modules/course/examination/questionBank/add.vue +++ b/src/views/modules/course/examination/questionBank/add.vue @@ -360,23 +360,29 @@ export default { this.tableColumn = tableColumn; var that = this; this.$nextTick(() => { + if (!this.$refs.xTable) { + return; + } + this.clearRadioRowEevnt(); + this.clearCheckboxEevnt(); if (this.tableData.length > 0) { - console.log("this.tableData.length at line 354:", this.tableData); this.tableData.forEach((e, i) => { if (e.rightWrong == 1) { - console.log("e.rightWrong at line 356:", e); setTimeout(() => { + if (!that.$refs.xTable) { + return; + } if (this.dataForm.type == 1) { that.$refs.xTable.setCheckboxRow(this.tableData[i], true); + that.selectData = that.$refs.xTable.getCheckboxRecords(); } else { that.$refs.xTable.setRadioRow(this.tableData[i]); + that.selectRow = this.tableData[i]; } }, 50); } }); } - this.clearRadioRowEevnt(); - this.clearCheckboxEevnt(); this.$forceUpdate(); }); }, @@ -406,35 +412,58 @@ export default { this.selectRow = null; this.$refs.xTable.clearRadioRow(); }, + getRowKey(row) { + if (!row) { + return ""; + } + if (row.id !== undefined && row.id !== null && row.id !== "") { + return String(row.id); + } + return ( + row._X_ROW_KEY || + row._XID || + row._X_ROW_ID || + "" + ); + }, + isSameOptionRow(rowA, rowB) { + if (!rowA || !rowB) { + return false; + } + if (rowA === rowB) { + return true; + } + const keyA = this.getRowKey(rowA); + const keyB = this.getRowKey(rowB); + return keyA && keyB && keyA === keyB; + }, getRadioEvent1() { - var selectIds = []; + let selectedRows = []; if (this.dataForm.type == 0) { - var data = this.$refs.xTable.getRadioRecord(); - console.log("data at line 402:", data); - if (data && (data.id || data._X_ROW_KEY)) { - selectIds.push(data.id || data._X_ROW_KEY); - console.log("selectIds.push at line 404:", selectIds); + const data = + (this.$refs.xTable && this.$refs.xTable.getRadioRecord()) || + this.selectRow; + if (data) { + selectedRows = [data]; } } else { - var data = this.$refs.xTable.getCheckboxRecords(); - selectIds = data.map(e => { - return e.id || e._X_ROW_KEY; - }); - console.log("selectIds at line 369:", selectIds); + const data = + (this.$refs.xTable && this.$refs.xTable.getCheckboxRecords()) || + []; + selectedRows = data.length ? data : this.selectData; } - var list = [...this.tableData]; - list.map(e => { + const list = [...this.tableData]; + list.forEach(e => { e.rightWrong = 0; }); - if (selectIds.length > 0) { - list.map(e => { - if (selectIds.includes(e.id || e._X_ROW_KEY)) { + if (selectedRows.length > 0) { + list.forEach(e => { + if (selectedRows.some(row => this.isSameOptionRow(row, e))) { e.rightWrong = 1; } }); } - console.log("list at line 428:", list); return list; },