[测评系统]--前端(用户答题页面)
林致杰
2022-05-09 97bc50567901bcc3ea873f84e1958dda3f2b371d
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
<template>
  <div>
    <el-container  class="app-item-contain">
      <el-header class="align-center" v-if="guide">
        <h1></h1>
      </el-header>
      <el-main style="padding-top: 3%;">
        <div v-html="guideDescirption" v-if="guide" :style="ismobile?'padding-top: 2%;':'padding-top: 2%;margin: 0 auto;width:66%'"></div>
        <el-row class="do-align-center" v-if="guide">
          <el-button @click="startDo" type="primary" :disable="startDoDisable">{{$t('start')}}</el-button>
        </el-row >
        <el-form :model="form" ref="form" v-loading="formLoading" label-width="100%" v-else>
          <el-row :key="index"  v-for="(titleItem,index) in titleItems">
            <div class="q-content">{{titleItem.description}}</div>
            <el-card class="exampaper-item-box" style="border:2px solid #2b90ff;">
              <div class="align-center"><span style="font-size: small; float: left">{{$t('examinee')}}{{memberName}}</span><span style="margin-top: 0px;padding-right: 11%">●{{form.name}}●</span><span style="font-size: small; float: right">{{$t('partRemailTime')}}{{formatSecondsG(remainTime,$t('hour'),$t('min'),$t('second'))}}</span></div>
              <hr style="border : 1px dashed #b3d8ff;" />
              <el-form-item :key="index" label-width="1px" v-for="(questionItem, index) in questionItems">
                <QuestionIntelligenceEdit @callNextSubject="onChoice" :qType="questionItem.questionType" :question="questionItem"
                              :answer="answer.answerItems[questionItem.itemOrder-1]" :qLabel="questionItem.questionNumber" :order = "questionItem.itemOrder-1" :displayVal="displayVal"/>
              </el-form-item>
              <hr style="border : 0.5px dashed #b3d8ff;" />
              <div style="color: red;font-size: smaller">{{$t('pleaseAnswerCarefully')}}</div>
              <el-row class="do-align-center" v-if="order < problemLength">
            <el-button @click="preSubject" type="warning"  v-if ="preDisable" round>{{$t('lastQuestion')}}</el-button>
            <el-button @click="nextOrder" type="primary" v-if ="nextDisable" round>{{$t('nextQuestion')}}</el-button>
            <el-button @click="submitClick" type="success" v-if ="submitDisable"  round>{{$t('submission')}}</el-button>
          </el-row>
          <el-row class="do-align-center" v-else>
            <el-button @click="preSubject" type="warning" v-if ="preDisable" round>{{$t('lastQuestion')}}</el-button>
            <el-button @click="submitForm" type="success" v-if ="submitDisable"  round>{{$t('submission')}}</el-button>
          </el-row>
            </el-card>
          </el-row>
        </el-form>
 
      </el-main>
    </el-container>
    <el-row class="do-exam-title footer">
      <el-col :span="24">
        <!--测试的时候打开-->
        <!--<span class="do-exam-time">-->
          <!--<label>{{$t('remainingTime')}}</label>-->
          <!--<label>{{formatSecondsG(remainTime,$t('hour'),$t('min'),$t('second'))}}</label>-->
        <!--</span>-->
      </el-col>
    </el-row>
  </div>
</template>
 
<script>
import { mapState, mapGetters, mapMutations } from 'vuex'
import { formatSeconds, formatSecondsG, formatDate } from '@/utils'
import QuestionIntelligenceEdit from '../components/QuestionIntelligenceEdit'
import examPaperApi from '@/api/examPaper'
import examPaperAnswerApi from '@/api/examPaperAnswer'
import demographyApi from '@/api/demography'
 
