Przeglądaj źródła

add:考试新增手动组题功能;新增题库多选功能

luoaoxuan 1 rok temu
rodzic
commit
24225deb1e
1 zmienionych plików z 176 dodań i 27 usunięć
  1. 176 27
      src/views/platform/examination/exam/edit.vue

+ 176 - 27
src/views/platform/examination/exam/edit.vue

@@ -44,27 +44,59 @@
                     />
                 </el-select>
             </el-form-item> -->
-            <el-form-item label="考试题库:" prop="ti_ku_id_">
+            <el-form-item label="考试题库:">
+                <template slot="label">
+                    考试题库
+                    <el-tooltip
+                        effect="dark"
+                        content="如果选择多个题库或手动添加选题,最终生成的考试将是所选题目的总和,并将自动生成一个组合题库。"
+                        placement="top"
+                    >
+                        <i class="el-icon-question question-icon">:</i>
+                    </el-tooltip>
+                </template>
                 <div class="tiku">
-                    <div>
+                    <div class="item">
                         <ibps-custom-dialog
-                            v-model="form.ti_ku_id_"
+                            v-model="allQuestions.tiKu"
                             size="small"
                             template-key="tkdhk"
-                            :multiple="false"
+                            :multiple="true"
                             :disabled="isDisabled"
                             type="dialog"
                             class="custom-dialog"
                             placeholder="请选择考试题库"
+                            style="width:90%"
                         />
+                        <div class="number">题数:{{ allQuestionsNumber.tiKuNumber }}</div>
+                    </div>
+                </div>
+            </el-form-item>
+            <el-form-item label="手动选题:">
+                <template slot="label">
+                    手动选题
+                    <el-tooltip
+                        effect="dark"
+                        content="如果选择多个题库或手动添加选题,最终生成的考试将是所选题目的总和,并将自动生成一个组合题库。"
+                        placement="top"
+                    >
+                        <i class="el-icon-question question-icon">:</i>
+                    </el-tooltip>
+                </template>
+                <div class="tiku">
+                    <div class="item">
+                        <ibps-custom-dialog
+                            v-model="allQuestions.handQuestions"
+                            size="small"
+                            template-key="tmlb"
+                            multiple
+                            type="dialog"
+                            class="custom-dialog"
+                            placeholder="请选择考试题目"
+                            style="width:90%"
+                        />
+                        <div class="number">题数:{{ allQuestionsNumber.handQuestionsNumber }}</div>
                     </div>
-
-                    <!-- <el-button
-            type="primary"
-            @click="randTiku"
-            :disabled="randButtonDisabled"
-            >随机题库</el-button
-          > -->
                 </div>
             </el-form-item>
             <el-form-item>
@@ -80,7 +112,7 @@
                 </template>
                 <el-radio-group v-model="form.sui_ji_chou_ti_" :disabled="isDisabled">
                     <el-radio label="0">关闭</el-radio>
-                    <el-radio label="1" :disabled="!(!!form.ti_ku_id_)">开启</el-radio>
+                    <el-radio label="1" :disabled="allQuestionsNumber.tiKuNumber+allQuestionsNumber.handQuestionsNumber==0">开启</el-radio>
                 </el-radio-group>
             </el-form-item>
             <el-form-item v-if="form.sui_ji_chou_ti_ === '1'">
@@ -351,6 +383,7 @@
 </template>
 
 <script>
