/* eslint-disable */
<template>
  <BaseContainer>
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 是否加急 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:isUrgent')">
          <el-select v-model="searchData.IsUrgent" clearable style="width:120px;">
            <el-option v-for="item of $d.YesOrNo" :key="'IsUrgent' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 临床数据是否完备 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:completeClinicalDataEnum')">
          <el-select v-model="searchData.CompleteClinicalDataEnum" clearable style="width:120px;">
            <el-option v-for="item of $d.CompleteClinicalDataEnum" :key="'CompleteClinicalDataEnum' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 中心编号 -->
        <el-form-item :label="$t('trials:reviewTrack:table:siteCode')">
          <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:reviewTrack:table:subjectCode')">
          <el-input v-model="searchData.SubjectCode" style="width:100px;" />
        </el-form-item>
        <!-- 任务名称 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:taskName')">
          <el-input
            v-model="searchData.TaskName"
            style="width:100px;"
            clearable
          />
        </el-form-item>
        <!-- 任务类型 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:taskType')">
          <el-select v-model="searchData.ReadingCategory" clearable style="width:120px;">
            <el-option v-for="item of $d.ReadingCategory" :key="'ReadingCategory' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 阅片人 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:reader')">
          <el-select v-model="searchData.DoctorUserId" clearable style="width:120px;">
            <el-option v-for="item of doctorUserList" :key="'DoctorUserId' + item.DoctorUserId" :value="item.DoctorUserId" :label="`${item.UserName}(${item.FullName})`" />
          </el-select>
        </el-form-item>
        <!-- 角色 -->
        <!-- <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:role')">
          <el-select v-model="searchData.ArmEnum" clearable style="width:120px;">
            <el-option v-for="item of $d.ArmEnum" :key="'ArmEnum' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item> -->
        <!-- 阅片标准 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:criterionName')">
          <el-select v-model="searchData.TrialReadingCriterionId" clearable style="width:120px;">
            <el-option v-for="item of trialCriterionList" :key="'TrialReadingCriterionId' + item.TrialReadingCriterionId" :value="item.TrialReadingCriterionId" :label="item.TrialReadingCriterionName" />
          </el-select>
        </el-form-item>
        <!-- 阅片状态 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:readingStatus')">
          <el-select v-model="searchData.ReadingTaskState" clearable style="width:120px;">
            <el-option v-for="item of $d.ReadingTaskState" :key="'ReadingTaskState' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 任务状态 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:taskStatus')">
          <el-select v-model="searchData.TaskState" clearable style="width:120px;">
            <el-option v-show="item.value === 3 || item.value === 4" v-for="item of $d.TaskState" :key="'TaskState' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 重阅 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:applyStatus')">
          <el-select v-model="searchData.ReReadingApplyState" clearable style="width:120px;">
            <el-option v-for="item of $d.ReReadingApplyState" :key="'ReReadingApplyState' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 分配时间 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:assignTime')">
          <el-date-picker
            v-model="timeList"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            @change="changeTimeList"
          />
        </el-form-item>
        <!-- 分配时间 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewTrack:table:signTime')">
          <el-date-picker
            v-model="timeList2"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            @change="changeTimeList2"
          />
        </el-form-item>
        <el-form-item style="margin-bottom:10px">
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">
            {{ $t('common:button:search') }}
          </el-button>
          <el-button type="primary" icon="el-icon-refresh-left" @click="handleReset">
            {{ $t('common:button:reset') }}
          </el-button>
        </el-form-item>
      </el-form>
    </template>
    <template slot="main-container">
      <el-table
        v-adaptive="{bottomOffset:60}"
        v-loading="loading"
        :data="list"
        stripe
        height="100"
        @sort-change="handleSortChange"
      >
        <!-- 是否加急 -->
        <el-table-column
          prop="IsUrgent"
          :label="$t('trials:reviewTrack:table:isUrgent')"
          width="120"
          sortable="custom"
          align="center"
        >
          <template slot-scope="scope">
            <!-- <el-tag v-if="scope.row.IsUrgent" type="danger">{{ $fd('YesOrNo', scope.row.IsUrgent) }}</el-tag>
            <el-tag v-else type="primary">{{ $fd('YesOrNo', scope.row.IsUrgent) }}</el-tag> -->
            <el-tooltip placement="top">
              <div slot="content">
                <span>{{`加急原因：${$fd('TaskUrgentType',scope.row.TaskUrgentType)}`}}</span><br/>
                <span>{{scope.row.TaskUrgentRemake?`备注：${scope.row.TaskUrgentRemake}`:''}}</span>
              </div>
             <div>
              <el-button :disabled="!(!scope.row.TaskState && (scope.row.ReadingTaskState === 0 || scope.row.ReadingTaskState === 1)) || !scope.row.IsCanEditUrgentState" v-if="scope.row.IsUrgent" type="danger" size="mini" @click="changeUrgentStatus(scope.row)">{{ $fd('YesOrNo', scope.row.IsUrgent) }}</el-button>
             </div>
            </el-tooltip>
              <el-button :disabled="!(!scope.row.TaskState && (scope.row.ReadingTaskState === 0 || scope.row.ReadingTaskState === 1)) || !scope.row.IsCanEditUrgentState" v-if="!scope.row.IsUrgent" type="primary" size="mini" @click="changeUrgentStatus(scope.row)">{{ $fd('YesOrNo', scope.row.IsUrgent) }}</el-button>

          </template>
        </el-table-column>
        <!-- 临床数据是否完备 -->
        <el-table-column
          prop="CompleteClinicalDataEnum"
          :label="$t('trials:reviewTrack:table:completeClinicalDataEnum')"
          width="160"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.CompleteClinicalDataEnum === -1">
              {{$fd('CompleteClinicalDataEnum', scope.row.CompleteClinicalDataEnum)}}
            </span>
            <el-button type="text" v-else @click="handleView(scope.row)">
              {{$fd('CompleteClinicalDataEnum', scope.row.CompleteClinicalDataEnum)}}
            </el-button>
          </template>
        </el-table-column>
        <!-- 中心编号 -->
        <el-table-column
          prop="TrialSiteCode"
          :label="$t('trials:reviewTrack:table:siteCode')"
          width="100"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 受试者编号 -->
        <el-table-column
          prop="SubjectCode"
          :label="$t('trials:reviewTrack:table:subjectCode')"
          min-width="150"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.BlindSubjectCode && scope.row.BlindSubjectCode !== scope.row.SubjectCode">
              {{ `${scope.row.SubjectCode}/${scope.row.BlindSubjectCode}` }}
            </span>
            <span v-else>{{scope.row.SubjectCode}}</span>
          </template>
        </el-table-column>
        <!-- 任务名称 -->
        <el-table-column
          prop="VisitTaskNum"
          :label="$t('trials:reviewTrack:table:taskName')"
          width="140"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.TaskBlindName && scope.row.TaskName !== scope.row.TaskBlindName">
              {{ `${scope.row.TaskName}/${scope.row.TaskBlindName}` }}
            </span>
            <span v-else>{{scope.row.TaskName}}</span>
          </template>
        </el-table-column>
        <!-- 盲态任务标识 -->
        <!-- <el-table-column
          prop="TaskBlindName"
          :label="$t('trials:reviewTrack:table:blindName')"
          width="160"
          sortable="custom"
          show-overflow-tooltip
        /> -->
        <!-- 任务类型 -->
        <el-table-column
          prop="ReadingCategory"
          :label="$t('trials:reviewTrack:table:taskType')"
          width="140"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.ReadingCategory === 1" type="primary">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
            <el-tag v-if="scope.row.ReadingCategory === 2" type="info">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
            <el-tag v-if="scope.row.ReadingCategory === 4" type="danger">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
            <el-tag v-if="scope.row.ReadingCategory === 5" type="warning">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
          </template>
        </el-table-column>
        <!-- 阅片人 -->
        <el-table-column
          prop="UserName"
          :label="$t('trials:reviewTrack:table:reader')"
          width="130"
          sortable="custom"
          show-overflow-tooltip
        >
          <template v-if="scope.row.UserName" slot-scope="scope">
            {{ scope.row.UserName }}({{ scope.row.FullName }})
          </template>
        </el-table-column>
        <!-- 角色 -->
        <!-- <el-table-column
          prop="ArmEnum"
          :label="$t('trials:reviewTrack:table:role')"
          width="100"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.ArmEnum === 0" type="primary">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
            <el-tag v-if="scope.row.ArmEnum === 1" type="primary">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
            <el-tag v-if="scope.row.ArmEnum === 2" type="success">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
            <el-tag v-if="scope.row.ArmEnum === 3" type="info">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
            <el-tag v-if="scope.row.ArmEnum === 4" type="danger">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
            <el-tag v-if="scope.row.ArmEnum === 5" type="warning">{{ $fd('ArmEnum', scope.row.ArmEnum) }}</el-tag>
          </template>
        </el-table-column> -->
        <!-- 阅片标准 -->
        <el-table-column
          prop="TrialReadingCriterionName"
          :label="$t('trials:reviewTrack:table:criterionName')"
          min-width="180"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 阅片状态 -->
        <el-table-column
          prop="ReadingTaskState"
          :label="$t('trials:reviewTrack:table:readingStatus')"
          width="160"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.ReadingTaskState === 2" type="primary">{{ $fd('ReadingTaskState', scope.row.ReadingTaskState) }}</el-tag>
            <el-tag v-else type="danger">{{ $fd('ReadingTaskState', scope.row.ReadingTaskState) }}</el-tag>
          </template>
        </el-table-column>
         <!-- 分配时间 -->
        <el-table-column
          prop="AllocateTime"
          :label="$t('trials:reviewTrack:table:assignTime')"
          width="180"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 建议完成时间 -->
        <el-table-column
          prop="SuggesteFinishedTime"
          :label="$t('trials:reviewTrack:table:suggesteFinishedTime')"
          width="210"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 阅片完成时间 -->
        <el-table-column
          prop="SignTime"
          :label="$t('trials:reviewTrack:table:signTime')"
          min-width="180"
          sortable="custom"
          show-overflow-tooltip
        />
        <el-table-column
          prop="ReadingDuration"
          :label="$t('trials:reviewTrack:table:readingDuration')"
          width="140"
          show-overflow-tooltip
        />
        <!-- 任务状态 -->
        <el-table-column
          prop="TaskState"
          :label="$t('trials:reviewTrack:table:taskStatus')"
          width="140"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.TaskState === 0" type="primary">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
            <el-tag v-if="scope.row.TaskState === 1" type="info">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
            <el-tag v-if="scope.row.TaskState === 3" type="danger">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
            <el-tag v-if="scope.row.TaskState === 4" type="warning">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
            <el-tag v-if="scope.row.TaskState === 5" type="danger">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
          </template>
        </el-table-column>
        
        
        
       
        <!-- 申请状态 -->
        <el-table-column
          prop="ReReadingApplyState"
          :label="$t('trials:reviewTrack:table:applyStatus')"
          min-width="140"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.ReReadingApplyState === 4 || scope.row.ReReadingApplyState === 5" type="danger">{{ $fd('ReReadingApplyState', scope.row.ReReadingApplyState) }}</el-tag>
            <el-tag v-if="scope.row.ReReadingApplyState === 2" type="primary">{{ $fd('ReReadingApplyState', scope.row.ReReadingApplyState) }}</el-tag>
            <el-tag v-if="scope.row.ReReadingApplyState === 3" type="warning">{{ $fd('ReReadingApplyState', scope.row.ReReadingApplyState) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          :label="$t('common:action:action')"
          width="120"
        >
          <template slot-scope="scope">
            <!-- 查看阅片结果 -->
            <el-button
              :disabled="scope.row.ReadingTaskState !== 2"
              icon="el-icon-view"
              circle
              :title="$t('trials:reviewTrack:action:viewResults')"
              @click="lookReadingResults(scope.row)"
            />
            <!-- 退回已影响任务列表 -->
            <el-button
              :disabled="!scope.row.IsPMSetBack"
              icon="el-icon-document-copy"
              circle
              :title="$t('trials:reviewTrack:action:backToTaskList')"
              @click="getInfluencedTaskList(scope.row)"
            />
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
      <!-- 退回影响任务列表/已影响任务列表 -->
      <el-dialog
        v-if="reReadingOrBackVisible"
        :title="$t('trials:reviewTrack:dialog:impactList')"
        :visible.sync="reReadingOrBackVisible"
        width="1460px"
        append-to-body
        :close-on-click-modal="false"
        custom-class="base-dialog-wrapper"
      >
        <div class="base-dialog-body">
          <el-table
            v-loading="loading2"
            :data="influenceTaskList"
            stripe
            height="100"
            style="min-height: 400px;"
          >
          <!-- 任务编号 -->
            <el-table-column
              prop="TaskCode"
              :label="$t('trials:reviewTrack:table:taskCode')"
              min-width="100"
              show-overflow-tooltip
            />
            <!-- 中心编号 -->
            <el-table-column
              prop="TrialSiteCode"
              :label="$t('trials:reviewTrack:table:siteCode')"
              min-width="100"
              show-overflow-tooltip
            />
            <!-- 受试者编号 -->
            <el-table-column
              prop="SubjectCode"
              :label="$t('trials:reviewTrack:table:subjectCode')"
              min-width="120"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span v-if="scope.row.BlindSubjectCode && scope.row.BlindSubjectCode !== scope.row.SubjectCode">
                  {{ `${scope.row.SubjectCode}/${scope.row.BlindSubjectCode}` }}
                </span>
                <span v-else>{{scope.row.SubjectCode}}</span>
              </template>
            </el-table-column>
            <!-- 任务名称 -->
            <el-table-column
              prop="VisitTaskNum"
              :label="$t('trials:reviewTrack:table:taskName')"
              min-width="120"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span v-if="scope.row.TaskBlindName && scope.row.TaskName !== scope.row.TaskBlindName">
                  {{ `${scope.row.TaskName}/${scope.row.TaskBlindName}` }}
                </span>
                <span v-else>{{scope.row.TaskName}}</span>
              </template>
            </el-table-column>
            <!-- 盲态任务标识 -->
            <!-- <el-table-column
              prop="TaskBlindName"
              :label="$t('trials:reviewTrack:table:blindName')"
              min-width="120"
              show-overflow-tooltip
            /> -->
            <!-- 阅片标准 -->
            <el-table-column
              prop="TrialReadingCriterionName"
              :label="$t('trials:reviewTrack:table:criterionName')"
              min-width="100"
              show-overflow-tooltip
            >
            </el-table-column>
            <!-- 任务状态 -->
            <el-table-column
              prop="TaskState"
              :label="$t('trials:reviewTrack:table:taskStatus')"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.TaskState === 0" type="primary">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
                <el-tag v-if="scope.row.TaskState === 1" type="info">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
                <el-tag v-if="scope.row.TaskState === 3" type="danger">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
                <el-tag v-if="scope.row.TaskState === 4" type="warning">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
                <el-tag v-if="scope.row.TaskState === 5" type="danger">{{ $fd('TaskState', scope.row.TaskState) }}</el-tag>
              </template>
            </el-table-column>
            <!-- 任务类型 -->
            <el-table-column
              prop="ReadingCategory"
              min-width="100"
              :label="$t('trials:reviewTrack:table:taskType')"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.ReadingCategory === 1" type="primary">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
                <el-tag v-if="scope.row.ReadingCategory === 2" type="info">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
                <el-tag v-if="scope.row.ReadingCategory === 4" type="danger">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
                <el-tag v-if="scope.row.ReadingCategory === 5" type="warning">{{ $fd('ReadingCategory', scope.row.ReadingCategory) }}</el-tag>
              </template>
            </el-table-column>
            <!-- 阅片状态 -->
            <el-table-column
              prop="ReadingTaskState"
              :label="$t('trials:reviewTrack:table:readingStatus')"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.ReadingTaskState === 2" type="primary">{{ $fd('ReadingTaskState', scope.row.ReadingTaskState) }}</el-tag>
                <el-tag v-else type="danger">{{ $fd('ReadingTaskState', scope.row.ReadingTaskState) }}</el-tag>
              </template>
            </el-table-column>
            <!-- 生效后影响 -->
            <el-table-column
              prop="OptType"
              :label="$t('trials:reviewTrack:applyReread:title:postEffectiveImpacts')"
              min-width="100"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-if="scope.row.OptType === 0" type="primary">{{ $fd('ReReadingOrBackOptType', scope.row.OptType) }}</el-tag>
                <el-tag v-if="scope.row.OptType === 1" type="danger">{{ $fd('ReReadingOrBackOptType', scope.row.OptType) }}</el-tag>
                <el-tag v-if="scope.row.OptType === 2" type="warning">{{ $fd('ReReadingOrBackOptType', scope.row.OptType) }}</el-tag>
              </template>
            </el-table-column>
            <!-- 阅片人 -->
            <el-table-column
              prop="UserName"
              :label="$t('trials:reviewTrack:table:reader')"
              min-width="160"
              show-overflow-tooltip
            >
              <template v-if="scope.row.DoctorUser" slot-scope="scope">
                {{ scope.row.DoctorUser.UserName }}({{ scope.row.DoctorUser.FullName }})
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>
    </template>
  </BaseContainer>
</template>
<script>
import { getTrialSiteSelect } from '@/api/trials'
import { getTrialCriterionList, getReadingTaskList, getDoctorUserSelectList, getInfluencedTaskList } from '@/api/trials/reading'
import { getToken } from '@/utils/auth'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'

const searchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    Asc: true,
    SortField: '',
    TrialId: null,
    TrialSiteId: null,
    SubjectId: null,
    SubjectCode: null,
    IsUrgent: null,
    TaskName: null,
    TaskState: null,
    DoctorUserId: null,
    ReadingCategory: null,
    TaskAllocationState: null,
    BeginAllocateDate: null,
    EndAllocateDate: null,
    ReadingTaskState: null,
    CompleteClinicalDataEnum: null,
    BeginSignTime: null,
    EndSignTime: null,
    ReReadingApplyState: null,
    IsEffect: false
    // ArmEnum: null
  }
}
export default {
  name: 'RecordList',
  components: { BaseContainer, Pagination },
  data() {
    return {
      searchData: searchDataDefault(),
      list: [],
      total: 0,
      loading: false,
      timeList: [],
      timeList2: [],
      siteOptions: [],
      doctorUserList: [],
      trialCriterionList: [],
      trialId: this.$route.query.trialId,
      reReadingOrBackVisible: false,
      loading2: false,
      influenceTaskList: [],
      openWindow: null,
    }
  },
  mounted() {
    this.getList()
    this.getSite()
    this.getDoctorUserSelectList()
    this.getTrialCriterionList()
  },
  beforeDestroy() {
    if (this.openWindow) {
      this.openWindow.close()
    }
  },
  methods: {
    getList() {
      this.searchData.TrialId = this.$route.query.trialId
      this.loading = true
      getReadingTaskList(this.searchData).then(res => {
        this.loading = false
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    getInfluencedTaskList(row) {
      this.reReadingOrBackVisible = true
      this.loading2 = true
      this.rowData = { ...row }
      getInfluencedTaskList(row.Id).then(res => {
        this.influenceTaskList = res.Result
        this.loading2 = false
      })
    },
    getSite() {
      getTrialSiteSelect(this.trialId).then(res => {
        this.siteOptions = res.Result
      })
    },
    getDoctorUserSelectList() {
      getDoctorUserSelectList(this.$route.query.trialId).then(res => {
        this.doctorUserList = res.Result
      })
    },
    getTrialCriterionList() {
      getTrialCriterionList(this.trialId).then(res => {
        this.trialCriterionList = res.Result
      }).catch(() => {})
    },
    // 查看阅片结果
    lookReadingResults(row) {
      if (this.openWindow) {
        this.openWindow.close()
      }
      var token = getToken()
      var path
      if (row.ReadingTool === 0 || row.ReadingTool === 2|| row.ReadingTool === 3) {
        path = `/readingDicoms?TrialReadingCriterionId=${row.TrialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${row.SubjectCode}&subjectId=${row.SubjectId}&visitTaskId=${row.Id}&isReadingTaskViewInOrder=${row.IsReadingTaskViewInOrder}&criterionType=${row.CriterionType}&readingTool=${row.ReadingTool}&TokenKey=${token}`
      } else {
        path = `/noneDicomReading?TrialReadingCriterionId=${row.TrialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${row.SubjectCode}&subjectId=${row.SubjectId}&visitTaskId=${row.Id}&isReadingTaskViewInOrder=${row.IsReadingTaskViewInOrder}&criterionType=${row.CriterionType}&readingTool=${row.ReadingTool}&TokenKey=${token}`
      }
      // const routeData = this.$router.resolve({
      //   path: `/readingPage?subjectId=${row.SubjectId}&trialId=${row.TrialId}&visitTaskId=${row.Id}&TokenKey=${token}`
      // })
      this.openWindow = window.open(path, '_blank')
    },
    changeTimeList() {
      if (this.timeList) {
        this.searchData.BeginAllocateDate = this.timeList[0]
        this.searchData.EndAllocateDate = this.timeList[1]
      } else {
        this.searchData.BeginAllocateDate = null
        this.searchData.EndAllocateDate = null
      }
    },
    changeTimeList2() {
      if (this.timeList2) {
        this.searchData.BeginSignTime = this.timeList2[0]
        this.searchData.EndSignTime = this.timeList2[1]
      } else {
        this.searchData.BeginSignTime = null
        this.searchData.EndSignTime = null
      }
    },
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    handleReset() {
      this.timeList = []
      this.timeList2 = []
      this.searchData = searchDataDefault()
      this.getList()
    },
    // 排序
    handleSortChange(column) {
      if (column.order === 'ascending') {
        this.searchData.Asc = true
      } else {
        this.searchData.Asc = false
      }
      this.searchData.SortField = column.prop
      this.searchData.PageIndex = 1
      this.getList()
    }
  }
}
</script>
