<template>
  <BaseContainer>
    <!-- 顶部搜索条件 -->
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 项目编号 -->
        <el-form-item :label="$t('trials:trials-list:table:trialId')">
          <el-input v-model="searchData.Code" style="width: 100px" clearable />
        </el-form-item>
        <!-- 研究方案号 -->
        <el-form-item :label="$t('trials:trials-list:table:researchNumber')">
          <el-input v-model="searchData.ResearchProgramNo" style="width: 100px" clearable />
        </el-form-item>
        <!-- 试验名称 -->
        <el-form-item :label="$t('trials:trials-list:table:experimentName')">
          <el-input v-model="searchData.ExperimentName" style="width: 100px" clearable />
        </el-form-item>

        <!-- Sponsor -->
        <el-form-item :label="$t('trials:trials-list:table:sponsor')">
          <el-select v-model="searchData.SponsorId" style="width: 150px" clearable>
            <el-option v-for="item in sponsorList" :key="item.Id" :label="item.SponsorName" :value="item.Id" />
          </el-select>
        </el-form-item>
        <!-- 阅片标准 -->
        <el-form-item v-if="hasPermi(['role:ir'])" :label="$t('trials:trials-list:table:IR_ReadingCriterionList')">
          <el-select v-model="searchData.CriterionType" style="width: 150px" clearable>
            <el-option v-for="item in $d.CriterionType" :key="item.id" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <!-- 联系人 -->
        <el-form-item v-if="hasPermi(['role:ir'])" :label="$t('trials:trials-list:table:IR_PMEmailList')">
          <el-input v-model="searchData.PM_EMail" style="width: 100px" clearable />
        </el-form-item>
        <el-form-item>
          <!-- <el-button type="text" @click="isShow = !isShow">More</el-button> -->
          <!-- Search -->
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">
            {{ $t('common:button:search') }}
          </el-button>
          <!-- Reset -->
          <el-button type="primary" icon="el-icon-refresh-left" @click="handleReset">
            {{ $t('common:button:reset') }}
          </el-button>
          <!-- Export -->
          <el-button v-hasPermi="['trials:trials-list:export']" type="primary" icon="el-icon-download"
            :loading="exportLoading" @click="handleExportTrial">
            {{ $t('common:button:export') }}
          </el-button>
        </el-form-item>
      </el-form>
      <span style="margin-left: auto">
        <!-- New -->
        <el-button v-hasPermi="['trials:trials-list:new']" icon="el-icon-plus" type="primary" @click="handleNew">
          {{ $t('common:button:new') }}
        </el-button>
      </span>
    </template>

    <!-- 更多搜索条件 -->
    <el-drawer :visible.sync="isShow" :with-header="false" size="390px">
      <div style="padding: 10px">
        <el-form label-width="140px">
          <el-form-item label="Trial ID">
            <el-input v-model="searchData.Code" placeholder="Trial ID" style="width: 100%" clearable />
          </el-form-item>
          <el-form-item label="Indication">
            <el-input v-model="searchData.Indication" placeholder="Indication" style="width: 100%" clearable />
          </el-form-item>
          <el-form-item label="Assessment Criteria">
            <el-select v-model="searchData.CriterionIds" placeholder="Assessment Criteria" style="width: 100%" clearable
              multiple>
              <!-- <el-option
                v-for="(key,value) of dictionaryList.ReadingStandard"
                :key="key"
                :label="key"
                :value="value"
              /> -->
              <el-option v-for="item of dict.type.ReadingStandard" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="Sponsor">
            <el-select v-model="searchData.SponsorId" placeholder="Sponsor" style="width: 100%" clearable>
              <el-option v-for="item in sponsorList" :key="item.Id" :label="item.SponsorName" :value="item.Id" />
            </el-select>
          </el-form-item>
          <el-form-item label="CRO">
            <el-select v-model="searchData.CROId" placeholder="CRO" style="width: 100%" clearable>
              <el-option v-for="item of croList" :key="item.Id" :label="item.CROName" :value="item.Id" />
            </el-select>
          </el-form-item>
          <el-form-item label="Phase">
            <el-select v-model="searchData.Phase" placeholder="Phase" style="width: 100%" clearable>
              <el-option v-for="item in phaseOptions" :key="item.value" :label="item.value" :value="item.value" />
            </el-select>
          </el-form-item>

          <el-form-item label="ReviewType">
            <el-select v-model="searchData.ReviewTypeIds" placeholder="ReviewType" style="width: 100%" clearable
              multiple>
              <!-- <el-option
                v-for="(key,value) of dictionaryList.ReviewType"
                :key="key"
                :label="key"
                :value="value"
              /> -->
              <el-option v-for="item of dict.type.ReviewType" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="Modality">
            <el-select v-model="searchData.ModalityIds" multiple placeholder="Modality" style="width: 100%" clearable>
              <!-- <el-option
                v-for="(key,value) of dictionaryList.ReadingType"
                :key="key"
                :label="key"
                :value="value"
              /> -->
              <el-option v-for="item of dict.type.ReadingType" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="Expedited: ">
            <el-select v-model="searchData.Expedited" value-key="value" clearable style="width: 100%">
              <el-option v-for="item in expeditedOption" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="BeginDate: ">
            <el-date-picker v-model="searchData.BeginDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
              :picker-options="beginPickerOption" :clearable="false" style="width: 100%" />
          </el-form-item>
          <el-form-item label="EndDate: ">
            <el-date-picker v-model="searchData.EndDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
              :picker-options="endpickerOption" :clearable="false" style="width: 100%" />
          </el-form-item>

          <el-form-item label="Attended Reviewer Type:">
            <el-select v-model="searchData.AttendedReviewerType" placeholder="Attended Reviewer Type"
              style="width: 100%" clearable>
              <el-option v-for="item of $d.AttendedReviewerType" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSelectSearch">Search</el-button>
            <el-button type="primary" @click="handleReset">Reset</el-button>
            <el-button type="primary" @click="isShow = false">Back</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer>

    <!-- 项目列表 -->
    <template slot="main-container">
      <el-table v-adaptive="{ bottomOffset: 60 }" v-loading="listLoading" :data="list" stripe height="100"
        @selection-change="handleSelectChange" @sort-change="handleSortChange" @row-click="rowClick">
        <el-table-column type="selection" align="left" width="45" />
        <el-table-column type="index" width="40" align="left" />
        <el-table-column prop="TrialCode" :label="$t('trials:trials-list:table:trialId')" show-overflow-tooltip
          sortable="custom" width="120" />
        <el-table-column prop="ResearchProgramNo" :label="$t('trials:trials-list:table:researchNumber')"
          show-overflow-tooltip sortable="custom" min-width="160" />

        <el-table-column prop="ExperimentName" :label="$t('trials:trials-list:table:experimentName')"
          show-overflow-tooltip sortable="custom" min-width="240" />
        <el-table-column prop="Sponsor" :label="$t('trials:trials-list:table:sponsor')" show-overflow-tooltip
          sortable="custom" min-width="120" />
        <el-table-column prop="TrialStatusStr" :label="$t('trials:trials-list:table:status')" show-overflow-tooltip
          sortable="custom" min-width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.TrialStatusStr === 'Initializing'" type="info">{{ $fd('TrialStatusEnum',
              scope.row.TrialStatusStr) }}</el-tag>
            <el-tag v-if="scope.row.TrialStatusStr === 'Ongoing'" type="primary">{{ $fd('TrialStatusEnum',
              scope.row.TrialStatusStr) }}</el-tag>
            <el-tag v-if="scope.row.TrialStatusStr === 'Completed'" type="warning">{{ $fd('TrialStatusEnum',
              scope.row.TrialStatusStr) }}</el-tag>
            <el-tag v-if="scope.row.TrialStatusStr === 'Stopped'" type="danger">{{ $fd('TrialStatusEnum',
              scope.row.TrialStatusStr) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="hasPermi(['role:pm', 'role:apm'])" prop="ExpetiedTaskCount"
          :label="$t('trials:trials-list:table:ExpetiedTaskCount')" show-overflow-tooltip sortable="custom"
          min-width="120" />
        <el-table-column v-if="hasPermi(['role:pm', 'role:apm'])" prop="ReReadingApprovalCount"
          :label="$t('trials:trials-list:table:ReReadingApprovalCount')" show-overflow-tooltip sortable="custom"
          min-width="180" />
        <el-table-column v-if="hasPermi(['role:pm', 'role:apm'])" prop="PendingReconciliationCount"
          :label="$t('trials:trials-list:table:PendingReconciliationCount')" show-overflow-tooltip sortable="custom"
          min-width="140" />
        <el-table-column v-if="hasPermi(['role:pm', 'role:apm'])" prop="PendingResponseCount"
          :label="$t('trials:trials-list:table:PendingResponseCount')" show-overflow-tooltip sortable="custom"
          min-width="140" />
        <el-table-column v-if="hasPermi(['role:crc', 'role:cra'])" prop="CRC_UrgentCount"
          :label="$t('trials:trials-list:table:CRC_UrgentCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:crc', 'role:cra'])" prop="CRC_QCQuestionCount"
          :label="$t('trials:trials-list:table:CRC_QCQuestionCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:crc', 'role:cra'])" prop="CRC_CheckQuestionCount"
          :label="$t('trials:trials-list:table:CRC_CheckQuestionCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:ir'])" prop="IR_ReadingCriterionList"
          :label="$t('trials:trials-list:table:IR_ReadingCriterionList')" show-overflow-tooltip min-width="160">
          <template slot-scope="scope">
            {{ scope.row.IR_ReadingCriterionList.join(', ') }}
          </template>
        </el-table-column>
        <el-table-column v-if="hasPermi(['role:ir'])" prop="IR_UrgentCount"
          :label="$t('trials:trials-list:table:IR_UrgentCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:ir'])" prop="IR_UnReadCount"
          :label="$t('trials:trials-list:table:IR_UnReadCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:ir'])" prop="IR_TotalReadCount"
          :label="$t('trials:trials-list:table:IR_TotalReadCount')" show-overflow-tooltip sortable="custom"
          min-width="170" />
        <el-table-column v-if="hasPermi(['role:ir'])" prop="IR_PMEmailList"
          :label="$t('trials:trials-list:table:IR_PMEmailList')" show-overflow-tooltip min-width="170">
          <template slot-scope="scope">
            {{ scope.row.IR_PMEmailList.join(', ') }}
          </template>
        </el-table-column>
        <el-table-column v-if="hasPermi(['role:iqc'])" prop="IQC_UrgentCount"
          :label="$t('trials:trials-list:table:IQC_UrgentCount')" show-overflow-tooltip sortable="custom"
          min-width="140" />
        <el-table-column v-if="hasPermi(['role:iqc'])" prop="IQC_ToBeClaimedCount"
          :label="$t('trials:trials-list:table:IQC_ToBeClaimedCount')" show-overflow-tooltip sortable="custom"
          min-width="140" />
        <el-table-column v-if="hasPermi(['role:iqc'])" prop="IQC_AuditToBeDealedCount"
          :label="$t('trials:trials-list:table:IQC_AuditToBeDealedCount')" show-overflow-tooltip sortable="custom"
          min-width="140" />
        <el-table-column v-if="hasPermi(['role:iqc'])" prop="IQC_QuestionToBeDealedCount"
          :label="$t('trials:trials-list:table:IQC_QuestionToBeDealedCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:mim'])" prop="MIM_UrgentCount"
          :label="$t('trials:trials-list:table:MIM_UrgentCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <!-- <el-table-column
          v-if="hasPermi(['role:mim'])"
          prop="MIM_UrgentCount"
          :label="$t('trials:trials-list:table:MIM_UrgentCount')"
          show-overflow-tooltip
          sortable="custom"
          min-width="160"
        /> -->
        <el-table-column v-if="hasPermi(['role:mim'])" prop="MIM_PendingReviewCount"
          :label="$t('trials:trials-list:table:MIM_PendingReviewCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:mim'])" prop="MIM_PendingResponseCount"
          :label="$t('trials:trials-list:table:MIM_PendingResponseCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:spm', 'role:cpm'])" prop="SPM_ReReadingApprovalCount"
          :label="$t('trials:trials-list:table:SPM_ReReadingApprovalCount')" show-overflow-tooltip sortable="custom"
          min-width="160" />
        <el-table-column v-if="hasPermi(['role:spm', 'role:cpm'])" prop="SPM_ReviewerSelectApprovalCount" :label="$t('trials:trials-list:table:SPM_ReviewerSelectApprovalCount')
          " show-overflow-tooltip sortable="custom" min-width="160" />
        <el-table-column prop="CreateTime" :label="$t('trials:trials-list:table:createDate')" show-overflow-tooltip
          sortable="custom" width="180" />
        <el-table-column :label="$t('common:action:action')" width="260" align="left" fixed="right">
          <template slot-scope="scope">
            <!-- 详情 -->
            <el-button v-hasPermi="['trials:trials-list:panel']" circle icon="el-icon-info" :disabled="(scope.row.TrialStatusStr === 'Initializing' &&
              !hasPermi(['role:pm'])) ||
              scope.row.IsDeleted ||
              ((scope.row.TrialStatusStr === 'Completed' ||
                scope.row.TrialStatusStr === 'Stopped') &&
                !(
                  hasPermi(['role:qa']) ||
                  hasPermi(['role:ea']) ||
                  hasPermi(['role:pm']) ||
                  hasPermi(['role:op']) ||
                  hasPermi(['role:dev']) ||
                  hasPermi(['role:admin'])
                ))
              " :title="$t('trials:trials-list:action:panel')" @click.stop="handleDetail(scope.row)" />
            <!-- 编辑项目基本信息 -->
            <el-button v-hasPermi="['trials:trials-list:edit']" circle icon="el-icon-edit-outline"
              :disabled="scope.row.IsDeleted" :title="$t('trials:trials-list:action:edit')"
              @click.stop="handleEdit(scope.row)" />
            <!-- 修改项目状态 -->
            <el-button v-hasPermi="['trials:trials-list:status']" circle icon="el-icon-edit"
              :disabled="scope.row.IsDeleted" :title="$t('trials:trials-list:action:status')"
              @click.stop="handleStatus(scope.row)" />
            <!--项目文档-->
            <el-button v-hasPermi="[
              'trials:trials-panel:trial-summary:trial-document:inspect',
              'trials:trials-panel:trial-summary:trial-document:manage',
            ]" circle icon="el-icon-folder-opened" :disabled="(scope.row.TrialStatusStr === 'Initializing' &&
              !hasPermi(['role:pm'])) ||
              scope.row.IsDeleted ||
              ((scope.row.TrialStatusStr === 'Completed' ||
                scope.row.TrialStatusStr === 'Stopped') &&
                !(
                  hasPermi(['role:qa']) ||
                  hasPermi(['role:ea']) ||
                  hasPermi(['role:pm'])
                ))
              " :title="$t('trials:trials-list:action:trialDocument')" @click.stop="toTrialDocument(scope.row)" />
            <!-- 废除项目 -->
            <el-button v-hasPermi="['trials:trials-list:abolish']" circle icon="el-icon-delete" :disabled="scope.row.IsDeleted ||
              scope.row.TrialStatusStr !== 'Initializing'
              " :title="$t('trials:trials-list:action:abolition')" @click.stop="handleAbandon(scope.row)" />
            <!--             代办详情-->
            <!--            <el-button-->
            <!--              v-hasPermi="['trials:trials-list:abolish']"-->
            <!--              circle-->
            <!--              icon="el-icon-receiving"-->
            <!--              :disabled="scope.row.TrialStatusStr === 'Initializing'"-->
            <!--              :title="$t('trials:trials-list:action:commission')"-->
            <!--              @click.stop="handleCommission(scope.row)"-->
            <!--            />-->
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize"
        @pagination="getList" />
    </template>

    <!-- 新增/编辑项目 -->
    <el-dialog v-if="dialogVisible" :visible.sync="dialogVisible" :title="title" :fullscreen="true" append-to-body
      custom-class="base-dialog-wrapper">
      <TrialForm :trial-id="currentId" @getList="getList" @closeDialog="closeDialog" />
    </el-dialog>

    <!-- 修改项目状态 -->
    <el-dialog v-if="statusVisible" :visible.sync="statusVisible" :close-on-click-modal="false"
      :title="$t('trials:trials-list:dialogTitle:changeStatus')" width="700px" custom-class="base-dialog-wrapper"
      append-to-body>
      <TrialStatusForm :data="currentRow" @closeDialog="closeStatusDialog" @getList="getList" />
    </el-dialog>

    <el-dialog v-if="doneDialogVisible" :visible.sync="doneDialogVisible" :title="doneTitle" :fullscreen="true"
      append-to-body custom-class="base-dialog-wrapper">
      <DoneList :trial-id="currentId" @getList="getList" @closeDialog="doneDialogVisible = false" />
    </el-dialog>
  </BaseContainer>
