<template>
  <div class="box-1">
    <div class="header">
     <div class="header__left">
        <img src="@/assets/images/ticket.png" />
        <div
          class="header__left-item"
          v-for="(item, index) in scenicStore.scenicSpotData.data"
          :key="index"
        >
          <div class="label">{{ item.name }}</div>
          <countup :end-val="item.value" />
        </div>

      </div>
      <div>
        <div v-for="(item, index) in scenicStore.scenicSpotData.infoList" :key="index">
          <div class="label">{{ item.name }}</div>
          <p class="value" :class="{ error: [3, 4].includes(item.type) }">{{ item.value }}</p>
        </div>
      </div>
    </div>
    <div class="main">
		<a @click="hanldeToDetails"  class="look-btn">
			查看详情
			<!-- <img src="@/assets/images/d-ico-1.png" /> -->
		</a>
      <iframe v-if="scenicSpotId == 'root000000'" width="100%" height="100%" src="/map/sxzd/bdc.html"></iframe>
      <iframe v-if="scenicSpotId == 'root00000000'" width="100%" height="100%" src="/map/sxzd/sxzd.html"></iframe>
      <iframe v-if="scenicSpotId == '龙桥河'" width="100%" height="100%" src="/map/lqh/lqh.html"></iframe>
    </div>
    <div class="footer">
      <div class="flex">
        <div class="item">
          <circle-progress
            :width="170"
            :height="90"
            :value="parseFloat(scenicStore.wordkOrderData.toDayData.rate)"
            :title="`${scenicStore.wordkOrderData.toDayData.rate}%`"
            subTitle="完成率"
          />
          <div>
            <div class="bg">
              <span class="label">今日工单总条数：</span>
              <span class="value success">
                <countup :end-val="scenicStore.wordkOrderData.toDayData.count" />
              </span>
            </div>
            <div class="bg">
              <span class="label">工单完成数：</span>
              <span class="value">
                <countup :end-val="scenicStore.wordkOrderData.toDayData.end" />
              </span>
            </div>
          </div>
        </div>
        <div class="item">
          <circle-progress
            :width="170"
            :height="90"
            :value="parseFloat(scenicStore.wordkOrderData.warnData.rate)"
            :title="`${scenicStore.wordkOrderData.warnData.rate}%`"
            subTitle="完成率"
          />
          <div>
            <div class="bg">
              <span class="label">今日紧急工单数：</span>
              <span class="value error">
                <countup :end-val="scenicStore.wordkOrderData.warnData.count" />
              </span>
            </div>
            <div class="bg">
              <span class="label">紧急工单完成数：</span>
              <span class="value">
                <countup :end-val="scenicStore.wordkOrderData.warnData.end" />
              </span>
            </div>
          </div>
        </div>
      </div>
      <div class="flex align-center justify-between">
        <div>
          <Vue3SeamlessScroll
            class="list"
            :list="scenicStore.wordkOrderList"
            :limitScrollNum="3"
            :hover="true"
            :step="0.2"
            :wheel="true"
            :isWatch="true"
          >
            <div class="cell" v-for="(item, index) in scenicStore.wordkOrderList" :key="index">
              <span :class="`tag--${item.level}`">{{ item.level_text }}</span>
              <p class="content">
                {{ item.title }}
              </p>
            </div>
          </Vue3SeamlessScroll>
        </div>
        <img class="more" src="@/assets/images/more-col.png" alt="查看更多" @click="handleMore" />
      </div>
    </div>
  </div>
  <video-dialog v-model="videoShow" :src="src" :cameraIndexCode="cameraIndexCode" />
</template>

<script setup>
  import countup from 'vue-countup-v3'
  import { Vue3SeamlessScroll } from 'vue3-seamless-scroll'
  import { getSpotListApi } from '@/api/sentiment'
  import { useRouter } from 'vue-router'

  import { useScenicStore } from '@/stores/scenic'

  import { useMap } from '@/hooks/map'
  import {getPreviewUrlApi} from "@/api/home.js";
import pubSub from 'pubsub-js'
  const router = useRouter()
  const scenicStore = useScenicStore()
  const { initMap, addMarker, map, marker } = useMap()

  let props = defineProps({
    scenicSpotId: {
      type: String,
      default: () => ''
    }
  })

  let scenicChange = null
  const handleMore = () => {
    router.push('/workOrder')
  }
  let hrefItem = ref(null)
  const hanldeToDetails = async()=>{
	  // let spotRes = await getSpotListApi()
	  // return false;
	  pubSub.publish('navToChange',hrefItem.value)

	  router.push('/monitor')
  }
  let src = ref('')
  let cameraIndexCode = ref('')
  let videoShow = ref(false)
  window.addEventListener("message", async(e) => {
    let {code,data} = await getPreviewUrlApi({
      type: 'hls',
      cameraIndexCode:e.data.cameraIndexCode
    })
    if(code===200){
      src.value = data.url
      cameraIndexCode.value = e.data.cameraIndexCode
      videoShow.value = true
    }
  });

  onMounted(() => {
    scenicChange = PubSub.subscribe('scenicChange', (msg, data) => {
		hrefItem.value = data
      // initMap('scenic-map', data.lng, data.lat, 15)
      // map.value.setDisplayOptions({
      //   poiText: false, // 隐藏poi标注
      //   poiIcon: false, // 隐藏poi图标
      //   building: false // 隐藏楼块
      // })
      // var bounds = new BMapGL.Bounds(
      //   new BMapGL.Point(109.604998,31.030391),
      //   new BMapGL.Point(109.624833,31.044965)
      // )
      // var imgOverlay = new BMapGL.GroundOverlay(bounds, {
      //   type: 'image',
      //   url: sxzd,
      //   opacity: 1
      // })
      // map.value.addOverlay(imgOverlay)
    })
  })
  onUnmounted(() => {
    PubSub.unsubscribe(scenicChange)
  })
