考试管理-分类改为单选
This commit is contained in:
parent
26370a4c46
commit
640f36842f
@ -33,8 +33,13 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="tags">
|
||||
<el-select multiple v-model="form.tags" @change="getQuestionAmount">
|
||||
<el-option v-for="label in labels" :key="label" :label="label" :value="label"></el-option>
|
||||
<el-select v-model="form.tags" @change="getQuestionAmount">
|
||||
<el-option
|
||||
v-for="item in labels"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="题目数量" prop="amount">
|
||||
@ -44,8 +49,7 @@
|
||||
style="width: calc(100% - 280px); float: left; margin-right: 10px;"
|
||||
/>
|
||||
<span v-if="this.form.type === 1" style="width: 190px; float: left;">
|
||||
{{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }}, 剩余
|
||||
{{ remainNum }}题
|
||||
{{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('publish.scorePerQuestion')" prop="score">
|
||||
@ -94,7 +98,7 @@ export default {
|
||||
message(new Error(this.$t('publish.inputQuestionNumberError')))
|
||||
} else if (!Number(value)) {
|
||||
message(new Error(this.$t('publish.inputValidNumber')))
|
||||
} else if (Number(value) > this.remainNum && this.form.type === 1) {
|
||||
} else if (Number(value) > this.topicNum && this.form.type === 1) {
|
||||
message(new Error(this.$t('publish.inputNumberError')))
|
||||
} else {
|
||||
message()
|
||||
@ -113,13 +117,12 @@ export default {
|
||||
id: '',
|
||||
type: '',
|
||||
subtype: '',
|
||||
tags: [],
|
||||
tags: '',
|
||||
amount: 1,
|
||||
score: 1,
|
||||
},
|
||||
labels: [],
|
||||
topicNum: 0,
|
||||
remainNum: 0,
|
||||
index: -1,
|
||||
dialogShow: false,
|
||||
rules: {
|
||||
@ -132,7 +135,7 @@ export default {
|
||||
},
|
||||
created() {
|
||||
getLabelList().then(resp => {
|
||||
this.labels = resp.data
|
||||
this.labels = [{ label: '无', value: '' }, ...resp.data.map(item => ({ label: item, value: item }))]
|
||||
})
|
||||
},
|
||||
mounted() {},
|
||||
@ -150,13 +153,11 @@ export default {
|
||||
amount: detail.amount,
|
||||
score: detail.score,
|
||||
id: detail.id || '',
|
||||
tags: detail.tags
|
||||
tags: detail.tags || '',
|
||||
}
|
||||
this.topicNum = detail.topicNum
|
||||
this.remainNum = detail.remainNum
|
||||
} else {
|
||||
this.isEditMode = false
|
||||
this.remainNum = 0
|
||||
}
|
||||
})
|
||||
},
|
||||
@ -167,56 +168,21 @@ export default {
|
||||
rule =>
|
||||
rule.type === this.form.type &&
|
||||
rule.subtype === this.form.subtype &&
|
||||
rule.tags.length === this.form.tags.length &&
|
||||
rule.tags.every(tag => this.form.tags.includes(tag))
|
||||
rule.tags === this.form.tags
|
||||
)
|
||||
return isDuplicated
|
||||
},
|
||||
getQuestionAmount(e) {
|
||||
if (!(this.form.type && this.form.subtype)) return
|
||||
if (this.form.type === 2) return //实训题暂不支持查询数量
|
||||
// if (this.isDuplicated()) {
|
||||
// this.$message.warning('与已有规则重复, 请重新选择')
|
||||
// return
|
||||
// }
|
||||
const param = {
|
||||
orgId: this.$store.state.user.companyId,
|
||||
groupType: this.form.type,
|
||||
subType: this.form.subtype,
|
||||
tags: this.form.tags,
|
||||
}
|
||||
if (this.form.tags) param.tags = this.form.tags
|
||||
getQuestionAmount(param).then(resp => {
|
||||
const num = resp.data
|
||||
this.topicNum = num
|
||||
const { type, subtype, tags } = this.form
|
||||
if (this.ruleList.length > 0) {
|
||||
const smallerRangeRules = this.ruleList.filter(
|
||||
(rule, i) =>
|
||||
rule.type === type &&
|
||||
rule.subtype === subtype &&
|
||||
rule.tags.length >= tags.length &&
|
||||
(tags.every(tag => rule.tags.includes(tag)) || tags.length === 0) &&
|
||||
(this.isEditMode ? this.index !== i : true) //排除正在编辑中的自己
|
||||
)
|
||||
//更小(及相同)的题目集合中已占用的题目数
|
||||
const amount1 = smallerRangeRules.reduce((prev, curr) => prev + curr.amount, 0)
|
||||
const largerRangeRules = this.ruleList.filter(
|
||||
(rule, i) =>
|
||||
rule.type === type &&
|
||||
rule.subtype === subtype &&
|
||||
rule.tags.length < tags.length &&
|
||||
(rule.tags.every(tag => tags.includes(tag)) || rule.tags.length === 0) &&
|
||||
(this.isEditMode ? this.index !== i : true)
|
||||
)
|
||||
//更大的题目集合中未占用的题目数的最小值
|
||||
const amount2 = largerRangeRules.reduce(
|
||||
(prev, curr) => (curr.topicNum - curr.amount < prev ? curr.topicNum - curr.amount : prev),
|
||||
num
|
||||
)
|
||||
this.remainNum = amount2 - amount1
|
||||
} else {
|
||||
this.remainNum = num
|
||||
}
|
||||
this.topicNum = resp.data
|
||||
})
|
||||
},
|
||||
clearSubtype() {
|
||||
@ -231,11 +197,7 @@ export default {
|
||||
return
|
||||
}
|
||||
}
|
||||
this.$emit(
|
||||
'submit',
|
||||
{ ...this.form, topicNum: this.topicNum, remainNum: this.remainNum },
|
||||
this.isEditMode
|
||||
)
|
||||
this.$emit('submit', { ...this.form, topicNum: this.topicNum }, this.isEditMode)
|
||||
this.handleCancel()
|
||||
}
|
||||
})
|
||||
|
@ -105,7 +105,6 @@ export default {
|
||||
amount: formData.amount,
|
||||
score: formData.score,
|
||||
topicNum: formData.topicNum,
|
||||
remainNum: formData.remainNum,
|
||||
tags: formData.tags,
|
||||
}
|
||||
if (isEdit) {
|
||||
|
Loading…
Reference in New Issue
Block a user