ZhangXianQiang
2024-05-17 65a176dbc0e9c81781bb4db176f51aa4fd3dc3d3
fix:修改随机试卷回显
1个文件已修改
281 ■■■■ 已修改文件
src/views/exam/personalRandomTemplate/edit.vue 281 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/exam/personalRandomTemplate/edit.vue
@@ -2,13 +2,13 @@
  <div class="app-container">
    <el-form :model="form" ref="form" label-width="200px" v-loading="formLoading" :rules="rules">
      <el-form-item label="考生:" prop="menuIds" required>
        <el-select v-model="form.menuIds" :collapse-tags="true" multiple placeholder="请选择" @focus="selectStudent"></el-select>
        <el-select v-model="form.menuIds" :collapse-tags="true" multiple placeholder="请选择" @focus="selectStudent"
          popper-class="examinee-popper"></el-select>
      </el-form-item>
      <el-form-item label="课目:" prop="subjectId" required >
        <el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="课目" multiple
                   collapse-tags   @visible-change="subjectIdEvent">
          <el-option v-for="item in subjectFilter" :key="item.id" :value="item.id"
                     :label="item.name+' '"></el-option>
        <el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="课目" multiple collapse-tags
          @visible-change="subjectIdEvent">
          <el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name + ' '"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="部门:" prop="deptId" required>
@@ -40,7 +40,8 @@
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item :key="item.subjectId" :label="item.label"   required  v-for="(item,key) in form.questionTypeVMS"  v-if="form.paperType ==7">
      <el-form-item :key="item.subjectId" :label="item.label" required v-for="(item, key) in form.questionTypeVMS"
        v-if="form.paperType == 7">
        <el-row >
          <el-col :span="3" >
            <span>多选题: </span>
@@ -66,13 +67,16 @@
      <!--      <el-form-item label="总数分:" v-if="form.paperType==7"  prop="name" required>-->
      <!--        <el-input v-model="form.name"/>-->
      <!--      </el-form-item>-->
      <el-form-item :key="index" :label="'标题'+(index+1)+':'" required v-for="(titleItem,index) in form.titleItems">
      <el-form-item :key="index" :label="'标题' + (index + 1) + ':'" required
        v-for="(titleItem, index) in form.titleItems">
        <el-input v-model="titleItem.name" style="width: 80%"/>
        <el-button  v-if="form.paperType!=7" type="text" class="link-left" style="margin-left: 20px" size="mini" @click="addQuestion(titleItem)">
        <el-button v-if="form.paperType != 7" type="text" class="link-left" style="margin-left: 20px" size="mini"
          @click="addQuestion(titleItem)">
          添加题目
        </el-button>
        <el-button type="text" class="link-left" size="mini" @click="form.titleItems.splice(index,1)">删除</el-button>
        <el-card class="exampaper-item-box" v-if="titleItem.questionItems&&titleItem.questionItems.length!==0&&subjectIdList.length<2">
        <el-card class="exampaper-item-box"
          v-if="titleItem.questionItems && titleItem.questionItems.length !== 0 && subjectIdList.length < 2">
          <el-form-item :key="questionIndex" :label="'题目'+(questionIndex+1)+':'"
                        v-for="(questionItem,questionIndex) in titleItem.questionItems" style="margin-bottom: 15px">
            <el-row>
@@ -104,7 +108,8 @@
        </el-form-item>
        <el-form-item label="题型:">
          <el-select v-model="questionPage.queryParam.questionType" clearable>
            <el-option v-for="item in questionTypeEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
            <el-option v-for="item in questionTypeEnum" :key="item.key" :value="item.key"
              :label="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
@@ -142,12 +147,12 @@
          <el-button type="primary" @click="selectStudent">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="student.listLoading" :data="tableData" border fit highlight-current-row style="width: 100%" @selection-change="handleSelection">
        <el-table-column type="selection"></el-table-column>
      <el-table ref="multipleTable" v-loading="student.listLoading" :data="tableData" border fit highlight-current-row
        style="width: 100%" @selection-change="handleSelection" row-key="id">
        <el-table-column type="selection" :reserve-selection="true"></el-table-column>
        <el-table-column prop="realName" label="用户"/>
      </el-table>
      <pagination v-show="total > 0" :total="total"
                  :page.sync="student.pageIndex" :limit.sync="student.pageSize"
      <pagination v-show="total > 0" :total="total" :page.sync="student.pageIndex" :limit.sync="student.pageSize"
                  @pagination="selectStudent"/>
      <span slot="footer" class="dialog-footer">
          <el-button @click="studentDialog = false">取 消</el-button>
