<template>
  <div class="videoListDiv">
    <div class="count">
      <span class="font">摄像头总数:</span>
      <span style="margin: 0 15px 0 7px; font-size: 16px; font-family: Source Han Sans CN; font-weight: bold; color: #ebcf49">{{ count }}个</span
      ><span class="font">在线率:</span>
      <span style="font-size: 16px; font-family: Source Han Sans CN; font-weight: bold; color: #ebcf49"> {{ percentage }}% </span></div
    >

    <div class="tempVideoListDiv">
      <!-- <a-carousel class="showDataarrows" arrows :slides-to-show="6" :slides-to-scroll="2">
           -->
      <a-carousel class="showDataarrows" arrows>
        <template #prevArrow>
          <div class="custom-slick-arrow" style="left: 0px; z-index: 999">
            <img src="/src/assets/lunbo/left.png" alt="Previous Arrow" />
          </div>
        </template>
        <template #nextArrow>
          <div class="custom-slick-arrow" style="right: 0px; z-index: 999">
            <img src="/src/assets/lunbo/right.png" alt="Next Arrow" />
          </div>
        </template>

        <!-- <template v-for="item in item2" :key="'groupItem_' + item.deviceCode" >
            <div class="imageItem" @click="goToVideo(item)">
              <div class="imageItem2" :class="{ active: selectedOption === item.deviceCode }">
                <a-image :preview="false" :src="item.url || ''" fallback="./static/img/videoImage/no.png" />
                <span :title="item.deviceName"> {{ item.dangerPointName || '' }}</span>
              </div>
            </div>
          </template> -->

        <div v-for="(item2, index) in videoList" :key="index" style="height: 100%">
          <ul style="margin: 35px 0">
            <li class="box" v-for="value in item2" :key="'groupItem_' + value.deviceCode" @click="goToVideo(value, item2)">
              <div class="items">
                <a-image
                  style="width: 100%; height: 100%; object-fit: cover"
                  :preview="false"
                  :src="value.url || ''"
                  fallback="./static/img/videoImage/no.png"
                />
                <span :title="value.deviceName"> {{ value.dangerPointName || '' }}</span>
              </div>
              <!-- <div  :class="{ active: selectedOption === value.deviceCode }">
                <a-image :preview="false" :src="value.url || ''" fallback="./static/img/videoImage/no.png" />
                <span :title="value.deviceName"> {{ value.dangerPointName || '' }}</span>
              </div> -->
            </li>
          </ul>
        </div>
      </a-carousel>
    </div>
  </div>
</template>