+import dayjs from 'dayjs'
 import ActionUtils from '@/utils/action'
 import { examTypeOptions, scoringType } from '../constants'
 export default {
@@ -379,6 +412,17 @@ export default {
             level
         } = this.$store.getters || {}
         return {
+            level: level.second || level.first,
+            userId: userId,
+            allQuestions: {
+                handQuestions: '',
+                tiKu: ''
+            },
+            allQuestionsNumber: {
+                handQuestionsNumber: 0,
+                tiKuNumber: 0
+            },
+            curQuestions: [],
             handList: [
                 { itemType: '单选题', questionNumber: 0, list: [], step: 1 },
                 { itemType: '多选题', questionNumber: 0, list: [], step: 1 },
@@ -489,16 +533,44 @@ export default {
             }
             // immediate: true
         },
-        'form.ti_ku_id_': {
+        'allQuestions': {
             handler (val) {
-                if (val) {
-                    const sql = `select * from t_questions where parent_id_ = '${val}' and zhuang_tai_ = '启用' order by field(ti_xing_, '单选题', '多选题', '判断题', '填空题', '简答题')`
-                    this.$common.request('sql', sql).then((res) => {
-                        const { data = [] } = res.variables || {}
-                        this.getHandList(data)
+                const allRequests = []
+                const { tiKu, handQuestions } = val
+                if (tiKu) {
+                    const sql = `select * from t_questions where parent_id_ in (${tiKu.split(',').map(i => `'${i}'`)}) and zhuang_tai_ = '启用' order by field(ti_xing_, '单选题', '多选题', '判断题', '填空题', '简答题')`
+                    allRequests.push(this.$common.request('sql', sql))
+                }
+                if (handQuestions) {
+                    const sql = `select * from t_questions where id_ in (${handQuestions.split(',').map(i => `'${i}'`)}) and zhuang_tai_ = '启用' order by field(ti_xing_, '单选题', '多选题', '判断题', '填空题', '简答题')`
+                    allRequests.push(this.$common.request('sql', sql))
+                }
+                if (allRequests.length) {
+                    Promise.all(allRequests).then(res => {
+                        const { data: data1 = [] } = res?.[0]?.variables || {}
+                        const { data: data2 = [] } = res?.[1]?.variables || {}
+                        if (!this.allQuestions.tiKu) {
+                            this.allQuestionsNumber.handQuestionsNumber = data1.length
+                        } else if (!this.allQuestions.handQuestions) {
+                            this.allQuestionsNumber.tiKuNumber = data1.length
+                        } else {
+                            this.allQuestionsNumber.tiKuNumber = data1.length
+                            this.allQuestionsNumber.handQuestionsNumber = data2.length
+                        }
+                        this.curQuestions = [...data1, ...data2]
+                        this.getHandList()
+                    }).catch(err => {
+                        console.error(err)
                     })
+                } else {
+                    this.allQuestionsNumber.tiKuNumber = 0
+                    this.allQuestionsNumber.handQuestionsNumber = 0
+                    this.form.sui_ji_chou_ti_ = '0'
+                    this.curQuestions = []
+                    this.getHandList()
                 }
-            }
+            },
+            deep: true
         }
     },
     mounted () {
@@ -506,7 +578,8 @@ export default {
     },
     methods: {
         // 分类计算
-        getHandList (data) {
+        getHandList () {
+            const data = this.curQuestions
             // 确定每种类型的题目
             this.handList.forEach(hand => {
                 hand.list = data.filter(item => item.ti_xing_ === hand.itemType)
@@ -608,6 +681,7 @@ export default {
                         })
                     }
                 }
+                this.allQuestions.tiKu = this.form.ti_ku_id_
             })
         },
         // 随机题库 弃用
@@ -622,8 +696,11 @@ export default {
             })
         },
         handleSubmit () {
-            this.$refs.form.validate((valid) => {
+            this.$refs.form.validate(async (valid) => {
                 if (valid) {
+                    if (this.allQuestionsNumber.tiKuNumber + this.allQuestionsNumber.handQuestionsNumber === 0) {
+                        return this.$message.warning('请先选择题目!')
+                    }
                     this.form.sui_ji_ti_shu_ = []
                     this.form.chou_ti_zong_fen_ = 0
                     this.form.ti_mu_zong_shu_ = 0
@@ -632,9 +709,9 @@ export default {
                         if (this.form.chou_ti_fang_shi_ === '1') {
                             this.handList.forEach(item => {
                                 if (item.list.length > 0) {
-                                    this.form.sui_ji_ti_shu_.push(item.questionNumber)
-                                    this.form.ti_mu_zong_shu_ += item.questionNumber
-                                    this.form.chou_ti_zong_fen_ += item.list.slice(0, item.questionNumber).reduce((pre, cur) => {
+                                    this.form.sui_ji_ti_shu_.push(item.questionNumber || 0)
+                                    this.form.ti_mu_zong_shu_ += item.questionNumber || 0
+                                    this.form.chou_ti_zong_fen_ += item.list.slice(0, item.questionNumber || 0).reduce((pre, cur) => {
                                         return pre + +cur.fen_zhi_
                                     }, 0)
                                 } else {
@@ -644,9 +721,9 @@ export default {
                         } else if (this.form.chou_ti_fang_shi_ === '2') {
                             this.levelList.forEach(item => {
                                 if (item.list.length > 0) {
-                                    this.form.sui_ji_ti_shu_.push(item.questionNumber)
-                                    this.form.ti_mu_zong_shu_ += item.questionNumber
-                                    this.form.chou_ti_zong_fen_ += item.list.slice(0, item.questionNumber).reduce((pre, cur) => {
+                                    this.form.sui_ji_ti_shu_.push(item.questionNumber || 0)
+                                    this.form.ti_mu_zong_shu_ += item.questionNumber || 0
+                                    this.form.chou_ti_zong_fen_ += item.list.slice(0, item.questionNumber || 0).reduce((pre, cur) => {
                                         return pre + +cur.fen_zhi_
                                     }, 0)
                                 } else {
@@ -675,6 +752,15 @@ export default {
                     delete this.form.minutes
                     this.form.chuang_jian_shi_j = this.$common.getDateNow(19)
                     this.form.xian_kao_shi_jian = xian_kao_shi_jian !== '不限' ? this.$common.getFormatDate('string', 16, xian_kao_shi_jian) : xian_kao_shi_jian
+                    // 这里表示为组合题 需要生成一个新的题库
+                    if (this.allQuestions.tiKu.indexOf(',') !== -1 || this.allQuestions.handQuestions) {
+                        const tiKuId = await this.createBank()
+                        console.log(tiKuId)
+                        this.form.ti_ku_id_ = tiKuId
+                    } else {
+                        this.form.ti_ku_id_ = this.allQuestions.tiKu
+                    }
+
                     // 表单验证通过,提交表单
                     this.submitForm()
                 } else {
@@ -682,6 +768,62 @@ export default {
                 }
             })
         },
+        async createBank () {
+            // 1. 新建题库
+            const addParams = {
+                tableName: 't_question_bank',
+                paramWhere: [{
+                    ti_ku_ming_cheng_: '组合题库' + dayjs().format('YYYYMMDDHHmmss'),
+                    shi_fou_gong_kai_: '是',
+                    bian_zhi_ren_: this.userId,
+                    bian_zhi_shi_jian: this.$common.getDateNow(19),
+                    ti_ku_fen_lei_: '专业组考试',
+                    suo_shu_fan_wei_: '科级',
+                    ti_ku_zhuang_tai_: '可用',
+                    xian_kao_ci_shu_: this.form.xian_kao_ci_shu_,
+                    da_biao_zhan_bi_: this.form.da_biao_zhan_bi_,
+                    miao_shu_: this.form.kao_shi_miao_shu_,
+                    ping_fen_ren_: '',
+                    di_dian_: this.level,
+                    bian_zhi_bu_men_: '',
+                    kao_shi_shi_chang: this.form.kao_shi_shi_chang,
+                    ti_shu_: this.curQuestions.length,
+                    zong_fen_: this.curQuestions.reduce((sum, item) => sum + parseInt(item.fen_zhi_), 0)
+                }]
+            }
+            const { variables: { cont }} = await this.$common.request('add', addParams)
+            if (cont.length > 0) {
+                const addParams = {
+                    tableName: 't_questions',
+                    paramWhere: this.curQuestions.map(item => ({
+                        di_dian_: this.level,
+                        parent_id_: cont[0].id_,
+                        bu_men_: item.bu_men_ || '',
+                        chu_ti_ren_: item.chu_ti_ren_,
+                        chu_ti_shi_jian_: item.chu_ti_shi_jian_,
+                        xu_hao_: item.xu_hao_ || '',
+                        ti_gan_: item.ti_gan_,
+                        ti_xing_: item.ti_xing_,
+                        fu_tu_: item.fu_tu_ || '',
+                        xuan_xiang_lei_xi: item.xuan_xiang_lei_xi || '',
+                        da_an_: item.da_an_ || '',
+                        fen_zhi_: item.fen_zhi_,
+                        xuan_xiang_shu_: item.xuan_xiang_shu_ || '',
+                        zheng_que_da_an_: item.zheng_que_da_an_,
+                        ping_fen_fang_shi: item.ping_fen_fang_shi || '',
+                        ping_fen_ren_: item.ping_fen_ren_ || '',
+                        bei_zhu_: item.bei_zhu_ || '',
+                        zhuang_tai_: item.zhuang_tai_,
+                        biao_qian_: item.biao_qian_ || '',
+                        nan_du_: item.nan_du_ || 0
+                    }))
+                }
+                await this.$common.request('add', addParams)
+                return cont[0].id_
+            }
+
+            // 2.新建题目
+        },
         submitForm () {
             const addParams = {
                 tableName: 't_exams',
@@ -781,5 +923,12 @@ export default {
         .el-button {
             margin-left: 20px;
         }
+        .item{
+            display: flex;
+            gap: 20px;
+            .number{
+                width: 100px;
+            }
+        }
     }
 </style>