<template>
  <div class="container">
    <div class="block1">
      <div v-if="data.videoSrc" class="video">
        <iframe
          :src="data.videoSrc.VIDEOURL"
          style="width: 100%; height: 100%"
        />
        <!--        <img src="/src/assets/images/map/img16.png" alt="" />-->
      </div>
    </div>
    <div class="block2">
      <layout-title title="实时告警监控" />
      <div class="options">
        <div
          v-infinite-scroll="load"
          :infinite-scroll-disabled="disabled"
          class="scroll"
        >
          <div
            class="option mb-10"
            v-for="(item, index) in data.block1OptionsList"
            :key="index"
          >
            <div class="img">
              <img :src="VITE_FILE_URL + item.IMG_PATH" alt="" />
            </div>
            <div class="info" :class="item.ISTRUE === 3 ? '' : 'bg_blue'">
              <div class="title">
                <div class="tit">{{ item.TYPE }}</div>
                <div class="ico">
                  <img
                    :src="item.ISTRUE === 3 ? data.img1 : data.img2"
                    alt=""
                  />
                </div>
              </div>
              <div class="time">{{ item.WARNING_TIME }}</div>
              <div class="text">{{ "摄像头名称：" + item.VIDEONAME }}</div>
              <div class="text">{{ "摄像头编号：" + item.CODE }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import LayoutTitle from "./title.vue";
import { reactive, computed } from "vue";
import { getAiWarningList, getCameraTopToShow } from "@/request/bi/mapApi.js";
const VITE_FILE_URL = import.meta.env.VITE_FILE_URL;

const data = reactive({
  img1: new URL("/src/assets/images/map/img17.png", import.meta.url).href,
  img2: new URL("/src/assets/images/map/img18.png", import.meta.url).href,
  videoSrc: {},
  loading: false,
  currentPage: 1,
  totalPage: 1,
  block1OptionsList: [
    // {
    //   img: new URL("/src/assets/images/map/img16.png", import.meta.url).href,
    //   title: "未戴安全帽",
    //   time: "2023-08-09  15:14:23",
    //   text: "告警源：油品库包装裤袋",
    //   type: 1,
    // },
    // {
    //   img: new URL("/src/assets/images/map/img16.png", import.meta.url).href,
    //   title: "未戴安全帽",
    //   time: "2023-08-09  15:14:23",
    //   text: "告警源：油品库包装裤袋",
    //   type: 1,
    // },
    // {
    //   img: new URL("/src/assets/images/map/img16.png", import.meta.url).href,
    //   title: "未戴安全帽",
    //   time: "2023-08-09  15:14:23",
    //   text: "告警源：油品库包装裤袋",
    //   type: 1,
    // },
    // {
    //   img: new URL("/src/assets/images/map/img16.png", import.meta.url).href,
    //   title: "未戴安全帽",
    //   time: "2023-08-09  15:14:23",
    //   text: "告警源：油品库包装裤袋",
    //   type: 1,
    // },
    // {
    //   img: new URL("/src/assets/images/map/img16.png", import.meta.url).href,
    //   title: "未戴安全帽",
    //   time: "2023-08-09  15:14:23",
    //   text: "告警源：油品库包装裤袋",
    //   type: 2,
    // },
  ],
});
const getAiWarningData = async () => {
  const resData = await getAiWarningList({
    currentPage: data.currentPage,
    showCount: 10,
  });
  resData.varList.forEach((item) => {
    data.block1OptionsList.push(item);
  });
  data.totalPage = resData.page.totalPage;
  data.loading = false;
};
const getCameraTopToShowData = async () => {
  const resData = await getCameraTopToShow();
  data.videoSrc = resData.pd;
};

// 无限滚动
const disabled = computed(() => {
  return noMore.value;
});
const load = () => {
  data.loading = true;
  data.currentPage += 1;
  getAiWarningData();
};
const noMore = computed(() => {
  return data.currentPage >= data.totalPage;
});
getAiWarningData();
getCameraTopToShowData();
</script>
<style scoped lang="scss">
.container {
  width: 100%;

  .block1 {
    width: 430px;

    .video {
      width: 100%;
      height: 260px;
      border: 2px solid #11acd7;
      border-radius: 4px;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .block2 {
    width: 430px;
    margin-top: 10px;

    .options {
      width: 100%;
      min-height: 100px;
      background-image: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0),
        rgba(0, 0, 0, 0.8)
      );
      border-radius: 10px;
      border: 1px solid;
      border-image: linear-gradient(
          to bottom,
          rgba(58, 122, 149, 0),
          rgba(16, 188, 236, 1)
        )
        1;
      border-top: none;
      display: flex;
      flex-direction: column;
      padding: 10px;
      .scroll {
        max-height: 600px;
        overflow-y: auto;

        &::-webkit-scrollbar {
          width: 5px;
        }

        &::-webkit-scrollbar-thumb {
          border-radius: 5px;
          background: rgba(2, 30, 81, 0.851);
        }

        &::-webkit-scrollbar-track {
          border-radius: 5px;
          background: rgba(255, 255, 255, 0.1);
        }

        .tr {
          &:nth-child(odd) {
            background-color: transparent;
          }
        }
      }
      .option {
        width: 100%;
        display: flex;
        align-items: center;

        .img {
          width: 180px;
          height: 115px;
          border: 1px solid #11acd7;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .info {
          flex: 1;
          background-image: linear-gradient(
            to top,
            rgba(0, 0, 0, 0),
            rgba(148, 129, 39, 0.6)
          );
          padding: 10px;
          height: 115px;
          display: flex;
          justify-content: space-between;
          flex-direction: column;

          .title {
            width: 100%;
            display: flex;
            justify-content: space-between;
            font-size: 16px;

            .tit {
              font-weight: bold;
            }
          }
        }

        .bg_blue {
          background-image: linear-gradient(
            to top,
            rgba(0, 0, 0, 0),
            rgba(2, 119, 242, 0.6)
          );
        }
      }
    }
  }

  @keyframes slideY {
    0% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-5px);
    }
    100% {
      transform: translateY(0);
    }
  }
  @keyframes scale {
    0% {
      transform: translateX(-50%) scale(1);
    }
    50% {
      transform: translateX(-50%) scale(0.5);
    }
    100% {
      transform: translateX(-50%) scale(1);
    }
  }
}
</style>