<script>
import tFMapUitl from '/@/utils/TFMapUitl';
import { reactive, ref, onMounted } from 'vue';
import { useMonitorDevicesStore } from '/@/store/modules/monitorDevices';
import { LeftCircleOutlined, RightCircleOutlined } from '@ant-design/icons-vue';
import { getloadImg } from '/@/api/map/getData.ts';
import { message } from 'ant-design-vue';
export default {
  name: 'VideoList',
  components: {
    LeftCircleOutlined,
    RightCircleOutlined,
  },
  // LigongDeviceSensorOnline
  setup() {
    const monitorDevicesStore = useMonitorDevicesStore();
    const videoList = reactive([]);
    getVideoList();
    const selectedOption = ref(0);
    let count = ref(0);
    let percentage = ref(0);
    onMounted(() => {
      monitorDevicesStore
        .ligongDeviceSensorOnliness({
          sensorType: 'L4SP',
        })
        .then((res) => {
          console.log(res, '要使用视频监控接口了要使用视频监控接口了要使用视频监控接口了要使用视频监控接口了');
          let online = 0;
          let offline = 0;
          res.result.map((e) => {
            if (e.typeCode == 'onlineSensor' || e.typeCode == 'offlineSensor') {
              count.value += e.count;
            }
            if (e.typeCode == 'onlineSensor') {
              online = e.count;
            } else if (e.typeCode == 'offlineSensor') {
              offline = e.count;
            }
          });
          percentage.value = ((online * 100) / count.value).toFixed(2);
        })
        .catch((err) => {
          console.log('err', err);
        });
    });
    /**
     * 获取视频列表
     */
    function getVideoList() {
      tFMapUitl.clearArray(videoList);
      monitorDevicesStore
        .LigongGetVideoList({
          pageNo: 1,
          pageSize: 1000,
        })
        .then((e) => {
          let tempArr = [];
          if (e.code == 200 && e.result && e.result.records) {
            // for(let i=0;i<4;i++){
            //   e.result.records.push(...e.result.records)
            // }
            for (let i = 0; i < e.result.records.length; i++) {
              const tempIndex = Math.floor(i / 6);
              // e.result.records[i].url='./static/img/videoImage/'+e.result.records[i].sensorCode+'.png';
              e.result.records[i].url = './static/img/videoImage/' + e.result.records[i].sensorSerial + '.png';
              if (tempArr[tempIndex]) {
                tempArr[tempIndex].data.push(e.result.records[i]);
              } else {
                tempArr[tempIndex] = { data: [], id: e.result.records[i].deviceCode };
                tempArr[tempIndex].data = [e.result.records[i]];
                // tempArr[tempIndex].data.push([e.result.records[i]][0]);
                // tempArr[tempIndex].data.push([e.result.records[i]][0]);
                // tempArr[tempIndex].data.push([e.result.records[i]][0]);
                // tempArr[tempIndex].data.push([e.result.records[i]][0]);
                // tempArr[tempIndex].data.push([e.result.records[i]][0]);
              }
            }
            console.log('视频数据', tempArr);
            console.log('视频数据', tempArr[0]);
            console.log('视频数据', tempArr[0].data);
            // let arr =[{key:value},{key:value},{key:value},{key:value},{key:value},{key:value},
            // {key:value},{key:value},{key:value},{key:value},{key:value},{key:value},]
            // let result =[[{key:value},{key:value},{key:value},{key:value},{key:value},{key:value}],[
            // {key:value},{key:value},{key:value},{key:value},{key:value},{key:value}
            // ]
            // ]
            // tempArr=[{data:[{value:1},{value:1},{value:1},{value:1}]},{data:[{value:1},{value:1},{value:1},{value:1}]}]
            // let results = [];
            // for (let i = 0; i < tempArr[0].data.length; i += 6) {
            //   results.push(tempArr[0].data.slice(i, i + 6));
            // }
            let results = [];
            for (let i = 0; i < tempArr.length; i++) {
              let tempData = tempArr[i].data;
              for (let j = 0; j < tempData.length; j += 6) {
                results.push(tempData.slice(j, j + 6));
              }
            }

            console.log(results, '这是切片数据----------------');

            // videoList.push(...tempArr);
            videoList.push(...results);
            console.log(videoList, 'videoList');
          }
        });
    }

    /**
     * 定位到视频点
     */
    function goToVideo(i, e) {
      console.log(e, 'e');
      selectedOption.value = i.deviceCode;
      if (i.deviceLon && i.deviceLat) {
        let op = {
          destination: { x: i.deviceLon, y: i.deviceLat, z: 1000 },
          orientation: { heading: 0, pitch: -1.5629777805927172, range: 8000 },
        };
        map.flyToRange(op, () => {
          tFMapUitl.mapPointLocation_list([i.deviceLon, i.deviceLat]);
          var html = tFMapUitl.sbdMarkerDom(i);
          map.openInfoWindowHtml(html, { position: [i.deviceLon, i.deviceLat] }, () => tFMapUitl.clearPointLocation_list(map));
          map.popup.setOffset(0, -120);
        });
      } else {
        // console.log("未传入坐标");
        message.info('未传入坐标');
      }
    }
    return {
      videoList,
      goToVideo,
      selectedOption,
      count,
      percentage,
    };
  },
};
</script>

