fuliqi
2024-07-04 ff3b5c2ba2a757f050cf833f1af340f384874934
src/views/exam/paper/edit.vue
@@ -1,11 +1,6 @@
<template>
  <div class="app-container">
    <el-form :model="form" ref="form" label-width="150px" v-loading="formLoading" :rules="rules">
      <el-form-item label="学科:" prop="subjectId" required>
        <el-select v-model="form.subjectId" placeholder="学科">
          <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="试卷类型:" prop="paperType" required>
        <el-select v-model="form.paperType" placeholder="试卷类型">
          <el-option v-for="item in paperTypeEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
@@ -77,14 +72,15 @@
      </el-form-item>
      <!-- 题目配置信息 随机试卷或新建随序才显示 -->
      <el-form-item v-show="form.paperType ===2 || (form.paperType ===3 && !form.id)" :key="index"
                    :label="translateQuestionType(item.questionType)+':'" v-for="(item,index) in form.questionSetting">
                    :label="translateQuestionType(item.questionType)+':'" v-for="(item,index) in form.questionSetting"
      >
        <div>
          <span style="margin-right: 10px">{{ '标题' }}</span>
          <el-input v-model="item.title" style="margin-bottom: 20px;margin-right: 30px;width: 800px"/>
          <el-button type="primary" @click=addToQuestionSetting(item.questionType) >添加</el-button>
          <el-button type="primary" @click=addToQuestionSetting(item.questionType)>添加</el-button>
          <div style="display: flex;" :key="index" v-for="(setting,index) in item.settingList">
            <span style="margin-right: 10px;margin-bottom: 10px;">{{ '难度' }}</span>
          <div style="display: flex;margin-bottom: 10px;" :key="index" v-for="(setting,index) in item.settingList">
            <span style="margin-right: 10px;">{{ '难度' }}</span>
            <el-rate v-model="setting.difficult" :precision="0" :min="0" style="margin-right: 25px;padding: 5px 0"/>
            <span style="margin-right: 10px">{{ '科目' }}</span>
            <el-select v-model="setting.subjectId" placeholder="学科" style="margin-right: 25px">
@@ -93,7 +89,9 @@
            <span style="margin-right: 10px">{{ '数量' }}</span>
            <el-input-number v-model="setting.num" :precision="0" :min="0" style="margin-right: 25px"/>
            <span style="margin-right: 10px">{{ '每题分数' }}</span>
            <el-input-number v-model="setting.score" :min="0" :precision="1"/>
            <el-input-number v-model="setting.score" :min="0" :precision="1" style="margin-right: 25px"/>
            <el-button type="danger" icon="el-icon-delete" circle
                       @click="removeQuestionSetting(item,index)"></el-button>
          </div>
        </div>
@@ -129,6 +127,11 @@
      <el-form :model="questionPage.queryParam" ref="queryForm" :inline="true">
        <el-form-item label="ID:">
          <el-input v-model="questionPage.queryParam.id" clearable></el-input>
        </el-form-item>
        <el-form-item label="学科:">
          <el-select v-model="questionPage.queryParam.subjectIdInt" placeholder="学科">
            <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="queryForm">查询</el-button>
@@ -171,7 +174,6 @@
    return {
      form: {
        id: null,
        subjectId: null,
        paperType: 1,
        name: '',
        num: 0,
@@ -243,12 +245,6 @@
      subjects: [],
      formLoading: false,
      rules: {
        level: [
          { required: true, message: '请选择年级', trigger: 'change' }
        ],
        subjectId: [
          { required: true, message: '请选择学科', trigger: 'change' }
        ],
        paperType: [
          { required: true, message: '请选择试卷类型', trigger: 'change' }
        ],
@@ -264,6 +260,7 @@
        showDialog: false,
        queryParam: {
          id: null,
          subjectIdInt: null,
          questionType: [],
          subjectId: [],
          pageIndex: 1,
@@ -386,6 +383,13 @@
    addQuestion (titleItem) {
      this.currentTitleItem = titleItem
      this.questionPage.queryParam.questionType = []
      if (!titleItem.questionType) {
        this.$message({
          message: '请先选择题型',
          type: 'warning'
        })
        return
      }
      this.questionPage.queryParam.questionType.push(titleItem.questionType)
      this.questionPage.showDialog = true
      this.search()
@@ -405,8 +409,12 @@
      this.updateTotalScore()
      this.form.num = this.form.num - 1
    },
    removeQuestionSetting (item, index) {
      item.settingList.splice(index, 1)
    },
    queryForm () {
      this.questionPage.queryParam.pageIndex = 1
      this.questionPage.queryParam.subjectId = [this.questionPage.queryParam.subjectIdInt]
      this.search()
    },
    confirmQuestionSelect () {
@@ -420,8 +428,6 @@
      this.questionPage.showDialog = false
    },
    search () {
      this.questionPage.queryParam.subjectId = []
      this.questionPage.queryParam.subjectId.push(this.form.subjectId)
      this.questionPage.listLoading = true
      questionApi.pageList(this.questionPage.queryParam).then(data => {
        const re = data.data
@@ -448,14 +454,46 @@
        deductTypeScore: 0,
        visibility: '1',
        questionSetting: [
          { questionType: 1, title: '单选题', score: null, num: null },
          { questionType: 2, title: '多选题', score: null, num: null },
          { questionType: 3, title: '判断题', score: null, num: null },
          { questionType: 4, title: '填空题', score: null, num: null },
          { questionType: 5, title: '简答题', score: null, num: null },
          { questionType: 6, title: '语音题', score: null, num: null },
          { questionType: 7, title: '计算题', score: null, num: null },
          { questionType: 8, title: '分析题', score: null, num: null },
          {
            title: '单选题',
            questionType: 1,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '多选题',
            questionType: 2,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '判断题',
            questionType: 3,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '填空题',
            questionType: 4,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '简答题',
            questionType: 5,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '语音题',
            questionType: 6,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '计算题',
            questionType: 7,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          },
          {
            title: '分析题',
            questionType: 8,
            settingList: [{ difficult: null, score: null, num: null, subjectId: null }]
          }
        ],
        questionTitleList: []
      }
@@ -470,8 +508,10 @@
    totalNum () {
      if (this.form.paperType === 2 || this.form.paperType === 3) {
        let total = 0
        for (let item of this.form.questionSetting) {
          total += parseInt(item.num || 0, 10)
        for (let settings of this.form.questionSetting) {
          for (let item of settings.settingList) {
            total += parseInt(item.num || 0, 10)
          }
        }
        this.form.num = total
        return total
@@ -482,10 +522,12 @@
    totalScore () {
      if (this.form.paperType === 2 || this.form.paperType === 3) {
        let total = 0
        for (let item of this.form.questionSetting) {
          const num = parseInt(item.num || 0, 10)
          const score = parseFloat(item.score || 0)
          total += num * score
        for (let settings of this.form.questionSetting) {
          for (let item of settings.settingList) {
            const num = parseInt(item.num || 0, 10)
            const score = parseFloat(item.score || 0)
            total += num * score
          }
        }
        this.form.score = total.toFixed(1)
        return total.toFixed(1) // 保留一位小数