<template>
  <div class="uploadList">
    <el-divider content-position="left">{{
      $t("trials:uploadImage:button:uploadTableTitle")
    }}</el-divider>
    <div class="top" style="margin-bottom: 10px">
      <el-button
        type="primary"
        size="small"
        v-if="!isLoad"
        style="position: relative;
}"
      >
        <span style="opacity: 0">{{
          $t("trials:uploadImage:button:selectFolder")
        }}</span>
        <label for="file">
          {{ $t("trials:uploadImage:button:selectFolder") }}
        </label>
      </el-button>
      <el-button
        type="primary"
        size="small"
        class="el-icon-upload2"
        @click.stop="notUp"
        v-else
      >
        {{ $t("trials:uploadImage:button:selectFolder") }}
      </el-button>
      <input
        type="file"
        name="file"
        id="file"
        ref="file"
        style="display: none"
        webkitdirectory
        multiple
        @change="beginScanFiles($event)"
      />
    </div>
    <!--本地影像检查-->
    <el-table
      :data="uploadList"
      style="width: 100%"
      v-adaptive="{ bottomOffset: 50 }"
    >
      <el-table-column type="index" width="40" />
      <!--检查信息-->
      <el-table-column min-width="200" show-overflow-tooltip>
        <template slot="header">
          <el-tooltip placement="top">
            <div slot="content">
              {{ $t("trials:uploadImage:table:studyDetail1") }}<br />
              {{ $t("trials:uploadImage:table:studyDetail2") }}<br />
              {{ $t("trials:uploadedDicoms:table:studyDate") }}
            </div>
            <span>{{ $t("trials:uploadImage:table:studyInfo") }}</span>
          </el-tooltip>
        </template>
        <template slot-scope="scope">
          <div style="line-height: 15px">
            <div>
              <div>
                <span>
                  <span style="font-weight: 500">Acc:</span>
                  <span
                    :class="{
                      colorOfRed: !scope.row.dicomInfo.AccessionNumber,
                    }"
                    >{{ scope.row.dicomInfo.AccessionNumber || "N/A" }}</span
                  >
                </span>
              </div>
              <div style="display: inline-block; margin-right: 2px">
                <span v-if="scope.row.dicomInfo.Modalities.length > 0">
                  {{ scope.row.dicomInfo.Modalities.join("、") }},
                </span>
                <span v-else style="color: #f44336">N/A,</span>
              </div>
              <div style="display: inline-block; margin-right: 2px">
                <span v-if="scope.row.SeriesInstanceUidList.length"
                  >{{ scope.row.SeriesInstanceUidList.length }} Series,
                </span>
                <span v-else style="color: #f44336">N/A,</span>
              </div>
              <div style="display: inline-block">
                <span v-if="scope.row.count"
                  >{{ scope.row.count }} Instances
                </span>
                <span v-else style="color: #f44336">N/A</span>
              </div>
            </div>

            <div>
              <div style="display: inline-block; margin-right: 2px">
                <span v-if="scope.row.dicomInfo.seriesBodyPartExamined">
                  {{ scope.row.dicomInfo.seriesBodyPartExamined }},
                </span>
                <span v-else style="color: #f44336">N/A, </span>
              </div>
              <div style="display: inline-block">
                <span v-if="scope.row.dicomInfo.StudyDescription">
                  {{ scope.row.dicomInfo.StudyDescription }}</span
                >
                <span v-else style="color: #f44336">N/A</span>
              </div>
            </div>
            <div>
              {{ scope.row.dicomInfo.StudyTime }}
            </div>
          </div>
        </template>
      </el-table-column>
      <!--患者信息-->
      <el-table-column min-width="130" show-overflow-tooltip>
        <template slot="header">
          <el-tooltip placement="top">
            <div slot="content">
              {{ $t("trials:uploadImage:table:pId") }}<br />
              {{ $t("trials:uploadImage:table:patientName") }}<br />
              {{ $t("trials:uploadImage:table:pInfo") }}
            </div>
            <span>{{ $t("trials:uploadImage:table:patientInfo") }}</span>
          </el-tooltip>
        </template>
        <template slot-scope="scope">
          <div style="line-height: 15px">
            <div>
              <span v-if="scope.row.dicomInfo.PatientId"
                ><span style="font-weight: 500">PID: </span
                >{{ scope.row.dicomInfo.PatientId }}</span
              >
              <span v-else style="color: #f44336">N/A</span>
            </div>
            <div>
              <span
                :class="[scope.row.dicomInfo.PatientName ? '' : 'colorOfRed']"
              >
                {{ scope.row.dicomInfo.PatientName || "N/A" }}
              </span>
            </div>
            <div>
              <span
                :class="[scope.row.dicomInfo.PatientSex ? '' : 'colorOfRed']"
              >
                {{ scope.row.dicomInfo.PatientSex || "N/A" }},
              </span>

              <span
                :class="[scope.row.dicomInfo.PatientAge ? '' : 'colorOfRed']"
              >
                {{ scope.row.dicomInfo.PatientAge || "N/A" }},
              </span>

              <span
                :class="[
                  scope.row.dicomInfo.PatientBirthDate ? '' : 'colorOfRed',
                ]"
              >
                {{ scope.row.dicomInfo.PatientBirthDate || "N/A" }}
              </span>
            </div>
          </div>
        </template>
      </el-table-column>
      <!--上传进度-->
      <el-table-column
        prop="schedule"
        :label="$t('trials:uploadImage:table:schedule')"
        min-width="150"
      >
        <template slot-scope="scope">
          <el-progress
            color="#409eff"
            :percentage="scope.row.schedule"
            v-if="scope.row.schedule || scope.row.schedule === 0"
          />
        </template>
      </el-table-column>
      <!--上传状态-->
      <el-table-column
        prop="status"
        :label="$t('trials:uploadImage:table:status')"
        min-width="120"
      >
        <template slot-scope="scope">
          <el-tag
            :type="
              ['warning', 'success', 'danger', 'primary', 'success', 'danger'][
                scope.row.status
              ]
            "
            v-if="scope.row.status || scope.row.status === 0"
            >{{ $fd("UploadStatus", scope.row.status) }}
          </el-tag>
        </template>
      </el-table-column>
      <!--已有/成功/失败-->
      <el-table-column
        prop="scheduleNum"
        :label="$t('trials:uploadImage:table:scheduleNum')"
        min-width="140"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.count">{{
            `${scope.row.count} /${scope.row.successCount} / ${scope.row.failCount}`
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('common:action:action')"
        fixed="right"
        width="140"
      >
        <!-- <template slot-scope="scope">
        </template> -->
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import {
  preArchiveDicomStudy,
  addOrUpdateArchiveTaskStudy,
} from "@/api/load.js";
import { parseDicom, getThumbnail, dicomToOSS } from "@/utils/parseDicom.js";
import store from "@/store";
export default {
  name: "uploadList",
  props: {
    SopInstanceUidList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    StudyInstanceUidList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    UploadStudyList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isLoad: false,
      uploadList: [], // 待上传文件列表
      dicomList: [], // 上传的文件列表
      requestNum: 6,
      hasOtherStudy: false, // 是否上传文件检查与列表不一致
      isClose: false,
    };
  },
  watch: {
    isLoad() {
      store.dispatch("trials/setUnLock", this.isLoad);
      if (!this.isLoad) {
        this.$refs.file.value = null;
        if (this.dicomList.some((item) => item.isUpload === 3)) {
          this.$confirm(this.$t("trials:uploadImage:confirm:failUpload"), {
            type: "warning",
            distinguishCancelAndClose: true,
            confirmButtonText: this.$t("common:button:confirm"),
            cancelButtonText: this.$t("common:button:cancel"),
          })
            .then(() => {
              this.againUpload();
            })
            .catch((err) => {
              console.log(err);
            });
        }
      }
    },
  },
  methods: {
    // 失败重传
    againUpload() {
      for (let i = 0; i < this.uploadList.length; i++) {
        let item = this.uploadList[i];
        if (item.status > 2) continue;
        item.status = 0;
        item.failCount = 0;
        item.schedule = Math.floor(
          ((item.successCount + item.failCount) / item.count) * 100
        );
        let arr = this.dicomList.filter(
          (dicom) =>
            dicom.StudyInstanceUid === item.StudyInstanceUid &&
            dicom.isUpload === 3
        );
        arr.forEach((item) => (item.isUpload = 0));
        this.setUploadTask(arr);
      }
    },
    async setUploadTask(arr) {
      let num = arr.length > this.requestNum ? this.requestNum : arr.length;
      let funArr = [];
      for (let i = 0; i < num; i++) {
        funArr.push(this.handleUploadTask(arr, i));
      }
      if (funArr.length > 0) {
        let res = await Promise.all(funArr);
      }
    },
    // 预上传
    async preArchiveDicomStudy(post, index) {
      try {
        let res = await preArchiveDicomStudy(post);
        if (res.IsSuccess) {
          let item = this.uploadList[index];
          item.StudyMonitorId = res.Result;
          let arr = this.dicomList.filter(
            (dicom) => dicom.StudyInstanceUid === item.StudyInstanceUid
          );
          this.setUploadTask(arr);
        } else {
          return false;
        }
      } catch (err) {
        console.log(err);
        return false;
      }
    },
    // 上传
    async beginScanFiles(e) {
      let files = e.target.files;
      try {
        this.dicomList = [];
        this.hasOtherStudy = false;
        for (var i = 0; i < files.length; ++i) {
          if (files[i].name.indexOf("DICOMDIR") >= 0) continue;
          let dicom = await parseDicom(files[i]);
          if (!dicom) continue;
          let has = this.dicomList.some(
            (item) => item.SopInstanceUid === dicom.SopInstanceUid
          );
          if (has) continue;
          has = this.StudyInstanceUidList.some(
            (item) => item.StudyInstanceUid === dicom.StudyInstanceUid
          );
          if (!has) {
            this.hasOtherStudy = true;
            continue;
          }
          if (this.SopInstanceUidList.includes(dicom.SopInstanceUid)) continue;

          this.isLoad = true;
          dicom.file = files[i];
          dicom.isUpload = 0;
          this.StudyInstanceUidList.some((item) => {
            if (item.StudyInstanceUid === dicom.StudyInstanceUid) {
              dicom.params = {
                TrialId: this.$route.query.trialId,
                SubjectId: item.SubjectId,
                VisitTaskId: item.VisitTaskId,
                SourceSubjectVisitId: item.SourceSubjectVisitId,
              };
              let uploadHas = this.uploadList.some((uploadData) => {
                if (uploadData.StudyInstanceUid === dicom.StudyInstanceUid) {
                  if (uploadData.status > 0) {
                    uploadData.count = 1;
                    uploadData.successCount = 0;
                    uploadData.failCount = 0;
                    uploadData.schedule = 0;
                    uploadData.status = 0;
                    uploadData.FileSize = dicom.file.size;
                    uploadData.SeriesInstanceUidList = [
                      dicom.SeriesInstanceUid,
                    ];
                    uploadData.dicomInfo = {
                      AccessionNumber: dicom.AccessionNumber,
                      Modalities: dicom.Modalities,
                      seriesBodyPartExamined: dicom.seriesBodyPartExamined,
                      StudyDescription: dicom.StudyDescription,
                      StudyTime: this.getTime(dicom.StudyDate, dicom.StudyTime),
                      PatientName: dicom.PatientName,
                      PatientId: dicom.PatientId,
                      PatientAge: dicom.PatientAge,
                      PatientSex: dicom.PatientSex,
                      PatientBirthDate: dicom.PatientBirthDate,
                    };
                  } else {
                    uploadData.FileSize += dicom.file.size;
                    uploadData.count++;
                  }
                  if (
                    !uploadData.SeriesInstanceUidList.includes(
                      dicom.SeriesInstanceUid
                    )
                  ) {
                    uploadData.SeriesInstanceUidList.push(
                      dicom.SeriesInstanceUid
                    );
                  }
                }

                return uploadData.StudyInstanceUid === dicom.StudyInstanceUid;
              });
              if (!uploadHas) {
                let uploadData = {
                  TrialId: this.$route.query.trialId,
                  SubjectId: item.SubjectId,
                  SourceSubjectVisitId: item.SourceSubjectVisitId,
                  StudyId: dicom.StudyId,
                  StudyInstanceUid: dicom.StudyInstanceUid,
                  FileSize: dicom.file.size,
                  count: 1,
                  successCount: 0,
                  failCount: 0,
                  schedule: 0,
                  status: 0,
                  SeriesInstanceUidList: [dicom.SeriesInstanceUid],
                  IsDicomReUpload: false,
                  dicomInfo: {
                    AccessionNumber: dicom.AccessionNumber,
                    Modalities: dicom.Modalities,
                    seriesBodyPartExamined: dicom.seriesBodyPartExamined,
                    StudyDescription: dicom.StudyDescription,
                    StudyTime: this.getTime(dicom.StudyDate, dicom.StudyTime),
                    PatientName: dicom.PatientName,
                    PatientId: dicom.PatientId,
                    PatientAge: dicom.PatientAge,
                    PatientSex: dicom.PatientSex,
                    PatientBirthDate: dicom.PatientBirthDate,
                  },
                };
                if (
                  this.UploadStudyList.some(
                    (d) => d.StudyInstanceUid === uploadData.StudyInstanceUid
                  )
                ) {
                  uploadData.IsDicomReUpload = true;
                }
                this.uploadList.push(uploadData);
              }
            }
            return item.StudyInstanceUid === dicom.StudyInstanceUid;
          });
          this.dicomList.push(dicom);
        }
        if (this.dicomList.length <= 0 && this.hasOtherStudy) {
          let confirm = await this.$confirm(
            this.$t("trials:uploadImage:confirmMessage:failSubject"),
            {
              type: "warning",
              distinguishCancelAndClose: true,
              confirmButtonText: this.$t("common:button:confirm"),
              cancelButtonText: this.$t("common:button:cancel"),
            }
          );
          if (confirm !== "confirm") return false;
          this.$refs.file.click();
          return false;
        }
        let funArr = [];
        for (let i = 0; i < this.uploadList.length; i++) {
          let item = this.uploadList[i];
          let data = {
            TrialId: item.TrialId,
            SubjectId: item.SubjectId,
            SubjectVisitId: item.SourceSubjectVisitId,
            FileSize: item.FileSize,
            IsDicomReUpload: item.IsDicomReUpload,
            FileCount: item.count,
          };
          funArr.push(this.preArchiveDicomStudy(data, i));
        }
        if (funArr && funArr.length > 0) {
          let res = await Promise.all(funArr);
        }
      } catch (err) {
        console.log(err);
        this.$refs.file.value = null;
      }
    },
    // 并发上传
    async handleUploadTask(arr, index) {
      if (this.isClose) return false;
      arr[index].isUpload = 1;
      let path = `/${arr[index].params.TrialId}/TaskImage/${
        arr[index].params.SubjectId
      }/${arr[index].params.VisitTaskId}/${
        arr[index].StudyInstanceUid
      }/${this.getGuid(
        arr[index].StudyInstanceUid +
          arr[index].SeriesInstanceUid +
          arr[index].SOPInstanceUid +
          arr[index].params.TrialId +
          arr[index].params.VisitTaskId
      )}`;
      let uploadDicom = this.uploadList.filter(
        (item) => item.StudyInstanceUid === arr[index].StudyInstanceUid
      )[0];
      let res = await dicomToOSS(arr[index].file, path);
      if (res) {
        arr[index].path = res;
        uploadDicom.successCount++;
        arr[index].isUpload = 2;
      } else {
        uploadDicom.status = 2;
        uploadDicom.failCount++;
        arr[index].isUpload = 3;
      }
      uploadDicom.schedule = Math.floor(
        ((uploadDicom.successCount + uploadDicom.failCount) /
          uploadDicom.count) *
          100
      );
      if (uploadDicom.schedule >= 100) {
        if (uploadDicom.successCount === uploadDicom.count) {
          uploadDicom.status = 1;
          if (!uploadDicom.Study) {
            let res = await this.formatDicom(arr, arr[index].StudyInstanceUid);
            if (res) {
              uploadDicom.Study = res[arr[index].StudyId];
              uploadDicom.status = 3;
            }
          }
          try {
            res = await addOrUpdateArchiveTaskStudy(uploadDicom);
            if (res.IsSuccess) {
              uploadDicom.status = 4;
              this.$emit("getList");
              let ind = this.uploadList.findIndex(
                (item) => item.StudyInstanceUid === uploadDicom.StudyInstanceUid
              );
              this.uploadList.splice(ind, 1);
            } else {
              uploadDicom.status = 5;
            }
            let flag = this.dicomList.every((item) => item.isUpload > 1);
            if (flag) this.isLoad = false;
          } catch (err) {
            uploadDicom.status = 5;
            let flag = this.dicomList.every((item) => item.isUpload > 1);
            if (flag) this.isLoad = false;
          }
        } else if (
          uploadDicom.count ===
          uploadDicom.successCount + uploadDicom.failCount
        ) {
          let flag = this.dicomList.every((item) => item.isUpload > 1);
          if (flag) this.isLoad = false;
        }
      }
      let ind = arr.findIndex((item) => !item.isUpload);
      if (ind >= 0) {
        return this.handleUploadTask(arr, ind);
      } else {
        return false;
      }
    },
    // 数据整理
    async formatDicom(arr, StudyInstanceUid) {
      let studyObj = {};
      for (let i = 0; i < arr.length; i++) {
        let dicom = arr[i];
        if (dicom.StudyInstanceUid !== StudyInstanceUid) continue;
        let thumbnailPath = `/${dicom.params.TrialId}/TaskImage/${dicom.params.SubjectId}/${dicom.params.VisitTaskId}/${dicom.StudyInstanceUid}/${dicom.SeriesInstanceUid}.jpg`;
        if (!studyObj[dicom.StudyId]) {
          studyObj[dicom.StudyId] = {
            StudyId: dicom.StudyId,
            StudyInstanceUid: dicom.StudyInstanceUid,
            StudyTime: this.getTime(dicom.StudyDate, dicom.StudyTime),
            Modalities: dicom.Modalities,
            Description: dicom.StudyDescription,
            SeriesCount: 1,
            InstanceCount: 1,
            InstitutionName: dicom.InstitutionName,
            PatientId: dicom.PatientId,
            PatientName: dicom.PatientName,
            PatientAge: dicom.PatientAge,
            PatientSex: dicom.PatientSex,
            AccessionNumber: dicom.AccessionNumber,
            PatientBirthDate: dicom.PatientBirthDate,
            AcquisitionTime: dicom.AcquisitionTime,
            AcquisitionNumber: dicom.AcquisitionNumber,
            TriggerTime: dicom.TriggerTime,
            BodyPartExamined: dicom.BodyPartExamined,
            SeriesList: [
              {
                StudyInstanceUid: dicom.StudyInstanceUid,
                SeriesInstanceUid: dicom.SeriesInstanceUid,
                SeriesNumber: dicom.SeriesNumber,
                SeriesTime: this.getTime(dicom.SeriesDate, dicom.SeriesTime),
                Modality: dicom.Modality,
                Description: dicom.SeriesDescription,
                InstanceCount: 1,
                SliceThickness: dicom.SliceThickness,
                ImagePositionPatient: dicom.ImagePosition,
                ImageOrientationPatient: dicom.ImageOrientation,
                BodyPartExamined: dicom.seriesBodyPartExamined,
                SequenceName: dicom.SequenceName,
                ProtocolName: dicom.ProtocolName,
                ImagerPixelSpacing: dicom.ImagePixelSpacing,
                AcquisitionTime: dicom.AcquisitionTime,
                AcquisitionNumber: dicom.AcquisitionNumber,
                TriggerTime: dicom.TriggerTime,
                ImageResizePath: await getThumbnail(
                  dicom.file,
                  thumbnailPath,
                  dicom
                ),
                InstanceList: [
                  {
                    StudyInstanceUid: dicom.StudyInstanceUid,
                    SeriesInstanceUid: dicom.SeriesInstanceUid,
                    SopInstanceUid: dicom.SopInstanceUid,
                    InstanceNumber: dicom.ImageOrInstanceNumber,
                    InstanceTime: this.getTime(
                      dicom.ContentDate,
                      dicom.ContentTime
                    ),
                    ImageRows: dicom.Rows || 0,
                    ImageColumns: dicom.Columns || 0,
                    SliceLocation: dicom.SliceLocation,
                    SliceThickness: dicom.SliceThickness,
                    NumberOfFrames: dicom.NumberOfFrames || 0,
                    PixelSpacing: dicom.PixelSpacing,
                    ImagerPixelSpacing: dicom.ImagePixelSpacing,
                    FrameOfReferenceUID: dicom.FrameOfReferenceUID,
                    WindowCenter: dicom.WindowCenter,
                    WindowWidth: dicom.WindowWidth,
                    Path: dicom.path,
                    HtmlPath: "",
                  },
                ],
              },
            ],
          };
        } else {
          let seriesHas = studyObj[dicom.StudyId].SeriesList.some((item) => {
            if (item.SeriesInstanceUid === dicom.SeriesInstanceUid) {
              item.InstanceCount++;
              let instance = {
                StudyInstanceUid: dicom.StudyInstanceUid,
                SeriesInstanceUid: dicom.SeriesInstanceUid,
                SopInstanceUid: dicom.SopInstanceUid,
                InstanceNumber: dicom.ImageOrInstanceNumber,
                InstanceTime: this.getTime(
                  dicom.ContentDate,
                  dicom.ContentTime
                ),
                ImageRows: dicom.Rows || 0,
                ImageColumns: dicom.Columns || 0,
                SliceLocation: dicom.SliceLocation,
                SliceThickness: dicom.SliceThickness,
                NumberOfFrames: dicom.NumberOfFrames || 0,
                PixelSpacing: dicom.PixelSpacing,
                ImagerPixelSpacing: dicom.ImagePixelSpacing,
                FrameOfReferenceUID: dicom.FrameOfReferenceUID,
                WindowCenter: dicom.WindowCenter,
                WindowWidth: dicom.WindowWidth,
                Path: dicom.path,
                HtmlPath: "",
              };
              item.InstanceList.push(instance);
            }
            return item.SeriesInstanceUid === dicom.SeriesInstanceUid;
          });
          if (!seriesHas) {
            studyObj[dicom.StudyId].SeriesCount++;
            let series = {
              StudyInstanceUid: dicom.StudyInstanceUid,
              SeriesInstanceUid: dicom.SeriesInstanceUid,
              SeriesNumber: dicom.SeriesNumber,
              SeriesTime: this.getTime(dicom.SeriesDate, dicom.SeriesTime),
              Modality: dicom.Modality,
              Description: dicom.SeriesDescription,
              InstanceCount: 1,
              SliceThickness: dicom.SliceThickness,
              ImagePositionPatient: dicom.ImagePosition,
              ImageOrientationPatient: dicom.ImageOrientation,
              BodyPartExamined: dicom.seriesBodyPartExamined,
              SequenceName: dicom.SequenceName,
              ProtocolName: dicom.ProtocolName,
              ImagerPixelSpacing: dicom.ImagePixelSpacing,
              AcquisitionTime: dicom.AcquisitionTime,
              AcquisitionNumber: dicom.AcquisitionNumber,
              TriggerTime: dicom.TriggerTime,
              ImageResizePath: await getThumbnail(
                dicom.file,
                thumbnailPath,
                dicom
              ),
              InstanceList: [
                {
                  StudyInstanceUid: dicom.StudyInstanceUid,
                  SeriesInstanceUid: dicom.SeriesInstanceUid,
                  SopInstanceUid: dicom.SopInstanceUid,
                  InstanceNumber: dicom.ImageOrInstanceNumber,
                  InstanceTime: this.getTime(
                    dicom.ContentDate,
                    dicom.ContentTime
                  ),
                  ImageRows: dicom.Rows || 0,
                  ImageColumns: dicom.Columns || 0,
                  SliceLocation: dicom.SliceLocation,
                  SliceThickness: dicom.SliceThickness,
                  NumberOfFrames: dicom.NumberOfFrames || 0,
                  PixelSpacing: dicom.PixelSpacing,
                  ImagerPixelSpacing: dicom.ImagePixelSpacing,
                  FrameOfReferenceUID: dicom.FrameOfReferenceUID,
                  WindowCenter: dicom.WindowCenter,
                  WindowWidth: dicom.WindowWidth,
                  Path: dicom.path,
                  HtmlPath: "",
                },
              ],
            };
            studyObj[dicom.StudyId].SeriesList.push(series);
          }
          studyObj[dicom.StudyId].InstanceCount++;
        }
      }
      return studyObj;
    },
    // dicom时间转换
    getTime(date, time) {
      let studyTime = "";
      if (date) {
        date = `${date.substring(0, 4)}-${date.substring(
          4,
          6
        )}-${date.substring(6, 8)}`;
      }
      if (time) {
        time = `${time.substring(0, 2)}:${time.substring(
          2,
          4
        )}:${time.substring(4, 6)}`;
      }
      if (date) {
        studyTime = time ? `${date} ${time}` : `${date} 00:00:00`;
      }
      return studyTime;
    },
  },
  beforeDestroy() {
    this.isClose = true;
    store.dispatch("trials/setUnLock", false);
  },
};
</script>
<style lang="scss" scoped>
.colorOfRed {
  color: #f44336;
}
label {
  cursor: pointer;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 9px 15px;
}
</style>