<template>
  <BaseContainer class="consistency-list">
    <!-- 搜索框 -->
    <template slot="search-container">
      <el-form :inline="true">
        <!-- 中心编号 -->
        <el-form-item :label="$t('trials:consistencyCheck:table:siteId')">
          <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:consistencyCheck:table:subjectId')">
          <el-input :maxLength="$inputMax" v-model="searchData.SubjectInfo" style="width:100px;" />
        </el-form-item>
        <!-- 访视名称 -->
        <el-form-item class="my_multiple" :label="$t('trials:consistencyCheck:table:visitName')">
          <el-select
            v-model="searchData.VisitPlanArray"
            style="width:140px"
            clearable
            multiple
          >
            <el-option
              v-for="(item, index) of visitPlanOptions"
              :key="index"
              :label="item.VisitName"
              :value="item.VisitNum"
            >
              <span style="float: left">{{ item.VisitName }}</span>
            </el-option>
            <el-option
              key="Other"
              label="OutPlan"
              value="1.11"
            />
          </el-select>
        </el-form-item>
        <!-- 核查状态 -->
        <el-form-item :label="$t('trials:consistencyCheck:table:checkState')">
          <el-select v-model="searchData.CheckState" clearable style="width:120px">
            <el-option v-for="item of $d.CheckState" :key="item.value" :value="item.value" :label="item.label" />
          </el-select>
        </el-form-item>
        <!-- 查询 -->
        <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-download" @click="handleExport(1)">
          {{ $t('trials:consistencyCheck:button:export1') }}
        </el-button>
        <!-- 导出一致性核查记录表 -->
        <el-button type="primary" icon="el-icon-download" @click="handleExport(2)">
          {{ $t('trials:consistencyCheck:button:export2') }}
        </el-button>
        <!-- 下载模板 -->
        <el-button
          type="primary"
          icon="el-icon-download"
          @click="handleDownload"
        >
          {{ $t('trials:consistencyCheck:button:download') }}
        </el-button>
      </el-form>
      <!-- 上传 -->
      <el-button
        v-hasPermi="['trials:trials-panel:visit:consistency-check:upload']"
        type="primary"
        icon="el-icon-upload2"
        style="margin-left:auto;"
        @click="handleOpenUploadDialog"
      >
        {{ $t('trials:consistencyCheck:button:upload') }}
      </el-button>
    </template>

    <!-- 一致性核查列表 -->
    <template slot="main-container">
      <el-table
        ref="consistencyTable"
        v-loading="loading"
        v-adaptive="{bottomOffset:60}"
        :data="list"
        stripe
        height="100"
        @sort-change="handleSortByColumn"
      >
        <el-table-column type="index" width="40" />
        <!-- 是否加急 -->
        <el-table-column
          prop="IsUrgent"
          :label="$t('trials:consistencyCheck: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="CheckChallengeState"
          :label="$t('trials:consistencyCheck:table:checkChallengeState')"
          show-overflow-tooltip
          min-width="130"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.CheckChallengeState === 0"> -- </span>
            <el-tag v-else-if="scope.row.CheckChallengeState === 1" type="danger">
              {{ userTypeEnumInt === 2? $fd('CheckChallengeState', 1) : $fd('CheckChallengeState', 2) }}
            </el-tag>
            <el-tag v-else-if="scope.row.CheckChallengeState === 2" type="danger">
              {{ userTypeEnumInt === 2?$fd('CheckChallengeState', 2) : $fd('CheckChallengeState', 1) }}
            </el-tag>
            <el-tag v-else-if="scope.row.CheckChallengeState === 3">{{ $fd('CheckChallengeState', scope.row.CheckChallengeState) }}</el-tag>
          </template>
        </el-table-column>
        <!-- 中心编号 -->
        <el-table-column
          prop="TrialSiteCode"
          :label="$t('trials:consistencyCheck:table:siteId')"
          show-overflow-tooltip
          min-width="100"
          sortable="custom"
        />
        <!-- 受试者编号 -->
        <el-table-column
          prop="SubjectCode"
          :label="$t('trials:consistencyCheck:table:subjectId')"
          show-overflow-tooltip
          min-width="110"
          sortable="custom"
        />
        <!-- 访视名称 -->
        <el-table-column
          prop="VisitName"
          :label="$t('trials:consistencyCheck:table:visitName')"
          show-overflow-tooltip
          min-width="100"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.VisitName }}</span>
            <span v-if="scope.row.IsCheckBack" class="status-primary-circle">回</span>
          </template>
        </el-table-column>

        <!-- 检查类型 -->
        <el-table-column
          prop="Modalitys"
          :label="$t('trials:consistencyCheck:table:modality')"
          show-overflow-tooltip
          min-width="100"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.Modalitys }}</span>
          </template>
        </el-table-column>

        <!-- 检查日期 -->
        <el-table-column
          prop="LatestScanDate"
          :label="$t('trials:consistencyCheck:table:scanDate')"
          show-overflow-tooltip
          min-width="100"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.LatestScanDate.split(' ')[0] }}</span>
          </template>
        </el-table-column>

        <!-- 核查前状态 -->
        <!-- <el-table-column
          prop="AuditState"
          :label="$t('trials:consistencyCheck:table:auditState')"
          show-overflow-tooltip
          min-width="120"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.AuditState*1 === 0">--</span>
            <el-tag v-else-if="scope.row.AuditState*1 === 3" type="warning">{{ $fd('AuditStatePE', scope.row.AuditState*1) }}</el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 4 && scope.row.QCProcessEnum === 1" type="warning">
              {{ $fd('AuditStatePE', scope.row.AuditState*1) }}
            </el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 4 && scope.row.QCProcessEnum === 2" type="warning">
              {{ $fd('AuditStateRC', scope.row.AuditState*1) }}
            </el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 5" type="warning">
              {{ $fd('AuditStateRC', scope.row.AuditState*1) }}
            </el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 6" type="warning">
              {{ $fd('AuditStateRC', scope.row.AuditState*1) }}
            </el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 7" type="danger"> {{ $fd('AuditStateRC', scope.row.AuditState*1) }}</el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 8 && scope.row.QCProcessEnum !== 0"> {{ $fd('AuditStateRC', scope.row.AuditState*1) }}</el-tag>
            <el-tag v-else-if="scope.row.AuditState*1 === 8 && scope.row.QCProcessEnum === 0">{{ $fd('SubmitState', 2) }}</el-tag>
          </template>
        </el-table-column> -->
        <!-- 回退状态 -->
        <el-table-column
          prop="RequestBackState"
          :label="$t('trials:consistencyCheck:table:requestBackState')"
          show-overflow-tooltip
          min-width="120"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.RequestBackState*1 === 0">{{ $fd('RequestBackState', scope.row.RequestBackState*1) }}</span>
            <el-tag v-else-if="scope.row.RequestBackState*1 === 1">{{ $fd('RequestBackState', scope.row.RequestBackState*1) }}</el-tag>
            <el-tag v-else-if="scope.row.RequestBackState*1 === 2" type="warning">{{ $fd('RequestBackState', scope.row.RequestBackState*1) }}</el-tag>
            <el-tag v-else-if="scope.row.RequestBackState*1 === 3" type="danger">{{ $fd('RequestBackState', scope.row.RequestBackState*1) }}</el-tag>
          </template>
        </el-table-column>
        <!-- 核查时间 -->
        <el-table-column
          prop="CheckTime"
          :label="$t('trials:consistencyCheck:table:checkTime')"
          show-overflow-tooltip
          min-width="150"
          sortable="custom"
        />
        <!-- 核查通过时间 -->
        <el-table-column
          prop="CheckPassedTime"
          :label="$t('trials:consistencyCheck:table:checkPassedTime')"
          show-overflow-tooltip
          min-width="150"
          sortable="custom"
        />
        <!-- 核查状态 -->
        <el-table-column
          prop="CheckState"
          :label="$t('trials:consistencyCheck:table:checkState')"
          show-overflow-tooltip
          min-width="120"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.CheckState === 0"> -- </span>
            <el-tag v-else-if="scope.row.CheckState === 9" type="danger">{{ $fd('CheckState', scope.row.CheckState) }}</el-tag>
            <el-tag v-else-if="scope.row.CheckState === 10" type="danger">{{ $fd('CheckState', scope.row.CheckState) }}</el-tag>
            <el-tag v-else-if="scope.row.CheckState === 11">{{ $fd('CheckState', scope.row.CheckState) }}</el-tag>
          </template>
        </el-table-column>
        <!-- 不一致项 -->
        <el-table-column
          prop="CheckResult"
          :label="$t('trials:consistencyCheck:table:checkResult')"
          show-overflow-tooltip
          min-width="120"
        />
        <el-table-column
          v-if="hasPermi(['trials:trials-panel:visit:consistency-check:reply', 'trials:trials-panel:visit:consistency-check:apply-fallback','trials:trials-panel:visit:consistency-check:fallback','trials:trials-panel:visit:consistency-check:close','trials:trials-panel:visit:consistency-check:pass'])"
          :label="$t('common:action:action')"
          width="200"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              circle
              :title="$t('trials:consistencyCheck:action:reply')"
              :disabled="scope.row.CheckState < 10"
              icon="el-icon-chat-dot-square"
              @click="handleReply(scope.row)"
            />
            <!-- 关闭 -->
            <el-button
              v-hasPermi="['trials:trials-panel:visit:consistency-check:close']"
              circle
              :title="$t('trials:consistencyCheck:action:close')"
              icon="el-icon-close"
              :disabled="scope.row.CheckChallengeState === 0 || scope.row.CheckChallengeState === 3 || scope.row.RequestBackState === 1"
              @click="handleOpenReason(scope.row, 'close')"
            />
            <!-- 通过 -->
            <el-button
              v-hasPermi="['trials:trials-panel:visit:consistency-check:pass']"
              circle
              :title="$t('trials:consistencyCheck:action:pass')"
              icon="el-icon-circle-check"
              :disabled="scope.row.CheckState === 11 || scope.row.CheckChallengeState === 1 || scope.row.CheckChallengeState === 2"
              @click="handleOpenReason(scope.row, 'pass')"
            />
          </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="chatVisible"
      v-dialogDrag
      :visible.sync="chatVisible"
      :close-on-click-modal="false"
      width="800px"
      :title="$t('trials:consistencyCheck:dialogTitle:qsContent') + `(${currentRow.SubjectCode} ${currentRow.VisitName})`"
    >
      <ConsistencyCheckForm ref="chatForm" :data="currentRow" :is-reply="isReply" :dialog-list="currentDialogList" @close="chatVisible = false" @getDialogList="getDialogList" @handleApplyBack="handleApplyBack" @handleBack="handleBack" />
    </el-dialog>

    <!-- 签名 -->
    <el-dialog
      v-if="signVisible"
      :visible.sync="signVisible"
      :close-on-click-modal="false"
      width="600px"
    >
      <div slot="title">
        <span style="font-size:18px;">{{ $t('common:dialogTitle:sign') }}</span>
        <span style="font-size:12px;margin-left:5px">{{ `(${$t('common:label:sign')}${ currentUser })` }}</span>
      </div>
      <SignForm ref="signForm" :sign-code-enum="signCode" :subject-visit-id="currentRow.Id" @closeDialog="closeSignDialog" />
    </el-dialog>

    <!-- 原因 -->
    <el-dialog
      v-if="ReasonVisible"
      :visible.sync="ReasonVisible"
      :close-on-click-modal="false"
      append-to-body
      custom-class="base-dialog-wrapper"
      :width="currentRow.type === 'pass' ? '750px' : '600px'"
      :title="ReasonTitle"
    >
      <div style="padding:10px;border: 1px solid #e0e0e0;max-height:650px;overflow-y: auto;">
        <el-form
          ref="reasonForm"
          :rules="rules"
          :model="QuestionForm"
          class="demo-ruleForm"
          size="small"
          label-width="120px"
        >
          <el-form-item
            :label="$t(`trials:qcQuality:label:${currentRow.type}Reason`)"
            prop="Type"
            :rules="[
              { required: true, message: $t('common:ruleMessage:select')},
            ]"
          >
            <el-radio-group v-model="QuestionForm.Type" @change="typeChange">
              <!-- 问题已解决 -->
              <el-radio :label="1">{{ $t(`trials:check:radio:${currentRow.type}reason${1}`) }}</el-radio>
              <!-- 问题无法解决强制关闭质疑 -->
              <el-radio :label="2">{{ $t(`trials:check:radio:${currentRow.type}reason${2}`) }}</el-radio>
              <!-- 其他 -->
              <el-radio v-if="currentRow.type === 'pass'" :label="3">{{ $t(`trials:check:radio:${currentRow.type}reason${3}`) }}</el-radio>
              <!-- 其他 -->
              <el-radio v-if="currentRow.type === 'pass'" :label="4">{{ $t(`trials:check:radio:${currentRow.type}reason${4}`) }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- 原因 -->
          <el-form-item v-if="(currentRow.type === 'pass' && QuestionForm.Type === 4) || (currentRow.type !== 'pass' && QuestionForm.Type === 2)" :label="$t(`trials:consistencyCheck:label:${currentRow.type}reason`)" prop="Remake">
            <el-input :maxLength="$inputMax"
              v-model="QuestionForm.Remake"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4}"
              :placeholder="$t('common:ruleMessage:specify')"
              maxlength="500"
              show-word-limit
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <!-- 取消 -->
        <el-button :disabled="btnLoading" size="small" type="primary" @click="ReasonVisible = false;QuestionForm = { Type: null, Reason: null }">
          {{ $t('common:button:cancel') }}
        </el-button>
        <!-- 保存 -->
        <el-button :loading="btnLoading" size="small" type="primary" @click="passOrCloes">
          {{ $t('common:button:save') }}
        </el-button>
      </div>
    </el-dialog>

    <base-model :config="upload_cfg">
      <template slot="dialog-body">
        <UploadExcel @refreshTable="refreshTable" />
      </template>
    </base-model>
  </BaseContainer>