<style lang="less" scoped>
.videoListDiv {
  height: 200px;
  width: 100%;
  color: #fff;
  position: absolute;

  .count{
    position: absolute; 
    z-index: 12;
    left: 10px;
  }
}
.showDataarrows {
  width: 100%;
  height: 100%;
}
:deep(.slick-slider),
:deep(.slick-list),
:deep(.slick-track) {
  height: 100%;
}
:deep(.slick-slide div:first-child) {
  display: inline-block;
  position: relative;
  float: left;
  width: 100%;
  height: 68px;
  top:0%
  // height: 100%;
}
.tempVideoListDiv {
  height: 100%;
  width: 100%;
  // position: relative;
  padding-left: 10px;
  color: #fff;
  // display: flex !important;
  flex-flow: row wrap;
  overflow-y: auto;
  // justify-content: center; /* 添加这行 */
  // align-items: center; /* 添加这行 */
 
}
.imageItem {
  //  width: 13% !important;
  // width: calc(100% / 3); /* 幻灯片宽度为父容器的1/3 */
  display: inline-block  !important; /* 水平排列 */
  // height: 50% !important;
  // position: relative;
  padding: 10px 10px 0px 0px;
  padding-left: 0px;
  .imageItem2.active {
    width: 100%;
    height: 100%;
    border: 2px solid #04f7fa !important;
  }
  /deep/ .ant-image {
    width: 100%;
    height: 100%;
    position: relative;
  }
  /deep/ .ant-image-img {
    width: 100%;
    // height: 125%;
  }
  span {
    position: absolute;
    bottom: 0px;
    width: 150%;
    height: 25px;
    left: 0px;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    display: block;
    padding-top: 2px;
  }
  /deep/.ant-carousel :deep(.slick-arrow.custom-slick-arrow) {
    z-index: 999;
    position: absolute;
    top: 0px;
    width: 25px;
    height: 25px;
    font-size: 25px;
    color: black;
    opacity: 0.3;
    z-index: 999;
    &:hover {
      color: black !important;
      opacity: 1 !important;
    }
  }
  .ant-carousel :deep(.slick-arrow.custom-slick-arrow) {
  // width: 25px;
  // height: 25px;
  // font-size: 25px;
  // color: #fff;
  // background-color: rgba(31, 45, 61, 0.11);
  // opacity: 0.3;
  z-index: 999 !important;
}
.ant-carousel :deep(.custom-slick-arrow:before) {
  display: none;
  z-index: 999;
}
  /deep/.ant-carousel :deep(.slick-arrow.custom-slick-arrow:before) {
    display: none;
  z-index: 999;
  }


}
// .custom-slick-arrow .slick-arrow slick-next{

// }

// /deep/ .ant-carousel /deep/ .slick-prev,
//  /deep/ .ant-carousel /deep/ .slick-next {
//     top: 25px !important;
//     background: transparent;
//   }
/deep/.ant-carousel :deep(.custom-slick-arrow:before) {
  z-index: 999;
  display: none;
}
/deep/.ant-carousel :deep(.custom-slick-arrow:hover) {
  z-index: 999;
  opacity: 0.5;
}

/deep/.ant-carousel :deep(.slick-slide h3) {
  // color: #fff;
}
/deep/.slick-dots.slick-dots-bottom {
  display: none !important;
}

// .custom-slick-arrow {
//   // z-index: 999 !important;
//   // :deep(svg) {
//   //   width: 20px;
//   //   height: 20px;
//   //   color: rgb(255 255 255 / 30%);
//   //   &:hover {
//   //     color: rgb(255 255 255 / 100%);
//   //   }
//   // }
// }
.font{
  font-size: 14px;
font-family: Source Han Sans CN;
font-weight: 500;
color: #FFFFFF;
// line-height: 80px;
}

li.box:nth-child(2n) {
  margin-right: 0px;
}

.box {
  display: inline-block;
  // display: flex;
  // flex-wrap: wrap;
  // overflow-y: auto;
  width: 33%;
  height: 68px;
  // flex-wrap: wrap;
  position: relative;
.items{
  // width: 100%; height: 100%;background-color: aliceblue; margin: 2px;
  height: 66px;
}

  span {
    position: absolute;
    bottom: 0px;
    width: 100%;
    height: 25px;
    left: 0px;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    display: block;
    padding-top: 2px;
  }

  .imageItem2.active {
    width: 100%;
    height: 100%;
    border: 2px solid #04f7fa !important;
  }
  /deep/ .ant-image {
    width: 100%;
    height: 100%;
    position: relative;
  }
  /deep/ .ant-image-img {
    width: 100%;
    // height: 125%;
  }
  
}
.image {
  float: left;
  width: auto;
  height: 100%;
  margin-right: 30px;
  margin-left: 7px;
}

.text {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ant-carousel ::v-deep(.custom-slick-arrow:before) {
  display: none;
  z-index: 999;
}

.ant-carousel ::v-deep(.custom-slick-arrow:hover) {
  z-index: 999;
  opacity: 0.5;
}
</style>
