odc.xiaohui
2023-06-21 1bc2820c01b47fd13d38b19b1975c9b093abf479
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<template>
  <div class="app-container">
    <el-form :model="form" ref="form" label-width="200px" v-loading="formLoading" :rules="rules">
      <el-form-item label="部门:" prop="departmentIds" required>
        <el-select v-model="form.departmentIds" placeholder="部门"  @change="levelChange" multiple
                   collapse-tags>
          <el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课目:" prop="subjectId" required>
        <el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="课目" multiple
                   collapse-tags   >
          <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="paperType" required>
        <el-select v-model="form.paperType" placeholder="试卷类型"  @visible-change="subjectIdEvent">
          <el-option v-for="item in paperTypeEnum" :key="item.key" :value="item.key" :label="item.value" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间限制:" required v-show="form.paperType===4">
        <el-date-picker v-model="form.limitDateTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange"
                        range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="试卷名称:"  prop="name" required >
        <el-row :gutter="20">
          <el-col :span="9">
            <el-input v-model="form.name"/>
          </el-col>
          <el-col :span="2" v-if="form.paperType==7">
            <span>总数分:</span>
          </el-col>
          <el-col :span="9" v-if="form.paperType==7">
            <el-input disabled v-model="form.aggregateSource"/>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item :key="key" :label="titlejs(key)"   required  v-for="(value,key,index) in form.subjectSource"  v-if="form.paperType ==7">
        <el-row >
          <el-col :span="3" >
            <span>题目数量:</span>
          </el-col>
          <el-col :span="9">
            <el-input v-model="form.subjectSource[key]" style="width: 80%"/>
          </el-col>
        </el-row>
      </el-form-item>
<!--      <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-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>
        <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.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>
              <el-col :span="23">
                <QuestionShow :qType="questionItem.questionType" :question="questionItem"/>
              </el-col>
              <el-col :span="1">
                <el-button type="text" size="mini" @click="titleItem.questionItems.splice(questionIndex,1)">删除
                </el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-card>
      </el-form-item>
      <el-form-item label="建议时长:" prop="suggestTime" required>
        <el-input v-model="form.suggestTime" placeholder="分钟"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
        <el-button type="success" @click="addTitle">添加标题</el-button>
      </el-form-item>
    </el-form>
    <el-dialog :visible.sync="questionPage.showDialog"  width="70%">
      <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.questionType" clearable>
            <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>
          <el-button type="primary" @click="queryForm">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="questionPage.listLoading" :data="questionPage.tableData"
                @selection-change="handleSelectionChange" border fit highlight-current-row style="width: 100%">
        <el-table-column type="selection" width="35"></el-table-column>
        <el-table-column prop="id" label="Id" width="60px"/>
        <el-table-column prop="questionType" label="题型" :formatter="questionTypeFormatter" width="70px"/>
        <el-table-column prop="shortTitle" label="题干" show-overflow-tooltip/>
      </el-table>
      <pagination v-show="questionPage.total>0" :total="questionPage.total"
                  :page.sync="questionPage.queryParam.pageIndex" :limit.sync="questionPage.queryParam.pageSize"
                  @pagination="search"/>
      <span slot="footer" class="dialog-footer">
          <el-button @click="questionPage.showDialog = false">取 消</el-button>
          <el-button type="primary" @click="confirmQuestionSelect">确定</el-button>
     </span>
    </el-dialog>
  </div>
</template>
 
<script>
 
import { mapGetters, mapState, mapActions } from 'vuex'
import Pagination from '@/components/Pagination'
import QuestionShow from '../question/components/Show'
import examPaperApi from '@/api/examPaper'
import questionApi from '@/api/question'
 
