/* eslint-disable */
<template>
  <BaseContainer>
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 中心编号 -->
        <el-form-item :label="$t('trials:reviewTrack:table:siteCode')">
          <el-select v-model="searchData.SiteId" clearable filterable style="width:120px;">
            <el-option
              v-for="(item,index) of siteOptions"
              :key="index"
              :label="item.TrialSiteCode"
              :value="item.SiteId"
            />
          </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: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: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">
          <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"
        @expand-change="handleEpandChange"
      >
        <!-- 任务编号 -->
        <el-table-column
            width="50"
            sortable="custom"
            show-overflow-tooltip
            type="expand"
        >
          <template slot-scope="props" >
            <div style="padding: 0 20px">
              <el-table
                  v-loading="props.row.EpandLoading"
                  v-if="props.row.StudyList"
                  :data="props.row.StudyList"
                  stripe
              >
                <el-table-column type="index" width="40" />
                <!-- Study ID -->
                <el-table-column
                    prop="StudyCode"
                    :label="$t('trials:studyList:table:studyId')"
                    show-overflow-tooltip
                    sortable="custom"
                    min-width="100"
                />
                <!-- Image Type -->
                <el-table-column
                    prop="IsDicom"
                    :label="$t('trials:studyList:table:imageType')"
                    sortable="custom"
                    min-width="100"
                >
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.IsDicom" type="primary">DICOM</el-tag>
                    <el-tag v-else type="danger">Non-DICOM</el-tag>
                  </template>
                </el-table-column>

                <el-table-column
                    prop="StudyTime"
                    sortable="custom"
                    min-width="200"
                    show-overflow-tooltip
                >
                  <template slot="header">
                    <el-tooltip placement="top">
                      <!-- Modality,Body Part Examined,Count,Study Date -->
                      <!-- Study Info -->
                      <div slot="content">
                        {{ `${$t('trials:studyList:table:modality')}, ${$t('trials:studyList:table:bodyPart')}, ${$t('trials:studyList:table:studyDate')}, ${$t('trials:studyList:table:count')}` }}
                      </div>
                      <span>{{ $t('trials:studyList:table:studyInfo') }}</span>
                    </el-tooltip>
                  </template>
                  <template slot-scope="scope">
                    <div style="display: flex;align-items: center">
                      <div v-if="scope.row.Modalities">{{ scope.row.Modalities }}({{ scope.row.Count }}), </div>
                      <div v-else style="color:#f44336;">N/A, </div>
                      <div v-if="scope.row.Bodypart" style="margin:0 3px;">{{ getBodyPart(scope.row.Bodypart) }}, </div>
                      <div v-else style="color:#f44336;margin:0 3px;">N/A, </div>
                      <div v-if="scope.row.StudyTime">{{ moment(scope.row.StudyTime).format('YYYY-MM-DD') }} </div>
                      <div v-else style="color:#f44336;">N/A </div>
                      <div>
                      </div>
                    </div>
                  </template>
                </el-table-column>

                <el-table-column
                    min-width="100"
                    show-overflow-tooltip
                >
                  <template slot="header">
                    <el-tooltip placement="top">
                      <div slot="content">
                        {{ `${$t('trials:studyList:table:visitName')}, ${$t('trials:studyList:table:visitNum')}` }}<br>
                      </div>
                      <span>{{ $t('trials:studyList:table:visit') }}</span>
                    </el-tooltip>
                  </template>
                  <template slot-scope="scope">
                    <span v-if="scope.row.VisitName">{{ scope.row.VisitName }}, </span>
                    <span v-else style="color:#f44336;">N/A, </span>
                    <span>{{ scope.row.VisitNum }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                    prop="SubjectCode"
                    :label="$t('trials:studyList:table:subject')"
                    sortable="custom"
                    show-overflow-tooltip
                />
                <el-table-column
                    min-width="100"
                    show-overflow-tooltip
                >
                  <template slot="header">
                    <el-tooltip placement="top">
                      <div slot="content">
                        {{ `${$t('trials:studyList:table:siteId')}, ${$t('trials:studyList:table:siteName')}` }}
                      </div>
                      <span>{{ $t('trials:studyList:table:site') }}</span>
                    </el-tooltip>
                  </template>
                  <template slot-scope="scope">
                    <span v-if="scope.row.TrialSiteCode">{{ scope.row.TrialSiteCode }}, </span>
                    <span v-else style="color:#f44336;">N/A, </span>
                    <span v-if="scope.row.TrialSiteAliasName">{{ scope.row.TrialSiteAliasName }}</span>
                    <span v-else style="color:#f44336;">N/A</span>
                  </template>
                </el-table-column>
                <el-table-column
                    prop="Uploader"
                    :label="$t('trials:studyList:table:uploader')"
                    show-overflow-tooltip
                    sortable="custom"
                    min-width="100"
                />
                <el-table-column
                    prop="UploadTime"
                    :label="$t('trials:studyList:table:uploadTime')"
                    show-overflow-tooltip
                    sortable="custom"
                    min-width="120"
                />
              </el-table>
            </div>
          </template>
        </el-table-column>
        <!-- 任务编号 -->
        <el-table-column
          prop="TaskCode"
          :label="$t('trials:reviewTrack:table:taskCode')"
          width="120"
          sortable="custom"
          show-overflow-tooltip
        >
        </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="120"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 任务名称 -->
        <el-table-column
          prop="VisitTaskNum"
          :label="$t('trials:reviewTrack:table:taskName')"
          width="140"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{scope.row.TaskName}}
          </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="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="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="TrialReadingCriterionName"
          :label="$t('trials:reviewTrack:table:criterionName')"
          min-width="140"
          sortable="custom"
          show-overflow-tooltip
        />
        <el-table-column
            prop="UserName"
            label="下载进度"
            width="200"
            show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-progress v-if="scope.row.downloadNum" :percentage="scope.row.downloadNum * 100/scope.row.downloadCount"></el-progress>
          </template>
        </el-table-column>
        <el-table-column
            prop="status"
            label="状态"
            width="130"
        >
        </el-table-column>

        <el-table-column
          fixed="right"
          :label="$t('common:action:action')"
          width="260"
        >
          <template slot-scope="scope">
            <el-button
              icon="el-icon-document-copy"
              circle
              title="推送"
              @click="handlePush(scope.row)"
            />
            <el-button
                icon="el-icon-upload"
                circle
                :title="$t('trials:reviewTrack:action:backToTaskList')"
                @click="openFindReading(scope.row)"
            />
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
          v-if="pushVisible"
          title="推送"
          :visible.sync="pushVisible"
          width="600px"
          :close-on-click-modal="false"
      >
        <el-form
            ref="readDataForm"
            v-loading="loading"
            :model="form"
            size="small"
            label-width="120px"
        >
          <el-form-item label="推送工作站" prop="pacs_id">
            <el-select v-model="form.pacs_id">
              <el-option v-for="item of pacsList" :value="item._id" :label="item.aet">{{item.aet}}</el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="item.StudyCode" v-for="item of studyList" :rules="[{message: $t('common:ruleMessage:specify'), trigger: ['blur', 'change']},]">
            <el-select multiple v-model="form[item.StudyId]">
              <el-option v-for="item of item.ModalitySeriesList" :value="item.SeriesIdList.toString()" :label="item.Modality">{{item.Modality}}</el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div style="text-align: right">
          <el-button
              :disabled="btnLoading"
              size="small"
              type="primary"
              @click="handleCancel"
          >
            {{ $t('common:button:cancel') }}
          </el-button>
          <!-- 保存 -->
          <el-button size="small" type="primary" :loading="btnLoading" @click="handleSave">
            {{ $t('common:button:confirm') }}
          </el-button>
        </div>
      </el-dialog>
      <el-dialog
          v-if="pullVisible"
          title="拉取"
          :visible.sync="pullVisible"
          width="800px"
          :close-on-click-modal="false"
      >
        <el-form
            ref="findReadDataForm"
            v-loading="loading"
            :model="findForm"
            size="small"
            :rules="rules"
            label-width="120px"
        >
          <el-form-item label="拉取工作站" prop="pacs_id">
            <el-select v-model="findForm.pacs_id" @change="pacsListChange">
              <el-option v-for="item of pacsList" :value="item._id" :label="item.aet">{{item.aet}}</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="任务编号">
            {{rowData.TaskCode}}
          </el-form-item>
          <el-form-item label="访视">
            {{rowData.TaskBlindName}}
          </el-form-item>
          <el-form-item label="阅片人">
            {{`${rowData.UserName}(${rowData.FullName})`}}
          </el-form-item>
          <el-form-item label="模态" prop="modeList">
            <el-select v-model="findForm.modeList" multiple>
              <el-option v-for="item of modeList" :value="item" :label="item">{{item}}</el-option>
            </el-select>
            <el-button style="margin-left: 20px" size="mini" type="primary" @click="findReading">
              查询序列
            </el-button>
          </el-form-item>
          <el-table
              style="margin-bottom: 20px"
              v-loading="loading"
              v-if="seriesList.length > 0"
              :data="seriesList"
              stripe
              height="280"
              @selection-change="handleSelectionChange"
          >
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>
            <!-- 任务编号 -->
            <el-table-column
                width="180"
                prop="StudyInstanceUID"
                label="检查"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                label="序列ID"
                prop="SeriesInstanceUID"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                width="100"
                label="序列编号"
                prop="SeriesNumber"
                show-overflow-tooltip
            >
            </el-table-column>
            <!-- 任务编号 -->
            <el-table-column
                width="80"
                label="模态"
                prop="Modality"
                show-overflow-tooltip
            >
            </el-table-column>
            <!-- 任务编号 -->
            <el-table-column
                width="80"
                label="状态"
                prop="status"
                show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{scope.row.status ? '已拉取' : '未推送'}}
              </template>
            </el-table-column>
        </el-table>
          <span style="font-size: 12px;color:#f66">确认拉取后，选择的序列会分配到该任务的阅片人</span>
        </el-form>
        <div style="text-align: right">
          <el-button
              :disabled="btnLoading"
              size="small"
              type="primary"
              @click="pullVisible = false"
          >
            {{ $t('common:button:cancel') }}
          </el-button>
          <!-- 保存 -->
          <el-button size="small" type="primary" :loading="btnLoading" @click="handleMove">
            确认拉取
          </el-button>
        </div>
      </el-dialog>
      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
    </template>
  </BaseContainer>
