<template>
  <div class="report-wrapper">
    <el-card v-loading="loading" shadow="never">
      <div slot="header" class="clearfix report-header">
        <!-- 电子影像病例报告表（eICRF） -->
        <h3 style="margin:0;padding:0;">{{ $t('trials:readingReport:title:eicrf') }}</h3>
        <div style="margin-left:auto">
          <el-switch
            v-model="isShowDetail"
            :active-text="$t('trials:readingReport:title:expandDetails')"
            :inactive-text="$t('trials:readingReport:title:collapseDetails')"
            style="margin-right:5px;"
            @change="handleShowDetail"
          />
          <el-button
            v-if="readingTaskState<2"
            type="primary"
            size="small"
            @click="getReportInfo(false)"
          >
            <!-- 刷新 -->
            {{ $t('trials:readingReport:button:refresh') }}
          </el-button>
          <el-button
            v-if="readingTaskState<2 && CriterionType !== 10"
            type="primary"
            size="small"
            @click="handleSave(true)"
          >
            <!-- 保存 -->
            {{ $t('common:button:save') }}
          </el-button>
          <el-button
            v-if="readingTaskState<2"
            type="primary"
            size="small"
            @click="beforeLeave"
          >
            <!-- 提交 -->
            {{ $t('common:button:submit') }}
          </el-button>
        </div>
      </div>
      <div ref="tableWrapper" style="height:100%;overflow-y: auto;">
        <el-table
          v-if="height"
          ref="reportList"
          :data="taskQuestions"
          row-key="Id"
          border
          default-expand-all
          :height="height"
          :tree-props="{children: 'Childrens', hasChildren: 'hasChildren'}"
          size="mini"
        >
          <el-table-column
            prop=""
            label=""
            show-overflow-tooltip
            width="350px"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.QuestionName" :style="{color: ((scope.row.isLymphNodes === 1 && scope.row.QuestionMark === 1) || (scope.row.isLymphNodes === 0 && scope.row.QuestionMark === 0)) && scope.row.LesionType === 0 ? '#f66' : '#fff'}">{{ scope.row.BlindName ? scope.row.QuestionName : scope.row.QuestionName }}</span>
              <span
                v-else
                style="font-weight: bold;font-size: 16px;color: #f44336;"
              >
                {{ language==='en'?scope.row.GroupEnName:scope.row.GroupName }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            v-for="task in visitTaskList"
            :key="task.VisitTaskId"
            prop="date"

            show-overflow-tooltip
            width="150px"
          >
            <template slot="header">
              <div v-if="task.IsCurrentTask">
                <div>
                  {{ task.BlindName }}
                </div>
                <!--                <div v-if="task.LatestScanDate">-->
                <!--                  {{ task.LatestScanDate.split(' ')[0] }}-->
                <!--                </div>-->
              </div>
              <div v-else>
                <div>
                  {{ task.BlindName }}
                  <el-button type="text" size="small" @click="previewDicoms(task)">
                    <span class="el-icon-view" />
                  </el-button>
                </div>
              </div>
            </template>
            <template slot-scope="scope">
              <span :style="{color: ((scope.row.isLymphNodes === 1 && scope.row.QuestionMark === 1) || (scope.row.isLymphNodes === 0 && scope.row.QuestionMark === 0)) && scope.row.LesionType === 0 ? '#f66' : '#fff'}">
                <template v-if="task.VisitTaskId === visitTaskId && readingTaskState < 2 && [14].includes(scope.row.QuestionType)">
                  <!-- 是否存在疾病（基线时可修改） -->

                  <!-- <template v-else-if="task.IsBaseLine && scope.row.QuestionType=== 13">
                    {{ $fd(scope.row.DictionaryCode, currentEvaluateResult) }}
                  </template> -->
                  <!-- 访视点备注（是否存在疾病与系统不一致或者整体肿瘤评估与系统不一致时，必填） -->
                  <template v-if="task.VisitTaskId === visitTaskId">
                    <template v-if="task.VisitTaskId === visitTaskId">
                      <!-- 输入框 -->
                      <el-input :maxLength="$inputMax"
                        v-if="scope.row.Type==='input'"
                        v-model="QuestionTypeList[scope.row.QuestionType]"
                        size="mini"
                        @change="(v) => {handleChange(v, scope.row.QuestionType)}"
                      />
                      <el-input :maxLength="$inputMax"
                        v-else-if="scope.row.Type==='textarea'"
                        v-model="QuestionTypeList[scope.row.QuestionType]"
                        type="textarea"
                        show-word-limit
                        :autosize="{ minRows: 2, maxRows: 4}"
                        size="mini"
                        maxlength="100"
                        @change="(v) => {handleChange(v, scope.row.QuestionType)}"
                      />
                      <!-- 系统评估结果为：xxx,与当前调整的结果不一致，请填写调整原因 -->
                      <!--                      <p v-if="currentEvaluateResult !== tumorEvaluate" style="width: 140px;padding:0 2px;white-space: normal;word-break: break-all;word-wrap: break-word;">{{ $t('trials:readingReport:title:sysEvaluationRes') }}<span style="color:red">{{ $fd('OverallAssessment',tumorEvaluate) }}</span>{{ $t('trials:readingReport:message:msg1') }}</p>-->
                      <!--                      <p v-else-if="currentExistDisease !== isExistDisease" style="width: 140px;padding:0 2px;white-space: normal;word-break: break-all;word-wrap: break-word;">{{ $t('trials:readingReport:title:sysEvaluationRes') }}<span style="color:red">{{ $fd('ExistDisease',isExistDisease) }}</span>{{ $t('trials:readingReport:message:msg1') }}</p>-->
                    </template>
                    <template v-else>
                      <span>{{ currentTaskReason }}</span>
                    </template>

                  </template>
                  <template v-else-if="scope.row.DictionaryCode">
                    {{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}
                  </template>
                  <template v-else>
                    {{ scope.row.Answers[task.VisitTaskId] }}
                  </template>
                </template>
                <!--                <template v-else-if="scope.row.QuestionType=== 15">-->
                <!--                  <el-tooltip v-if="getAnswerInfo(scope.row.Answer,task.VisitTaskId,'IsGlobalChange')" :content="`${$t('trials:reading:warnning:msg55')}${$fd(scope.row.DictionaryCode, getAnswerInfo(scope.row.Answer,task.VisitTaskId,'GlobalChangeAnswer'))}`" placement="top" effect="light">-->
                <!--                    <span style="color:red;"> {{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}</span>-->
                <!--                  </el-tooltip>-->
                <!--                  <span v-else>{{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}</span>-->
                <!--                </template>-->
                <!--                <template v-else-if="scope.row.QuestionType=== 13">-->
                <!--                  <el-tooltip v-if="getAnswerInfo(scope.row.Answer,task.VisitTaskId,'IsGlobalChange')" :content="`${$t('trials:reading:warnning:msg55')}${$fd(scope.row.DictionaryCode, getAnswerInfo(scope.row.Answer,task.VisitTaskId,'GlobalChangeAnswer'))}`" placement="top" effect="light">-->
                <!--                    <span style="color:red;"> {{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}</span>-->
                <!--                  </el-tooltip>-->
                <!--                  <span v-else>{{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}</span>-->
                <!--                </template>-->
                <template v-else-if="task.VisitTaskId === visitTaskId && readingTaskState < 2 && ([10, 11, 12, 13, 14, 15].includes(scope.row.QuestionType))">
                  <el-select
                    v-if="scope.row.Type==='select' && scope.row.DictionaryCode"
                    v-model="QuestionTypeList[scope.row.QuestionType]"
                    size="mini"
                    @change="(v) => {handleChange(v, scope.row.QuestionType)}"
                  >
                    <el-option
                      v-for="item of $d[scope.row.DictionaryCode]"
                      :key="item.id"
                      :value="item.value"
                      :label="item.label"
                    />
                  </el-select>
                </template>
                <template v-else-if="scope.row.QuestionType=== 22">
                  {{ scope.row.Answers[task.VisitTaskId] === '-1' ? $t('trials:readingReport:title:unknow') : scope.row.Answers[task.VisitTaskId] }}
                </template>

                <template v-else-if="scope.row.DictionaryCode">
                  {{ $fd(scope.row.DictionaryCode, scope.row.Answers[task.VisitTaskId]) }}
                </template>
                <template v-else-if="CriterionType === 10">
                  {{ isNaN(parseInt(scope.row.Answers[task.VisitTaskId]))?scope.row.Answers[task.VisitTaskId]:`${scope.row.Answers[task.VisitTaskId]}` }}
                </template>
                <template v-else-if="(scope.row.ValueType === 0 || scope.row.ValueType === 1) && scope.row.Unit">
                  {{ isNaN(parseInt(scope.row.Answers[task.VisitTaskId]))?scope.row.Answers[task.VisitTaskId]:`${scope.row.Answers[task.VisitTaskId]} ${$fd('ValueUnit',scope.row.Unit)}` }}
                </template>
                <template v-else-if="scope.row.ValueType === 2">
                  {{ isNaN(parseInt(scope.row.Answers[task.VisitTaskId]))?scope.row.Answers[task.VisitTaskId]:`${scope.row.Answers[task.VisitTaskId]}%` }}
                </template>
                <template v-else-if="scope.row.Answers && scope.row.Answers.hasOwnProperty(task.VisitTaskId)">
                  {{ scope.row.Answers[task.VisitTaskId] }}
                </template>
              </span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>

    <!-- 签名框 -->
    <el-dialog
      v-if="signVisible"
      :visible.sync="signVisible"
      :close-on-click-modal="false"
      width="600px"
      custom-class="base-dialog-wrapper"
    >
      <div slot="title">
        <span style="font-size:18px;">{{ $t('common:dialogTitle:sign') }}</span>
        <span style="font-size:12px;margin-left:5px">{{ `(${$t('common:label:sign')}${ currentUser })` }}</span>
      </div>
      <SignForm ref="signForm" :sign-code-enum="signCode" @closeDialog="closeSignDialog" />
    </el-dialog>
  </div>
</template>
<script>
import { getReadingReportEvaluation, changeDicomReadingQuestionAnswer, submitDicomVisitTask, verifyVisitTaskQuestions } from '@/api/trials'
import DicomEvent from './DicomEvent'
import const_ from '@/const/sign-code'
import SignForm from '@/views/trials/components/newSignForm'
import { getToken } from '@/utils/auth'
import store from '@/store'
import { mapGetters } from 'vuex'
import { changeURLStatic } from '@/utils/history.js'
export default {
  name: 'ReportPage',
  components: { SignForm },
  props: {
    visitTaskId: {
      type: String,
      required: true
    },
    questionFormChangeState: {
      type: Boolean,
      default() {
        return false
      }
    }
  },
  data() {
    return {
      currentUser: zzSessionStorage.getItem('userName'),
      QuestionTypeList: [],
      signVisible: false,
      signCode: null,
      visitTaskList: [],
      taskQuestions: [],
      loading: false,
      answers: [],
      readingTaskState: 2,
      tumorEvaluate: null,
      currentEvaluateResult: null,
      isExistDisease: null,
      currentExistDisease: null,
      currentTaskReason: '',
      answerArr: [],
      questions: [],
      isShowDetail: false,
      CriterionType: 0,
      height: 0
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  watch: {
    taskQuestions() {
      this.$nextTick(() => {
        this.getTableHeight()
        this.$refs.reportList && this.$refs.reportList.doLayout()
        this.setScrollTop()
      })
    }
  },
  created() { this.getTableHeight() },
  mounted() {
    console.log(this.questionFormChangeState)
    this.CriterionType = parseInt(localStorage.getItem('CriterionType'))
    window.addEventListener('resize', () => {
      this.handleResize()
      this.setScrollTop()
    })
    DicomEvent.$on('getReportInfo', isRefresh => {
      if (!isRefresh) return
      this.getReportInfo()
    })
    this.getReportInfo()
  },
  beforeDestroy() {
    DicomEvent.$off('getReportInfo')
  },
  methods: {
    myConfirm(msg) {
      return new Promise(resolve => {
        this.$confirm(msg, {
          type: 'warning',
          showCancelButton: true
        }).then(() => {
          resolve(true)
        }).catch(() => {
          resolve(false)
        })
      })
    },
    async beforeLeave() {
      console.log(this.questionFormChangeState)
      if (this.questionFormChangeState) {
        var msg = this.$t('trials:readingReport:message:msg5')
        var isgo = await this.myConfirm(msg)
        if (isgo) {
        } else {
          return Promise.resolve(true)
        }
      }
      var list = null
      DicomEvent.$emit('getAllUnSaveLesions', val => {
        list = val
      })
      if (list.length > 0) {
        var arr = []
        list.map(i => {
          arr.push(i.lessionName)
        })
        // 请先保存${arr.join('、')}病灶信息！
        var msg = this.$t('trials:reading:warnning:msg200')
        msg = msg.replace('xxx', arr.join(this.language === 'en' ? ', ' : '、'))
        this.$confirm(msg, {
          type: 'warning',
          showCancelButton: false
        }).then(() => {
        }).catch(() => {
        })
      } else {
        this.handleConfirm()
      }
    },
    getAnswerInfo(answerArr, visitTaskId, prop) {
      var i = answerArr.findIndex(i => i.VisitTaskId === visitTaskId)
      if (i === -1) return ''
      var val = answerArr[i][prop]
      return isNaN(parseInt(val)) ? val : parseInt(val)
    },
    getTableHeight() {
      this.height = window.innerHeight - 170
    },
    getReportInfo(IsCalculate) {
      this.loading = true
      var params = {
        visitTaskId: this.visitTaskId,
        trialId: this.$router.currentRoute.query.trialId,
        IsCalculate: IsCalculate !== false
      }
      getReadingReportEvaluation(params).then(res => {
        this.readingTaskState = res.Result.ReadingTaskState
        this.tumorEvaluate = res.Result.CalculateResult.TumorEvaluate ? parseInt(res.Result.CalculateResult.TumorEvaluate) : null
        this.isExistDisease = res.Result.CalculateResult.IsExistDisease ? parseInt(res.Result.CalculateResult.IsExistDisease) : null
        this.answerArr = []
        this.questions = res.Result.TaskQuestions.concat()
        this.visitTaskList = res.Result.VisitTaskList
        var taskQuestions = this.getQuestions(res.Result.TaskQuestions, !this.isShowDetail, null, null)
        this.taskQuestions = []
        taskQuestions.forEach(item => {
          this.$set(this.taskQuestions, this.taskQuestions.length, item)
        })
        console.log(taskQuestions)
        this.setScrollTop()
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    setScrollTop(a) {
      setTimeout(() => {
        this.$refs.reportList.bodyWrapper.scrollTop = this.$refs.reportList.bodyWrapper.scrollHeight
        this.$refs.reportList.bodyWrapper.scrollTop = this.$refs.reportList.bodyWrapper.scrollHeight
        this.getTableHeight()
      }, 50)
    },
    getQuestions(questions, isNTFilterLength, lesionType, isLymphNodes) {
      const arr = []
      if (questions.length !== 0) {
        questions.forEach((item) => {
          // 过滤病灶标识  病灶名称  部位  器官  位置  是否淋巴结
          // 非靶病灶和新病灶 过滤长径和短径信息
          // 非淋巴结靶病灶 过滤短径

          lesionType = item.LesionType
          var filterArr = [7]
          if ((item.LesionType === 1 || item.LesionType === 2) && isNTFilterLength) {
            filterArr = [0, 1, 3, 4, 5, 6, 2, 8, 10, 7]
          } else {
            filterArr = [3, 4, 5, 6, 2, 8, 10, 7]
          }
          if (lesionType === 0 && isLymphNodes === 0 && !this.isShowDetail && this.CriterionType === 1) {
            filterArr.push(1)
          }
          if (isLymphNodes === 0) {
            filterArr.push(1)
          }
          if (!(filterArr.includes(item.QuestionMark))) {
            const obj = item
            obj.Answers = {}
            if (item.RowIndex > 0) {
              try {
                var idx = item.Childrens.findIndex(i => i.QuestionMark === 8)
                var idxLoc = item.Childrens.findIndex(i => i.QuestionMark === 10)
                var state = item.Childrens.findIndex(i => i.QuestionMark === 7)
                if (idx > -1) {
                  if (item.Childrens[idx].Answer.length > 0) {
                    var k = item.Childrens[idx].Answer.findIndex(v => v.Answer !== '')
                    var part = ''
                    if (obj.IsCanEditPosition) {
                      part = `${item.Childrens[idx].Answer[k].Answer}--${item.Childrens[idxLoc].Answer[k].Answer}`
                    } else {
                      part = `${item.Childrens[idx].Answer[k].Answer}`
                    }
                    if (item.SplitOrMergeLesionName && k > -1) {
                      // obj.QuestionName = `${obj.QuestionName} --${part} (Split from ${item.SplitOrMergeLesionName})`
                      obj.QuestionName = `${obj.QuestionName} --${part}`
                      var Answers = {}
                      console.log(state)
                      if (state >= 0) {
                        this.visitTaskList.forEach(v => {
                          const o = item.Childrens[state].Answer.find(v1 => {
                            return v1.VisitTaskId === v.VisitTaskId
                          })
                          if (o) {
                            Answers[o.VisitTaskId] = this.$fd(item.Childrens[state].DictionaryCode, parseInt(o.Answer))
                          }
                        })
                      }
                      console.log(Answers)
                      this.$set(obj, 'Answers', Answers)
                      // obj.QuestionName = `${obj.QuestionName} `
                    } else if (!item.SplitOrMergeLesionName && k > -1) {
                      obj.QuestionName = `${obj.QuestionName}--${part}`
                      var Answers = {}
                      console.log(state)
                      if (state >= 0) {
                        this.visitTaskList.forEach(v => {
                          const o = item.Childrens[state].Answer.find(v1 => {
                            return v1.VisitTaskId === v.VisitTaskId
                          })
                          if (o) {
                            Answers[o.VisitTaskId] = this.$fd(item.Childrens[state].DictionaryCode, parseInt(o.Answer))
                          }
                        })
                      }
                      console.log(Answers)
                      this.$set(obj, 'Answers', Answers)
                      // obj.QuestionName = `${obj.QuestionName} `
                    } else {
                      obj.QuestionName = `${obj.QuestionName} `
                    }

                    if (this.CriterionType === 1) {
                      var idxLymphNode = item.Childrens.findIndex(i => i.QuestionMark === 2)
                      if (idxLymphNode > -1) {
                        isLymphNodes = item.Childrens[idxLymphNode].Answer[k].Answer ? parseInt(item.Childrens[idxLymphNode].Answer[k].Answer) : null
                        console.log('isLymphNodes', item.Childrens)
                        item.Childrens.forEach(v => {
                          this.$set(v, 'isLymphNodes', isLymphNodes)
                        })
                      }
                    }
                  }
                }
              } catch (e) {
                console.log(e)
              }
            }
            item.Answer.forEach(i => {
              if (item.DictionaryCode) {
                obj.Answers[i.VisitTaskId] = i.Answer ? parseInt(i.Answer) : null
              } else {
                obj.Answers[i.VisitTaskId] = i.Answer
              }
            })
            if (item.QuestionType === 10) {
              this.QuestionTypeList[10] = obj.Answers[this.visitTaskId]
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 10 })
            }
            if (item.QuestionType === 11) {
              this.QuestionTypeList[11] = obj.Answers[this.visitTaskId]
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 11 })
            }
            if (item.QuestionType === 12) {
              this.QuestionTypeList[12] = obj.Answers[this.visitTaskId]
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 12 })
            }
            if (item.QuestionType === 15) {
              this.QuestionTypeList[15] = obj.Answers[this.visitTaskId]
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 15 })
            }
            if (item.QuestionType === 13) {
              this.QuestionTypeList[13] = obj.Answers[this.visitTaskId]
              console.log(this.currentEvaluateResult)
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 13 })
            }
            if (item.QuestionType === 14) {
              this.QuestionTypeList[14] = obj.Answers[this.visitTaskId]
              this.answerArr.push({ id: item.QuestionId, answer: obj.Answers[this.visitTaskId], questionType: 14 })
            }
            if (item.Childrens.length >= 1) {
              obj.Childrens = this.getQuestions(item.Childrens, isNTFilterLength, lesionType, isLymphNodes)
            }
            arr.push(obj)
          }
        })
      }
      return arr
    },
    handleShowDetail(val) {
      this.getReportInfo()
      // this.taskQuestions = this.getQuestions(res.Result.TaskQuestions, !this.isShowDetail, null)
    },
    handleExistDiseaseChange(val) {
      // this.currentExistDisease = parseInt(val)
      if (val === this.isExistDisease && this.tumorEvaluate === this.currentEvaluateResult) {
        this.currentTaskReason = ''
        this.evaluateReasonChange('')
      }
      this.currentTaskReason = ''
      this.evaluateReasonChange('')
      var idx = this.answerArr.findIndex(i => i.questionType === 15)
      console.log(this.answerArr, idx, val)
      if (idx > -1) {
        this.answerArr[idx].answer = val
      }
    },
    handleChange(val, questionType) {
      var idx = this.answerArr.findIndex(i => i.questionType === questionType)
      if (idx > -1) {
        this.answerArr[idx].answer = val
      }
    },
    handleEvaluateResultChange(val) {
      // this.currentEvaluateResult = parseInt(val)
      if (val === this.tumorEvaluate && this.isExistDisease === this.currentExistDisease) {
        this.currentTaskReason = ''
        this.evaluateReasonChange('')
      }
      this.currentTaskReason = ''
      this.evaluateReasonChange('')
      var idx = this.answerArr.findIndex(i => i.questionType === 13)
      if (idx > -1) {
        this.answerArr[idx].answer = val
      }
    },

    evaluateReasonChange(val) {
      var idx = this.answerArr.findIndex(i => i.questionType === 14)
      if (idx > -1) {
        this.answerArr[idx].answer = val
      }
    },
    async handleConfirm() {
      await this.handleSave(false)
      await this.verifyVisitTaskQuestions()
      const { ImageAssessmentReportConfirmation } = const_.processSignature
      this.signCode = ImageAssessmentReportConfirmation
      this.signVisible = true
    },
    verifyVisitTaskQuestions() {
      return new Promise((resolve, reject) => {
        this.loading = true
        verifyVisitTaskQuestions({ visitTaskId: this.visitTaskId }).then(res => {
          this.loading = false
          resolve()
        }).catch(() => {
          this.loading = false
          reject()
        })
      })
    },
    handleResize() {
      this.$nextTick(() => {
        this.$refs.reportList && this.$refs.reportList.doLayout()
      })
    },
    // 关闭签名框
    closeSignDialog(isSign, signInfo) {
      if (isSign) {
        this.signConfirm(signInfo)
      } else {
        this.signVisible = false
      }
    },
    // 签名并确认
    signConfirm(signInfo) {
      this.loading = true
      var params = {
        data: {
          visitTaskId: this.visitTaskId
        },
        signInfo: signInfo
      }
      submitDicomVisitTask(params).then(async res => {
        if (res.IsSuccess) {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          if (this.$refs['signForm']) {
            this.$refs['signForm'].btnLoading = false
          }

          this.signVisible = false
          // window.location.reload()
          // window.opener.postMessage('refreshTaskList', window.location)

          // 设置当前任务阅片状态为已读
          this.readingTaskState = 2
          store.dispatch('reading/setVisitTaskReadingTaskState', { visitTaskId: this.visitTaskId, readingTaskState: 2 })
          // DicomEvent.$emit('setReadingState', 2)
          await store.dispatch('reading/setCurrentReadingTaskState', 2)
          window.opener.postMessage('refreshTaskList', window.location)
          // '当前阅片任务已完成，是否进入下一个阅片任务？'
          this.$confirm(this.$t('trials:readingReport:message:msg4'), {
            type: 'warning',
            distinguishCancelAndClose: true
          })
            .then(() => {
              // var token = getToken()
              // var subjectCode = this.$router.currentRoute.query.subjectCode
              // var subjectId = this.$router.currentRoute.query.subjectId
              // var trialId = this.$router.currentRoute.query.trialId

              // this.$router.push({
              //   path: `/readingPage?subjectCode=${subjectCode}&subjectId=${subjectId}&trialId=${trialId}&TokenKey=${token}`
              // })
              DicomEvent.$emit('getNextTask')
            })
            .catch(action => {
              changeURLStatic('visitTaskId', this.visitTaskId)
            })
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
        if (this.$refs['signForm'] && this.$refs['signForm'].btnLoading) {
          this.$refs['signForm'].btnLoading = false
        }
      })
    },
    previewDicoms(task) {
      var token = getToken()
      var subjectCode = this.$router.currentRoute.query.subjectCode
      var subjectId = this.$router.currentRoute.query.subjectId
      var trialId = this.$router.currentRoute.query.trialId
      var isReadingTaskViewInOrder = this.$router.currentRoute.query.isReadingTaskViewInOrder
      var criterionType = this.$router.currentRoute.query.criterionType
      var readingTool = this.$router.currentRoute.query.readingTool
      var path = `/readingDicoms?trialId=${trialId}&subjectCode=${subjectCode}&subjectId=${subjectId}&visitTaskId=${task.VisitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}`
      const routeData = this.$router.resolve({ path })
      window.open(routeData.href, '_blank')
    },
    handleSave(isPrompt) {
      return new Promise((resolve, reject) => {
        var isBeill
        var evaluateResult = ''
        var evaluateAjustReason = ''
        console.log(this.answerArr)
        this.answers = []
        var isExistEvaluateResult = false
        this.answerArr.map(item => {
          if (item.questionType === 13) {
            evaluateResult = item.answer
            isExistEvaluateResult = true
          }
          if (item.questionType === 14) {
            evaluateAjustReason = item.answer
          }
          if (item.questionType === 15) {
            isBeill = item.answer
          }
          this.answers.push({ id: item.id, answer: item.answer })
        })
        console.log(this.currentExistDisease, this.isExistDisease, evaluateAjustReason)
        // if (this.currentExistDisease !== this.isExistDisease && !evaluateAjustReason) {
        //   this.$confirm(this.$t('trials:readingReport:message:msg2'), {
        //     type: 'warning',
        //     showCancelButton: false,
        //     callback: action => {}
        //   })
        //   reject()
        //   return
        // }
        // if (isExistEvaluateResult && evaluateResult === null) {
        //   // 请将疗效评估信息填写完整
        //   this.$confirm(this.$t('trials:readingReport:message:msg2'), {
        //     type: 'warning',
        //     showCancelButton: false,
        //     callback: action => {}
        //   })
        //   reject()
        //   return
        // }
        // if (isExistEvaluateResult && (evaluateResult !== this.tumorEvaluate) && !evaluateAjustReason) {
        //   // 请填写整体评估调整原因
        //   this.$confirm(this.$t('trials:readingReport:message:msg3'), {
        //     type: 'warning',
        //     showCancelButton: false,
        //     callback: action => {}
        //   })
        //   reject()
        //   return
        // }
        this.loading = true
        var params = {
          visitTaskId: this.visitTaskId,
          answers: this.answers
        }
        changeDicomReadingQuestionAnswer(params).then(res => {
          if (isPrompt) {
            this.$message.success(this.$t('common:message:savedSuccessfully'))
          }
          this.loading = false
          resolve()
        }).catch(() => {
          this.loading = false
          reject()
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.report-wrapper{

  height: 100%;
  padding: 10px 0px;
  // background-color: #fff;
  background-color: #000;
  ::-webkit-scrollbar {
    width: 7px;
    height: 7px;
  }
  ::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: #d0d0d0;
  }
  .report-header{
    display: flex;
  }
  .el-card{
    display:flex;flex-direction: column;height: 100%;
    background-color: #000;
    color: #ffffff;
    border:none;
    >>>.el-card__body{
      flex: 1;
    }
  }

  // >>>.el-table__cell{
  //   background-color: #000;
  //   color: #ffffff;
  // }
  // >>>.el-table{
  //   background-color: #000;
  //   color: #ffffff;
  // }
  // >>>.el-table__cell{
  //   background-color: #000;
  //   color: #ffffff;
  // }

  >>>.el-table, .el-table__expanded-cell {
    background-color: #000;
    color: #fff;
    border-color:#444444;
  }

  >>>.el-table th, .el-table tr {
    background-color: #000;
    color: #fff;
    border-color:#444444;
  }
  >>>.el-table__body tr > td{
    background-color:#000 !important;
    color: #fff;
    border-color:#444444;
  }
  >>>.el-table__body tr:hover > td{
    background-color:#858282 !important;
    color: #fff;
    border-color:#444444;
  }
  >>>.el-table--border th.gutter:last-of-type{
    border: none;
  }
  >>>.el-card__header{
    border: none;
    padding: 10px;
  }
}
>>>.el-switch__label{
  color:#fff;
}
>>>.el-switch__label.is-active{
  color: #00D1B2;
}
</style>
