<template>
  <BaseContainer>
    <!-- 搜索框 -->
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 中心编号 -->
        <el-form-item :label="$t('trials:researchStaff:table:siteId')">
          <el-select v-model="searchData.TrialSiteId" clearable filterable style="width:120px;">
            <el-option v-for="(item, index) of siteOptions" :key="index" :label="item.TrialSiteCode"
              :value="item.TrialSiteId" />
          </el-select>
        </el-form-item>
        <!-- 中心名称 -->
        <el-form-item :label="$t('trials:researchStaff:table:siteName')">
          <el-input v-model="searchData.TrialSiteName" class="mr" clearable style="width:120px;" />
        </el-form-item>
        <!-- 状态 -->
        <el-form-item :label="$t('trials:researchRecord:table:status')">
          <el-select v-model="searchData.State" clearable filterable style="width: 120px">
            <el-option v-for="(item, index) of $d.ResearchRecord" :key="index" :label="item.label"
              :value="item.value" />
          </el-select>
        </el-form-item>
        <!-- 是否废除 -->
        <!-- <el-form-item :label="$t('trials:researchRecord:table:isDeleted')">
          <el-select v-model="searchData.IsDeleted" clearable filterable style="width: 120px">
            <el-option v-for="item of $d.YesOrNo" v-show="item.raw.ValueCN !== '无'" :key="`IsDeleted${item.value}`"
              :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <!-- 查询 -->
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">
            {{ $t('common:button:search') }}
          </el-button>
        </el-form-item>
        <!-- 重置 -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-refresh-left" @click="handleReset">
            {{ $t('common:button:reset') }}
          </el-button>
        </el-form-item>
        <!-- 导出 -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-download" :disabled="list.length === 0" @click="handleExport">
            {{ $t('common:button:export') }}
          </el-button>
        </el-form-item>
      </el-form>
    </template>

    <template slot="main-container">
      <el-table ref="questionsList" v-loading="loading" v-adaptive="{ bottomOffset: 55 }" :data="list" stripe
        height="100" @sort-change="handleSortByColumn">
        <el-table-column type="index" width="50" />

        <!-- 项目编号 -->
        <!-- <el-table-column
          prop="TrialCode"
          :label="$t('trials:researchForm:form:trialId')"
          show-overflow-tooltip
          sortable="custom"
          min-width="100"
        /> -->
        <!-- 试验方案号 -->
        <!-- <el-table-column
          prop="ResearchProgramNo"
          :label="$t('trials:researchForm:form:researchNo')"
          show-overflow-tooltip
          sortable="custom"
          min-width="100"
        /> -->
        <!-- 试验名称 -->
        <!-- <el-table-column
          prop="ExperimentName"
          :label="$t('trials:researchForm:form:researchName')"
          show-overflow-tooltip
          sortable="custom"
          min-width="100"
        /> -->
        <!-- 适应症类型 -->
        <!-- <el-table-column
          prop="IndicationType"
          :label="$t('trials:researchForm:form:decleareType')"
          show-overflow-tooltip
          sortable="custom"
          min-width="100"
        /> -->
        <!-- 适应症类型 -->
        <!-- <el-table-column
          prop="IndicationType"
          :label="$t('trials:researchForm:form:decleareType')"
          show-overflow-tooltip
          sortable="custom"
          min-width="100"
        /> -->

        <!-- 中心编号 -->
        <el-table-column prop="TrialSiteCode" :label="$t('trials:researchStaff:table:siteId')" show-overflow-tooltip
          sortable="custom" min-width="100" />
        <!-- 中心名称 -->
        <el-table-column prop="SiteName" :label="$t('trials:researchStaff:table:siteName')" show-overflow-tooltip
          sortable="custom" min-width="100" />
        <!-- 状态 -->
        <el-table-column prop="State" :label="$t('trials:researchRecord:table:status')" min-width="150"
          sortable="custom" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.State === 0" type="primary">{{
              $fd('ResearchRecord', scope.row.State)
            }}</el-tag>
            <el-tag v-if="scope.row.State === 1" type="info">{{
              $fd('ResearchRecord', scope.row.State)
            }}</el-tag>
            <el-tag v-if="scope.row.State === 2" type="warning">{{
              $fd('ResearchRecord', scope.row.State)
            }}</el-tag>
            <el-tag v-if="scope.row.State === 3" type="danger">{{
              $fd('ResearchRecord', scope.row.State)
            }}</el-tag>
          </template>
        </el-table-column>
        <!-- 是否废除 -->
        <!-- <el-table-column prop="IsDeleted" :label="$t('trials:researchRecord:table:isDeleted')" min-width="100"
          sortable="custom" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.IsDeleted" type="danger">{{
              $fd('YesOrNo', scope.row.IsDeleted)
            }}</el-tag>
            <el-tag v-else type="primary">{{
              $fd('YesOrNo', scope.row.IsDeleted)
            }}</el-tag>
          </template>
        </el-table-column> -->
        <!-- 联系人 -->
        <el-table-column prop="UserName" :label="$t('trials:researchForm:form:contactor')" show-overflow-tooltip
          sortable="custom" min-width="100" />
        <!-- 联系电话 -->
        <el-table-column prop="Phone" :label="$t('trials:researchForm:form:contactorPhone')" show-overflow-tooltip
          sortable="custom" min-width="100" />
        <!-- 联系邮箱 -->
        <el-table-column prop="Email" :label="$t('trials:researchForm:form:contactorEmail')" show-overflow-tooltip
          sortable="custom" min-width="100" />
        <el-table-column v-show="otherInfo.IsSupportUploadFile" prop="SiteSurveyFile.FileName"
          :label="$t('trials:researchForm:form:SiteSurveyFile')" show-overflow-tooltip min-width="100">
          <template slot-scope="scope">
            <el-button v-if="scope.row.SiteSurveyFile && scope.row.SiteSurveyFile.FileName" type="text"
              @click="viewFile(scope.row.SiteSurveyFile)">
              {{ scope.row.SiteSurveyFile.FileName }}
            </el-button>
          </template>
        </el-table-column>
        <template v-if="!notShowFieldList.includes('AverageEngravingCycle')">
          <!-- 平均刻盘周期（天） -->
          <el-table-column prop="AverageEngravingCycle" :label="$t('trials:researchForm:form:engravingCycle')"
            show-overflow-tooltip />
        </template>
        <template v-if="!notShowFieldList.includes('IsRoutineMRIPDEE')">
          <!--  MRI-PDFF 是否为本中心该适应症的常规诊疗检查项目？ -->
          <el-table-column prop="IsRoutineMRIPDEE" :label="$t('trials:researchForm:form:IsRoutineMRIPDEE')"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ $fd('YesOrNo', scope.row.IsRoutineMRIPDEE) }}
            </template>
          </el-table-column>
        </template>
        <template
          v-if="!notShowFieldList.includes('MRIPDFFScanTime') || !notShowFieldList.includes('MRIPDFFLeadTime') || !notShowFieldList.includes('MRIPDFFOther')">
          <!--  MRI-PDFF 检查的检测周期（含单次检查时长、预约等待时长等） -->
          <!-- <el-table-column :label="$t('trials:researchForm:form:IsRoutineMRIPDEE')"> -->
            <!-- 单次检查时长（分钟） -->
            <el-table-column v-show="!notShowFieldList.includes('MRIPDFFScanTime')" prop="MRIPDFFScanTime"
              :label="$t('trials:researchForm:form:MRIPDFFScanTime')" show-overflow-tooltip />
            <!-- 平均预约等待时长（天） -->
            <el-table-column v-show="!notShowFieldList.includes('MRIPDFFLeadTime')" prop="MRIPDFFLeadTime"
              :label="$t('trials:researchForm:form:MRIPDFFLeadTime')" show-overflow-tooltip />
            <!-- 特殊情况备注-->
            <el-table-column v-show="!notShowFieldList.includes('MRIPDFFOther')" prop="MRIPDFFOther"
              :label="$t('trials:researchForm:form:MRIPDFFOther')" show-overflow-tooltip />
          <!-- </el-table-column> -->
        </template>
        <template
          v-if="!notShowFieldList.includes('IsAuthorizeRadiologistsParticipate') || !notShowFieldList.includes('AssignFixedTechnologists')">
          <!--  如已选择研究者评估，项目是否会授权影像科老师参与本试验？如不单独授权，是否可在试验中保持 1-2 名固定技师操作？ -->
          <el-table-column prop="IsAuthorize" :label="$t('trials:researchForm:form:IsAuthorize')" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.IsAuthorizeRadiologistsParticipate">
                {{ $t('trials:researchForm:form:IsAuthorizeRadiologistsParticipate') }}
              </span>
              <span v-else-if="scope.row.AssignFixedTechnologists">
                {{ $t('trials:researchForm:form:AssignFixedTechnologists') }}
              </span>
            </template>
          </el-table-column>
        </template>
        <template v-if="!notShowFieldList.includes('IsConfirmImagingTechnologist')">
          <!--  请确认参与本项目影像采集的影像技师具备对应的资质（如：“技师证”，对应设备的“大型设备上岗证”） -->
          <el-table-column prop="IsConfirmImagingTechnologist" :label="$t('trials:researchForm:form:isQualified')"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ $fd('YesOrNo', scope.row.IsConfirmImagingTechnologist) }}
            </template>
          </el-table-column>
        </template>
        <template v-if="!notShowFieldList.includes('NotConfirmReson')">
          <!-- 原因 -->
          <el-table-column prop="NotConfirmReson" :label="$t('trials:researchForm:form:notQualifiedReason')"
            show-overflow-tooltip />
        </template>
        <template v-if="!notShowFieldList.includes('EfficacyEvaluatorType')">
          <!-- 研究单位疗效评估人员类型 -->
          <el-table-column prop="EfficacyEvaluatorType" :label="$t('trials:researchForm:form:staffType')"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ $fd('EfficacyEvaluatorType', scope.row.EfficacyEvaluatorType) }}
            </template>
          </el-table-column>
        </template>
        <template v-if="!notShowFieldList.includes('IsFollowStudyParameters')">
          <!-- 是否严格按照研究单位影像手册参数完成图像采集 -->
          <el-table-column prop="IsFollowStudyParameters" :label="$t('trials:researchForm:form:isFollowStudyParam')"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ $fd('YesOrNo', scope.row.IsFollowStudyParameters) }}
            </template>
          </el-table-column>
        </template>
        <template v-if="!notShowFieldList.includes('NotFollowReson')">
          <!-- 不能严格按照研究单位影像手册参数采集图像原因 -->
          <el-table-column prop="NotFollowReson" :label="$t('trials:researchForm:form:notFollowStudyParam')"
            show-overflow-tooltip />
        </template>
        <template v-if="!notShowFieldList.includes('ISStrictManualBurnFlag')">
          <!-- 是否严格按照影像手册参数完成刻盘 -->
          <el-table-column prop="ISStrictManualBurnFlag" :label="$t('trials:researchForm:form:ISStrictManualBurnFlag')"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ $fd('YesOrNo', scope.row.ISStrictManualBurnFlag) }}
            </template>
          </el-table-column>
        </template>
        <template v-if="!notShowFieldList.includes('NotStrictManualBurnFlagReason')">
          <!-- 不能严格按照影像手册参数完成刻盘原因 -->
          <el-table-column prop="NotStrictManualBurnFlagReason"
            :label="$t('trials:researchForm:form:NotStrictManualBurnFlagReason')" show-overflow-tooltip />
        </template>
      </el-table>

      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize"
        @pagination="getList" />
    </template>
  </BaseContainer>
