/* eslint-disable */
<template>
  <BaseContainer>
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 中心编号 -->
        <el-form-item :label="$t('trials:reviewAssign:readingTask: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:reviewAssign:readingTask:table:subjectCode')">
          <el-input disabled v-model="searchData.SubjectCode" style="width:100px;" />
        </el-form-item>
        <!-- 访视/阅片期名称 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewAssign:readingTask:table:visitName')">
          <el-input
            v-model="searchData.TaskName"
            disabled
            style="width:100px;"
            clearable
          />
        </el-form-item>
        <!-- 阅片人 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewAssign:readingTask: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:reviewAssign:readingTask:table:criterionName')">
          <el-select disabled 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:reviewAssign:readingTask: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:reviewAssign:readingTask:table:taskStatus')">
          <el-select v-model="searchData.TaskState" clearable style="width:120px;">
            <el-option 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:reviewAssign:readingTask:table:taskType')">
          <el-select v-model="searchData.ReadingCategory" clearable style="width:120px;">
            <el-option v-for="item of $d.ReadingCategory" v-if="item.value !== 4" :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:reviewAssign:readingTask:table:assignStatus')">
          <el-select v-model="searchData.TaskAllocationState" clearable style="width:120px;">
            <el-option v-for="item of $d.TaskAllocationState" :key="'TaskAllocationState' + item.label" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 分配时间 -->
        <el-form-item style="margin-bottom:10px" :label="$t('trials:reviewAssign:readingTask: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">
          <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-button type="primary" icon="el-icon-edit-outline" @click="openAllocationConfigVisible">-->
          <!--            分配规则-->
          <!--          </el-button>-->
          <!--          <el-button type="primary" icon="el-icon-edit-outline" @click="openAutoAlloction">-->
          <!--            分配阅片人-->
          <!--          </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:reviewAssign:readingTask:table:isUrgent')"
          show-overflow-tooltip
          min-width="100"
          sortable="custom"
        >
          <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>
          </template>
        </el-table-column>
        <!-- 任务编号 -->
        <el-table-column
          prop="TaskCode"
          :label="$t('trials:reviewAssign:readingTask:table:taskCode')"
          min-width="100"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 中心编号 -->
        <el-table-column
          prop="TrialSiteCode"
          :label="$t('trials:reviewAssign:readingTask:table:siteCode')"
          min-width="100"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 受试者编号 -->
        <el-table-column
          prop="SubjectCode"
          :label="$t('trials:reviewAssign:readingTask:table:subjectCode')"
          min-width="120"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 访视/阅片期名称 -->
        <el-table-column
          prop="VisitTaskNum"
          :label="$t('trials:reviewAssign:readingTask:table:visitName')"
          min-width="160"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ scope.row.TaskName }}
          </template>
        </el-table-column>
        <!-- 盲态任务标识 -->
        <el-table-column
          prop="TaskBlindName"
          :label="$t('trials:reviewAssign:readingTask:table:blindName')"
          min-width="140"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 任务创建时间 -->
        <el-table-column
          prop="CreateTime"
          :label="$t('trials:reviewAssign:readingTask:table:createTime')"
          min-width="140"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 任务状态 -->
        <el-table-column
          prop="TaskState"
          :label="$t('trials:reviewAssign:readingTask:table:taskStatus')"
          min-width="100"
          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="ReadingCategory"
          :label="$t('trials:reviewAssign:readingTask:table:taskType')"
          min-width="100"
          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="TaskAllocationState"
          :label="$t('trials:reviewAssign:readingTask:table:assignStatus')"
          min-width="100"
          sortable="custom"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-tag v-if="!scope.row.TaskAllocationState" type="danger">{{ $fd('TaskAllocationState', scope.row.TaskAllocationState) }}</el-tag>
            <el-tag v-else type="primary">{{ $fd('TaskAllocationState', scope.row.TaskAllocationState) }}</el-tag>
          </template>
        </el-table-column>
        <!-- 角色 -->
        <el-table-column
          prop="ArmEnum"
          :label="$t('trials:reviewAssign:readingTask:table:role')"
          sortable="custom"
          min-width="80"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <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:reviewAssign:readingTask:table:reader')"
          min-width="180"
          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:reviewAssign:readingTask:table:criterionName')"
          min-width="180"
          sortable="custom"
          show-overflow-tooltip
        />
        <!-- 分配时间 -->
        <el-table-column
          prop="AllocateTime"
          :label="$t('trials:reviewAssign:readingTask:table:assignTime')"
          min-width="100"
          sortable="custom"
          show-overflow-tooltip
        />
      </el-table>
      <!-- 分页组件 -->
      <pagination class="page" :total="total" :page.sync="searchData.PageIndex" :limit.sync="searchData.PageSize" @pagination="getList" />
    </template>
  </BaseContainer>
