|
@@ -53,14 +53,7 @@
|
|
</el-select>
|
|
</el-select>
|
|
<el-button size="mini" type="primary" @click="searchQuestion" style="margin-left:10px;">查询</el-button>
|
|
<el-button size="mini" type="primary" @click="searchQuestion" style="margin-left:10px;">查询</el-button>
|
|
</el-col>
|
|
</el-col>
|
|
- <el-table
|
|
|
|
- :row-key="getRowKey"
|
|
|
|
- ref="multipleTable"
|
|
|
|
- :data="questions"
|
|
|
|
- tooltip-effect="dark"
|
|
|
|
- style="width: 100%"
|
|
|
|
- @selection-change="handleSelectionChange"
|
|
|
|
- >
|
|
|
|
|
|
+ <el-table :row-key="getRowKey" ref="multipleTable" :data="questions" tooltip-effect="dark" style="width: 100%" @select="handleSelect">
|
|
<el-table-column prop="_id" type="selection" width="55" :reserve-selection="true"> </el-table-column>
|
|
<el-table-column prop="_id" type="selection" width="55" :reserve-selection="true"> </el-table-column>
|
|
<el-table-column prop="type" label="类型">
|
|
<el-table-column prop="type" label="类型">
|
|
<template slot-scope="scope">
|
|
<template slot-scope="scope">
|
|
@@ -109,7 +102,6 @@ export default {
|
|
form: {},
|
|
form: {},
|
|
questions: [], //问题数组
|
|
questions: [], //问题数组
|
|
questiontotal: 0, //问题总数
|
|
questiontotal: 0, //问题总数
|
|
- multipleSelection: [], //选择的问题数组
|
|
|
|
qtype: null, //选择的问题类型
|
|
qtype: null, //选择的问题类型
|
|
qtypeoptions: [
|
|
qtypeoptions: [
|
|
{ value: '0', label: '单选' },
|
|
{ value: '0', label: '单选' },
|
|
@@ -151,20 +143,29 @@ export default {
|
|
this.$set(this, `questions`, list.data);
|
|
this.$set(this, `questions`, list.data);
|
|
this.$set(this, `questiontotal`, list.total);
|
|
this.$set(this, `questiontotal`, list.total);
|
|
}
|
|
}
|
|
|
|
+ if (this.form.question) {
|
|
|
|
+ this.matchQuestion(this.form.question);
|
|
|
|
+ } else {
|
|
|
|
+ this.$refs.multipleTable.clearSelection();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
// 查看详情
|
|
// 查看详情
|
|
async detailBtn(item) {
|
|
async detailBtn(item) {
|
|
this.dialogFormVisible = true;
|
|
this.dialogFormVisible = true;
|
|
this.form = item;
|
|
this.form = item;
|
|
- this.searchQuestion();
|
|
|
|
|
|
+ await this.searchQuestion();
|
|
|
|
+ this.matchQuestion(this.form.question);
|
|
|
|
+ },
|
|
|
|
+ // 匹配选中的问题
|
|
|
|
+ matchQuestion(rows) {
|
|
this.$nextTick(function() {
|
|
this.$nextTick(function() {
|
|
- item.question.forEach(row => {
|
|
|
|
|
|
+ this.$refs.multipleTable.clearSelection();
|
|
|
|
+ rows.forEach(row => {
|
|
let r = this.questions.find(f => f._id == row._id);
|
|
let r = this.questions.find(f => f._id == row._id);
|
|
- //this.multipleSelection.push(row);
|
|
|
|
- this.$refs.multipleTable.toggleRowSelection(r);
|
|
|
|
|
|
+ if (r) this.$refs.multipleTable.toggleRowSelection(r);
|
|
});
|
|
});
|
|
|
|
+ this.$forceUpdate();
|
|
});
|
|
});
|
|
- console.log(this.multipleSelection);
|
|
|
|
},
|
|
},
|
|
//删除
|
|
//删除
|
|
async deleteBtn() {
|
|
async deleteBtn() {
|
|
@@ -177,7 +178,6 @@ export default {
|
|
},
|
|
},
|
|
//提交问卷
|
|
//提交问卷
|
|
async submitFrom() {
|
|
async submitFrom() {
|
|
- this.form.question = this.multipleSelection;
|
|
|
|
let res;
|
|
let res;
|
|
if (this.form.id) res = await this.update(this.form);
|
|
if (this.form.id) res = await this.update(this.form);
|
|
else res = await this.create(this.form);
|
|
else res = await this.create(this.form);
|
|
@@ -193,11 +193,16 @@ export default {
|
|
this.qtype = null;
|
|
this.qtype = null;
|
|
this.form = {};
|
|
this.form = {};
|
|
this.searchQuestion();
|
|
this.searchQuestion();
|
|
- this.multipleSelection = [];
|
|
|
|
},
|
|
},
|
|
//选中问题时触发
|
|
//选中问题时触发
|
|
- handleSelectionChange(val) {
|
|
|
|
- this.multipleSelection = val;
|
|
|
|
|
|
+ handleSelect(selection, row) {
|
|
|
|
+ let index = this.form.question.findIndex(item => item._id == row._id);
|
|
|
|
+ if (index >= 0) {
|
|
|
|
+ this.form.question.splice(index, 1);
|
|
|
|
+ } else {
|
|
|
|
+ this.form.question.push(row);
|
|
|
|
+ }
|
|
|
|
+ console.log(this.form.question);
|
|
},
|
|
},
|
|
//题库分页
|
|
//题库分页
|
|
questionChange(val) {
|
|
questionChange(val) {
|