export default {
  components: { Pagination, QuestionShow },
  data () {
    return {
      subjectIdList:[],
      form: {
        aggregateSource:100,
        id: null,
        departmentIds: [],
        subjectId: [],
        paperType: 1,
        limitDateTime: [],
        name: '',
        suggestTime: null,
        titleItems: [],
        subjectSource:null
      },
      subjectFilter: null,
      formLoading: false,
      rules: {
        departmentIds: [
          { required: true, message: '请选择部门', trigger: 'change' }
        ],
        subjectId: [
          { required: true, message: '请选择课目', trigger: 'change' }
        ],
        paperType: [
          { required: true, message: '请选择试卷类型', trigger: 'change' }
        ],
        name: [
          { required: true, message: '请输入试卷名称', trigger: 'blur' }
        ],
        suggestTime: [
          { required: true, message: '请输入建议时长', trigger: 'blur' }
        ]
      },
      questionPage: {
        multipleSelection: [],
        showDialog: false,
        queryParam: {
          id: null,
          questionType: null,
          subjectId: 1,
          pageIndex: 1,
          pageSize: 5
        },
        listLoading: true,
        tableData: [],
        total: 0
      },
      currentTitleItem: null
    }
  },
  created () {
    let id = this.$route.query.id
    let _this = this
    this.initSubject(function () {
      _this.subjectFilter = _this.subjects
    })
    if (id && parseInt(id) !== 0) {
      _this.formLoading = true
      examPaperApi.select(id).then(re => {
        _this.form = re.response
        _this.formLoading = false
      })
    }
  },
  methods: {
    titlejs(val){
      console.log(val)
      let str = ''
        this.subjectFilter.forEach(item=>{
          if (item.id == val){
            str = item.name
          }
        })
      return str
    },
    subjectIdEvent(e){
      console.log(e,this.$refs.subjectIdRef.selected)
      let arr=[]
      if (e){
 
      }else {
        this.$refs.subjectIdRef.selected.forEach(item=>{
          arr.push({
            label:item.label,
            id:item.value
          })
        })
        console.log(arr)
      }
 
      if (this.form.paperType ==7){
        //說明是隨機
        this.subjectIdList = arr
        let obj1={}
        arr.forEach((item,index)=>{
          obj1[item.id]=''
 
          // let obj={
          //   item
          // }
 
          // for (let i in obj) {
          //   i=item.id
          //   obj[i]= ''
          //   obj1[i] = ''
          //   console.log('键名:', i);
          //   console.log('键值:', obj[i]);
          // }
        })
        this.form.subjectSource = obj1
        console.log(this.form.subjectSource)
        // this.form.paperType = 7
        this.form.titleItems = []
      }else {
        this.form.subjectSource={}
        this.subjectIdList = []
        this.form.paperType = 1
      }
    },
    submitForm () {
      let _this = this
      console.log(this.subjectIdList)
      console.log(this.form.subjectSource)
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.formLoading = true
          if (this.subjectIdList.length=1){
            this.form.subjectId= this.form.subjectId
          }
 
          examPaperApi.edit(this.form).then(re => {
            if (re.code === 1) {
              _this.$message.success(re.message)
              _this.delCurrentView(_this).then(() => {
                _this.$router.push('/exam/paper/list')
              })
            } else {
              _this.$message.error(re.message)
              this.formLoading = false
            }
          }).catch(e => {
            this.formLoading = false
          })
        } else {
          return false
        }
      })
    },
    addTitle () {
      this.form.titleItems.push({
        name: '',
        questionItems: []
      })
    },
    addQuestion (titleItem) {
      this.currentTitleItem = titleItem
      this.questionPage.showDialog = true
      this.search()
    },
    removeTitleItem (titleItem) {
      this.form.titleItems.remove(titleItem)
    },
    removeQuestion (titleItem, questionItem) {
      titleItem.questionItems.remove(questionItem)
    },
    queryForm () {
      this.questionPage.queryParam.pageIndex = 1
      this.search()
    },
    confirmQuestionSelect () {
      let _this = this
      this.questionPage.multipleSelection.forEach(q => {
        questionApi.select(q.id).then(re => {
          _this.currentTitleItem.questionItems.push(re.response)
        })
      })
      this.questionPage.showDialog = false
    },
    levelChange () {
      // this.form.subjectId = null
      // this.subjectFilter = this.subjects.filter(data =>{
      //   return this.form.departmentIds.forEach(item=>{data.level == item})
      // })
      //
      // this.subjectFilter = []
      // this.form.departmentIds.forEach(item=>{
      //   this.subjects.forEach(jectitem=>{
      //     if (item==jectitem.level){
      //       this.subjectFilter.push(jectitem)
      //     }
      //   })
      // })
      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.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
      })
    },
    handleSelectionChange (val) {
      this.questionPage.multipleSelection = val
    },
    questionTypeFormatter (row, column, cellValue, index) {
      return this.enumFormat(this.questionTypeEnum, cellValue)
    },
    subjectFormatter (row, column, cellValue, index) {
      return this.subjectEnumFormat(cellValue)
    },
    resetForm () {
      let lastId = this.form.id
      this.$refs['form'].resetFields()
      this.form = {
        id: null,
        departmentIds: [],
        subjectId: null,
        paperType: 1,
        limitDateTime: [],
        name: '',
        suggestTime: null,
        titleItems: []
      }
      this.form.id = lastId
    },
    ...mapActions('exam', { initSubject: 'initSubject' }),
    ...mapActions('tagsView', { delCurrentView: 'delCurrentView' })
  },
  computed: {
    ...mapGetters('enumItem', ['enumFormat']),
    ...mapState('enumItem', {
      questionTypeEnum: state => state.exam.question.typeEnum,
      paperTypeEnum: state => state.exam.examPaper.paperTypeEnum,
      levelEnum: state => state.user.levelEnum
    }),
    ...mapState('exam', { subjects: state => state.subjects })
  }
}
</script>
 
<style lang="scss">
  .exampaper-item-box {
    .q-title {
      margin: 0px 5px 0px 5px;
    }
    .q-item-content {
    }
  }
</style>