</template>
<script>
import { getTrialSiteSelect, getVisitTaskList } from '@/api/trials'
import { getTrialCriterionList, getSubjectApplyDoctorTaskStatList, assignSubjectTaskToDoctor, manualAssignDoctorApplyTask, autoSubjectAssignDoctor, getTaskAllocationRuleList, getSubjectAssignList, assignSubjectDoctor, cancelSubjectAssignDoctor, deleteTaskAllocationRule, configTrialTaskInfo, getDoctorUserSelectList } from '@/api/trials/reading'
import BaseContainer from '@/components/BaseContainer'
import Pagination from '@/components/Pagination'
const searchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    Asc: true,
    SortField: '',
    TrialId: null,
    SiteId: null,
    SubjectId: null,
    SubjectCode: null,
    IsUrgent: null,
    TaskName: null,
    TaskState: null,
    DoctorUserId: null,
    ReadingCategory: null,
    TaskAllocationState: null,
    BeginAllocateDate: null,
    EndAllocateDate: null,
    TrialReadingCriterionId: null
  }
}
const taskSearchDataDefault = () => {
  return {
    PageIndex: 1,
    PageSize: 20,
    Asc: true,
    SortField: '',
    TrialId: null,
    SiteId: null,
    SubjectId: null,
    SubjectCode: null,
    DoctorUserId: null,
    IsHaveAssigned: null,
    IsAssignConfirmed: null,
    TrialReadingCriterionId: null
  }
}
export default {
  name: 'TrialsNotice',
  components: { BaseContainer, Pagination },
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      trialCriterionList: [],
      searchData: searchDataDefault(),
      taskSearchData: taskSearchDataDefault(),
      maxLength: 0,
      list: [],
      siteOptions: [],
      total: 0,
      SubjectAssignListTotal: 0,
      loading: false,
      AllocationConfigVisible: false,
      taskAllocationRuleVisible: false,
      AutoAlloctionVisible: false,
      WaitApplyVisible: false,
      applyVisible: false,
      manualAllocationVisible: false,
      trialId: this.$route.query.trialId,
      currentData: {},
      param: {},
      DoctorUserList: [],
      TaskAllocationRuleList: [],
      btnLoading: false,
      value: true,
      value1: true,
      TrialTaskInfo: {
        TrialId: null,
        TaskAllocateObjEnum: 0,
        FollowVisitAutoAssignDefaultState: 0,
        FollowGlobalVisitAutoAssignDefaultState: 0,
        TaskAllocateDefaultState: 1,
        IsFollowVisitAutoAssign: true,
        IsFollowGlobalVisitAutoAssign: true
      },
      ReadingType: null,
      rules: {
        DoctorUserId: [{ required: true, message: this.$t('common:ruleMessage:select'), trigger: 'blur' }]
      },
      title: '',
      rowData: {},
      ApplyTaskInfo: {},
      timeList: [],
      WaitApplyList: [],
      SubjectAssignList: [],
      SubjectAssignSelectList: [],
      TaskAllocationRuleSelectList: [],
      readVisible: false,
      TaskOptType: null,
      OtherInfo: null
    }
  },
  mounted() {
    // this.searchData.ReadingCategory = this.allocationReadingCategory
    // this.searchData.SubjectCode = this.allocationSubjectCode
    this.searchData.TrialReadingCriterionId = this.data.TrialReadingCriterionId
    this.searchData.SubjectCode = this.data.SubjectCode
    this.searchData.TaskName = this.data.VisitName
    console.log(this.data)
    this.getDoctorUserSelectList()
    this.getSite()
    this.getList()
    this.getTrialCriterionList()
  },
  methods: {
    getTrialCriterionList() {
      getTrialCriterionList(this.trialId).then(res => {
        this.trialCriterionList = res.Result
      }).catch(() => {})
    },
    assignSubjectTaskToDoctor(row, type) {
      this.rowData = { ...row }
      this.rowData.TaskOptType = type
      if (type === 1 || type === 2) {
        this.readVisible = true
      } else if (type === 3) {
        this.$confirm('是否确定分配').then(() => {
          this.btnLoading = true
          this.loading = true
          var params = Object.assign({}, this.rowData)
          assignSubjectTaskToDoctor(params).then(res => {
            this.$message.success(this.$t('common:message:savedSuccessfully'))
            this.btnLoading = false
            this.loading = false
            this.readVisible = false
            this.getList()
          }).catch(() => {
            this.btnLoading = false
            this.loading = false
          })
        })
      } else if (type === 4) {
        this.$confirm('是否确定取消分配').then(() => {
          this.btnLoading = true
          this.loading = true
          var params = Object.assign({}, this.rowData)
          assignSubjectTaskToDoctor(params).then(res => {
            this.$message.success(this.$t('common:message:savedSuccessfully'))
            this.btnLoading = false
            this.loading = false
            this.readVisible = false
            this.getList()
          }).catch(() => {
            this.btnLoading = false
            this.loading = false
          })
        })
      }
    },
    assignSubjectTaskToDoctorSave() {
      this.$refs.readDataForm.validate(valid => {
        if (!valid) return
        this.btnLoading = true
        this.loading = true
        var params = Object.assign({}, this.rowData)
        assignSubjectTaskToDoctor(params).then(res => {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.btnLoading = false
          this.loading = false
          this.readVisible = false
          this.getList()
        }).catch(() => {
          this.btnLoading = false
          this.loading = false
        })
      })
    },
    manualAssignDoctorApplyTaskSave() {
      this.loading = true
      this.btnLoading = true
      manualAssignDoctorApplyTask(this.ApplyTaskInfo).then(res => {
        this.loading = false
        this.btnLoading = false
        this.$message.success('生效成功')
        this.WaitApplyVisible = false
        this.getList()
        this.openAutoAlloction()
      }).catch(() => {
        this.loading = false
        this.btnLoading = false
      })
    },
    manualAssignDoctorApplyTask(row) {
      var params = {
        TrialId: this.trialId,
        SubjectIdList: Object.assign([], this.SubjectAssignSelectList.map(v => v.SubjectId))
      }
      this.ApplyTaskInfo = {
        TrialId: this.trialId,
        SubjectDoctorUserList: Object.assign([], this.SubjectAssignSelectList.map(v => {
          v.DoctorUserIdArmList = v.DoctorUserList
          return v
        }))
      }
      if (row) {
        params.SubjectIdList = [row.SubjectId]
        var param = Object.assign({}, row)
        param.DoctorUserIdArmList = param.DoctorUserList
        this.ApplyTaskInfo = Object.assign({}, row)
        delete this.ApplyTaskInfo.DoctorUserList
        delete this.ApplyTaskInfo.DoctorUserIdList
        this.ApplyTaskInfo.SubjectDoctorUserList = [
          param
        ]
      }
      this.loading = true
      this.btnLoading = true
      getSubjectApplyDoctorTaskStatList(params).then(res => {
        if (res.Result.length === 0) {
          this.$alert('该项目没有有效阅片人')
          return
        }
        this.WaitApplyList = res.Result
        this.WaitApplyVisible = true
        this.loading = false
        this.btnLoading = false
      }).catch(() => {
        this.loading = false
        this.btnLoading = false
      })
    },
    autoSubjectAssignDoctor() {
      this.$confirm('确定执行自动分配？').then(() => {
        this.loading = true
        this.btnLoading = true
        autoSubjectAssignDoctor({ TrialId: this.trialId }).then(res => {
          this.loading = false
          this.btnLoading = false
          this.$message.success('自动分配成功')
          this.getList()
          this.openAutoAlloction()
        }).catch(() => {
          this.loading = false
          this.btnLoading = false
        })
      })
    },
    handleSaveTaskAllocationRuleSelectList() {
      if (this.TaskAllocationRuleSelectList.length === 0) {
        this.$alert('请选择阅片人')
        return
      }
      var num
      if (this.ReadingType === 2) {
        num = 2
      } else {
        num = 1
      }
      if (this.TaskAllocationRuleSelectList.length !== num) {
        this.$alert(`当前阅片模式为${this.$fd('ReadingMethod', this.ReadingType)}，请选择正确阅片人数量`)
        return
      }
      this.loading = true
      this.btnLoading = true
      var params = {
        DoctorUserIdArmList: this.TaskAllocationRuleSelectList.map((v, i) => { return { DoctorUserId: v.DoctorUserId, ArmEnum: this.ReadingType === 1 ? 1 : i + 1 } }),
        SubjectIdList: this.SubjectAssignSelectList.map(v => v.SubjectId),
        TrialId: this.trialId,
        IsReAssign: true
      }
      assignSubjectDoctor(params).then(v => {
        this.loading = false
        this.btnLoading = false
        this.openAutoAlloction()
        this.TaskAllocationRuleSelectList = []
        this.SubjectAssignSelectList = []
        this.getDoctorUserSelectList()
        this.$message.success('分配成功')
        this.manualAllocationVisible = false
      }).catch(() => {
        this.loading = false
        this.btnLoading = false
      })
    },
    selectable(row) {
      var num
      if (this.ReadingType === 2) {
        num = 2
      } else {
        num = 1
      }
      if (this.TaskAllocationRuleSelectList.length === num && !this.TaskAllocationRuleSelectList.find(v => { return v.UserName === row.UserName })) {
        return false
      } else {
        return true
      }
    },
    cancelSubjectAssignDoctor(row) {
      if (row) {
        this.$confirm('确定要清空该受试者的阅片人吗?').then(() => {
          var params = {
            SubjectIdList: [row.SubjectId],
            TrialId: this.trialId
          }
          this.loading = true
          this.btnLoading = true
          cancelSubjectAssignDoctor(params).then(v => {
            this.$message.success('清空成功')
            this.loading = false
            this.btnLoading = false
            this.openAutoAlloction()
          }).catch(v => {
            this.loading = false
            this.btnLoading = false
          })
        })
        return
      }
      if (this.SubjectAssignSelectList.length === 0) {
        this.$alert('请勾选要清空阅片人的受试者')
        return
      }
      this.$confirm('确定要清空该受试者的阅片人吗?').then(() => {
        var params = {
          SubjectIdList: this.SubjectAssignSelectList.map(v => v.SubjectId),
          TrialId: this.trialId
        }
        this.loading = true
        this.btnLoading = true
        cancelSubjectAssignDoctor(params).then(v => {
          this.$message.success('清空成功')
          this.loading = false
          this.btnLoading = false
          this.openAutoAlloction()
        }).catch(v => {
          this.loading = false
          this.btnLoading = false
        })
      })
    },
    manualAllocation(row) {
      if (row) {
        this.SubjectAssignSelectList = [row]
      }
      if (this.SubjectAssignSelectList.length === 0) {
        this.$alert('请勾选要分配的受试者')
        return
      }
      this.manualAllocationVisible = true
    },
    handleTaskAllocationRuleListSelectChange(e) {
      this.TaskAllocationRuleSelectList = e
    },
    handleSubjectAssignListSelectChange(e) {
      this.SubjectAssignSelectList = e
    },
    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
      }
    },
    handleCancel() {
      this.AllocationConfigVisible = false
    },
    handleSave() {
      this.btnLoading = true
      this.loading = true
      var params = Object.assign({}, this.TrialTaskInfo)
      params.TrialId = this.$route.query.trialId
      configTrialTaskInfo(params).then(res => {
        this.btnLoading = false
        this.loading = false
        this.AllocationConfigVisible = false
        this.getList()
        this.$message.success(this.$t('common:message:savedSuccessfully'))
      }).catch(() => {
        this.btnLoading = false
        this.loading = false
      })
    },
    handleDelete(row) {
      this.$confirm(`确定要删除${row.UserName}(${row.FullName})的任务分配规则?`, {
        type: 'warning',
        distinguishCancelAndClose: true
      }).then(() => {
        this.loading = true
        deleteTaskAllocationRule(row.Id, false).then(res => {
          this.loading = false
          this.$message.success('删除成功')
          this.openAllocationConfigVisible()
        }).catch(() => { this.loading = false })
      })
    },
    addOrEdit(row) {
      if (row) {
        this.rowData = { ...row }
        this.title = '编辑'
      } else {
        this.rowData = {}
        this.title = '新增'
      }
      this.taskAllocationRuleVisible = true
    },
    openAllocationConfigVisible() {
      this.loading = true
      getTaskAllocationRuleList({
        TrialId: this.$route.query.trialId
      }).then(res => {
        this.loading = false
        this.TaskAllocationRuleList = res.Result
        this.TrialTaskInfo = Object.assign({}, res.OtherInfo)
        this.AllocationConfigVisible = true
        this.taskAllocationRuleVisible = false
      }).catch(() => { this.loading = false })
    },
    openAutoAlloction() {
      this.loading = true
      getTaskAllocationRuleList({
        TrialId: this.$route.query.trialId
      }).then(async(res) => {
        this.taskSearchData.TrialId = this.$route.query.trialId
        var params = Object.assign({}, this.taskSearchData)
        var SubjectAssignListRes = await getSubjectAssignList(params)
        this.SubjectAssignList = SubjectAssignListRes.Result.CurrentPageData
        this.SubjectAssignListTotal = SubjectAssignListRes.Result.TotalCount
        this.loading = false
        this.TaskAllocationRuleList = res.Result
        this.TrialTaskInfo = Object.assign({}, res.OtherInfo)
        this.AutoAlloctionVisible = true
      }).catch(() => { this.loading = false })
    },
    getDoctorUserSelectList() {
      getDoctorUserSelectList(this.$route.query.trialId).then(res => {
        this.DoctorUserList = res.Result
        if (this.DoctorUserList.length > 0) {
          this.ReadingType = this.DoctorUserList[0].ReadingType
        }
      })
    },
    getList() {
      this.searchData.TrialId = this.$route.query.trialId
      this.loading = true
      getVisitTaskList(this.searchData).then(res => {
        this.loading = false
        this.OtherInfo = res.OtherInfo
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
      }).catch(() => { this.loading = false })
    },
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
    },
    handleReset2() {
      this.taskSearchData = taskSearchDataDefault()
      this.openAutoAlloction()
    },
    getSite() {
      getTrialSiteSelect(this.trialId).then(res => {
        this.siteOptions = res.Result
      })
    },
    // 排序
    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>
<style lang="scss" scoped>
  >>>.hidden-row{
    display: none;
  }
  >>>.el-dialog__body {
    padding: 15px 20px;
  }

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