@@ -159,14 +164,14 @@
<script>
import { mapGetters, mapState, mapActions } from 'vuex'
import Pagination from '@/components/Pagination'
import QuestionShow from '../question/components/Show'
import examPaperApi from '@/api/examPaper'
import userApi from '@/api/user'
import questionApi from '@/api/question'
import departmentApi from '@/api/department'
import allCascader from '@/components/Cascader'
import { mapGetters, mapState, mapActions } from 'vuex';
import Pagination from '@/components/Pagination';
import QuestionShow from '../question/components/Show';
import examPaperApi from '@/api/examPaper';
import userApi from '@/api/user';
import questionApi from '@/api/question';
import departmentApi from '@/api/department';
import allCascader from '@/components/Cascader';
export default {
  components: { Pagination, QuestionShow ,allCascader},
@@ -254,35 +259,35 @@
        total: 0
      },
      currentTitleItem: null
    }
    };
  },
  created () {
    examPaperApi.selflist().then(res => {
      console.log(res)
      this.subjectFilter = res.response
    })
      console.log(res);
      this.subjectFilter = res.response;
    });
    departmentApi.getDeptAdmins().then(res => {
      this.depts = res.response
    })
      this.depts = res.response;
    });
  },
   async mounted () {
     let id = this.$route.query.id
     let _this = this
    let id = this.$route.query.id;
    let _this = this;
     this.initSubject(function () {
       _this.subjectFilter = _this.subjects
     })
      _this.subjectFilter = _this.subjects;
    });
     if (id && parseInt(id) !== 0) {
       _this.formLoading = true
      _this.formLoading = true;
       await examPaperApi.selfselect(id).then(re => {
         _this.form = re.response
         _this.form.menuIds = JSON.parse(re.response.menuIds)
         _this.optionsData = _this.form.menuIds
         console.log(_this.form)
        _this.form = re.response;
        _this.form.menuIds = JSON.parse(re.response.menuIds);
        _this.optionsData = _this.form.menuIds;
        console.log(_this.form);
         _this.formLoading = false
       })
        _this.formLoading = false;
      });
     }
     departmentApi.selectDepartmentUser().then(res => {
       console.log("res", res);
@@ -290,55 +295,64 @@
       _this.options = res.response.map(x => {
         return {
           value: x.department.id, label: x.department.name, children: x.userList.map(xx => {
             return { value: xx.id, label: xx.realName }
            return { value: xx.id, label: xx.realName };
           })
         }
       })
     })
        };
      });
    });
     // this.subjectIdEvent(false)
   },
  methods: {
    handleSelection (val) {
      this.student.multipleSelection = val
      this.student.multipleSelection = val;
    },
    confirmStudentSelect () {
      this.student.multipleSelection.forEach(q => {
          this.form.menuIds.push(q.id)
      })
      this.studentDialog = false
      this.form.menuIds = this.student.multipleSelection.map((item) => item.id);
      this.studentDialog = false;
    },
    getTags () {
      userApi.tagList(null).then(data => {
        this.tags = data.response
      })
        this.tags = data.response;
      });
    },
    selectStudent() {
     this.getTags();
      this.studentDialog = true;
      this.student.listLoading = true;
      examPaperApi.selectStudent(this.student).then(res => {
        this.tableData = res.response.list
        this.total = res.response.total
        this.student.listLoading = false
      })
        this.tableData = res.response.list;
        this.total = res.response.total;
        this.student.listLoading = false;
        this.$nextTick(() => {
          this.tableData.map(data => {
            if (this.form.menuIds.find(item => item === data.id)) {
              this.$refs.multipleTable.toggleRowSelection(data, true);
            } else {
              this.$refs.multipleTable.toggleRowSelection(data, false);
            }
          });
        });
      });
    },
    cascaderChangeFun(event){
      console.log(event)
      this.form.menuIds = event
      console.log(event);
      this.form.menuIds = event;
    },
    titlejs(val){
      console.log(val)
      let str = ''
      console.log(val);
      let str = '';
      this.subjectFilter.forEach(item=>{
        if (item.id == val){
          str = item.name
          str = item.name;
        }
      })
      return str
      });
      return str;
    },
    subjectIdEvent(e){
      console.log(e,this.$refs.subjectIdRef.selected)
      let arr=[]
      console.log(e, this.$refs.subjectIdRef.selected);
      let arr = [];
      if (e){
      }else {
@@ -349,17 +363,17 @@
            singleChoice:'',
            multipleChoice:'',
            trueFalse:''
          })
        })
        console.log(arr)
        this.form.questionTypeVMS = arr
          });
        });
        console.log(arr);
        this.form.questionTypeVMS = arr;
      }
      if (this.form.paperType ==7){
        //說明是隨機
        this.subjectIdList = arr
        let obj1={}
        let arr1 = []
        this.subjectIdList = arr;
        let obj1 = {};
        let arr1 = [];
        arr.forEach((item,index)=>{
          // obj1[item.id]=''
          arr1.push({
@@ -367,7 +381,7 @@
            singleChoice:'',
            multipleChoice:'',
            trueFalse:''
          })
          });
          // let obj={
          //   item
          // }
@@ -379,94 +393,95 @@
          //   console.log('键名:', i);
          //   console.log('键值:', obj[i]);
          // }
        })
        this.form.subjectSource = obj1
        });
        this.form.subjectSource = obj1;
        console.log(this.form.subjectSource)
        console.log(this.form.questionTypeVMS)
        console.log(this.form.subjectSource);
        console.log(this.form.questionTypeVMS);
        // this.form.paperType = 7
        this.form.titleItems = []
        this.form.titleItems = [];
      }else {
        this.form.subjectSource={}
        this.subjectIdList = []
        this.form.subjectSource = {};
        this.subjectIdList = [];
        // this.form.paperType = 1
      }
    },
    submitForm () {
      let _this = this
      console.log(this.subjectIdList)
      console.log(this.form.subjectSource)
      let _this = this;
      console.log(this.subjectIdList);
      console.log(this.form.subjectSource);
      this.$refs.form.validate((valid) => {
        if (valid) {
          const tempForm = JSON.parse(JSON.stringify(this.form));
          this.formLoading = true;
          if (this.subjectIdList.length == 1){
            this.form.subjectId= this.form.subjectId
            tempForm.subjectId = tempForm.subjectId;
          };
          let lastHasAll = this.form.menuIds.find(arr => {
          let lastHasAll = tempForm.menuIds.find(arr => {
            return arr[0] === 'all';
          });
          if (lastHasAll){
            this.form.menuIds = this.form.menuIds.slice(1)
            tempForm.menuIds = tempForm.menuIds.slice(1);
          }
          // let op = [];
          // for(var ele of this.form.menuIds){
          //   op.push(ele[1])
          // };
          this.form.userIds = this.form.menuIds;
          this.form.menuIds = JSON.stringify(this.form.menuIds);
          console.log("laks",this.form)
          if(this.form.questionTypeVMS == null){
            this.form.questionTypeVMS = [];
          tempForm.userIds = tempForm.menuIds;
          tempForm.menuIds = JSON.stringify(tempForm.menuIds);
          console.log("laks", this.form);
          if (tempForm.questionTypeVMS == null) {
            tempForm.questionTypeVMS = [];
          }
          this.form.status = 0
          examPaperApi.selfedit(this.form).then(re => {
          tempForm.status = 0;
          examPaperApi.selfedit(tempForm).then(re => {
            if (re.code === 1) {
              _this.$message.success(re.message)
              _this.$message.success(re.message);
              _this.delCurrentView(_this).then(() => {
                _this.$router.push('/exam/personalRandomTemplate/list')
              })
                _this.$router.push('/exam/personalRandomTemplate/list');
              });
            } else {
              _this.$message.error(re.message)
              this.formLoading = false
              _this.$message.error(re.message);
              this.formLoading = false;
            }
          }).catch(e => {
            this.formLoading = false
          })
            this.formLoading = false;
          });
        } else {
          return false
          return false;
        }
      })
      });
    },
    addTitle () {
      this.form.titleItems.push({
        name: '',
        questionItems: []
      })
      });
    },
    addQuestion (titleItem) {
      this.currentTitleItem = titleItem
      this.questionPage.showDialog = true
      this.search()
      this.currentTitleItem = titleItem;
      this.questionPage.showDialog = true;
      this.search();
    },
    removeTitleItem (titleItem) {
      this.form.titleItems.remove(titleItem)
      this.form.titleItems.remove(titleItem);
    },
    removeQuestion (titleItem, questionItem) {
      titleItem.questionItems.remove(questionItem)
      titleItem.questionItems.remove(questionItem);
    },
    queryForm () {
      this.questionPage.queryParam.pageIndex = 1
      this.search()
      this.questionPage.queryParam.pageIndex = 1;
      this.search();
    },
    confirmQuestionSelect () {
      let _this = this
      let _this = this;
      this.questionPage.multipleSelection.forEach(q => {
        questionApi.select(q.id).then(re => {
          _this.currentTitleItem.questionItems.push(re.response)
        })
      })
      this.questionPage.showDialog = false
          _this.currentTitleItem.questionItems.push(re.response);
        });
      });
      this.questionPage.showDialog = false;
    },
    levelChange () {
      // this.form.subjectId = null
@@ -482,35 +497,35 @@
      //     }
      //   })
      // })
      console.log(this.subjects,this.form.departmentIds)
      console.log(this.subjects, this.form.departmentIds);
      // this.subjectFilter = this.subjects
    },
    search () {
      if (this.subjectIdList.length=1){
        this.questionPage.queryParam.subjectId = this.form.subjectId
        this.questionPage.queryParam.subjectId = this.form.subjectId;
      }
      this.questionPage.listLoading = true
      this.questionPage.listLoading = true;
      questionApi.pageList(this.questionPage.queryParam).then(data => {
        const re = data.response
        this.questionPage.tableData = re.list
        this.questionPage.total = re.total
        this.questionPage.queryParam.pageIndex = re.pageNum
        this.questionPage.listLoading = false
      })
        const re = data.response;
        this.questionPage.tableData = re.list;
        this.questionPage.total = re.total;
        this.questionPage.queryParam.pageIndex = re.pageNum;
        this.questionPage.listLoading = false;
      });
    },
    handleSelectionChange (val) {
      this.questionPage.multipleSelection = val
      this.questionPage.multipleSelection = val;
    },
    questionTypeFormatter (row, column, cellValue, index) {
      return this.enumFormat(this.questionTypeEnum, cellValue)
      return this.enumFormat(this.questionTypeEnum, cellValue);
    },
    subjectFormatter (row, column, cellValue, index) {
      return this.subjectEnumFormat(cellValue)
      return this.subjectEnumFormat(cellValue);
    },
    resetForm () {
      let lastId = this.form.id
      this.$refs['form'].resetFields()
      let lastId = this.form.id;
      this.$refs['form'].resetFields();
      this.form= {
        aggregateSource:100,
        id: null,
@@ -523,8 +538,8 @@
        titleItems: [],
        subjectSource:null,
        questionTypeVMS:[]
      }
      this.form.id = lastId
      };
      this.form.id = lastId;
    },
    ...mapActions('exam', { initSubject: 'initSubject' }),
    ...mapActions('tagsView', { delCurrentView: 'delCurrentView' }),
@@ -539,7 +554,7 @@
    }),
    ...mapState('exam', { subjects: state => state.subjects })
  }
}
};
</script>
<style lang="scss">
@@ -547,7 +562,11 @@
  .q-title {
    margin: 0px 5px 0px 5px;
  }
  .q-item-content {
  .q-item-content {}
  }
.examinee-popper {
  display: none !important;
}
</style>