From 30232619eeb95099a30fb5579da898d698dcacbb Mon Sep 17 00:00:00 2001
From: ZhangXianQiang <1135831638@qq.com>
Date: 星期二, 28 五月 2024 09:34:46 +0800
Subject: [PATCH] fix:多选回显问题
---
src/views/exam/personalRandomTemplate/edit.vue | 83 +++++++++++++++++----------
src/views/exam/paper/edit.vue | 70 ++++++++++++-----------
2 files changed, 88 insertions(+), 65 deletions(-)
diff --git a/src/views/exam/paper/edit.vue b/src/views/exam/paper/edit.vue
index 6c393de..6816708 100644
--- a/src/views/exam/paper/edit.vue
+++ b/src/views/exam/paper/edit.vue
@@ -1,9 +1,11 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="200px" v-loading="formLoading" :rules="rules">
- <el-form-item label="鑰冪敓锛�" prop="examineeList" required>
- <el-select v-model="form.examineeList" :collapse-tags="true" multiple placeholder="璇烽�夋嫨" @focus="selectStudent"
+ <el-form-item label="鑰冪敓锛�" prop="userIds" required>
+ <el-select v-model="form.userIds" :collapse-tags="true" multiple placeholder="璇烽�夋嫨" @focus="selectStudent"
popper-class="examinee-popper">
+ <el-option v-for="item in form.examineeList" :value="item.id" :label="item.realName"
+ :key="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="璇剧洰锛�" prop="subjectId" required>
@@ -155,7 +157,7 @@
<el-table-column prop="realName" label="瀛﹀憳" />
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="student.pageIndex" :limit.sync="student.pageSize"
- @pagination="selectStudent" />
+ @pagination="getStudent" />
<span slot="footer" class="dialog-footer">
<el-button @click="studentDialog = false">鍙� 娑�</el-button>
<el-button type="primary" @click="confirmStudentSelect">纭畾</el-button>
@@ -181,13 +183,17 @@
tags: [],
depts: [],
studentDialog: false,
+
+ isFirstShow: true,
+
+
student: {
deptIds: [],
pageIndex: 1,
pageSize: 5,
listLoading: true,
multipleSelection: [],
- excludeTagIds: []
+ excludeTagIds: [],
},
tableData: [],
total: 0,
@@ -213,13 +219,14 @@
titleItems: [],
subjectSource: {},
questionTypeVMS: [],
- examineeList: []
+ examineeList: [],
+ userNames: []
},
subjectFilter: null,
formLoading: false,
rules: {
- examineeList: [
- { required: true, message: '璇烽�夋嫨', trigger: 'change' }
+ userIds: [
+ { required: true, message: '璇烽�夋嫨鑰冪敓', trigger: 'change' }
],
subjectId: [
{ required: true, message: '璇烽�夋嫨璇剧洰', trigger: 'change' }
@@ -263,10 +270,15 @@
if (id && parseInt(id) !== 0) {
_this.formLoading = true;
examPaperApi.select(id).then(re => {
+ const { userIds, userNames } = re.response;
+
_this.form = re.response;
- // _this.form.menuIds = JSON.parse(re.response.menuIds);
- _this.examineeList = JSON.parse(re.response.userIds).map(item => item.realName);
- console.log(_this.form);
+ _this.form.examineeList = userIds.map((item, index) => {
+ return {
+ id: item,
+ realName: userNames && userNames[index] ? userNames[index] : ''
+ };
+ });
_this.formLoading = false;
});
}
@@ -289,21 +301,21 @@
this.getTags();
this.studentDialog = true;
this.student.listLoading = true;
+ this.getStudent();
+ },
+ getStudent() {
+ this.student.listLoading = true;
examPaperApi.selectStudent(this.student).then(res => {
this.tableData = res.response.list;
this.total = res.response.total;
this.student.listLoading = false;
-
- this.$nextTick(() => {
- this.tableData.map(data => {
- if (this.form.userIds.find(item => item === data.id)) {
- this.$refs.multipleTable.toggleRowSelection(data, true);
- } else {
- this.$refs.multipleTable.toggleRowSelection(data, false);
- }
+ if (this.studentDialog && this.isFirstShow) {
+ this.isFirstShow = false;
+ this.form.examineeList.forEach(item => {
+ this.$refs.multipleTable.toggleRowSelection(item, true);
});
- });
+ }
});
},
handleChange(val) {
@@ -362,9 +374,6 @@
// }
});
this.form.subjectSource = obj1;
-
- console.log(this.form.subjectSource);
- console.log(this.form.questionTypeVMS);
// this.form.paperType = 7
this.form.titleItems = [];
} else {
@@ -383,8 +392,8 @@
if (this.subjectIdList.length == 1) {
tempForm.subjectId = tempForm.subjectId;
};
- tempForm.userIds = tempForm.menuIds;
- // tempForm.menuIds = JSON.stringify(tempForm.menuIds);
+
+ tempForm.menuIds = tempForm.userIds.join(',');
if (tempForm.questionTypeVMS == null) {
tempForm.questionTypeVMS = [];
@@ -414,7 +423,6 @@
});
},
addQuestion(titleItem) {
- console.log('titleItem', titleItem);
this.currentTitleItem = titleItem;
this.questionPage.showDialog = true;
this.search();
@@ -441,15 +449,15 @@
this.questionPage.showDialog = false;
},
confirmStudentSelect() {
- // this.form.menuIds = this.student.multipleSelection.map((item) => item.id);
- this.form.userIds = this.student.multipleSelection.map((item) => {
+ this.form.userIds = this.student.multipleSelection.map((item) => item.id);
+
+ this.form.examineeList = this.student.multipleSelection.map((item) => {
return {
id: item.id,
realName: item.realName
};
});
- this.form.examineeList = this.student.multipleSelection.map((item) => item.realName);
-
+ this.student.multipleSelection = [];
this.studentDialog = false;
},
@@ -525,10 +533,6 @@
levelEnum: state => state.user.levelEnum
}),
...mapState('exam', { subjects: state => state.subjects }),
-
- examineeFormat() {
- return this.examineeList.map(item => item.realName);
- }
}
};
</script>
diff --git a/src/views/exam/personalRandomTemplate/edit.vue b/src/views/exam/personalRandomTemplate/edit.vue
index efa8130..763f87d 100644
--- a/src/views/exam/personalRandomTemplate/edit.vue
+++ b/src/views/exam/personalRandomTemplate/edit.vue
@@ -1,9 +1,12 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="200px" v-loading="formLoading" :rules="rules">
- <el-form-item label="鑰冪敓锛�" prop="menuIds" required>
- <el-select v-model="form.menuIds" :collapse-tags="true" multiple placeholder="璇烽�夋嫨" @focus="selectStudent"
- popper-class="examinee-popper"></el-select>
+ <el-form-item label="鑰冪敓锛�" prop="userIds" required>
+ <el-select v-model="form.userIds" :collapse-tags="true" multiple placeholder="璇烽�夋嫨" @focus="selectStudent"
+ popper-class="examinee-popper">
+ <el-option v-for="item in form.examineeList" :value="item.id" :label="item.realName"
+ :key="item.id"></el-option>
+ </el-select>
</el-form-item>
<el-form-item label="璇剧洰锛�" prop="subjectId" required>
<el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="璇剧洰" multiple collapse-tags
@@ -192,6 +195,8 @@
multipleSelection: [],
excludeTagIds: []
},
+ isFirstShow: true,
+
tableData: [],
total: 0,
props: {
@@ -228,11 +233,16 @@
suggestTime: null,
titleItems: [],
subjectSource: {},
- questionTypeVMS: []
+ questionTypeVMS: [],
+ examineeList: [],
+ userIds: []
},
subjectFilter: null,
formLoading: false,
rules: {
+ userIds: [
+ { required: true, message: '璇烽�夋嫨鑰冪敓', trigger: 'change' }
+ ],
subjectId: [
{ required: true, message: '璇烽�夋嫨璇剧洰', trigger: 'change' }
],
@@ -289,10 +299,18 @@
if (id && parseInt(id) !== 0) {
_this.formLoading = true;
await examPaperApi.selfselect(id).then(re => {
+ const { userIds, userNames } = re.response;
_this.form = re.response;
- _this.form.menuIds = JSON.parse(re.response.menuIds);
- _this.optionsData = _this.form.menuIds;
- console.log(_this.form);
+ if (userIds && userIds.length) {
+ _this.form.examineeList = userIds.map((item, index) => {
+ return {
+ id: item,
+ realName: userNames && userNames[index] ? userNames[index] : ''
+ };
+ });
+ } else {
+ _this.form.examineeList = [];
+ }
_this.formLoading = false;
});
@@ -316,7 +334,14 @@
this.student.multipleSelection = val;
},
confirmStudentSelect() {
- this.form.menuIds = this.student.multipleSelection.map((item) => item.id);
+ this.form.userIds = this.student.multipleSelection.map((item) => item.id);
+ this.form.examineeList = this.student.multipleSelection.map((item) => {
+ return {
+ id: item.id,
+ realName: item.realName
+ };
+ });
+ this.student.multipleSelection = [];
this.studentDialog = false;
},
getTags() {
@@ -328,20 +353,20 @@
this.getTags();
this.studentDialog = true;
this.student.listLoading = true;
-
+ this.getStudent();
+ },
+ getStudent() {
+ this.student.listLoading = true;
examPaperApi.selectStudent(this.student).then(res => {
this.tableData = res.response.list;
this.total = res.response.total;
this.student.listLoading = false;
- this.$nextTick(() => {
- this.tableData.map(data => {
- if (this.form.menuIds.find(item => item === data.id)) {
- this.$refs.multipleTable.toggleRowSelection(data, true);
- } else {
- this.$refs.multipleTable.toggleRowSelection(data, false);
- }
+ if (this.studentDialog && this.isFirstShow) {
+ this.isFirstShow = false;
+ this.form.examineeList.forEach(item => {
+ this.$refs.multipleTable.toggleRowSelection(item, true);
});
- });
+ }
});
},
cascaderChangeFun(event) {
@@ -416,8 +441,6 @@
},
submitForm() {
let _this = this;
- console.log(this.subjectIdList);
- console.log(this.form.subjectSource);
this.$refs.form.validate((valid) => {
if (valid) {
const tempForm = JSON.parse(JSON.stringify(this.form));
@@ -426,19 +449,15 @@
tempForm.subjectId = tempForm.subjectId;
};
- let lastHasAll = tempForm.menuIds.find(arr => {
- return arr[0] === 'all';
- });
- if (lastHasAll) {
- tempForm.menuIds = tempForm.menuIds.slice(1);
- }
- // let op = [];
- // for(var ele of this.form.menuIds){
- // op.push(ele[1])
- // };
- tempForm.userIds = tempForm.menuIds;
- tempForm.menuIds = JSON.stringify(tempForm.menuIds);
- console.log("laks", this.form);
+ // let lastHasAll = tempForm.menuIds.find(arr => {
+ // return arr[0] === 'all';
+ // });
+ // if (lastHasAll) {
+ // tempForm.menuIds = tempForm.menuIds.slice(1);
+ // }
+
+ tempForm.menuIds = tempForm.userIds.join(',');
+
if (tempForm.questionTypeVMS == null) {
tempForm.questionTypeVMS = [];
}
--
Gitblit v1.8.0