</template>
<script>
import {
  abandonTrial,
  ifTrialCanOngoing,
  getTrialToBeDoneList,
} from '@/api/trials'
import { getTrialList_Export } from '@/api/export'
import store from '@/store'
import { mapGetters } from 'vuex'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
import TrialForm from './components/TrialForm'
import TrialStatusForm from './components/TrialStatusForm'
import DoneList from './components/DoneList'
const searchDataDefault = () => {
  return {
    Code: '',
    CriterionIds: [],
    SponsorId: '',
    ReviewTypeIds: [],
    CROId: '',
    Expedited: '',
    Indication: '',
    Phase: '',
    ModalityIds: [],
    BeginDate: '',
    EndDate: '',
    AttendedReviewerType: '',
    ResearchProgramNo: '',
    ExperimentName: '',
    PageIndex: 1,
    PageSize: 20,
    Asc: false,
    SortField: '',
    CriterionType: null,
    PM_EMail: null,
  }
}
export default {
  name: 'Trials',
  components: {
    Pagination,
    BaseContainer,
    TrialForm,
    TrialStatusForm,
    DoneList,
  },
  dicts: ['ReadingStandard', 'ReviewType', 'ReadingType'],
  data() {
    return {
      exportLoading: false,
      userTypeEnumInt: zzSessionStorage.getItem('userTypeEnumInt') * 1,
      doneDialogVisible: false,
      doneTitle: null,
      selectArr: [],
      searchData: searchDataDefault(),
      list: [],
      listLoading: false,
      total: 0,
      isShow: false,
      dialogVisible: false,
      title: '',
      currentId: '',
      statusVisible: false,
      currentRow: {},
      currentUser: zzSessionStorage.getItem('userName'),
      phaseOptions: [
        { value: 'I' },
        { value: 'II' },
        { value: 'III' },
        { value: 'IV' },
      ],
      expeditedOption: this.$d.TrialExpeditedState,
      beginPickerOption: {
        disabledDate: (time) => {
          if (this.searchData.EndDate) {
            return time.getTime() > new Date(this.searchData.EndDate).getTime()
          } else {
            return time.getTime() > Date.now()
          }
        },
      },
      endpickerOption: {
        disabledDate: (time) => {
          if (this.searchData.BeginDate) {
            return (
              time.getTime() > Date.now() ||
              time.getTime() <= new Date(this.searchData.BeginDate).getTime()
            )
          } else {
            return time.getTime() > Date.now()
          }
        },
      },
    }
  },
  computed: {
    ...mapGetters(['sponsorList', 'croList']),
  },
  created() {
    this.initPage()
  },
  mounted() {
    this.$EventBus.$on('reload', (data) => {
      window.location.reload()
    })
  },
  methods: {
    initPage() {
      this.getList()
      store.dispatch('global/getSponsorList')
      store.dispatch('global/getCROList')
    },
    // 获取项目列表信息
    getList() {
      this.listLoading = true
      getTrialToBeDoneList(this.searchData)
        .then((res) => {
          this.list = res.Result.CurrentPageData
          this.total = res.Result.TotalCount
          this.listLoading = false
        })
        .catch(() => {
          this.listLoading = false
        })
    },

    // 查询
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    // 查询
    handleSelectSearch() {
      this.searchData.PageIndex = 1
      this.getList()
      this.isShow = false
    },
    // 重置
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
    },
    // 新增项目
    handleNew() {
      // this.$router.push({ name: 'CreateTrial' })
      this.title = this.$t('trials:trials-list:dialogTitle:new')
      this.currentId = ''
      this.dialogVisible = true
    },
    // 编辑项目
    handleEdit(row) {
      this.title = this.$t('trials:trials-list:dialogTitle:edit')
      this.currentId = row.Id
      this.dialogVisible = true
    },
    handleCommission(row) {
      this.doneTitle = this.$t('trials:trials-list:dialogTitle:doneTitle')
      this.currentId = row.Id
      this.doneDialogVisible = true
    },
    closeDialog() {
      this.dialogVisible = false
    },
    // 状态
    handleStatus(row) {
      if (row.TrialStatusStr === 'Initializing') {
        this.listLoading = true
        ifTrialCanOngoing(row.Id)
          .then((res) => {
            this.listLoading = false
            if (res.Result) {
              this.currentRow = { ...row }
              this.statusVisible = true
            } else {
              this.$confirm(res.ErrorMessage, {
                type: 'warning',
                showCancelButton: false,
                callback: (action) => { },
              })
            }
          })
          .catch(() => {
            this.listLoading = false
          })
      } else {
        this.currentRow = { ...row }
        this.statusVisible = true
      }
    },
    closeStatusDialog() {
      this.statusVisible = false
    },
    // 废除
    handleAbandon(row) {
      this.$confirm(this.$t('trials:trials-list:message:abolition'), {
        type: 'warning',
        distinguishCancelAndClose: true,
      })
        .then(() => {
          this.currentRow = { ...row }
          this.abandonTrial()
        })
        .catch(() => { })
    },
    // 废除项目
    abandonTrial() {
      this.listLoading = true
      abandonTrial(this.currentRow.Id, true)
        .then((res) => {
          this.listLoading = false
          if (res.IsSuccess) {
            this.getList()
            this.$message.success(
              this.$t('trials:trials-list:message:abolitionSuccessfully')
            )
          }
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    rowClick(row, col) {
      if (
        (row.TrialStatusStr === 'Initializing' &&
          !this.hasPermi(['role:pm'])) ||
        row.IsDeleted
      ) {
        return
      } else if (
        (row.TrialStatusStr === 'Completed' ||
          row.TrialStatusStr === 'Stopped') &&
        !(
          this.hasPermi(['role:qa']) ||
          this.hasPermi(['role:ea']) ||
          this.hasPermi(['role:pm']) ||
          hasPermi(['role:op']) ||
          hasPermi(['role:dev']) ||
          hasPermi(['role:admin'])
        )
      ) {
        return
      }
      this.$router.push({
        path: `/trials/trials-panel?trialId=${row.Id}&trialCode=${row.TrialCode}&researchProgramNo=${row.ResearchProgramNo}`,
      })
    },
    // panel
    handleDetail(row) {
      this.$router.push({
        path: `/trials/trials-panel?trialId=${row.Id}&trialCode=${row.TrialCode}&researchProgramNo=${row.ResearchProgramNo}`,
      })
    },
    // 跳转至项目文档
    toTrialDocument(row) {
      this.$router.push({
        path: `/trials/trials-panel/trial-summary/trial-document?trialId=${row.Id}&trialCode=${row.TrialCode}&researchProgramNo=${row.ResearchProgramNo}`,
      })
    },
    // 获取已勾选行数据
    handleSelectChange(val) {
      const arr = []
      for (let index = 0; index < val.length; index++) {
        arr.push(val[index])
      }
      this.selectArr = arr
    },
    // 排序
    handleSortChange(column) {
      if (column.order === 'ascending') {
        this.searchData.Asc = true
      } else {
        this.searchData.Asc = false
      }
      if (column.prop === 'Criterion') {
        this.searchData.SortField = 'CriterionId'
      } else {
        this.searchData.SortField = column.prop
      }
      this.searchData.PageIndex = 1
      this.getList()
    },
    // 导出Excel表格
    handleExportTrial() {
      this.exportLoading = true
      const data = {
        ...this.searchData,
      }
      data.TrialIdList = this.selectArr.map((item) => item.Id)
      return getTrialList_Export(data)
        .then((res) => {
          this.exportLoading = false
        })
        .catch(() => {
          this.exportLoading = false
        })
    },
  },
}
</script>