export default {
  name: 'intelligence',
  components: { QuestionIntelligenceEdit },
  data () {
    return {
      form: {},
      formLoading: false,
      answer: {
        questionId: null,
        doTime: 0,
        answerItems: [],
        verifyStatus: 2
      },
      timer: null,
      problemLength: 0,
      titleItemsLength: 0,
      remainTime: 999999,
      titleItemName: '', // 考试第二标题
      itemOrder: '', // 题目的序号
      questionItem: {}, // 题目
      titleItems: [],
      order: 0,
      guide: false,
      answered: [],
      submitDisable: false,
      doTime: 0,
      preDisable: false,
      nextDisable: true,
      partOrder: 1,
      parts: [],
      guideTitle: '',
      guideDescirption: '',
      isCallTain: '',
      memberName: '',
      startDoDisable: true,
      ismobile: false,
      questionItems: [],
      isNotToTime: false,
      originalTime: 0,
      isSubmiting: false,
      displayVal: 'block',
      isSubmitClick: false,
      timeoutValue: 6
    }
  },
  created: function () {
    let _this = this
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
    _this.ismobile = /ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(navigator.userAgent.toLowerCase())
    // 多语言
    _this.setLangFlag(false)
    _this.form = this.$route.query.formDo
    if (_this.form !== {} && _this.form !== undefined) {
      _this.timeReduce()
      _this.initAnswer()
      this.initCreate()
      _this.showNextGuide(false)
    } else {
      // 防止刷新成了不同的语言
      demographyApi.queryDemographyParamInfo(_this.memberToken).then(
        re => {
          if (re.response[0].langType !== null || re.response[0].langType.trim() !== '') {
            _this.setLangType(re.response[0].langType)
          }
          // 加载题目
          examPaperApi.select(_this.memberToken, _this.langType).then(re => {
            _this.form = re.response
            _this.initAnswer()
            examPaperApi.selectTokenId(_this.memberToken).then(re => {
              _this.answered = re.response.examItemOrderAndContentList
              _this.remainTime = re.response.remainTime
              let intelligenceRemainTime = this.getLocalValue('intelligenceRemainTime')
              if (this.isNotEmpty(intelligenceRemainTime) && intelligenceRemainTime > 0 && intelligenceRemainTime <= _this.remainTime) {
                _this.remainTime = intelligenceRemainTime
              }
              this.initCreate()
              _this.originalTime = _this.remainTime // 中间变量,原来的时间
              _this.isNotToTime = true // 先不记时
              _this.timeReduce()
              if (_this.answered !== null) {
                _this.answered.forEach(it => {
                  _this.answer.answerItems[parseInt(it.itemOrder) - 1].content = it.content
                  _this.answer.answerItems[parseInt(it.itemOrder) - 1].completed = true
                })
              }
              for (let i = 0; i < _this.answer.answerItems.length; i++) {
                if (!_this.answer.answerItems[i].completed || _this.answer.answerItems[i].content === null || _this.answer.answerItems[i].content === '') {
                  _this.questionItem = _this.form.titleItems[0].questionItems[i]
                  _this.partOrder = _this.questionItem.partOrder
                  _this.itemOrder = _this.form.titleItems[0].questionItems[i].itemOrder
                  _this.order = i
                  _this.preDisable = true
                  break
                }
                _this.isNotToTime = false
 
                if (_this.isForFinish(i)) {
                  _this.setSubmiting(true)
                  _this.$router.push({ path: '/exam/finish', query: { name: '', content: _this.$t('finishMsg') } })
                }
              }
              // 如果上一题不是本段,则不能返回上一段
              if (this.isDiffPartOrder()) {
                _this.isNotToTime = true
                _this.preDisable = false
              }
 
              if (this.isDiffPartOrder()) {
                _this.showNextGuide(false)
              }
 
              this.determineWhetherIntelligenceTitle()
            }).catch(e => {
              // _this.$message.error('题目查询异常')
            })
          }).catch(e => {
            _this.$message.info(_this.$t('noquestionMsg'))
          })
        }
      ).catch(e => {
      })
    }
  },
  mounted () {
  },
  beforeDestroy () {
    window.clearInterval(this.timer)
  },
  destroyed () {
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    beforeunloadFn (e) {
      if (!this.isSubmiting) {
        if (this.isLastQuestionOrderNum(this.order)) {
          this.answer.answerItems[this.order].content = ''
          this.answer.answerItems[this.order].completed = false
        }
        this.submitStage()
      }
    },
    autoChoiceTitleAndSwer: function (order) {
      let _this = this
      if (_this.form.titleItems[0].questionItems[order].template === 'intelligence_title') {
        _this.answer.answerItems[order].content = '1'
        _this.answer.answerItems[order].completed = true
      }
    },
    doCanNotOption: function (flag) {
      for (let i = 0; i < this.answer.answerItems.length; i++) {
        this.answer.answerItems[i].readOnly = flag
      }
    },
    determineWhetherIntelligenceTitle: function () {
      let _this = this
      _this.questionItems = []
      if (_this.remainTime === 0) {
        this.doCanNotOption(true)
      }
      while (_this.isNotEmpty(_this.form.titleItems[0].questionItems[_this.order].parentQuestionId)) {
        _this.order--
        // 如果是第一题,上一题不显示了
        if (_this.order === 0) {
          _this.preDisable = false
        }
      }
      if (_this.form.titleItems[0].questionItems[_this.order].template === 'intelligence_title') {
        _this.autoChoiceTitleAndSwer(_this.order)
        // 答题要放进去先
        _this.questionItems.push(_this.form.titleItems[0].questionItems[_this.order])
        let id = _this.form.titleItems[0].questionItems[_this.order].id
        for (let i = _this.order + 1; i < _this.form.titleItems[0].questionItems.length; i++) {
          // 后台已经排好顺序了。
          if (_this.form.titleItems[0].questionItems[i].parentQuestionId !== id.toString()) {
            break
          }
          _this.order = i
          _this.questionItems.push(_this.form.titleItems[0].questionItems[_this.order])
          _this.partOrder = _this.form.titleItems[0].questionItems[_this.order].partOrder
        }
 
        // 横排还是竖排
        _this.displayVal = 'block'
      } else {
        _this.questionItems.push(_this.form.titleItems[0].questionItems[_this.order])
        _this.partOrder = _this.form.titleItems[0].questionItems[_this.order].partOrder
        _this.displayVal = null
      }
      // 如果是本段的最后一题,显示提交按钮
      if (_this.isLastQuestionOrder()) {
        _this.submitDisable = true
      } else {
        _this.submitDisable = false
      }
    },
    initCreate: function () {
      let _this = this
      _this.formLoading = true
      if (_this.isEmpty(_this.remainTime)) {
        _this.remainTime = _this.form.parts[0].timeOut * 60
      }
      _this.problemLength = _this.form.titleItems[0].questionItems.length - 1
      _this.titleItemsLength = _this.form.titleItems.length
      _this.titleItems.push(_this.form.titleItems[0])
      _this.questionItem = _this.form.titleItems[0].questionItems[0]
      _this.partOrder = _this.questionItem.partOrder
      _this.itemOrder = _this.form.titleItems[0].questionItems[0].itemOrder
      _this.formLoading = false
      _this.memberName = _this.form.memberName
      _this.questionItems.push(_this.form.titleItems[0].questionItems[0])
      this.determineWhetherIntelligenceTitle()
    },
    formatSeconds (theTime) {
      return formatSeconds(theTime)
    },
    formatSecondsG (theTime, hour, min, second) {
      return formatSecondsG(theTime, hour, min, second)
    },
    formatDate (time, formatsrc) {
      return formatDate(time, formatsrc)
    },
    // 进入第二段的时候,把第一段没有答的都答一下。
    setPartDefaulAnswer: function (answerSubmit) {
      let _this = this
      answerSubmit.answerItems.forEach(it => {
        if (_this.partOrder > it.partOrder && it.content === null) {
          it.content = '0'
        }
      })
    },
    submitNextSubject: function (answerSubmit, nowPartOrder) {
      let _this = this
      _this.setSubmiting(true)
      // _this.setPartDefaulAnswer(answerSubmit)
      examPaperAnswerApi.answerSubmit(answerSubmit, _this.memberToken).then(re => {
        _this.formLoading = false // 控制不转圈
        _this.setSubmiting(false)
        if (re.code === 1) {
          // 跳到下一段
          if (!_this.isNull(re.response) && re.response.jump === 'next') {
          }
        } else {
          _this.$message.error(re.message)
        }
        // 展示指导语
        if (_this.isNextShowGuide(nowPartOrder)) {
          // 展示指导语
          _this.showNextGuide(true)
        } else {
          _this.nextQuestionOrder(nowPartOrder)
        }
      }).catch(e => {
        _this.reloadPage(e)
      })
    },
    submitStage: function () {
      let _this = this
      let nowPartOrder = _this.partOrder
      let answerSubmit = _this.getSubmitAnswerValue(nowPartOrder)
      _this.preDisable = false
      _this.questionItems = []
      this.submitNextSubject(answerSubmit, nowPartOrder)
    },
    timeOutNextPart: function () {
      let _this = this
      // 自动跳到下一段
      let questionNum = 0
      while (_this.isLastQuestionOrderNum(questionNum) || _this.form.titleItems[0].questionItems[questionNum].partOrder <= _this.partOrder) {
        if (!_this.isContentNotEmpty(questionNum)) {
          _this.answer.answerItems[questionNum].content = '0'
          _this.answer.answerItems[questionNum].completed = true
        }
        if (_this.isLastQuestionOrderNum(questionNum)) {
          _this.answer.finish = _this.timeoutValue
          _this.submitForm()
          return
        }
        _this.order = questionNum++
      }
      // if (!_this.isContentNotEmpty(_this.order)) {
      //   _this.answer.answerItems[_this.order].content = '0'
      //   _this.answer.answerItems[_this.order].completed = true
      // }
      this.submitStage()
      _this.isNotToTime = true
    },
    setLocalValue: function (key, value) {
      localStorage.setItem(key, value)
    },
    getLocalValue: function (key) {
      return localStorage.getItem(key)
    },
    removeLocalValue: function (key) {
      localStorage.removeItem(key)
    },
    timeReduce: function () {
      let _this = this
      _this.answer.doTime += _this.doTime
      _this.remainTime -= _this.doTime
      this.timer = setInterval(function () {
        if (_this.isNotToTime) {
          _this.remainTime = 0
        } else if (_this.remainTime <= 0) {
          _this.remainTime = 0
          ++_this.answer.doTime
          _this.formLoading = true
          _this.originalTime = 0 // 跳到下一段之后,就不能用后台返回的时间了
          _this.timeOutNextPart()
        } else {
          ++_this.answer.doTime
          --_this.remainTime
        }
        // 测试的时候去掉
        _this.setLocalValue('intelligenceRemainTime', _this.remainTime)
      }, 1000)
    },
    questionCompleted (completed) {
      return this.enumFormat(this.doCompletedTag, completed)
    },
    goAnchor (selector) {
      let _this = this
      let num = parseInt(selector.substr(10)) - 1
      this.itemOrder = _this.form.titleItems[0].questionItems[num].itemOrder
      this.questionItem = _this.form.titleItems[0].questionItems[num]
      _this.order = num
      setTimeout(function () {
        _this.$el.querySelector(selector).scrollIntoView({ behavior: 'instant', block: 'center', inline: 'nearest' })
      }, 200)
      _this.$refs['popovertag'].doClose()
    },
    initAnswer () {
      this.answer.id = this.form.id
      this.answer.questionOrder = this.form.questionOrder
      this.answer.optionOrder = this.form.optionOrder
      let titleItemArray = this.form.titleItems
      for (let tIndex in titleItemArray) {
        let questionArray = titleItemArray[tIndex].questionItems
        for (let qIndex in questionArray) {
          let question = questionArray[qIndex]
          this.answer.answerItems.push({ title: question.title, permanentId: question.permanentId, questionId: question.id, content: null, contentArray: [], completed: false, itemOrder: question.itemOrder, lastContent: null, startTime: question.startTime, endTime: question.endTime, partOrder: question.partOrder, questionReport: {}, readOnly: false })
        }
      }
 
      // 初始化开始时间,设置第一个时间
      for (let i = 0; i < this.answer.answerItems.length; i++) {
        if (this.answer.answerItems[i].startTime == null || this.answer.answerItems[i].startTime.trim() === '') {
          this.answer.answerItems[i].startTime = this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
          break
        }
      }
    },
    isContentNotEmpty: function (num) {
      let _this = this
      return _this.answer.answerItems[num].content !== '' && _this.answer.answerItems[num].content !== null && _this.answer.answerItems[num].content.trim() !== ''
    },
    nextQuestion: function (nowPartOrder) {
      let _this = this
      let num = ++_this.order
      // 跳到没有答的题目的段
      while (_this.isContentNotEmpty(num) && num !== _this.answer.answerItems.length - 1) {
        num = ++_this.order
        this.getEmptySubjct(num)
      }
      this.determineWhetherIntelligenceTitle()
      if (_this.partOrder !== nowPartOrder) {
        _this.isShowGuide(true)
      }
      _this.preDisable = true
      _this.isShowNextQuestionButton(_this)
      _this.answer.answerItems[_this.order].startTime = _this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
 
      // 如果是最后一个并且已经完成了,就提交
      if (num === _this.answer.answerItems.length - 1 && _this.isForFinish(num)) {
        this.submitForm()
      }
    },
    nextQuestionOrder: function (nowPartOrder) {
      if (this.order < this.problemLength) {
        this.nextQuestion(nowPartOrder)
      }
    },
    isNextShowGuide: function (nowPartOrder) {
      let _this = this
      // 本段的每一题都打完要指导语
      let showGuideFlag = true
      for (let i = 0; i < _this.answer.answerItems.length; i++) {
        if (_this.form.titleItems[0].questionItems[i].partOrder === nowPartOrder && !_this.isContentNotEmpty(i)) {
          showGuideFlag = false
        }
      }
      return showGuideFlag
    },
    catThaiSubmit: function (answerSubmit) {
      answerSubmit.isCallTain = 'CallThai'
    },
    getEmptySubjct: function (order) {
      let _this = this
      _this.itemOrder = _this.form.titleItems[0].questionItems[order].itemOrder
      _this.questionItem = _this.form.titleItems[0].questionItems[order]
      _this.partOrder = _this.questionItem.partOrder
      _this.preDisable = false
      _this.order = order
      _this.determineWhetherIntelligenceTitle()
    },
    onChoice () { // 是否显示提交按钮
      if (this.isLastQuestionOrder()) {
        return
      }
      this.isShowNextQuestionButton(this)
    },
    // 下一题
    nextSubject: function (data) {
      let _this = this
      _this.isShowGuide(false)
      let nowPartOrder = _this.partOrder
      // 设置上一题的结束时间
      this.answer.answerItems[data[0]].endTime = _this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
      // 跳到还没完成的拿到题的
      let complateOrder = _this.order
      // 停留在这道题
      if (_this.form.titleItems[0].questionItems[_this.order].parentQuestionId !== '') {
        complateOrder++
      }
      for (let i = 0; i < complateOrder; i++) {
        if (!_this.isContentNotEmpty(i)) {
          return
        }
      }
      // 循环没有答的题目
      for (let i = 0; i < _this.order; i++) {
        if (!this.isContentNotEmpty(i)) {
          // 返回之前没做的那道题
          this.getEmptySubjct(i)
          return
        }
        // 如果循环到最后一题就提交
        if (_this.isForFinish(i)) {
          _this.submitForm()
          return
        }
      }
 
      // 全部答完了就可以提交了,但是如果是最后一题就自己提交
      for (let i = 0; i < _this.answer.answerItems.length; i++) {
        if (!_this.isContentNotEmpty(i)) {
          break
        }
        if (i === _this.answer.answerItems.length - 1 && _this.order !== _this.answer.answerItems.length - 1) {
          _this.submitForm()
          return
        }
      }
      // this.answer.answerItems[_this.order].readOnly = true
      let answerSubmit = _this.getSubmitAnswerValue(nowPartOrder)
      // 已经答到了最后一题了,不用自动跳到下一题
      if (this.order + 1 > this.problemLength) {
        return
      }
      _this.preDisable = false
      this.submitNextSubject(answerSubmit, nowPartOrder)
    },
    isLastQuestionOrder: function () {
      let _this = this
      return _this.order >= _this.form.titleItems[0].questionItems.length - 1
    },
    isLastQuestionOrderNum: function (num) {
      let _this = this
      return num >= _this.form.titleItems[0].questionItems.length - 1
    },
    isSamePartOrder: function () {
      return this.form.titleItems[0].questionItems[this.order].partOrder === this.form.titleItems[0].questionItems[this.order + 1].partOrder
    },
    isPreSamePartOrder: function () {
      if (this.isEmpty(this.form.titleItems[0].questionItems[this.order - 1])) {
        return false
      }
      return this.form.titleItems[0].questionItems[this.order].partOrder === this.form.titleItems[0].questionItems[this.order - 1].partOrder
    },
    isShowNextQuestionButton: function (_this) {
      if (_this.isLastQuestionOrder()) {
        _this.nextDisable = false
        return
      }
      _this.nextDisable = true
    },
    isFinishThisPart () {
      for (let i = 0; i <= this.order; i++) {
        if (!this.isContentNotEmpty(i)) {
          return false
        }
      }
      return true
    },
    nextOrder () {
      let _this = this
      _this.order++
      // 如果是已经完成本段,提交展示指导语
      if (_this.isPreSamePartOrder(this)) {
        _this.preDisable = true
      } else {
        _this.preDisable = false
      }
      _this.determineWhetherIntelligenceTitle()
      // 展示指导语
      if (_this.isDiffPartOrder()) {
        this.showGuideDetail()
        this.submitStage() // 跳到下一段的时候,关闭浏览器有保存不上的现象,所以这里中途保存一下
      }
      _this.isShowNextQuestionButton(_this)
    },
    getSubmitAnswerValue (nowPartOrder) {
      let _this = this
      let answerSubmit = JSON.parse(JSON.stringify(_this.answer))
      answerSubmit.answerItems.forEach(answerItem => {
        // 题目报表,如果没有结束时间,开始时间也不需要
        if (answerItem.endTime == null || answerItem.endTime === '') {
          answerItem.startTime = ''
        }
        answerItem.questionReport = { questionOrder: answerItem.questionId, questionTitle: answerItem.title, permanentId: answerItem.permanentId, startTime: answerItem.startTime, endTime: answerItem.endTime, langType: _this.langType, partOrder: answerItem.partOrder, answer: answerItem.content }
      })
      answerSubmit.langType = _this.langType
      answerSubmit.isCallTain = _this.isCallTain
      answerSubmit.partOrder = nowPartOrder
      answerSubmit.itemOrder = _this.itemOrder
      answerSubmit.remainTime = _this.remainTime
      answerSubmit.submitClick = _this.isSubmitClick
      return answerSubmit
    },
    preSubject () {
      let _this = this
      _this.isShowGuide(false)
      if (_this.order <= 0) {
        _this.preDisable = false
        return
      }
      --this.order
      // 循环一直找到上一题
      if (_this.isNotEmpty(_this.form.titleItems[0].questionItems[_this.order].parentQuestionId)) {
        while (_this.isNotEmpty(_this.form.titleItems[0].questionItems[_this.order].parentQuestionId) && _this.form.titleItems[0].questionItems[_this.order].template !== 'intelligence_title') {
          --this.order
        }
        --this.order
        // 回到上一题的上一题
        while (_this.isNotEmpty(_this.form.titleItems[0].questionItems[_this.order].parentQuestionId) && _this.form.titleItems[0].questionItems[_this.order].template !== 'intelligence_title') {
          --this.order
        }
      }
      // 控制回到上一题的按钮的出现
      if (_this.order > 0 && _this.form.titleItems[0].questionItems[_this.order].partOrder === _this.form.titleItems[0].questionItems[_this.order - 1].partOrder) {
        _this.preDisable = true
      } else {
        _this.preDisable = false
      }
      _this.determineWhetherIntelligenceTitle()
      _this.isShowNextQuestionButton(_this)
    },
    isNotEmpty (obj) {
      return obj !== null && obj !== undefined && obj !== ''
    },
    isEmpty (obj) {
      return !this.isNotEmpty(obj)
    },
    submitClick () {
      let _this = this
      _this.isSubmitClick = true
      _this.$confirm(_this.$t('unfinish'), {
        title: _this.$t('prompt'),
        confirmButtonText: _this.$t('determine'),
        cancelButtonText: _this.$t('cancel'),
        showClose: false
      }).then(async () => {
        _this.submitForm()
      }).catch(async () => {
      })
    },
    submitForm () {
      let _this = this
      _this.submitDisable = false
      window.clearInterval(_this.timer)
      _this.formLoading = true
      if (_this.answer.finish === _this.timeoutValue) {
        _this.answer.verifyStatus = 1
        _this.submitAnswer(_this.$t('timeOutSubmit'))
      } else {
        _this.answer.verifyStatus = 1
        _this.answer.finish = 1
        for (let i = 0; i < _this.answer.answerItems.length; i++) {
          if (_this.answer.answerItems[i].content === null) {
            _this.answer.answerItems[i].content = '0'
          }
        }
        _this.submitAnswer(_this.$t('finishIntelligenceInfo'))
      }
    },
    startDo: function () {
      let _this = this
      _this.guide = false
      _this.isCallTain = ''
      _this.isNotToTime = false
      // _this.originalTime 跳到下一段之后会返回0的
      _this.remainTime = _this.originalTime !== 0 ? _this.originalTime : _this.form.parts[_this.partOrder - 1].timeOut * 60
      this.doCanNotOption(false)
    },
    isTimeoutFinish: function () { // 超时提交
      let _this = this
      return _this.answer.finish === _this.timeoutValue
    },
    submitAnswer: function (mess) {
      let _this = this
      this.answer.answerItems[_this.order].endTime = this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
      // 提交之前提交最后一段
      let answerSubmit = _this.getSubmitAnswerValue(_this.partOrder)
      _this.catThaiSubmit(answerSubmit)
      let loading = _this.$loading({
        lock: false,
        text: _this.$t('uploadInfo'),
        spinner: 'el-icon-loading'
      })
      // 超时马上返回
      if (this.isTimeoutFinish()) {
        loading.close()
        _this.$router.push({ path: '/exam/finish', query: { name: _this.form.name, content: mess } })
      }
      _this.setSubmiting(true)
      examPaperAnswerApi.answerSubmit(answerSubmit, _this.memberToken).then(re => {
        this.removeLocalValue('intelligenceRemainTime')
        if (re.code === 1) {
          loading.close()
          if (re.response.signalObject.code === 'fail') {
            _this.$router.push({
              path: '/exam/exception',
              query: { name: _this.form.name, content: _this.$t('submitExceptionInfo') }
            })
            return
          }
          if (this.isTimeoutFinish()) {
            return
          }
          _this.$router.push({ path: '/exam/finish', query: { name: _this.form.name, content: mess } })
        } else {
          _this.$message.error(re.message + '/exam/finish')
        }
        _this.formLoading = false
      }).catch(e => {
        _this.reloadPage(e)
        loading.close()
      })
    },
    setSubmiting (flag) {
      this.isSubmiting = flag
    },
    guideView: function () {
      // 数组的下标要减1
      let _this = this
      if (_this.isNotEmpty(_this.guideDescirption)) {
        _this.isNotToTime = true
        _this.isShowGuide(true)
        _this.preDisable = false
      } else {
        _this.isShowGuide(false)
        _this.preDisable = false
      }
    },
    showGuideDetail: function () {
      let _this = this
      if (_this.form.parts[_this.partOrder - 1].signals.length > 0) {
        _this.guideDescirption = _this.form.parts[_this.partOrder - 1].signals[0].signalDescription
      }
      // 指导语展示
      _this.guideView()
      _this.startDoDisable = false
    },
    showNextGuide: function (nextQuestion) {
      let _this = this
      if (!nextQuestion) {
        this.showGuideDetail()
        return
      }
      _this.isShowGuide(true)
      _this.nextQuestionOrder()
      this.showGuideDetail()
    },
    isNull: function (obj) {
      return obj === null || obj === undefined
    },
    isShowGuide (flag) {
      let _this = this
      _this.guide = flag
    },
    reloadPage (e) {
      let _this = this
      let mes = ''
      if (e.message !== null && e.message !== undefined && e.message.indexOf('timeout') !== -1) {
        mes = _this.$t('submitTimeout') + ',' + 'order:' + _this.order + ',' + e.message// 提交后台超时
      } else {
        mes = JSON.stringify(e) + ',' + 'order:' + _this.order + ',' + e.message
      }
      // 调试用
      // _this.$router.push({ path: '/exam/exception', query: { name: _this.form.name, content: _this.$t('submitExceptionInfo') + '<br>' + mes } })
      _this.$router.push({ path: '/exam/exception', query: { name: _this.form.name, content: _this.$t('submitExceptionInfo') } })
      _this.formLoading = false
    },
    isForFinish (i) {
      return i === this.answer.answerItems.length - 1 && (this.answer.answerItems[i].content !== null && this.answer.answerItems[i].content !== '')
    },
    isDiffPartOrder: function () {
      let _this = this
      return _this.form.titleItems[0].questionItems[_this.order].partOrder !== _this.form.titleItems[0].questionItems[_this.order - 1].partOrder
    },
    isLastPartOrder: function () {
      let _this = this
      // 最后一题和第一题不显示提交按钮
      if (_this.isEmpty(_this.form.titleItems[0].questionItems[_this.order + 1]) || _this.form.titleItems[0].questionItems[_this.order].partOrder === 0) {
        return false
      }
      return _this.form.titleItems[0].questionItems[_this.order].partOrder !== _this.form.titleItems[0].questionItems[_this.order + 1].partOrder
    },
    ...mapMutations('user', ['setLangType']),
    ...mapMutations('user', ['setLangFlag'])
  },
  computed: {
    ...mapGetters('enumItem', ['enumFormat']),
    ...mapState('enumItem', { doCompletedTag: state => state.exam.question.answer.doCompletedTag }),
    ...mapState('user', { memberToken: state => state.memberToken }),
    ...mapState('user', { langType: state => state.langType }),
    ...mapState('user', { langFlag: state => state.langFlag }),
    ...mapState('exam', { doUrl: state => state.doUrl })
  }
}
</script>
 
<style lang="scss" scoped>
  .align-center {
    text-align: center;
  }
 
  .exam-question-item {
    padding: 10px;
    font-size: large;
 
    .el-form-item__label {
      font-size: large !important;
    }
  }
 
  .question-title-padding {
    padding-left: 25px;
    padding-right: 25px;
  }
  .footer {
    position: absolute;
    position: fixed;
    z-index: 1000;
    bottom: 0px;
  }
</style>