</template>
<script>
import { getTrialSiteSelect } from '@/api/trials'
import { getSiteSurveyInfoList } from '@/api/research'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
import { getSiteSurveyInfoList_Export } from '@/api/export'
const searchDataDefault = () => {
  return {
    SortField: '',
    Asc: true,
    State: "",
    PageIndex: 1,
    PageSize: 20,
    TrialId: '',
    TrialSiteId: '',
    TrialSiteName: ''
  }
}
export default {
  name: 'Equipments',
  components: { BaseContainer, Pagination },
  data() {
    return {
      searchData: searchDataDefault(),
      loading: false,
      list: [],
      total: 0,
      trialId: '',
      otherInfo: {},
      siteOptions: [],
      notShowFieldList: []
    }
  },
  mounted() {
    this.trialId = this.$route.query.trialId
    this.getList()
    this.getSite()
  },
  methods: {
    async handleExport() {
      await getSiteSurveyInfoList_Export(this.searchData)
    },
    async getList() {
      try {
        this.loading = true
        this.searchData.TrialId = this.trialId
        let res = await getSiteSurveyInfoList(this.searchData)
        if (res.IsSuccess) {
          this.list = res.Result.CurrentPageData
          this.total = res.Result.TotalCount
          this.otherInfo = res.OtherInfo
          this.notShowFieldList = res.OtherInfo.NotShowFieldList
          this.$nextTick(() => {
            this.$refs.questionsList.doLayout()
          })
        }
      } catch (e) {
        console.log(e)
      } finally {
        this.loading = false
      }
    },
    // 获取site下拉框数据
    async getSite() {
      try {
        let res = await getTrialSiteSelect(this.trialId)
        this.siteOptions = res.Result
      } catch (e) {
        console.log(e)
      }
    },
    viewFile(siteSurveyFile) {
      this.$preview({
        path: siteSurveyFile.Path,
        type: siteSurveyFile.FileType,
        title: siteSurveyFile.FileName,
      })
    },
    // 重置
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
      this.$nextTick(() => {
        this.$refs.list.clearSort()
      })
    },
    // 查询
    handleSearch() {
      this.getList()
    },
    // 排序
    handleSortByColumn(column) {
      if (column.order === 'ascending') {
        this.searchData.Asc = true
      } else {
        this.searchData.Asc = false
      }
      this.searchData.SortField = column.prop
      this.getList()
    }
  }
}
</script>
