提交 1b625eb1 authored 作者: 王鹏飞's avatar 王鹏飞

chore: 优化考试选择试卷页面

上级 5260b868
<template> <template>
<el-card> <el-card>
<el-input v-model="queryItem" style="margin-bottom: 10px; width: 200px" clearable></el-input> <el-input
v-model="queryItem"
style="margin-bottom: 10px; width: 200px"
clearable
@change="handleSearch"
@clear="handleSearch"
></el-input>
<el-button type="primary" size="small" style="margin-left: 10px" @click="handleSearch">搜索</el-button> <el-button type="primary" size="small" style="margin-left: 10px" @click="handleSearch">搜索</el-button>
<el-button type="plain" size="small" @click="restValue">重置</el-button> <el-button type="plain" size="small" @click="handleReset">重置</el-button>
<el-transfer :data="ExamParerList" :titles="['备选栏', '已选栏']" style="margin-top: 10px" v-model="q"> <el-transfer
:data="leftData"
:titles="['备选栏', '已选栏']"
style="margin-top: 10px"
v-model="q"
:props="transferProps"
@change="handleChange"
>
</el-transfer> </el-transfer>
<el-pagination <el-pagination
:hide-on-single-page="true" :hide-on-single-page="true"
...@@ -33,6 +46,9 @@ ...@@ -33,6 +46,9 @@
<script> <script>
import { getExamPaperList, updateExam, getExamPaperDetail } from '../api' import { getExamPaperList, updateExam, getExamPaperDetail } from '../api'
export default { export default {
props: {
isEdit: { type: String, default: '' }
},
data() { data() {
return { return {
total: 0, total: 0,
...@@ -41,27 +57,34 @@ export default { ...@@ -41,27 +57,34 @@ export default {
ExamParerList: [], ExamParerList: [],
queryItem: '', queryItem: '',
q: [], q: [],
// filterMethod(query, item) { transferProps: { label: 'paper_title', key: 'id' },
// return item.label.indexOf(query) > -1 selectedList: []
// },
checkedArrs: []
} }
}, },
props: { computed: {
isEdit: { leftData() {
type: String, // 合并左右数据
default: '' const list = this.ExamParerList.filter(item => {
return !this.selectedList.find(data => data.id === item.id)
})
return [...this.selectedList, ...list]
} }
}, },
computed: {},
methods: { methods: {
handleChange(ids) {
this.selectedList = this.leftData.reduce((result, item) => {
if (ids.includes(item.id)) {
result.push(item)
}
return result
}, [])
},
handleSearch() { handleSearch() {
this.page = 1 this.page = 1
this.getExamParerList() this.getExamParerList()
}, },
handleChange() {}, handleReset() {
restValue() { this.page = 1
this.queryItem = '' this.queryItem = ''
this.getExamParerList() this.getExamParerList()
}, },
...@@ -74,14 +97,9 @@ export default { ...@@ -74,14 +97,9 @@ export default {
const params = { q: this.queryItem, page: this.page, 'per-page': this.limit } const params = { q: this.queryItem, page: this.page, 'per-page': this.limit }
this.ExamParerList = [] this.ExamParerList = []
getExamPaperList(params).then(res => { getExamPaperList(params).then(res => {
this.total = res.data.total const { total = 0, list = [] } = res.data
this.ExamParerList = res.data.list.reduce((a, b) => { this.total = total
this.ExamParerList.push({ label: b.paper_title, key: b.id }) this.ExamParerList = list
return this.ExamParerList
}, [])
if (this.$route.query.exam_id && this.$route.query.isEdit === '2') {
this.getDetailInfo() // 获取详情
}
}) })
}, },
// 上一步 // 上一步
...@@ -104,11 +122,9 @@ export default { ...@@ -104,11 +122,9 @@ export default {
} }
} }
} }
this.checkedArrs = listArray
console.log(this.checkedArrs)
const qs = this.q.toString() const qs = this.q.toString()
this.$emit('getCheckPaper', qs) this.$emit('getCheckPaper', qs)
this.$emit('getCheckPaperList', this.checkedArrs) this.$emit('getCheckPaperList', listArray)
}, },
// 保存 // 保存
saveExamInfo() { saveExamInfo() {
...@@ -124,23 +140,18 @@ export default { ...@@ -124,23 +140,18 @@ export default {
// 获取试卷详情 // 获取试卷详情
getDetailInfo() { getDetailInfo() {
getExamPaperDetail({ id: this.$route.query.exam_id }).then(res => { getExamPaperDetail({ id: this.$route.query.exam_id }).then(res => {
const parperList = res.data.exam_info.paper_list const list = res.data.exam_info.paper_list || []
const arr = [] this.q = list.map(item => item.id)
parperList.forEach(element => { this.selectedList = list
console.log(element)
const findItem = this.ExamParerList.find(item => {
return item.label === element.paper_title
}).key
console.log(this.ExamParerList)
findItem && arr.push(findItem)
})
this.q = arr
}) })
} }
}, },
mounted() { mounted() {
// 获取试卷列表 // 获取试卷列表
this.getExamParerList() this.getExamParerList()
if (this.$route.query.exam_id && this.$route.query.isEdit === '2') {
this.getDetailInfo() // 获取详情
}
} }
} }
</script> </script>
...@@ -149,7 +160,6 @@ export default { ...@@ -149,7 +160,6 @@ export default {
text-align: right; text-align: right;
margin-top: 20px; margin-top: 20px;
} }
ul { ul {
margin-left: 20px; margin-left: 20px;
li { li {
...@@ -160,8 +170,11 @@ ul { ...@@ -160,8 +170,11 @@ ul {
color: #000; color: #000;
} }
} }
::v-deep .el-transfer {
display: flex;
align-items: center;
}
::v-deep .el-transfer-panel { ::v-deep .el-transfer-panel {
width: 42%; flex: 1;
} }
</style> </style>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论