<template>
  <div class="trial-information">
    <div>
      <el-descriptions :column="2" border style="width: 1200px">
        <!--项目类型-->
        <el-descriptions-item :label="$t('trials:trials-list:form:trialType')">
          {{ $fd('TrialType', trialInfo.TrialType) }}
        </el-descriptions-item>
        <!--项目编号-->
        <el-descriptions-item :label="$t('trials:trials-list:form:TrialCode')">
          {{ trialInfo.TrialCode }}
        </el-descriptions-item>
        <!--研究方案号-->
        <el-descriptions-item :label="$t('trials:trials-list:form:researchNumber')">
          {{ trialInfo.ResearchProgramNo }}
        </el-descriptions-item>
        <!--试验名称-->
        <el-descriptions-item :label="$t('trials:trials-list:form:experimentName')">
          {{ trialInfo.ExperimentName }}
        </el-descriptions-item>
        <!--药物/器械名称-->
        <el-descriptions-item :label="$t('trials:trials-list:message:D/Dname')">
          {{ trialInfo.MedicineName }}
        </el-descriptions-item>
        <!--申办方-->
        <el-descriptions-item :label="$t('trials:trials-list:form:sponsor')">
          {{ trialInfo.Sponsor }}
        </el-descriptions-item>
        <!--主要研究者-->
        <el-descriptions-item :label="$t('trials:trials-list:form:pi')">
          {{ trialInfo.HeadPI }}
        </el-descriptions-item>
        <!--临床分期-->
        <el-descriptions-item :label="$t('trials:trials-list:form:phase')">
          {{ $fd('Trial_Phase', trialInfo.PhaseId, 'id') }}
        </el-descriptions-item>
        <!--适应症-->
        <el-descriptions-item :label="$t('trials:trials-list:form:indication')">
          {{ trialInfo.Indication }}
        </el-descriptions-item>
        <!--阅片标准-->
        <el-descriptions-item :span="4" :label="$t('trials:trials-list:form:criterion')">
          {{
            trialInfo.CriterionTypeList
              ? trialInfo.CriterionTypeList.map((item) =>
                $fd('CriterionType', item)
              ).join(', ')
              : ''
          }}
        </el-descriptions-item>
        <!--课题组-->
        <el-descriptions-item :label="$t('trials:trials-list:form:HospitalGroupName')">
          {{ trialInfo.HospitalGroupName }}
        </el-descriptions-item>
        <!--CRO-->
        <el-descriptions-item :label="$t('trials:trials-list:form:cro')">
          {{ trialInfo.CRO }}
        </el-descriptions-item>
        <!--联系人-->
        <el-descriptions-item :label="$t('trials:researchRecord:table:contactor')">
          {{ trialInfo.ContactUser }}
        </el-descriptions-item>
        <!--电话-->
        <el-descriptions-item :label="$t('trials:trials-myinfo:form:phone')">
          {{ trialInfo.ContactPhone }}
        </el-descriptions-item>
        <!--项目周期-->
        <el-descriptions-item :label="$t('trials:trials-list:form:projectCycle')">
          {{ trialInfo.AuthorizationDuration }}
        </el-descriptions-item>
        <!--创建日期-->
        <el-descriptions-item :label="$t('trials:trials-list:table:createDate')">
          {{ trialInfo.CreateTime }}
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div v-if="otherInfo && otherInfo.TrialId && isRight" v-hasPermi="['trials:trials-list:activate']"
      style="margin-top: 40px;">
      <el-descriptions :column="2" border style="width: 1200px">
        <p slot="title" style="margin: 0;">{{ $t('trials:trials-list:activate:title') }}</p>
        <!--单位名称-->
        <el-descriptions-item :label="$t('trials:trials-list:activate:organizationName')">
          {{ otherInfo.HospitalName }}
        </el-descriptions-item>
        <!--项目编号-->
        <el-descriptions-item :label="$t('trials:trials-list:table:trialId')">
          {{ otherInfo.TrialCode }}
        </el-descriptions-item>
        <!--评估标准-->
        <el-descriptions-item :label="$t('trials:trials-list:activate:evaluationCriteria')">
          {{
            otherInfo.CriterionTypeList.map((item) =>
              $fd('CriterionType', Number(item))
            ).join(',')
          }}
        </el-descriptions-item>
        <!--授权时长-->
        <el-descriptions-item :label="$t('trials:trials-list:activate:durationAuthorized')">
          {{ otherInfo.PurchaseDuration }}
        </el-descriptions-item>
        <!--激活日期-->
        <el-descriptions-item :label="$t('trials:trial-information:title:activationDate')">
          {{ otherInfo.ActiveTime }}
        </el-descriptions-item>
        <!--授权日期-->
        <el-descriptions-item :label="$t('trials:trials-list:table:dateAuthorized')">
          {{ otherInfo.AuthorizationDeadLineDate }}
        </el-descriptions-item>
      </el-descriptions>
      <!-- <div slot="extra">
        <el-button
          type="primary"
          size="small"
          style="margin-top: 10px"
          @click.stop="putActivate"
          >{{ $t("trials:activate:renewalAuthorization") }}</el-button
        >
      </div> -->
    </div>
    <div>
      <el-button type="primary" size="small" style="margin-top: 10px" @click.stop="putActivate"
        v-hasPermi="['trials:trials-list:activate']">{{ $t('trials:activate:renewalAuthorization') }}</el-button>
    </div>
    <activate-project v-if="activateVisible" :visible.sync="activateVisible" :data="otherInfo" @getList="initForm" />
  </div>
