<template>
  <div class="adReview_wrapper">
    <el-card v-if="isReadingShowSubjectInfo" shadow="never" :body-style="{ padding: '10px' }" style="margin-bottom:10px">
      <h4>
        <!-- 受试者： -->
        {{ $t('trials:adReview:title:subject') }}
        <span style="font-weight:normal">{{ subjectCode }} </span>
        <span style="font-weight:normal">({{ taskBlindName }})</span>
      </h4>
    </el-card>
    <el-card :body-style="{ padding: '10px' }" shadow="never">
      <!-- <div slot="header" class="clearfix">
        <span style="font-weight: bold;">评估结果</span>
      </div> -->
      <div slot="header" style="display: flex;flex-direction: row;justify-content: space-between;">
        <!-- 评估结果 -->
        <div style="font-weight: bold;">{{ $t('trials:adReview:title:result') }}</div>
        <div v-if="isExistsClinicalData">
          <!-- 临床数据 -->
          <el-button type="text" @click="previewCD">{{ $t('trials:adReview:title:clinicalData') }}</el-button>
        </div>
      </div>

      <el-table
        :data="adInfo.VisitInfoList"
        style="width: 100%"
      >
        <!-- 访视名称 -->
        <el-table-column
          prop="VisitName"
          :label="$t('trials:adReview:table:visitName')"
          show-overflow-tooltip
          width="150"
        />

        <!-- 评估结果 -->
        <el-table-column
          v-for="j in judgeQuestion"
          :key="j.armEnum"
          :label="j.armEnum===1?$t('trials:adReview:table:viewR1'):j.armEnum===2?$t('trials:adReview:table:viewR2'):$fd('ArmEnum', j.armEnum)"
          align="center"
          prop=""
        >
          <template>
            <el-table-column
              v-for="(qs,i) in j.judgeQuestionList"
              :key="i"
              prop=""
              :label="qs"
              show-overflow-tooltip
              width="150"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].QuestionType===1">
                  <span v-if="scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].DictionaryCode">{{ $fd(scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].DictionaryCode, parseInt(scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer )) }}</span>
                  <span v-else>{{ scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer }}</span>
                </div>
                <div v-else-if="scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].QuestionType===2">
                  <div v-if="scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer">
                    <span>{{ $fd('YesOrNo', scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer ) }}</span>
                    <!-- 查看详情 -->
                    <el-button
                      type="text"
                      style="margin-left:5px;"
                      @click="handleViewDetail(scope.row.VisitTaskInfoList[j.index].GlobalVisitTaskId)"
                    >
                      {{ $t('trials:adReview:table:view') }}
                    </el-button>
                  </div>

                  <div v-else>
                    {{ $fd('YesOrNo', scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer ) }}
                  </div>
                </div>
                <div v-else>{{ scope.row.VisitTaskInfoList[j.index].JudgeQuestionList[i].Answer }}</div>
              </template>
            </el-table-column>
          </template>
        </el-table-column>

        <!-- 查看详情 -->
        <el-table-column
          :label="criterionType === 10?$t('trials:adReview:table:visitInfoview'):$t('trials:adReview:table:view')"
          width="200"
        >
          <template slot-scope="scope">

            <!-- 查看R1详情 -->
            <el-button
              type="text"
              :title="$t('trials:adReview:table:viewR1')"
              @click="handleView(scope.row,1)"
            >
              R1
            </el-button>
            <!-- 查看R2详情 -->
            <el-button
              type="text"
              :title="$t('trials:adReview:table:viewR2')"
              @click="handleView(scope.row,2)"
            >
              R2
            </el-button>
          </template>
        </el-table-column>

        <!-- 全局详情 PCWG -->
        <el-table-column
          v-if="criterionType === 10"
          prop="VisitName"
          :label="$t('trials:adReview:table:glInfo')"
          show-overflow-tooltip
          width="150"
        >
          <template slot-scope="scope">
            <!-- 查看R1详情 -->
            <el-button
              v-if="scope.$index === adInfo.VisitInfoList.length -1"
              type="text"
              :title="$t('trials:adReview:table:viewR1')"
              @click="handleViewGl(scope.row,1)"
            >
              R1
            </el-button>
            <!-- 查看R2详情 -->
            <el-button
              v-if="scope.$index === adInfo.VisitInfoList.length -1"
              type="text"
              :title="$t('trials:adReview:table:viewR2')"
              @click="handleViewGl(scope.row,2)"
            >
              R2
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card :body-style="{ padding: '10px' }" class="box-mr">
      <div slot="header" class="clearfix">
        <!-- 裁判结果 -->
        <span style="font-weight: bold;">{{ $t('trials:adReview:title:adResult') }}</span>
      </div>
      <el-form
        ref="adForm"
        v-loading="loading"
        :model="adForm"
        style="width:800px"
        label-width="100"
      >
        <!-- 选择阅片人 -->
        <el-form-item
          :label="$t('trials:adReview:title:choseReader')"
          prop="judgeResultTaskId"
          :rules="[
            { required: true, message: this.$t('common:ruleMessage:select')},
          ]"
        >
          <el-radio-group
            v-model="adForm.judgeResultTaskId"
            :disabled="adInfo.ReadingTaskState >= 2"
          >
            <el-radio
              v-for="t in visitTaskArmList"
              :key="t.VisitTaskId"
              :label="t.VisitTaskId"
              @change="handleVisitTaskArmChange"
            >
              {{ $fd('ArmEnum', t.ArmEnum) }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 裁判原因 -->
        <el-form-item
          :label="$t('trials:adReview:title:adReason')"
          prop="judgeResultRemark"
          :rules="[
            { required: true, message: this.$t('common:ruleMessage:specify')},
            { max: 500, message: `${this.$t('common:ruleMessage:maxLength')} 500`, trigger: ['blur', 'change'] }
          ]"
        >
          <el-input
            v-model="adForm.judgeResultRemark"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 6}"
            :disabled="adInfo.ReadingTaskState >= 2"
          />
        </el-form-item>
        <!-- 截图说明 -->
        <el-form-item
          :label="$t('trials:adReview:title:screenShot')"
        >
          <el-upload
            :action="accept"
            :on-preview="handlePictureCardPreview"
            :before-upload="handleBeforeUpload"
            :http-request="uploadScreenshot"
            list-type="picture-card"
            :on-remove="handleRemove"
            :file-list="fileList"
            :class="{disabled:adInfo.ReadingTaskState >= 2}"
            :disabled="adInfo.ReadingTaskState >= 2"
          >
            <i slot="default" class="el-icon-plus" />
            <div slot="file" slot-scope="{file}">
              <img
                class="el-upload-list__item-thumbnail"
                :src="OSSclientConfig.basePath + file.url"
                alt=""
                crossorigin="anonymous"
              >
              <span class="el-upload-list__item-actions">
                <span
                  class="el-upload-list__item-preview"
                  @click="handlePictureCardPreview(file)"
                >
                  <i class="el-icon-zoom-in" />
                </span>

                <span
                  v-if="adInfo.ReadingTaskState < 2"
                  class="el-upload-list__item-delete"
                  @click="handleRemove(file)"
                >
                  <i class="el-icon-delete" />
                </span>
              </span>
            </div>
          </el-upload>
          <el-dialog
            append-to-body
            :visible.sync="imgVisible"
            width="600px"
          >
            <!-- <img width="100%" :src="imageUrl" alt="图片未找到"> -->
            <el-image :src="imageUrl" width="100%" crossorigin="anonymous">
              <div slot="placeholder" class="image-slot">
                {{ $t('trials:adReview:title:loading') }}<span class="dot">...</span>
              </div>
            </el-image>
          </el-dialog>
        </el-form-item>
        <el-form-item v-if="adInfo.ReadingTaskState < 2">
          <div style="text-align:center;">
            <!-- 保存 -->
            <el-button type="primary" @click="handleSave">{{ $t('common:button:save') }}</el-button>
            <!-- 提交 -->
            <el-button type="primary" @click="handleSubmit">{{ $t('common:button:submit') }}</el-button>
          </div>

        </el-form-item>
      </el-form>
    </el-card>

    <el-card v-if="isReadingShowPreviousResults" :body-style="{ padding: '10px' }">
      <div slot="header" class="clearfix">
        <!-- 既往裁判评估 -->
        <span style="font-weight: bold;">{{ $t('trials:adReview:title:previousRes') }}</span>
      </div>

      <el-table
        v-loading="priorLoading"
        :data="priorADList"
        style="width: 100%"
      >
        <!-- 裁判阅片 -->
        <el-table-column
          prop="TaskBlindName"
          :label="$t('trials:adReview:table:adReading')"
          show-overflow-tooltip
          width="200"
        />
        <el-table-column
          prop="JudgeResultArm"
          :label="$t('trials:adReview:table:adResult')"
          show-overflow-tooltip
          width="200"
        >
          <template slot-scope="scope">
            {{ $fd('ArmEnum', scope.row.JudgeResultArm) }}
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('common:action:action')"
          width="200"
        >
          <template slot-scope="scope">
            <!-- 查看详情 -->
            <el-button
              circle
              :title="$t('trials:adReview:table:view')"
              icon="el-icon-view"
              @click="handleViewDetail(scope.row.VisitTaskId)"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 签名框 -->
    <el-dialog
      v-if="signVisible"
      :visible.sync="signVisible"
      :close-on-click-modal="false"
      width="600px"
      custom-class="base-dialog-wrapper"
    >
      <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" @closeDialog="closeSignDialog" />
    </el-dialog>
  </div>
