<template>
  <div class="container">
    <!-- 遮罩层区域 -->
    <div class="mask" @click="handleCloseDetail"></div>
    <!-- 弹窗区域 -->
    <div class="detail">
      <!-- 标题区域 -->
      <div class="detail_title">路口详情</div>

      <!-- 视频区域 -->
      <div class="detail_video">
        <div class="video_box" id="videoDom"></div>
        <div class="video_title">
          {{ detailObj.place_name }}
        </div>
      </div>

      <!-- 详细信息区域 -->
      <div class="detail_msg">
        <div class="msg_img">
          <img src="@/assets/images/87.png" />
        </div>
        <div class="msg_info">
          <div class="info_title">{{ detailObj.place_name }}</div>
          <div class="info_num">
            当日：{{ detailObj.num }}人&nbsp;&nbsp;&nbsp;&nbsp;累计：{{
              currentTotal
            }}人
          </div>
        </div>
      </div>

      <!-- 边框线区域 -->
      <div class="detail_line"></div>

      <!-- 表格区域 -->
      <div class="detail_form">
        <el-table
          :data="tableData"
          style="width: 100%"
          v-loading="loading"
          element-loading-text="加载中..."
          element-loading-background="rgba(1,18,38, 0.8)"
        >
          <el-table-column prop="sm_name" label="姓名" align="center" />
          <el-table-column prop="sm_phone" label="电话" align="center" />
          <el-table-column prop="sm_time" label="时间" align="center" />
        </el-table>
      </div>

      <!-- 关闭按钮区域 -->
      <div class="detail_close" @click="handleCloseDetail"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from "vue";
// 引入路口相关的接口
import { reqJtNumByTotal, reqJtTableData } from "@/api/junction/index";
// 引入监控相关的数据接口
import { getVedio } from "@/api/video/index";
// @ts-ignore
import WasmPlayer from "@easydarwin/easywasmplayer";

// 父组件传递过来的数据
const props = defineProps(["detailObj"]);

const $emit = defineEmits(["closeDetail"]);

// 表格数据
const tableData = ref([]);

// 当前路口累计人数
const currentTotal = ref(0);

// loading加载效果控制
const loading = ref(true);

// 监控实例
const player = ref();

onMounted(() => {
  // console.log(props.detailObj);

  // 获取监控视频地址
  getVideosData();
  // 获取各路口累计人数
  getJtNumByTotal();
  // 获取表格数据
  getTableData();
});

onUnmounted(() => {
  // 页面卸载时销毁WasmPlayer实例
  player.value.destroy();
});

// 获取监控视频地址
const getVideosData = async () => {
  const res = await getVedio(props.detailObj.rtspaddr);
  player.value = new WasmPlayer(null, "videoDom");

  player.value.play(res, 1);
};

// 获取各路口累计人数
const getJtNumByTotal = async () => {
  const res = await reqJtNumByTotal();
  // console.log(res);

  // 匹配出当前路口的累计人数
  res.data.forEach((ele: any) => {
    if (ele.place_name === props.detailObj.place_name) {
      currentTotal.value = ele.num;
    }
  });
};

// 获取表格数据
const getTableData = async () => {
  const res = await reqJtTableData(props.detailObj.place_name);
  // console.log(res);
  tableData.value = res.data;
  loading.value = false;
};

// 点击关闭按钮图标回调
const handleCloseDetail = () => {
  $emit("closeDetail", false);
};
</script>

<style lang="scss" scoped>
.container {
  z-index: 9999;
  position: absolute;
  top: -151px;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba($color: #000000, $alpha: 0.6);

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 7072px;
    height: 1872px;
  }

  .detail {
    position: absolute;
    top: 220px;
    left: 1100px;
    width: 1016px;
    height: 1378px;
    color: #fff;
    background-image: url(@/assets/images/news-detail-background.png);
    background-size: 100% 100%;

    .detail_title {
      margin-top: 70px;
      font-size: 30px;
      font-weight: bold;
    }

    .detail_video {
      position: relative;
      margin: 75px 0 0 15px;
      width: 874px;
      height: 491px;

      .video_box {
        width: 100%;
        height: 100%;
      }

      .video_title {
        z-index: 10;
        position: absolute;
        top: 31px;
        left: 44px;
        padding: 15px 15px 0;
        font-size: 27px;
        background: linear-gradient(
          270deg,
          rgba(116, 180, 232, 0.29) 0%,
          rgba(44, 95, 143, 1) 100%
        );
      }
    }

    .detail_msg {
      display: flex;
      margin-top: 59px;
      margin-left: 57px;
      width: 768px;
      height: 74px;

      .msg_img {
        margin-right: 20px;
        width: 106px;
        height: 74px;
        border-radius: 10px;
        overflow: hidden;

        img {
          width: 100%;
          height: 100%;
          object-fit: contain;
        }
      }

      .msg_info {
        display: flex;
        flex-direction: column;
        justify-content: space-around;

        .info_title {
          font-size: 24px;
          font-weight: bold;
        }

        .info_num {
          font-size: 18px;
        }
      }
    }

    .detail_line {
      margin-top: 30px;
      margin-left: 63px;
      width: 772px;
      height: 6px;
      background-image: url(@/assets/images/news-list-bottomLine.png);
      background-size: 100% 100%;
    }

    .detail_form {
      margin-top: 24px;
      margin-left: 58px;
      width: 773px;
      height: 480px;
      overflow-y: auto;
    }

    .detail_close {
      position: absolute;
      top: 0;
      right: 0;
      width: 98px;
      height: 98px;
      cursor: pointer;
    }
  }
}

/*最外层透明*/
.detail_form ::v-deep(.el-table),
.detail_form ::v-deep(.el-table__expanded-cell) {
  background-color: transparent;
  color: white;
  border: none;
}
/* 表格内背景颜色 */
.detail_form ::v-deep(.el-table th),
.detail_form ::v-deep(.el-table tr),
.detail_form ::v-deep(.el-table td) {
  background-color: transparent !important;
  color: white;
  font-size: 16px;
  border-color: rgba(255, 255, 255, 0.1);
}

// 表格底部白线清除
::v-deep(.el-table__inner-wrapper::before) {
  height: 0;
}

// 修改表头背景颜色
::v-deep(.el-table__header) {
  background-color: rgba(58, 126, 199, 0.5);
}
// 清除表格默认padding
::v-deep(.el-table .el-table__body-wrapper .el-table__cell) {
  padding: 0;
  height: 55px;
}
</style>