</template>
<script>
import { getConsistencyVerificationList, getTrialSiteSelect, getTrialVisitStageSelect, cRCRequstCheckBack,
  closeCheckChallenge, setCheckPass, getCheckChallengeDialogList } from '@/api/trials'
import { DownloadCommonDoc } from '@/api/dictionary'
import { getDicomAndNoneDicomStudyList_Export, getConsistencyVerificationList_Export } from '@/api/export'
import { checkBack } from '@/api/trials/visit'
import BaseContainer from '@/components/BaseContainer'
import BaseModel from '@/components/BaseModel'
import ConsistencyCheckForm from './components/consistencyCheckForm'
import UploadExcel from './components/uploadExcel'
import SignForm from '@/views/trials/components/newSignForm'
import Pagination from '@/components/Pagination'
import const_ from '@/const/sign-code'
const searchDataDefault = () => {
  return {
    SiteId: '',
    SubjectInfo: '',
    VisitPlanArray: [],
    CheckState: null,
    PageIndex: 1,
    PageSize: 20
  }
}
export default {
  name: 'ConsistencyCheck',
  components: { BaseContainer, Pagination, ConsistencyCheckForm, UploadExcel, BaseModel, SignForm },
  data() {
    return {
      QuestionForm: {
        Type: null,
        Reason: null,
        Remake: null
      },
      searchData: searchDataDefault(),
      ReasonVisible: false,
      total: 0,
      list: [],
      btnLoading: false,
      loading: false,
      chatVisible: false,
      currentRow: {},
      currentDialogList: [],
      siteOptions: [],
      visitPlanOptions: [],
      userTypeEnumInt: zzSessionStorage.getItem('userTypeEnumInt') * 1,
      upload_cfg: { visible: false, title: this.$t('trials:consistencyCheck:button:upload'), width: '500px', showClose: true },
      rules: {
        Type: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }],
        Remake: [{ required: true, message: this.$t('common:ruleMessage:specify'), trigger: 'blur' }]
      },
      signVisible: false,
      signType: 0, // 0代表申请，1代表回退,2通过
      currentUser: zzSessionStorage.getItem('userName'),
      OtherInfo: {},
      signCode: '',
      trialId: this.$route.query.trialId,
      isReply: false,
      ReasonTitle: null
    }
  },
  mounted() {
    this.getList()
    this.getSite()
    this.getVisitPlanOptions()
  },
  methods: {
    handleExport(type) {
      if (type === 1) {
        getDicomAndNoneDicomStudyList_Export(this.searchData).then(res => {
        }).catch(() => { this.loading = false })
      } else {
        getConsistencyVerificationList_Export(this.searchData).then(res => {
        }).catch(() => { this.loading = false })
      }
    },
    typeChange(v) {
      if (v === (this.currentRow.type === 'pass' ? 4 : 2)) {
        this.QuestionForm.Reason = null
        this.QuestionForm.Remake = null
      } else {
        this.QuestionForm.Reason = this.$t(`trials:check:radio:${this.currentRow.type}reason${v}`)
      }
    },
    passOrCloes() {
      if (this.currentRow.type === 'pass') {
        this.pass()
      } else {
        this.handleClose(this.currentRow)
      }
    },
    handleOpenReason(row, type) {
      if (type === 'pass') {
        // 手动通过一次性核查原因
        this.ReasonTitle = this.$t('trials:consistencyCheck:dialogTitle:xfpassManually')
      } else {
        // 关闭一致性核查原因
        this.ReasonTitle = this.$t('trials:consistencyCheck:dialogTitle:xfclose')
      }
      this.currentRow = { ...row, Reason: null }
      this.currentRow.type = type
      this.QuestionForm = {
        Type: null,
        Reason: null,
        Remake: null
      }
      this.ReasonVisible = true
    },
    // 获取质疑列表
    getList() {
      this.loading = true
      this.searchData.TrialId = this.trialId
      getConsistencyVerificationList(this.searchData).then(res => {
        this.loading = false
        this.list = res.Result.CurrentPageData
        this.total = res.Result.TotalCount
        this.OtherInfo = res.OtherInfo
      }).catch(() => { this.loading = false })
    },
    // 回复质疑
    handleReply(row) {
      this.loading = true
      getCheckChallengeDialogList(row.Id).then(res => {
        this.loading = false
        if (res.IsSuccess) {
          Object.assign(row, res.Result.SubjectVisitCheck)
          this.currentRow = { ...row }
          this.currentDialogList = res.Result.DialogList
          this.isReply = true
          this.chatVisible = true
        }
      }).catch(() => { this.loading = false })
    },
    getDialogList() {
      this.loading = true
      this.$refs['chatForm'].loading = true
      getCheckChallengeDialogList(this.currentRow.Id).then(res => {
        this.loading = false
        if (res.IsSuccess) {
          var i = this.list.findIndex(item => item.Id === this.currentRow.Id)
          if (i > -1) {
            this.currentRow = Object.assign(this.list[i], res.Result.SubjectVisitCheck)
            this.currentDialogList = res.Result.DialogList
            this.$refs['chatForm'].addMessage(res.Result.DialogList[res.Result.DialogList.length - 1])
            // this.$refs['chatForm'].getMessageList(res.Result.DialogList)
          }
        }
      }).catch(() => {
        this.loading = false
        this.$refs['chatForm'].loading = false
      })
    },
    // 回退
    // handleBack(row) {
    //   this.signType = 1
    //   this.currentRow = { ...row }
    //   const { DataFallback } = const_.processSignature
    //   this.signCode = DataFallback
    //   this.signVisible = true
    // },
    handleBack() {
      this.signType = 1
      const { DataFallback } = const_.processSignature
      this.signCode = DataFallback
      this.signVisible = true
    },
    pass() {
      this.$refs.reasonForm.validate((valid) => {
        if (!valid) return
        this.btnLoading = true
        if (this.QuestionForm.Type === 4) {
          // 问题无法解决强制关闭质疑，已提醒中心下次注意
          this.QuestionForm.Reason = `${this.QuestionForm.Remake}`
        }
        var params = {
          Id: this.currentRow.Id,
          ManualPassReason: this.QuestionForm.Reason
        }
        setCheckPass(this.trialId, params)
          .then(res => {
            this.btnLoading = false
            if (res.IsSuccess) {
              this.getList()
              this.QuestionForm.Type = null
              this.ReasonVisible = false
              this.$message.success(this.$t('common:message:savedSuccessfully'))
            }
          }).catch(() => {
            this.btnLoading = false
          })
      })
    },
    back(signInfo) {
      this.loading = true
      var params = {
        data: { id: this.currentRow.Id },
        signInfo: signInfo
      }
      checkBack(params)
        .then(res => {
          this.loading = false
          if (signInfo) {
            this.$refs['signForm'].btnLoading = false
            this.signVisible = false
          }
          if (res.IsSuccess) {
            this.getList()
            // this.getDialogList()
            this.chatVisible = false
            // 回退成功
            this.$message.success(this.$t('trials:consistencyCheck:message:fallbackSuccessfully'))
          }
        }).catch(() => {
          this.loading = false
          if (signInfo) {
            this.$refs['signForm'].btnLoading = false
          }
        })
    },
    // 关闭质疑
    handleClose(row) {
      this.$refs.reasonForm.validate((valid) => {
        if (!valid) return
        var item = Object.assign({}, row)
        item.CheckChallengeState = 3
        this.btnLoading = true
        if (this.QuestionForm.Type === 2) {
          // 问题无法解决强制关闭质疑，已提醒中心下次注意
          this.QuestionForm.Reason = `${this.$t('trials:qcQuality:message:problemNotSolved')}<br/><br/>${this.$t('trials:consistencyCheck:title:note')}${this.QuestionForm.Remake}`
        }
        var params = {
          SubjectVisitId: row.Id,
          CloseCheckChallenge: this.QuestionForm.Reason
        }
        closeCheckChallenge(this.trialId, params)
          .then(res => {
            this.btnLoading = false
            if (res.IsSuccess) {
              this.getList()
              this.ReasonVisible = false
              this.QuestionForm.Type = null
              // 关闭成功
              this.$message.success(this.$t('trials:consistencyCheck:message:closedSuccessfully'))
            }
          }).catch(() => {
            this.btnLoading = false
          })
      })
    },
    handleDownload() {
      this.loading = true
      DownloadCommonDoc('VisitCheck_Template').then(data => {
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    // 打开上传excel弹窗
    handleOpenUploadDialog() {
      this.upload_cfg.visible = true
    },
    // 查看
    handleView(row) {
      this.currentRow = { ...row }
      this.isReply = false
      this.chatVisible = true
    },
    // crc申请回退
    // handleApplyBack(row) {
    //   this.$confirm(this.$t('trials:consistencyCheck:message:apply'), {
    //     type: 'warning',
    //     distinguishCancelAndClose: true
    //   })
    //     .then(() => {
    //       this.currentRow = { ...row }
    //       this.apply()
    //     }).catch(() => {})
    // },
    handleApplyBack() {
      this.$confirm(this.$t('trials:consistencyCheck:message:apply'), {
        type: 'warning',
        distinguishCancelAndClose: true
      })
        .then(() => {
          this.apply()
        }).catch(() => {})
    },
    apply() {
      this.loading = true
      cRCRequstCheckBack(this.trialId, this.currentRow.Id)
        .then(res => {
          this.loading = false
          if (res.IsSuccess) {
            // this.getList()
            this.getDialogList()
            // 申请成功
            // this.$message.success(this.$t('trials:consistencyCheck:message:appledSuccessfully'))
          }
        }).catch(() => {
          this.loading = false
        })
    },
    // 关闭签名弹窗
    closeSignDialog(isRefresh, signInfo) {
      if (!isRefresh) {
        this.signVisible = false
      } else {
        // 1代表回退,2通过
        if (this.signType === 1) {
          this.back(signInfo)
        }
      }
    },
    // 通过一致性核查
    handlePassCheck(row) {
      this.signType = 2
      this.currentRow = { ...row }
      const { ConsistencyCheckPassed } = const_.processSignature
      this.signCode = ConsistencyCheckPassed
      this.signVisible = true
    },
    // 重置
    handleReset() {
      this.searchData = searchDataDefault()
      this.getList()
      this.$nextTick(() => {
        this.$refs.consistencyTable.clearSort()
      })
    },
    // 查询
    handleSearch() {
      this.searchData.PageIndex = 1
      this.getList()
    },
    // 排序
    handleSortByColumn(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()
    },
    refreshTable() {
      this.upload_cfg.visible = false
      this.getList()
    },
    // 获取site下拉框数据
    getSite() {
      getTrialSiteSelect(this.trialId).then(res => {
        this.siteOptions = res.Result
      })
    },
    // 获取访视下拉框数据
    getVisitPlanOptions() {
      getTrialVisitStageSelect(this.trialId)
        .then((res) => {
          this.visitPlanOptions = res.Result
        })
    }
  }
}
</script>
<style lang="scss">
.consistency-list{
    .is-circle-urgent-red{
      border-radius: 50%;
      padding: 7px;
      line-height: 1;
      background-color: #f56c6c;
      width: 28px;
      color: #fff;
      border: 1px solid #DCDFE6;
    }
    .is-circle-urgent{
      border-radius: 50%;
      padding: 7px;
      line-height: 1;
      width: 28px;
      border: 1px solid #DCDFE6;
      font-size: 12px;
    }
    .status-primary-circle{
      display: inline-block;
      width:20px;
      height:20px;
      text-align: center;
      line-height: 20px;
      border-radius: 50%;
      background: #f56c6c;
      color:#fff;
      font-size: 10px;
  }
}
</style>