</template>
<script>
import { getJudgeReadingInfo,
  // uploadJudgeTaskImage,
  saveJudgeVisitTaskResult, submitJudgeVisitTaskResult, getReadingPastResultList } from '@/api/trials'
import { getAutoCutNextTask } from '@/api/user'
import const_ from '@/const/sign-code'
import { getToken } from '@/utils/auth'
import SignForm from '@/views/trials/components/newSignForm'
import DicomEvent from '@/views/trials/trials-panel/reading/dicoms/components/DicomEvent'
import store from '@/store'
import { changeURLStatic } from '@/utils/history.js'
export default {
  name: 'AdReview',
  components: { SignForm },
  props: {
    trialId: {
      type: String,
      required: true
    },
    subjectId: {
      type: String,
      required: true
    },
    visitTaskId: {
      type: String,
      required: true
    },
    readingCategory: {
      type: Number,
      required: true
    },
    subjectCode: {
      type: String,
      required: true
    },
    taskBlindName: {
      type: String,
      required: true
    },
    isReadingShowSubjectInfo: {
      type: Boolean,
      required: true
    },
    isReadingShowPreviousResults: {
      type: Boolean,
      required: true
    },
    isExistsClinicalData: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      adInfo: {},
      judgeQuestion: [],
      adForm: {
        visitTaskId: '',
        judgeResultTaskId: '',
        judgeResultRemark: '',
        // judgeResultImagePath: ''
        judgeResultImagePathList: []
      },
      currentUser: zzSessionStorage.getItem('userName'),
      signVisible: false,
      signCode: null,
      accept: '.png,.jpg,.jpeg',
      imgVisible: false,
      imageUrl: '',
      uploadDisabled: false,
      fileList: [],
      loading: false,
      visitTaskArmList: [],
      priorADList: [],
      priorLoading: false,
      judgeResultArmEnum: '',
      criterionType: null,
      openWindow: null
    }
  },
  // watch: {
  //   visitTaskId: {
  //     immediate: true,
  //     handler(val) {
  //       this.$nextTick(() => {
  //         this.getAdInfo()
  //         if (this.isReadingShowPreviousResults) {
  //           this.getPriorAdList()
  //         }
  //       })
  //     }
  //   }
  // },
  mounted() {
    this.criterionType = parseInt(this.$route.query.criterionType)
    this.getAdInfo()
    if (this.isReadingShowPreviousResults) {
      this.getPriorAdList()
    }
    DicomEvent.$on('resetOpenWindow', () => {
      if (this.openWindow) {
        this.openWindow.close()
      }
    })
  },
  beforeDestroy() {
    DicomEvent.$off('resetOpenWindow')
    if (this.openWindow) {
      this.openWindow.close()
    }
  },
  methods: {
    getAdInfo() {
      this.loading = true
      getJudgeReadingInfo({ visitTaskId: this.visitTaskId }).then(res => {
        var judgeQS = []
        if (res.Result.VisitInfoList.length > 0) {
          res.Result.VisitInfoList[0].VisitTaskInfoList.map((v, index) => {
            var qsObj = { armEnum: v.ArmEnum, judgeQuestionList: [], index: index }
            v.JudgeQuestionList.map(q => {
              if (q.QuestionType === 1) {
                qsObj.judgeQuestionList.push(q.QuestionName)
              } else if (q.QuestionType === 3 && this.criterionType === 10) {
                qsObj.judgeQuestionList.push(this.$t('trials:globalReview:table:visitRemark'))
              } else {
                qsObj.judgeQuestionList.push(this.$fd('JudgeReadingQuestionType', q.QuestionType))
              }
            })
            judgeQS.push(qsObj)
          })
        }
        this.judgeQuestion = judgeQS

        this.adInfo = res.Result
        this.adForm.judgeResultTaskId = res.Result.JudgeResultTaskId

        this.adForm.judgeResultRemark = res.Result.JudgeResultRemark
        this.fileList = []
        if (res.Result.JudgeResultImagePathList) {
          res.Result.JudgeResultImagePathList.map(url => {
            if (url) { this.fileList.push({ name: '', url: url }) }
          })
          this.adForm.judgeResultImagePathList = res.Result.JudgeResultImagePathList
        }
        this.visitTaskArmList = res.Result.VisitTaskArmList
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    getPriorAdList() {
      this.priorLoading = true
      getReadingPastResultList({ visitTaskId: this.visitTaskId }).then(res => {
        this.priorADList = res.Result
        this.priorLoading = false
      }).catch(() => { this.priorLoading = false })
    },
    handleVisitTaskArmChange(v) {
      var i = this.visitTaskArmList.findIndex(i => i.VisitTaskId === v)
      if (i > -1) {
        // 本人已完整查看两位独立阅片人的全部相关影像和评估数据，经过综合研判，更认同第一阅片人（R1）对该病例的整体评估，原因是：
        this.judgeResultArmEnum = this.visitTaskArmList[i].ArmEnum
        var msg = ''
        if (this.judgeResultArmEnum === 1) {
          msg = this.$t('trials:adReview:title:msg1')
        } else {
          msg = this.$t('trials:adReview:title:msg3')
        }
        // this.adForm.judgeResultRemark = `本人已完整查看两位独立阅片人的全部相关影像和评估数据，经过综合研判，更认同${this.$fd('ArmEnum', this.judgeResultArmEnum)}对该病例的整体评估，原因是：`
        this.adForm.judgeResultRemark = msg
      } else {
        this.judgeResultArmEnum = ''
      }
    },
    previewCD() {
      var token = getToken()
      const routeData = this.$router.resolve({
        path: `/clinicalData?subjectId=${this.subjectId}&trialId=${this.trialId}&visitTaskId=${this.visitTaskId}&TokenKey=${token}`
      })
      window.open(routeData.href, '_blank')
    },
    handleSave() {
      this.$refs['adForm'].validate((valid) => {
        if (!valid) return
        this.loading = true
        var paths = []
        this.fileList.map(file => {
          if (file.url) {
            paths.push(file.url)
          }
        })
        this.adForm.judgeResultImagePathList = paths
        this.adForm.visitTaskId = this.visitTaskId
        saveJudgeVisitTaskResult(this.adForm).then(res => {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      })
    },
    handleSubmit() {
      this.$refs['adForm'].validate((valid) => {
        if (!valid) return
        const { ImageAssessmentReportConfirmation } = const_.processSignature
        this.signCode = ImageAssessmentReportConfirmation
        this.signVisible = true
      })
    },
    // 关闭签名框
    closeSignDialog(isSign, signInfo) {
      if (isSign) {
        this.signConfirm(signInfo)
      } else {
        this.signVisible = false
      }
    },
    // 签名并确认
    signConfirm(signInfo) {
      this.loading = true
      var paths = []
      this.fileList.map(file => {
        paths.push(file.url)
      })
      var params = {
        data: {
          visitTaskId: this.visitTaskId,
          judgeResultTaskId: this.adForm.judgeResultTaskId,
          judgeResultRemark: this.adForm.judgeResultRemark,
          judgeResultImagePathList: paths
        },
        signInfo: signInfo
      }
      submitJudgeVisitTaskResult(params).then(async res => {
        if (res.IsSuccess) {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
          this.isEdit = false
          this.$refs['signForm'].btnLoading = false
          this.signVisible = false
          // window.location.reload()
          // window.opener.postMessage('refreshTaskList', window.location)
          // 设置当前任务阅片状态为已读
          this.adInfo.ReadingTaskState = 2
          var isAutoTask = await this.getAutoTaskVal()
          if (isAutoTask) {
            store.dispatch('reading/resetVisitTasks')
            DicomEvent.$emit('getNextTask')
          } else {
          // '当前阅片任务已完成，是否进入下一个阅片任务？'
            this.$confirm(this.$t('trials:adReview:title:msg2'), {
              type: 'warning',
              distinguishCancelAndClose: true
            })
              .then(() => {
                store.dispatch('reading/resetVisitTasks')
                DicomEvent.$emit('getNextTask')
              })
              .catch(action => {
                changeURLStatic('visitTaskId', this.visitTaskId)
              })
          }
          window.opener.postMessage('refreshTaskList', window.location)
        }
        this.loading = false
      }).catch(_ => {
        this.loading = false
        this.$refs['signForm'].btnLoading = false
      })
    },
    getAutoTaskVal() {
      return new Promise((resolve, reject) => {
        getAutoCutNextTask().then(res => {
          resolve(res.Result.AutoCutNextTask)
        }).catch(() => { reject() })
      })
    },
    handleViewDetail(visitTaskId) {
      if (this.openWindow) {
        this.openWindow.close()
      }
      var token = getToken()
      var criterionType = parseInt(localStorage.getItem('CriterionType'))
      var readingTool = this.$router.currentRoute.query.readingTool
      readingTool = isNaN(parseInt(readingTool)) ? null : parseInt(readingTool)
      var isReadingTaskViewInOrder = this.$router.currentRoute.query.isReadingTaskViewInOrder
      var trialReadingCriterionId = this.$router.currentRoute.query.TrialReadingCriterionId

      var path = ''
      if (readingTool === 0) {
        path = `/readingDicoms?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${visitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      } else {
        path = `/noneDicomReading?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${visitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      }
      var routeData = this.$router.resolve({ path })
      this.openWindow = window.open(routeData.href, '_blank')
    },
    handleView(row, armEnum) {
      if (this.openWindow) {
        this.openWindow.close()
      }
      // var token = getToken()
      // var task = row.VisitTaskInfoList.find(item => item.ArmEnum === armEnum)
      // const routeData = this.$router.resolve({
      //   path: `/readingPage?trialId=${this.trialId}&visitTaskId=${task.VisitTaskId}&TokenKey=${token}&isReadingShowPreviousResults=false`
      // })
      // window.open(routeData.href, '_blank')
      var token = getToken()
      var task = row.VisitTaskInfoList.find(item => item.ArmEnum === armEnum)
      var criterionType = this.$router.currentRoute.query.criterionType
      var readingTool = this.$router.currentRoute.query.readingTool
      readingTool = isNaN(parseInt(readingTool)) ? null : parseInt(readingTool)
      var isReadingTaskViewInOrder = this.$router.currentRoute.query.isReadingTaskViewInOrder
      var trialReadingCriterionId = this.$router.currentRoute.query.TrialReadingCriterionId

      var path = ''
      if (readingTool === 0) {
        path = `/readingDicoms?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${task.VisitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      } else {
        path = `/noneDicomReading?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${task.VisitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      }
      var routeData = this.$router.resolve({ path })
      this.openWindow = window.open(routeData.href, '_blank')
    },
    handleViewGl(row, armEnum) {
      if (this.openWindow) {
        this.openWindow.close()
      }
      var token = getToken()
      var task = row.VisitTaskInfoList.find(item => item.ArmEnum === armEnum)
      var criterionType = this.$router.currentRoute.query.criterionType
      var readingTool = this.$router.currentRoute.query.readingTool
      readingTool = isNaN(parseInt(readingTool)) ? null : parseInt(readingTool)
      var isReadingTaskViewInOrder = this.$router.currentRoute.query.isReadingTaskViewInOrder
      var trialReadingCriterionId = this.$router.currentRoute.query.TrialReadingCriterionId

      var path = ''
      if (readingTool === 0) {
        path = `/readingDicoms?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${task.GlobalVisitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      } else {
        path = `/noneDicomReading?TrialReadingCriterionId=${trialReadingCriterionId}&trialId=${this.trialId}&subjectCode=${this.subjectCode}&subjectId=${this.subjectId}&visitTaskId=${task.GlobalVisitTaskId}&isReadingTaskViewInOrder=${isReadingTaskViewInOrder}&criterionType=${criterionType}&readingTool=${readingTool}&TokenKey=${token}&key=${new Date().getTime()}`
      }
      var routeData = this.$router.resolve({ path })
      this.openWindow = window.open(routeData.href, '_blank')
    },
    // uploadScreenshot(param) {
    //   this.loading = true
    //   this.uploadDisabled = false
    //   const formData = new FormData()
    //   formData.append('file', param.file)
    //   uploadJudgeTaskImage(this.$route.query.trialId, this.visitTaskId, formData).then(res => {
    //     this.loading = false
    //     if (res.IsSuccess) {
    //       this.fileList.push({ name: res.Result.FileName, url: `${res.Result.Path}` })
    //     }
    //     this.uploadDisabled = true
    //   }).catch(() => {
    //     this.loading = false
    //   })
    // },
    async uploadScreenshot(param) {
      this.loading = true
      this.uploadDisabled = false
      var trialId = this.$route.query.trialId
      var file = await this.fileToBlob(param.file)
      const res = await this.OSSclient.put(`/${trialId}/Read/${this.subjectId}/visit/${param.file.name}`, file)
      console.log(res)
      this.fileList.push({ name: param.file.name, url: this.$getObjectName(res.url) })
      this.loading = false
      this.uploadDisabled = true
    },
    handleBeforeUpload(file) {
      // 检测文件类型是否符合要求
      if (this.checkFileSuffix(file.name)) {
        return true
      } else {
        const msg = this.$t('trials:adReview:title:msg4').replace('xxx', this.accept)
        this.$alert(msg)
        return false
      }
    },
    checkFileSuffix(fileName) {
      var index = fileName.lastIndexOf('.')
      var suffix = fileName.substring(index + 1, fileName.length)
      if (this.accept.toLocaleLowerCase().search(suffix.toLocaleLowerCase()) === -1) {
        return false
      } else {
        return true
      }
    },
    // 图片清空
    removeImage() {
      this.imageUrl = ''
      this.fileList = []
      this.adForm.judgeResultImagePath = ''
    },
    // 预览图片
    handlePictureCardPreview(file) {
      this.imageUrl = this.OSSclientConfig.basePath + file.url
      this.imgVisible = true
    },
    // 删除图片
    handleRemove(file, fileList) {
      var idx = this.fileList.findIndex(i => i.url === file.url)
      if (idx === -1) return
      this.fileList.splice(idx, 1)
    }
  }
}
</script>
<style lang="scss" scoped>
.adReview_wrapper{
  flex: 1;
  padding: 10px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  .box-mr{
    margin:10px 0;
  }
  .disabled{
    /deep/ .el-upload--picture-card {
      display: none;
    }
  }
  /deep/  .el-upload-list__item {
    transition: none !important;
  }
  /deep/  .el-upload-list__item-thumbnail {
      /* 图片在方框内显示长边 */
      object-fit: scale-down !important;
  }
}
</style>
