parent
479aba93eb
commit
2ae0f95eaf
8 changed files with 477 additions and 63 deletions
@ -0,0 +1,174 @@ |
||||
<template> |
||||
<div> |
||||
<el-dialog title="批量添加单选题" :visible.sync="quesVisible" width="1200px" :close-on-click-modal="false" |
||||
@closed="closeDia"> |
||||
<div class="tool"> |
||||
<ul class="filter"> |
||||
<li> |
||||
<label>搜索</label> |
||||
<el-input style="width: 250px;" placeholder="请输入模板名称" prefix-icon="el-icon-search" v-model="keyword" |
||||
clearable /> |
||||
</li> |
||||
</ul> |
||||
<div> |
||||
<el-button type="primary" @click="add">新增模板</el-button> |
||||
</div> |
||||
</div> |
||||
|
||||
<span slot="footer" class="dialog-footer"> |
||||
<el-button @click="quesVisible = false">关闭</el-button> |
||||
</span> |
||||
</el-dialog> |
||||
</div> |
||||
</template> |
||||
<script> |
||||
import Setting from '@/setting' |
||||
import Util from '@/libs/util' |
||||
import _ from 'lodash' |
||||
export default { |
||||
props: ['visible'], |
||||
data () { |
||||
return { |
||||
quesVisible: false, |
||||
keyword: '', |
||||
searchTimer: null, |
||||
submiting: false, |
||||
|
||||
}; |
||||
}, |
||||
watch: { |
||||
'keyword': function (val) { |
||||
clearTimeout(this.searchTimer) |
||||
// this.searchTimer = setTimeout(this.initData, 500) |
||||
}, |
||||
visible () { |
||||
this.quesVisible = this.visible |
||||
this.visible && this.getList() |
||||
} |
||||
}, |
||||
mounted () { |
||||
|
||||
}, |
||||
methods: { |
||||
// 获取模板列表 |
||||
async getList () { |
||||
try { |
||||
const res = await this.$post(this.api.examPaperTemplateList, { |
||||
pageNum: this.page, |
||||
pageSize: this.pageSize, |
||||
...this.filter |
||||
}) |
||||
this.list = res.pageList.records |
||||
this.total = res.pageList.total |
||||
} catch (e) { } |
||||
}, |
||||
// 新增 |
||||
add () { |
||||
this.form = _.cloneDeep(this.originForm) |
||||
this.detailVisible = true |
||||
}, |
||||
// 试卷大纲添加行 |
||||
addLine (i) { |
||||
this.form.paperOutline.splice(i + 1, 0, { |
||||
examQuestions: [], |
||||
outlineName: '', |
||||
questionNum: '', |
||||
questionType: '', |
||||
targetScore: '', |
||||
}) |
||||
}, |
||||
// 试卷大纲移除行 |
||||
delLine (i) { |
||||
this.form.paperOutline.length > 1 && this.form.paperOutline.splice(i, 1) |
||||
}, |
||||
// 使用模板 |
||||
async useTemplate (row) { |
||||
const data = await this.getDetail(row.templateId) |
||||
this.$parent.form.paperOutline = data.paperOutline |
||||
this.closeDia() |
||||
}, |
||||
// 获取详情 |
||||
async getDetail (id) { |
||||
const res = await this.$get(this.api.templateDetails, { |
||||
id |
||||
}) |
||||
return res.template |
||||
}, |
||||
// 编辑 |
||||
async edit (row) { |
||||
this.detailVisible = true |
||||
const data = await this.getDetail(row.templateId) |
||||
this.form = data |
||||
}, |
||||
// 删除 |
||||
async del (row) { |
||||
try { |
||||
await this.$confirm(`确认要删除【${row.templateName}】吗?`, '提示', { |
||||
confirmButtonText: '确定', |
||||
cancelButtonText: '取消', |
||||
type: 'warning', |
||||
closeOnClickModal: false, |
||||
}) |
||||
await this.$post(this.api.deleteTemplate, { |
||||
ids: [row.templateId] |
||||
}) |
||||
Util.successMsg('删除成功') |
||||
this.getList() |
||||
} catch (e) { } |
||||
}, |
||||
// 提交 |
||||
async submit () { |
||||
if (this.submiting) return false |
||||
const { form } = this |
||||
if (!form.templateName) return Util.warningMsg('请输入模板名称') |
||||
let invalid = 0 |
||||
for (const e of form.paperOutline) { |
||||
if (!e.questionType) { |
||||
Util.warningMsg('请选择题型') |
||||
invalid = 1 |
||||
break |
||||
} |
||||
if (!e.questionNum) { |
||||
Util.warningMsg('请输入目标题数') |
||||
invalid = 1 |
||||
break |
||||
} |
||||
if (!e.targetScore) { |
||||
Util.warningMsg('请输入目标分值') |
||||
invalid = 1 |
||||
break |
||||
} |
||||
} |
||||
if (invalid) return false |
||||
this.submiting = true |
||||
form.createSource = 1 |
||||
form.questionNum = this.questionNum |
||||
form.totalScore = this.totalScore |
||||
form.outlineNum = form.paperOutline.length |
||||
form.questionType = [...new Set(form.paperOutline.map(e => e.questionType))].join('、') |
||||
try { |
||||
await this.$post(this.api.saveExamPaperTemplate, form) |
||||
Util.successMsg('保存成功') |
||||
this.detailVisible = false |
||||
this.submiting = false |
||||
this.getList() |
||||
} catch (e) { |
||||
this.submiting = false |
||||
} |
||||
}, |
||||
// 弹框关闭回调 |
||||
closeDia () { |
||||
this.$emit('update:visible', false) |
||||
} |
||||
} |
||||
}; |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
.action-icon { |
||||
margin-right: 10px; |
||||
font-size: 18px; |
||||
color: $main-color; |
||||
cursor: pointer; |
||||
} |
||||
</style> |
Loading…
Reference in new issue