<template>
  <div class="body-head">
    <h3 style="visibility: hidden">场景管理</h3>
  </div>

  <el-table
    :data="pagging.state.table.rows"
    tooltip-effect="dark"
    style="width: 100%"
    size="large"
  >
    <!-- -1 计算失败  0 计算中 1 计算成功并可以外网访问，不能编辑 2计算成功只能内网，能编辑 -->
    <el-table-column label="序号" width="70" v-slot:default="{ $index }">
      <div style="text-align: center">
        {{ pagging.state.pag.size * (pagging.state.pag.currentPage - 1) + $index + 1 }}
      </div>
    </el-table-column>
    <el-table-column label="场景标题" prop="name"></el-table-column>
    <el-table-column label="S/N码" prop="snCode"></el-table-column>
    <!-- <el-table-column label="浏览数量" prop="viewCount"></el-table-column> -->
    <el-table-column label="拍摄时间" prop="createTime" v-slot:default="{ row }">
      {{ row.createTime.substr(0, 16) }}
    </el-table-column>
    <el-table-column label="状态" v-slot:default="{ row }: { row: QuoteScene }">
      {{ QuoteSceneStatusDesc[row.status] }}
    </el-table-column>
    <el-table-column label="所属架构" prop="deptName"></el-table-column>
    <el-table-column
      label="操作"
      v-slot:default="{ row }: { row: QuoteScene }"
      width="350px"
    >
      <span
        class="oper-span"
        @click="downHash(row)"
        v-if="row.status === QuoteSceneStatus.SUCCESS"
      >
        下载Hash
      </span>
      <span
        class="oper-span"
        @click="copySceneHandler(row)"
        v-if="row.status === QuoteSceneStatus.SUCCESS"
      >
        复制
      </span>
      <span
        class="oper-span"
        v-pdpath="['view']"
        @click="openSceneUrl(row, OpenType.query)"
        v-if="row.status === QuoteSceneStatus.SUCCESS"
      >
        查看
      </span>
      <span
        class="oper-span"
        v-pdpath="['edit']"
        @click="openSceneUrl(row, OpenType.edit)"
        v-if="row.status === QuoteSceneStatus.SUCCESS"
      >
        编辑
      </span>
      <span
        v-if="
          [SceneType.SWSS, SceneType.SWYDSS].includes(row.type) &&
          [QuoteSceneStatus.SUCCESS].includes(row.status) &&
          row.location === LocationEnum.Scene_Location_PointCloud
        "
        v-pdpath="['gen']"
        class="oper-span"
        @click="genMeshScene(row)"
      >
        生成obj
      </span>

      <span
        v-if="
          ![SceneType.SWSSMX, SceneType.SWYDMX].includes(row.type) &&
          row.status !== QuoteSceneStatus.RUN
        "
        class="oper-span delBtn"
        v-pdscene="row"
        @click="delSceneHandler(row)"
        v-pdpath="'del'"
      >
        删除
      </span>
      <span
        class="oper-span"
        @click="sceneDownloadHandler(row)"
        v-pdpath="['download']"
        v-if="row.num && row.status === QuoteSceneStatus.SUCCESS"
      >
        下载
      </span>
    </el-table-column>
  </el-table>
</template>

<script setup lang="ts">
import {
  QuoteScene,
  QuoteSceneStatus,
  delQuoteScene,
  SceneType,
  genMeshScene,
  LocationEnum,
  copyQuoteScene,
  downQuoteSceneHash,
} from "@/store/scene";
import { ScenePagging } from "./pagging";
import { QuoteSceneStatusDesc } from "@/constant/scene";
import { OpenType, openSceneUrl } from "../case/help";
import { confirm } from "@/helper/message";
import { sceneDownload } from "./quisk";
import { downSceneHash } from "@/request";

const props = defineProps<{ pagging: ScenePagging }>();
const delSceneHandler = async (scene: QuoteScene) => {
  if (await confirm("确定要删除当前场景吗？")) {
    await delQuoteScene(scene);
    props.pagging.refresh();
  }
};
const copySceneHandler = async (scene: QuoteScene) => {
  await copyQuoteScene(scene);
  props.pagging.refresh();
};
const downHash = async (scene: QuoteScene) => {
  downQuoteSceneHash(scene);
};
const sceneDownloadHandler = (scene: QuoteScene) => {
  sceneDownload({ scene });
};
</script>