</template>
<script>
import { getTrialSiteSelect,setTaskUrgent } from '@/api/trials'
import { getStudyModalityOSSPath, getStudyModalityList, getDicomAndNoneDicomStudyList, getVisitTaskList, getTrialCriterionList, PMSetTaskBack, getInfluencedTaskList, getReReadingOrBackInfluenceTaskList, getReadingTaskList, configTrialReadingTaskViewRule, getDoctorUserSelectList, applyReReading } from '@/api/trials/reading'
import { getToken } from '@/utils/auth'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
import RefereeRules from './components/RefereeRules.vue'
import exportList from './components/exportList.vue'
import ClinicalData from "../../subject/reading-period/components/ClinicalData";
import moment from 'moment'
const searchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    Asc: true,
    SortField: '',
    TrialId: null,
    SiteId: null,
    SubjectId: null,
    SubjectCode: null,
    TaskName: null,
    DoctorUserId: null,
    ReadingCategory: null,
  }
}
export default {
  name: 'TrialsNotice',
  components: { BaseContainer, Pagination, RefereeRules, ClinicalData, exportList },
  props: {
    AllocationReadingCategory: {
      type: String
    },
    AllocationSubjectCode: {
      type: String
    }
  },
  data() {
    return {
      pushVisible: false,
      seriesList: [],
      modeList: [],
      searchData: searchDataDefault(),
      epandLoading: false,
      exportVisible: false,
      moment,
      maxLength: 0,
      list: [],
      siteOptions: [],
      total: 0,
      SubjectAssignListTotal: 0,
      loading: false,
      ReadingRulesVisible: false,
      ApplyforReasonVisible: false,
      ReReadingOrBackVisible: false,
      clinicalDataVisible: false,
      InfluenceTaskList: [],
      form: {
        pacs_id: null
      },
      findForm: {
        pacs_id: null,
        modeList: null
      },
      ApplyforReasonForm: {
        Type: null,
        RequestReReadingReason: null
      },
      rules: {
        pacs_id: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }],
        modeList: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur', type: 'array' }],
      },
      RefereeAllocationVisible: false,
      trialId: this.$route.query.trialId,
      trialCode: this.$route.query.trialCode,
      currentData: {},
      param: {},
      DoctorUserList: [],
      TaskAllocationRuleList: [],
      btnLoading: false,
      value: true,
      value1: true,
      ReadingType: null,
      ReadingRulesInfo: {
        TrialId: this.$route.query.trialId,
        ReadingTaskViewEnum: 0,
        IsReadingTaskViewInOrder: false,
        IsReadingShowSubjectInfo: null,
        IsReadingShowPreviousResults: null
      },
      // rules: {
      //   DoctorUserId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }]
      // },
      title: '',
      rowData: {},
      timeList: [],
      SubjectAssignList: [],
      SubjectAssignSelectList: [],
      TaskAllocationRuleSelectList: [],
      readVisible: false,
      TaskOptType: null,
      OtherInfo: null,
      trialCriterionList: [],
      ReReadingOtherInfo: {
        IsIRAppyTaskInfluenced: false
      },
      TrialReadingCriterionId: null,
      urgentVisible: false,
      urgentForm: { VisitTaskId: '', IsUrgent: null,TaskUrgentType:null,TaskUrgentRemake:null },
      dialogLoading:false,
      openWindow:null,
      studyList: [],
      selectList: [],
      pacsList: [],
      t: null,
      pullVisible: false
    }
  },
  mounted() {
    this.searchData.ReadingCategory = this.AllocationReadingCategory
    this.searchData.SubjectCode = this.AllocationSubjectCode
    console.log(this.searchData.SubjectCode, this.searchData.ReadingCategory)
    this.getList()
    this.getSite()
    this.getDoctorUserSelectList()
    this.getTrialCriterionList()
    this.$axios({
      method: 'get',
      url: process.env.VUE_APP_NODE_SERVER_PATH + 'pacs' + this.getParams({trialId: this.$route.query.trialId}),
    }).then(res => {
      if (res.data.code !== 1) {
        this.$message.error(res.data.message)
      } else {
        this.pacsList = res.data.data
      }
      this.loading = false
    })
    this.t = setInterval(v => {
      this.getPercent()
    }, 1000)
  },
  beforeDestroy() {
    clearInterval(this.t)
    this.t = null
    if (this.openWindow) {
      this.openWindow.close()
    }
  },
  methods: {
    handleSelectionChange(list) {
      this.selectList = list
    },
    pacsListChange(value) {
      let o = this.pacsList.find(v => {
        return v._id == value
      })
      console.log(o)
      this.modeList = o.mode.split(',')
    },
    openFindReading(row) {
      this.rowData = {...row}
      this.pullVisible = true
      this.seriesList = []
      this.findForm = {
        pacs_id: null
      }
    },
    findReading() {
      this.$refs.findReadDataForm.validate(async valid => {
        if (!valid) return
        this.$axios({
          method: 'post',
          url: process.env.VUE_APP_NODE_SERVER_PATH + 'pacs/findReading',
          data: {
            pacs_id: this.findForm.pacs_id,
            task_id: this.rowData.Id,
            trialCode: this.trialCode,
            subjectCode: this.rowData.SubjectCode,
            TaskCode: this.rowData.TaskCode,
            modeList: this.findForm.modeList,
            StudyInstanceUidList: this.rowData.StudyInstanceUidList
          }
        }).then(res => {
          if (res.data.code !== 1) {
            this.$message.error(res.data.message)
          } else {
            this.seriesList = res.data.data
          }
          this.loading = false
        })
      })
    },
    getPercent() {
      this.$axios({
        method: 'post',
        url: process.env.VUE_APP_NODE_SERVER_PATH + 'pacs/percent',
        data: {
          task_ids: this.list.map(v => {
            return v.Id
          })
        }
      }).then(res => {
        if (res.data.code !== 1) {
          this.$message.error(res.data.message)
        } else {
          if (res.data.data) {
            res.data.data.forEach(v => {
              let o = this.list.find(v1 => {
                return v.task_id === v1.Id
              })
              if (o) {
                this.$set(o, 'downloadNum', v.downloadNum)
                this.$set(o, 'downloadCount', v.downloadCount)
                this.$set(o, 'status', v.status)
              }
            })
          }
        }
        this.loading = false
      })

    },
    handleCancel() {
      this.pushVisible = false
    },
    async handleMove() {
      if (!this.seriesList.length) {
        this.$message.warning(`请先查询工作站中的报告文件`)
        return
      }
      if (!this.selectList.length) {
        this.$message.error(`请勾选拉取序列`)
        return
      }
      var token = getToken()
      this.$axios({
        method: 'post',
        url: process.env.VUE_APP_NODE_SERVER_PATH + 'pacs/pullImage',
        data: {
          pacs_id: this.findForm.pacs_id,
          seriesList: this.selectList.map(v => {return v.SeriesInstanceUID}),
          task_id: this.rowData.Id,
          trialId: this.trialId,
          siteId: this.rowData.SiteId,
          subjectId: this.rowData.SubjectId,
          subjectVisitId: this.rowData.SubjectVisitId,
          trialCode: this.trialCode,
          subjectCode: this.rowData.SubjectCode,
          TaskCode: this.rowData.TaskCode,
          userName:  `${this.rowData.UserName}(${this.rowData.FullName})`,
          userId: this.rowData.DoctorUserId
        },
        headers: {
          'Authorization': 'Bearer ' + token
        }
      }).then(res => {
        if (res.data.code !== 1) {
          this.$message.error(res.data.message)
        } else {
          this.$message.success('拉取完成')
        }
        this.loading = false
      })
    },
    async handleSave() {
      this.$refs.readDataForm.validate(async valid => {
        if (!valid) return
        let arr = []
        Object.keys(this.form).forEach(v => {
          if (v !== 'pacs_id') {
            arr.push(...(this.form[v].join(',').split(',')))
          }
        })
        let newArr = arr.filter(i=>i && i.trim())
        let res = await getStudyModalityOSSPath(newArr)
        let imagesList = res.Result
        this.$axios({
          method: 'post',
          url: process.env.VUE_APP_NODE_SERVER_PATH + 'pacs/pushImage',
          data: {
            pacs_id: this.form.pacs_id,
            imagesList: imagesList,
            task_id: this.rowData.Id,
            trialCode: this.trialCode,
            subjectCode: this.rowData.SubjectCode,
            TaskCode: this.rowData.TaskCode
          }
        }).then(res => {
          if (res.data.code !== 1) {
            this.$message.error(res.data.message)
          } else {
            this.$message.success('推送完成')
          }
          this.loading = false
        })
      })
    },
    getParams(obj) {
      let result = ''
      let item
      for (item in obj) {
        if (obj[item] && String(obj[item])) {
          result += `&${item}=${obj[item]}`
        }
      }
      if (result) {
        result = '?' + result.slice(1)
      }
      return result
    },
    handlePush(row) {
      this.pushVisible = true
      this.rowData = {...row}
      this.$set(this, 'form', {
        pacs_id: null
      })
      getStudyModalityList(row).then(res => {
        this.studyList = res.Result
      })
    },
    getBodyPart(bodyPart) {
      if (!bodyPart) return ''
      var separator = ','
      if (bodyPart.indexOf('|') > -1) {
        separator = '|'
      } else if (bodyPart.indexOf(',') > -1) {
        separator = ','
      } else if (bodyPart.indexOf('，') > -1) {
        separator = '，'
      }
      var arr = bodyPart.split(separator)
      var newArr = arr.map(i => {
        return this.$fd('Bodypart', i.trim())
      })
      return newArr.join(' | ')
    },
    handleExport() {
      this.exportVisible = true
    },
    handleView(row) {
      this.TrialReadingCriterionId = row.TrialReadingCriterionId
      this.rowData = {...row}
      this.currentData = {
        Id: row.SourceSubjectVisitId || row.SouceReadModuleId,
        SubjectId: row.SubjectId,
        IsVisit: row.SourceSubjectVisitId ? true : false,
        TrialId: row.TrialId,
        IsBaseLine: row.VisitTaskNum === 0 ? true : false,
        TrialReadingCriterionId: row.TrialReadingCriterionId
      }
      this.clinicalDataVisible = true
    },
    getTrialCriterionList() {
      getTrialCriterionList(this.trialId).then(res => {
        this.trialCriterionList = res.Result
      }).catch(() => {})
    },
    getInfluencedTaskList(row) {
      this.loading = true
      this.opentype = 'look'
      this.rowData = { ...row }
      getInfluencedTaskList(row.Id).then(res => {
        this.InfluenceTaskList = res.Result
        this.ReReadingOrBackVisible = true
        this.loading = false
      })
    },
    PMSetTaskBack() {
      this.loading = true
      PMSetTaskBack(this.trialId, this.rowData.Id).then(res => {
        this.loading = false
        this.ReReadingOrBackVisible = false
        this.getList()
        // '退回成功'
        this.$message.success(this.$t('trials:reviewTrack:message:returnedSuccessfully'))
      }).catch(() => {this.loading = false})
    },
    openReReadingOrBackList(row) {
      this.loading = true
      this.rowData = {...row}
      this.opentype = 'read'
      getReReadingOrBackInfluenceTaskList(row.Id, false).then(res => {
        this.InfluenceTaskList = res.Result
        this.ReReadingOtherInfo = res.OtherInfo
        this.ReReadingOrBackVisible = true
        this.loading = false
      }).catch(() => {this.loading = false})
    },
    // 查看阅片结果
    lookReadingResults(row) {
      if (this.openWindow) {
        this.openWindow.close()
      }
      var token = getToken()
      var path
      if (row.ReadingTool === 0) {
        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')
    },
    openApplyReReading(row) {
      this.rowData = { ...row }
      this.loading = true
      getReReadingOrBackInfluenceTaskList(row.Id, true).then(res => {
        this.InfluenceTaskList = res.Result
        this.ReReadingOtherInfo = res.OtherInfo
        this.ApplyforReasonVisible = true
        this.ApplyforReasonForm = {
          Type: null,
          Remake: null
        }
        this.loading = false
      }).catch(() => {this.loading = false})
    },
    // 申请重阅
    applyReReading() {
      this.$refs.reasonForm.validate((valid) => {
        if (!valid) return
        this.loading = true
        this.btnLoading = true
        var params = {
          TaskIdList: [
            this.rowData.Id
          ],
          TrialId: this.$route.query.trialId,
          RequestReReadingType: 2,
          RequestReReadingReason: this.ApplyforReasonForm.Type === 2 ? this.ApplyforReasonForm.RequestReReadingReason : this.$t('trials:reviewTrack:message:ImageRetransfer')//图像重传
        }
        applyReReading(params).then(res => {
          this.loading = false
          this.btnLoading = false
          // '申请重阅成功'
          this.$message.success(this.$t('trials:reviewTrack:message:applyedSuccessfully'))
          this.getList()
          this.ApplyforReasonVisible = false
        }).catch(() => {
          this.loading = false
          this.btnLoading = false
        })
      })
    },
    // 重阅历史
    reReadingHistory(row) {
      this.$router.push({ path: `/trials/trials-panel/reading/reReadingTracking?trialId=${this.$route.query.trialId}&trialCode=${this.$route.query.trialCode}&researchProgramNo=${this.$route.query.researchProgramNo}&SiteId=${row.SiteId}&SubjectCode=${row.SubjectCode}&TaskName=${row.TaskName}&DoctorUserId=${row.DoctorUserId}` })
    },
    openRefereeAllocation() {
      this.RefereeAllocationVisible = true
    },
    openReadingRules() {
      this.ReadingRulesVisible = true
    },
    getDoctorUserSelectList() {
      getDoctorUserSelectList(this.$route.query.trialId).then(res => {
        this.DoctorUserList = res.Result
        if (this.DoctorUserList.length > 0) {
          this.ReadingType = this.DoctorUserList[0].ReadingType
        } else {
        }
      })
    },
    getList() {
      this.searchData.TrialId = this.$route.query.trialId
      this.loading = true
      getVisitTaskList(this.searchData).then(res => {
        this.loading = false
        this.OtherInfo = res.OtherInfo
        this.ReadingRulesInfo = Object.assign({}, this.OtherInfo)
        this.list = res.Result.CurrentPageData
        this.list.forEach(v => {
          this.$set(v, 'StudyList', [])
          this.$set(v, 'EpandLoading', false)
        })
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
    },
    getSite() {
      getTrialSiteSelect(this.trialId).then(res => {
        this.siteOptions = res.Result
      })
    },
    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
      }
    },
    changeUrgentStatus(row){
      this.rowData = {...row}
      this.urgentForm.VisitTaskId = row.Id
      this.urgentForm.IsUrgent = row.IsUrgent
      this.urgentForm.TaskUrgentType = row.TaskUrgentType
      this.urgentForm.TaskUrgentRemake = row.TaskUrgentRemake
      this.urgentVisible = true
    },
    handleTaskUrgentTypeChange(val){
      if(val !== 4){
        this.urgentForm.TaskUrgentRemake = null
      }
    },
    handleIsUrgentChange(val){
      if(!val){
        this.urgentForm.TaskUrgentType = null
        this.urgentForm.TaskUrgentRemake = null
      }
    },
    handleSaveUrgentStatus(){
      this.$refs.urgentForm.validate((valid) => {
        if (!valid) return
        this.dialogLoading = true
        setTaskUrgent(this.urgentForm).then(res=>{
          this.dialogLoading = false
          this.urgentVisible = false
          this.getList()
        }).catch(()=>{this.dialogLoading = false})
      })
    },
    // 排序
    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()
    },
    handleEpandChange(row) {
      this.$nextTick(() => {
        this.$set(row, 'EpandLoading', true)
        getDicomAndNoneDicomStudyList(row).then(res => {
          this.$set(row, 'StudyList', res.Result)
          this.$set(row, 'EpandLoading', false)
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  /deep/ .hidden-row{
    display: none;
  }
  /deep/ .el-dialog__body {
    padding: 15px 20px;
  }

  /deep/ .el-tag--danger.el-tag--dark {
    // background-color: #f56c6c!important;
    border-color: none!important;
    // color: #fff!important;
  }
  /deep/ #TaskAllocationRuleList thead .el-checkbox__inner{
    display: none;
  }
  /deep/ .el-descriptions-item__label.has-colon:after{
    display: none;
  }
</style>