</template>
<script>
import { getTrialInfoHir } from '@/api/trials'
import activateProject from '@/views/trials/trials-list/components/activate-project.vue'
export default {
  components: { 'activate-project': activateProject },
  data() {
    return {
      trialInfo: {},
      trialId: '',
      trialStatus: '',
      formLoading: false,
      otherInfo: {},
      isRight: true,
      activateVisible: false,
    }
  },
  mounted() {
    this.trialId = this.$route.query.trialId
    this.initForm()
  },
  methods: {
    // 更新授权
    putActivate() {
      this.activateVisible = true
      // console.log(this.activateVisible)
    },
    initForm() {
      this.formLoading = true
      getTrialInfoHir(this.trialId)
        .then((res) => {
          this.formLoading = false
          this.isRight = true
          this.otherInfo = res.OtherInfo
          if (res.Code === 5) {
            this.$confirm(res.ErrorMessage, {
              type: 'warning',
              showCancelButton: false,
            })
          }
          if (!res.OtherInfo) {
            this.isRight = false
            this.otherInfo = {
              TrialId: this.$route.query.trialId,
            }
          }
          this.trialInfo = res.Result
          this.trialInfo.ReviewTypeList =
            this.trialInfo.ReviewTypeList.length > 0
              ? this.trialInfo.ReviewTypeList.join(', ')
              : ''
          var modalityArr = []
          res.Result.ModalityIds.map((i) => {
            modalityArr.push(this.$fd('Modality', i, 'id'))
          })
          this.trialInfo.ModalityList = modalityArr.join(', ')
          this.trialInfo.Criterion =
            res.Result.CriterionList && res.Result.CriterionList.length > 0
              ? res.Result.CriterionList.join(', ')
              : ''
          // this.trialInfo.Expedited = this.$fd('Trial_BasicInfo', res.Result.Expedited)
          // this.trialInfo.AttendedReviewerType = this.$fd('Trial_BasicInfo', res.Result.AttendedReviewerType)
        })
        .catch((error) => {
          this.formLoading = false
          if (error.Code === 2) {
            this.isRight = false
            this.otherInfo = {
              TrialId: this.$route.query.trialId,
            }
          }
        })
    },
  },
}
</script>
<style lang="scss">
.trial-information {
  min-height: 100%;
  padding: 10px 0 0 10px;
  background: #fff;
}
</style>
<style scoped>
::v-deep .el-descriptions--medium.is-bordered .el-descriptions-item__cell {
  width: 10%;
}
</style>
