<template>
  <div>
    <div style="text-align:right">
      <el-button v-if="auditInfo.IsExistsClinicalData" type="text" @click="previewCD">
        {{ $t('trials:adReview:title:clinicalData') }}
      </el-button>
    </div>
    <el-table :data="oncologyInfo.OncologyVisits" style="width: 100%">
      <!-- 访视名称 -->
      <el-table-column prop="VisitName" :label="$t('trials:oncologyReview:title:visitName')" show-overflow-tooltip
        width="150" />
      <!-- 影像学阅片结果 -->
      <el-table-column :label="$t('trials:oncologyReview:title:readingRes')" align="center" prop=""
        show-overflow-tooltip>
        <template>
          <el-table-column v-for="(qs, index) in questionCols" :key="qs" prop="" :label="qs" show-overflow-tooltip
            width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.QuestionList[index].DictionaryCode">
                {{ $fd(scope.row.QuestionList[index].DictionaryCode, parseInt(scope.row.QuestionList[index].Answer))
                }}
              </span>
              <span v-else>
                {{ scope.row.QuestionList.length > index ? scope.row.QuestionList[index].Answer : '' }}
              </span>
              <span>
                {{
                  scope.row.QuestionList[index].ValueType == 2 ? '%' : scope.row.QuestionList[index].CustomUnit ?
                    scope.row.QuestionList[index].CustomUnit :
                    scope.row.QuestionList[index].Unit ? $fd("Unit", scope.row.QuestionList[index].Unit) : ''
                }}
              </span>
            </template>
          </el-table-column>
          <!-- 全局是否有更新 -->
          <el-table-column v-if="oncologyInfo.IsShowDetail" prop="IsHaveChange"
            :label="$t('trials:oncologyReview:title:isGlobalUpdate')" show-overflow-tooltip width="150">
            <template slot-scope="scope">
              <span>{{ $fd('YesOrNo', scope.row.IsHaveChange) }}</span>
              <!-- 查看详情 -->
              <el-button v-if="scope.row.IsHaveChange && !!oncologyInfo.GlobalTaskId" type="text"
                style="margin-left:5px;" @click="handleViewDetail(oncologyInfo.GlobalTaskId)">
                {{ $t('trials:oncologyReview:title:view') }}
              </el-button>
            </template>
          </el-table-column>
          <!-- 访视点注释 -->
          <el-table-column v-if="oncologyInfo.IsShowDetail" prop="VisitRemark"
            :label="$t('trials:oncologyReview:title:visitRemark')" show-overflow-tooltip width="150" />
        </template>
      </el-table-column>
      <!-- 肿瘤学阅片结果 -->
      <el-table-column :label="$t('trials:oncologyReview:title:oReviewRes')" align="center" prop="">
        <template>
          <!-- 结论 -->
          <el-table-column prop="EvaluationResult" :label="$t('trials:oncologyReview:title:findings')"
            show-overflow-tooltip width="150">
            <template slot-scope="scope">
              <el-select v-if="oncologyInfo.ReadingTaskState < 2" v-model="scope.row.EvaluationResult"
                :placeholder="$t('common:ruleMessage:select')">
                <el-option v-for="item in assessTypeList" :key="item.Id" :label="item.Value" :value="item.Code" />
              </el-select>
              <span v-else>{{ getAssessType(scope.row.EvaluationResult) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="EvaluationReason" show-overflow-tooltip width="250">
            <template slot="header">
              <el-tooltip placement="top">

                <div slot="content">
                  {{ oncologyInfo.TrialEvaluationReason }}
                </div>
                <div>
                  <!-- 原因 -->
                  <span>{{ $t('trials:oncologyReview:title:reason') }}</span>
                  <span style="color:red">*</span>
                </div>

              </el-tooltip>
            </template>
            <template slot-scope="scope">
              <el-input v-if="oncologyInfo.ReadingTaskState < 2" v-model="scope.row.EvaluationReason" />
              <span v-else>{{ scope.row.EvaluationReason }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table-column>

      <el-table-column v-if="oncologyInfo.IsShowDetail" :label="$t('common:action:action')" width="120">
        <template slot-scope="scope">
          <!-- 查看详情 -->
          <el-button circle :title="$t('trials:oncologyReview:title:view')" icon="el-icon-view"
            @click="handleViewDetail(scope.row.VisitTaskId)" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getToken } from '@/utils/auth'
export default {
  name: 'OReview',
  props: {
    auditInfo: {
      type: Object,
      default() {
        return {}
      }
    },
    rowData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      oncologyInfo: {},
      questionCols: []
    }
  },
  mounted() {
    this.initPage()
  },
  methods: {
    initPage() {
      var questions = []
      if (this.auditInfo.OncologyInfo.OncologyVisits.length > 0) {
        var task = this.auditInfo.OncologyInfo.OncologyVisits[0]
        task.QuestionList.map(qs => {
          questions.push(qs.QuestionName)
        })
      }
      this.questionCols = questions
      this.assessTypeList = this.auditInfo.OncologyInfo.AssessTypeList
      this.oncologyInfo = this.auditInfo.OncologyInfo
    },
    handleViewDetail(visitTaskId) {
      var trialId = this.$route.query.trialId
      var token = getToken()
      var criterionType = this.rowData.CriterionType
      var readingTool = this.rowData.ReadingTool
      readingTool = isNaN(parseInt(readingTool)) ? null : parseInt(readingTool)
      var isReadingTaskViewInOrder = this.rowData.IsReadingTaskViewInOrder
      var trialReadingCriterionId = this.rowData.TrialReadingCriterionId
      var path = ''

      if (readingTool === 0 || readingTool === 2) {
        path = `/readingDicoms?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${trialId}&subjectCode=${this.rowData.SubjectCode}&subjectId=${this.rowData.SubjectId}&visitTaskId=${visitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      } else {
        path = `/noneDicomReading?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${trialId}&subjectCode=${this.rowData.SubjectCode}&subjectId=${this.rowData.SubjectId}&visitTaskId=${visitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      }
      const routeData = this.$router.resolve({ path })
      window.open(routeData.href, '_blank')
    },
    previewCD() {
      var token = getToken()
      var trialId = this.$route.query.trialId
      const routeData = this.$router.resolve({
        path: `/clinicalData?subjectId=${this.auditInfo.SubjectId}&trialId=${trialId}&visitTaskId=${this.auditInfo.VisitTaskId}&TokenKey=${token}`
      })
      window.open(routeData.href, '_blank')
    },
    getAssessType(val) {
      var idx = this.assessTypeList.findIndex(i => i.Code === val)
      if (idx > -1) {
        return this.assessTypeList[idx].Value
      } else {
        return ''
      }
    }
  }
}
</script>