</script>

<style scoped lang="scss">
  .box-1 {
    margin-top: vh(120);
    width: vw(900);
    height: vh(950);
    padding: vw(10);
    box-sizing: border-box;
    background-image: url('@/assets/images/bg-3.png');
    background-size: 100% 100%;
    .header {
      display: flex;
      margin-top: vh(10);
      &__left {
        display: flex;
        align-items: center;
		margin-right:vw(10);
        > img {
          width: vw(74);
          height: auto;
        }
      }
      &__left-item {
        position: relative;
        width: vw(120);
        height: vh(58);
        padding-left: vw(10);
        display: flex;
        flex-direction: column;
        justify-content: center;
        background-image: url('@/assets/images/ticket-item-bg.png');
        background-size: 100% 100%;
		// margin-left:vw(30);
        .label {
          position: absolute;
          top: vh(-4);
          font-weight: 400;
          font-size: vw(14);
          color: #ffffff;
		  left:vw(0)
        }
      }
      & > div:nth-child(2) {
        flex: 1;
        display: flex;
        justify-content: space-between;
        .label {
          font-weight: 400;
          font-size: vw(16);
          color: #ffffff;
        }
        .value {
          font-weight: bold;
          font-size: vw(28);
          color: #02f9fa;
          text-align: center;
          line-height: vh(60);
        }
        .error {
          color: #ff4400;
        }
      }

      .countup-wrap {
        color: #02f9fa;
        font-size: vw(28);
        font-weight: bold;
      }
    }
    .main {
      width: 100%;
      height: vh(600);
      overflow-x: auto;
      overflow-y: hidden;
	  position:relative;
	  .look-btn{
		  cursor: pointer;
		  position: absolute;
		  right: vw(20);
		  top: 6%;
		  transform: translateY(-50%);
		  padding: vw(20);
		  display: flex;
		  align-items: center;
		  background: #0a4190;
		  border-radius: vw(4);
		  font-size: vw(16);
		  font-weight:700;
		  color: #fff;
		  z-index: 999;
		  img{
			  width:vw(100);
			  // height:;
		  }
	  }
      .scenic-box {
        width: 100%;
        height: 100%;
      }
      /* 滚动条整体样式 */
      &::-webkit-scrollbar {
        height: vh(10); /* 滚动条的宽度 */
      }
      /* 滚动条轨道 */
      &::-webkit-scrollbar-track {
        background: 'transparent'; /* 轨道的背景色 */
      }
      /* 滚动条滑块 */
      &::-webkit-scrollbar-thumb {
        background: rgba(0, 150, 255, 0.63); /* 滑块的背景色 */
        border-radius: 5px; /* 滑块的圆角 */
      }
      > img {
        width: auto;
        height: 100%;
      }
    }
    .footer {
      .item {
        flex: 1;
        height: vh(140);
        display: flex;
        align-items: center;
        background-image: url('@/assets/images/bg-3.png');
        background-size: 100% 100%;
        &:nth-child(1) {
          margin-right: vw(10);
        }
        .bg {
          padding-left: vw(20);
          width: vw(243);
          height: vh(40);
          display: flex;
          align-items: center;
          background: linear-gradient(90deg, rgba(0, 150, 255, 0.34) 0%, rgba(0, 150, 255, 0) 100%);
          &:nth-child(1) {
            margin-bottom: vh(4);
          }
          .label {
            width: vw(120);
            font-weight: 400;
            font-size: vw(14);
            color: #fff;
          }
          .value {
            font-weight: bold;
            font-size: vw(28);
            color: #fff;
          }
          .success {
            color: #02f9fa;
          }
          .error {
            color: #e21b1b;
          }
        }
      }
      .list {
        margin-top: vh(4);
        height: vh(116);
        overflow: hidden;
      }
      .cell {
        display: flex;
        margin-left: vw(4);
        margin-top: vh(12);
        &:nth-last-child(1) {
          margin-bottom: 0;
        }
        .tag {
          padding: 0 vw(16);
          font-weight: bold;
          font-size: vw(14);
          color: #fff;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: vw(2);
        }
        .tag--important {
          @extend .tag;
          background: #feae00;
        }
        .tag--warn {
          @extend .tag;
          background: #d9011b;
        }
        .tag--normal {
          @extend .tag;
          background: #2380fb;
        }
        .content {
          margin-left: vw(4);
          padding: 0 vw(10);
          width: vw(760);
          height: vh(24);
          line-height: vh(24);
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          font-weight: 400;
          font-size: vw(14);
          color: #ffffff;
          border-radius: vw(2);
          background: rgba(0, 150, 255, 0.28);
        }
      }
      .more {
        cursor: pointer;
        width: auto;
        height: vh(100);
        margin-top: vh(12);
      }
    }
  }
</style>
