<template>
  <div id="ssky">
    <div class="panel-left">
      <span class="title1-left" @click="handlePjylClick" :class="{'highlight': pjylSelected}">浦江游览</span>
      <div class="pl-b1 pl">
        <span class="title2-left">游览资源</span>
        <div class="ylzy-item" @click="handleBDListShow('ylzy-boat')">
          <img :src="require('@/assets/imgs/page_ssky/icon-youchuan.png')" alt="">
          <div>
            <span>游船数</span>
            <div>
              <span>{{ylzyData.boatNum}}</span><span>艘</span>
            </div>
          </div>
        </div>
        <div class="ylzy-item" @click="handleBDListShow('ylzy-dock')">
          <img :src="require('@/assets/imgs/page_ssky/icon-matou.png')" alt="">
          <div>
            <span>码头数</span>
            <div>
              <span>{{ylzyData.dockNum}}</span><span>个</span>
            </div>
          </div>
        </div>
      </div>
      <BoatDockList :list-data="ylzyData.boatList" :list-title="'游船信息'" v-if="boatDockListShow==='ylzy-boat'" @closeBoatList="boatDockListShow=false"/>
      <BoatDockList :list-data="ylzyData.dockList" :list-title="'码头信息'" v-if="boatDockListShow==='ylzy-dock'" @closeBoatList="boatDockListShow=false"/>
      <div class="pl-b2 pl">
        <span class="title2-left">码头客流量</span>
        <div class="plb2-row1">
          <i></i>
          <div>
            <span>当前总客流</span>
            <span>{{formatNum(mtkllData.total)}}</span>
          </div>
        </div>
        <div class="plb2-row2">
          <div class="plb2-item" v-for="item, index in mtkllData.catagory" :key="item.name">
            <span>{{item.name}}</span>
            <div>
              <div :style="'width:'+formatCataBarWidth(item.value)"></div>
            </div>
            <span>{{formatNum(item.value) }}</span>
          </div>
        </div>
       
      </div>
      <div class="pl-b3 pl">
        <span class="title2-left">临时航班</span>
        <transition-group name="lshbList" tag="div" style="height: 20vh;">
          <div class="lshb-item" v-for="item in lshbData.value" :key="item.name">
            <i></i>
            <div>
              <div>
                <span>{{ item.name }}</span>
              </div>
              <div>
                <div>
                  <span>{{ item.value }}</span>
                  <span>人</span>
                </div>
                <div>
                  <span>{{ item.type }}</span>
                  <i @click="showLshbDetail(item)"></i>
                </div>
              </div>
              <span>{{ item.ent }}</span>
            </div>
          </div>
        </transition-group>
      </div>
    </div>
    <div class="panel-right">
      <span class="title1-right" @click="handleDjldClick" :class="{'highlight': djldSelected}">对江轮渡</span>
      <div class="pr-b1 pr">
        <span class="title2-right">轮渡资源</span>
        <div class="prb1-main">
          <div @click="handleBDListShow('ldzy-dock')">
            <i></i>
            <div>
              <span>渡口数</span>
              <div>
                <span>{{ldzyData.dk}}</span>
                <span>个</span>
              </div>
            </div>
          </div>
          <div  @click="handleBDListShow('ldzy-boat')">
            <i></i>
            <div>
              <span>渡船数</span>
              <div>
                <span>{{ldzyData.dc}}</span>
                <span>艘</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <BoatDockList :list-data="ldzyData.dockList" :list-title="'渡口信息'" v-if="boatDockListShow==='ldzy-dock'" @closeBoatList="boatDockListShow=false"/>
      <BoatDockList :list-data="ldzyData.boatList" :list-title="'渡船信息'" v-if="boatDockListShow==='ldzy-boat'" @closeBoatList="boatDockListShow=false"/>
      <div class="pr-b2 pr">
        <span class="title2-right">轮渡客流量</span>
        <div class="prb2-p1">
          <img :src="require('@/assets/imgs/page_ssky/logo-ldkll.png')" alt="">
          <div>
            <div v-for="item, index in ldklData.value" :key="index">
              <span>{{item.name}}</span>
              <span>{{formatNum(item.value)}}</span>
            </div>
          </div>
        </div>
        <div class="prb2-p2" @click="handleLineClick" :class="{'highlight': lineSelected }">
          <div class="ldkl-list" id="ldklList">
            <ListBoxLdkll v-for="item, index in ldklLineData.value" :key="index" :list-data="item" />
          </div>
        </div>
      </div>
      <div class="pr-b3 pr">
        <span class="title2-right">预警信息</span>
        <div v-for="item, index in yjxxData" @click="yyxxClick(item.mmsi)" :key="index" class="prb3-item">
          <div>
            <img :src="require('@/assets/imgs/page_ssky/icon-yj.png')" alt="">
            <span>{{ item.name }}</span>
          </div>
          <div>
            <span>{{item.time}}</span>
            <span>{{item.type}}</span>
            <span :class="item.status==='已处理'? 'yj-green': 'yj-red'">{{item.status}}</span>
          </div>
        </div>
      </div>
    </div>
    <LshbDialog v-if="lshbDiaShow" :lshb-data="lshbCurrent.value" @closeDialog="closeLshbDia" />

  </div>
</template>

<script>
export default {
  name: 'SskyHome',
}
</script>

<script setup>
  import { reactive, ref, onMounted, nextTick } from 'vue'
  import ListBoxLdkll from './cpns/ListBoxLdkll'
  import LshbDialog from './cpns/LshbDialog.vue'
  import BoatDockList from './cpns/BoatDockList.vue'
  import { Getdjld, Getpjyl, GetLshb, GetTouristBoat, GetFerryStation, GetPJWharf } from '@/apis/ssky'
  import { useRafFn } from '@vueuse/core'
  import { addResponseEventListener, callUIInteraction } from '@/webRtcVideo.js'
  import bus from '@/utils/bus'


  onMounted(() => {
    getdjld()
    getpjyl()
    // getlshb()
  })

  function getdjld() {
    Getdjld().then(res => {
      if(res.data) {
        // ldzyData.dc = res.data.dc
        // ldzyData.dk = res.data.dk
        ldklData.value.forEach(i => {
          switch (i.name) {
            case '当前总客流':
              i.value = res.data.dailyPassengerFlow
              break
            case '行人数':
              i.value = res.data.pedestrian
              break
            case '两轮车数':
              i.value = res.data.bicycle
              break
            case '三轮车数':
              i.value = res.data.motorcycle
              break
          }
        })
        ldklLineData.value = res.data.lineList
        nextTick(() => {
          ldklListScroll()
        })

      }
    })
    GetTouristBoat().then(res => {
      if(res?.Result?.data) {
        ldzyData.boatList = res.Result.data.filter(item=>item.SHIPTYPENAME!=='旅游客船')
        ldzyData.dc = ldzyData.boatList.length //res.count
        ylzyData.boatList = res.Result.data.filter(item=>item.SHIPTYPENAME==='旅游客船')
      }
    })
    GetFerryStation().then(res => {
      if(res?.data?.Rows?.list) {
        ldzyData.dk = res.data.Rows.total
        ldzyData.dockList = res.data.Rows.list
      }
    })
  }

  function getpjyl() {
    Getpjyl().then(res => {
      if(res.data) {
        /* mtzyData.value.forEach(i => {
          switch (i.name) {
            case '游船码头':
              i.value = res.data.cruiseShipTerminal
              break;
            case '游艇码头':
              i.value = res.data.marina
              break;
            case '公务码头':
              i.value = res.data.officialDock
              break;
          }
        }) */
        mtkllData.total = res.data.sumFlights
        mtkllData.catagory.forEach(i => {
          switch(i.name) {
            case '公共航班':
              i.value = res.data.publicFlights
              break
            case '特色航班':
              i.value = res.data.featuredFlights
              break
            case '临时航班':
              i.value = res.data.temporaryFlights
              break
          }
        })
      }
    })
    GetPJWharf().then(res => {
      if(res?.data?.Rows?.list) {
        ylzyData.dockNum = res.data.Rows.total
        ylzyData.boatNum = 26
        ylzyData.dockList = res.data.Rows.list
      }

    })
  }

  function getlshb() {
    GetLshb().then(res => {
      if(res.data?.rows.length>0) {

      }
    })
  }

  function ldklListScroll() {
    const ldklList = document.getElementById('ldklList')
    let itemH = ldklList.clientHeight / Math.ceil(ldklLineData.value.length) * 2
    const { pause, resume } = useRafFn(() => {
      if(Math.abs(ldklList.style.top.slice(0, -2)) >= itemH) {
        ldklList.style.top = 0
        let ldklListTemp = [...ldklLineData.value]
        for(let i=0; i<2; i++) {
          ldklListTemp.push(ldklListTemp.shift())
        }
        ldklLineData.value = ldklListTemp
      }
      ldklList.style.top = (Number(ldklList.style.top.slice(0, -2)) - 0.5) + 'px'
    })
    ldklList.onmouseenter = pause
    ldklList.onmouseleave = resume
  }

  /* const mtzyData = reactive({value: [
    { name: '游船码头', value: 0 },
    { name: '游艇码头', value: 0 },
    { name: '公务码头', value: 0 },
  ]})  */

  const ylzyData = reactive({
    boatNum: 0,
    dockNum: 0,
    boatList: [],
    dockList: []
  })

  const boatDockListShow = ref(false)

  function handleBDListShow(name) {
    if(name.indexOf('ldzy')!==-1 && name!==boatDockListShow.value) {
      bus.emit('hideToolBox');
    }
    boatDockListShow.value = boatDockListShow.value===name? false: name
  }

  const mtkllData = reactive({
    total: 0,
    catagory: [
      { name: '公共航班', value: 0 },
      { name: '特色航班', value: 0 },
      { name: '临时航班', value: 0 },
    ]
  })

  const lshbData = reactive({value: [
    { name: '浦江游览6', value:  12, type: '包船', ent: '上海浦江游览集团有限公司' , mmsi: '413768391'},
    { name: '水晶公主',  value:  18, type: '包船', ent: '上海浦江游览集团有限公司' , mmsi: '413865158'},
  ]})

  function formatNum(num){
    let result = '';
    let int = num.toString();
    while (int.length > 3) {
      result = ',' + int.slice(-3) + result;
      int = int.slice(0, int.length - 3);
    }
    if (int) {
      result = int + result;
    }
    return result;
  }

  function formatCataBarWidth(value) {
    const maxv = mtkllData.catagory.reduce((pre, i) => Math.max(pre, i.value),0)
    const result = Math.floor(value/maxv*100)
    return result<10 ? result+10+'%' : result+'%'
  }

  const lshbDiaShow = ref(false)
  const lshbCurrent = reactive({value: {}})

  function showLshbDetail(data) {
    lshbCurrent.value = data
    lshbDiaShow.value = true
  }

  function closeLshbDia() {
    lshbDiaShow.value = false
    lshbCurrent.value = {}
  }

  function handleLsDelete() {

  }

  const ldzyData = reactive({
    dk: 0,
    dc: 0,
    boatList: [],
    dockList: []
  })

  const ldklData = reactive({value: [
    { name: '当前总客流', value: 0 },
    { name: '行人数', value: 0 },
    { name: '两轮车数', value: 0 },
    { name: '三轮车数', value: 0 },
  ]})

  const ldklLineData = reactive({value: [
    {name: "-", num1: "0", num2: "0", num3: "0", sum: "0"},
    {name: "-", num1: "0", num2: "0", num3: "0", sum: "0"},
  ]})

  const yjxxData = [
    { name: '世博客渡18', time: '01-13 09:47', type: '船舶避碰', status: '待处理' , mmsi : '413766676'},
    { name: '世博客渡18', time: '01-13 09:44', type: '人员越界', status: '已处理' , mmsi : '413766676'},
    { name: '世博客渡20', time: '01-13 09:42', type: '船舶避碰', status: '已处理' , mmsi : '413766678'}
  ]

  const lineSelected = ref(false)

  function handleLineClick() {
    lineSelected.value = !lineSelected.value
    if(lineSelected.value) {
      lineOn()
    } else {
      lineOff()
    }
  }

  const pjylSelected = ref(false)

  function handlePjylClick() {
    pjylSelected.value = !pjylSelected.value
    if(pjylSelected.value) {
      lymtOn()
    } else {
      lymtOff()
    }
  }

  const djldSelected = ref(false)

  function handleDjldClick() {
    djldSelected.value = !djldSelected.value
    if(djldSelected.value) {
      mtOn()
    } else {
      mtOff()
    }
  }

  function callUIInteractionFormat(action) {
    if(action['Parameters']) {
      action['Parameters'] = JSON.stringify(action['Parameters'])
    }
    callUIInteraction(action)
  }

  function lineOn() {
    let action = {
      "ActionName":"show_line"
    }
    callUIInteractionFormat(action);
  }

  function lineOff() {
    let action = {
      "ActionName":"close_line"
    }
    callUIInteractionFormat(action);
  }

  function mtOn() {
    let action = {
      "ActionName":"show_mt"
    }
    callUIInteractionFormat(action);
  }

  function mtOff() {
    let action = {
      "ActionName":"close_mt"
    }
    callUIInteractionFormat(action);
  }

  function lymtOn() {
    let action = {
      "ActionName":"show_lymt"
    }
    callUIInteractionFormat(action);
  }

  function lymtOff() {
    let action = {
      "ActionName":"close_lymt"
    }
    callUIInteractionFormat(action);
  }

  function yyxxClick(mmsi) {
    let action = {
      "ActionName":"position_by_type",
      "Parameters":{
        "position_type": 'boat',
        "position_name": mmsi
      }
    }

    callUIInteractionFormat(action);
  }

</script>

<style lang="scss" scoped>
#ssky {
  .panel-left, .panel-right {
    box-sizing: border-box;
    position: absolute;
    top: 105px;
    width: 380px;
    height: calc(100vh - 105px);
    text-align: left;
    display: flex;
    flex-direction: column;
  }
  .panel-left {
    left: 0;
    padding: 0 30px 10px;
    .boat-dock-list {
      left: 360px;
    }
    .title2-left {
      margin-bottom: 2.2vh;
    }
  }

  .panel-right {
    right: 0;
    padding: 0 30px 10px;
    .pr {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }

    .boat-dock-list {
      right: 360px;
    }
  }

  .pl-b1 {
    box-sizing: border-box;
    padding-right: 40px;
    margin-top: 1vh;

    .ylzy-item {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      color: #fff;
      cursor: pointer;
      &>div {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: center;
        width: 231px;
        height: 73px;
        margin-left: -40px;
        padding-left: 45px;
        background: url('@/assets/imgs/page_ssky/bg-ylzy.png') no-repeat;
        background-size: 100% 100%;
        &>span {
          font-size: 16px;
          color: rgba(91, 158, 224, 1);
        }
        &>div {
          span:first-child {
            margin-right: 6px;
            font-size: 26px;
            font-family: BarlowBold;
          }
          span:last-child {
            font-size: 14px;
          }
        }
      }
    }

  }

  .pl-b2 {
    margin-top: 3.5vh;
    .plb2-row1 {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-bottom: 20px;
      i {
        display: inline-block;
        width: 82px;
        height: 85px;
        background: url('@/assets/imgs/page_ssky/icon-zkl.png') no-repeat;
        background-size: contain;
        margin-right: 16px;
      }
      div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        span:first-child {
          font-size: 16px;
          margin-bottom: 6px;
        }
        span:last-child {
          font-size: 32px;
          font-family: BarlowBold;
          color: transparent;
          background: linear-gradient(0deg, rgba(255,192,66,1) 0%, rgba(255,255,255,1) 100%);
          -webkit-background-clip: text;
          text-shadow: 0 0 20px rgba(45, 172, 252, 0.4);
        }
      }
    }

    .plb2-row2 {
      .plb2-item {
        margin-bottom: 25px;
        padding-right: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &>span:nth-child(1) {
          font-size: 14px;
          font-weight: 400;
          color: #FFFFFF;
        }
        &>div:nth-child(2) {
          flex: 1;
          height: 4px;
          box-sizing: border-box;
          padding: 0 13px;
          div {
            position: relative;
            height: 100%;
            background: linear-gradient(90deg, rgba(102, 170, 255, 0.1) 0%, rgba(102, 170, 255, 1) 100%);
            &::after {
              position: absolute;
              right: -17px;
              top: -19px;
              content: '';
              display: block;
              width: 43px;
              height: 41px;
              background: url('@/assets/imgs/page_ssky/hangban-gg.png') no-repeat;
              background-size: cover;
            }
          }
        }
        &>span:nth-child(3) {
          width: 55px;
          text-align: right;
          font-size: 18px;
          font-family: Barlow;
          color: rgba($color: #fff, $alpha: 0.8);
        }
      }
      .plb2-item:nth-child(2)>div:nth-child(2)>div {
        background: linear-gradient(90deg, rgba(241, 216, 146, 0.1) 0%, rgba(241, 216, 146, 1) 100%);
        &::after {
          background: url('@/assets/imgs/page_ssky/hangban-ts.png') no-repeat;
          background-size: cover;
        }
      }
      .plb2-item:nth-child(3)>div:nth-child(2)>div {
        background: linear-gradient(90deg, rgba(193, 169, 249, 0.1) 0%, rgba(193, 169, 249, 1) 100%);
        &::after {
          background: url('@/assets/imgs/page_ssky/hangban-ls.png') no-repeat;
          background-size: cover;
        }
      }
    }
    
    
  }

  .pl-b3 {
    margin-top: 3vh;
    .lshb-item {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
  
      &>i {
        display: flex;
        width: 73px;
        height: 86px;
        background: url('@/assets/imgs/common/icon-lshb.png') no-repeat;
        background-size: 100% 100%;
      }
  
      &>div {
        &>div:nth-child(1) {
          box-sizing: border-box;
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 0 8px;
          width: 222px;
          height: 24px;
          background: url('@/assets/imgs/common/bg-text1.png') no-repeat;
          background-size: 100% 100%;
  
          span:nth-child(1) {
            font-size: 18px;
            font-weight: bold;
            font-style: italic;
            color: transparent;
            background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
            -webkit-background-clip: text;
          }
        }
  
        &>div:nth-child(2) {
          box-sizing: border-box;
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding-left: 8px;
          margin: 6px 0;

          &>div {
            display: flex;
            align-items: center;
          }
  
          div:nth-child(1) {
            &>span:nth-child(1) {
              margin-right: 7px;
              font-size: 18px;
              font-family: BarlowBold;
              color: #FFFFFF;
              line-height: 18px;
            }
            &>span:nth-child(2) {
              font-size: 12px;
              color: #FFFFFF;
            }
          }
  
          div:nth-child(2){
            &>span {
              font-size: 14px;
              font-style: italic;
              color: #FF0000;
            }
            &>i {
              display: inline-block;
              width: 24px;
              height: 24px;
              margin-left: 10px;
              background: url('@/assets/imgs/page_ssky/btn-detail.png') no-repeat;
              background-size: contain;
              cursor: pointer;
            }
          }
        }

        &>span:nth-child(3) {
          font-size: 13px;
          color: #FFFFFF;
          margin-left: 8px;
        }
      }
    }

    .lshbList-move,.lshbList-enter-active,.lshbList-leave-active{
      transition: all 0.5s ease;
    }
    .lshbList-enter-from
    // ,.lshbList-leave-to
    {
      opacity: 0;
      transform: translateX(-80px);
    }

  }

  .pr-b1 {
    margin-top: 1vh;
    .prb1-main {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 1vh;
      width: 98%;
      &>div {
        display: flex;
        align-items: center;
        cursor: pointer;
        i {
          display: block;
          width: 80px;
          height: 80px;
          background: url('@/assets/imgs/page_ssky/boat-dks.png') no-repeat;
          background-size: contain;
        }
        &>div {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: flex-start;
          &>span {
            font-size: 14px;
            font-weight: 400;
            color: #00FFFF;
          }
          &>div {
            span:nth-child(1) {
              font-size: 34px;
              font-family: BarlowBold;
              margin-right: 8px;
              text-shadow: 0 0 20px rgba(45, 172, 252, 1);
            }
            span:nth-child(2) {
              font-size: 14px;
            }
          }
        }

      }
      &>div:nth-child(2) > i {
        background: url('@/assets/imgs/page_ssky/boat-dcs.png') no-repeat;
        background-size: contain;
      }
    }
  }

  .pr-b2 {
    margin-top: 2vh;
    .prb2-p1 {
      display: flex;
      align-items: center;
      margin: 20px 0 10px 0;
      
      &>div {
        display: flex;
        flex-direction: column;
        
        &>div {
          box-sizing: border-box;
          padding-left: 30px;
          width: 225px;
          height: 34px;
          margin-bottom: 10px;
          line-height: 28px;
          background: url('@/assets/imgs/page_ssky/bg-ldkll.png') no-repeat;
          background-size: contain;
          span:nth-child(1) {
            display: inline-block;
            width: 50%;
            font-size: 13px;
            color: #FFFFFF;
          }
          span:nth-child(2) {
            display: inline-block;
            width: 50%;
            font-size: 14px;
            font-family: YSBTH;
            color: #FFEA00;
            &::before {
              content: '';
              display: inline-block;
              width: 7px;
              height: 10px;
              margin-right: 7px;
              background: url('@/assets/imgs/page_ssky/arrow-ldkll.png') no-repeat;
              background-size: 7px 8px;
              background-position: center;
            }
          }
        }
        &>div:not(:nth-child(1)) {
          span:nth-child(1) {
            &::before {
              content: '';
              display: inline-block;
              width: 4px;
              height: 4px;
              margin-right: 5px;
              transform: translateY(-2px);
              background: #00AAFF;
            }
          }
          span:nth-child(2) {
            color: #73D0FF;
          }
        }
      }
    }

    .prb2-p2 {
      width: calc(100% - 6px);
      height: 15vh;
      overflow: hidden;
      position: relative;
      border: 2px solid transparent;
      padding-left: 2px;
      .ldkl-list {
        cursor: pointer;
        position: absolute;
        top: 0;
      }
      &.highlight {
        border: 2px solid yellow;
      }
    }
  }

  .pr-b3 {
    margin-top: 1vh;
    .title2-right {
      margin-bottom: 2vh;
    }
    .prb3-item {
      margin: 0 15px 20px 0;
      &>div:nth-child(1) {
        width: 276px;
        height: 24px;
        display: flex;
        align-items: center;
        background: url('@/assets/imgs/page_ssky/bg-lundu-line.png') no-repeat;
        background-size: contain;
        margin-bottom: 10px;
        img {
          margin-left: -5px;
        }
        span {
          font-size: 18px;
          font-weight: bold;
          font-style: italic;
          color: transparent;
          line-height: 24px;
          background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
          -webkit-background-clip: text;
        }
      }
      &>div:nth-child(2) {
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #FFFFFF;
        padding-left: 5px;
        span:nth-child(1) {
          font-size: 16px;
          font-family: BarlowBold;
        }
        span:nth-child(2) {
          font-size: 14px;
        }
        span:nth-child(3) {
          display: inline-block;
          width: 65px;
          height: 32px;
          font-size: 13px;
          line-height: 32px;
          text-align: center;
          font-style: italic;
          &.yj-red {
            background: url('@/assets/imgs/page_ssky/bg-dcl.png') no-repeat;
            background-size: contain;
          }
          &.yj-green {
            background: url('@/assets/imgs/page_ssky/bg-ycl.png') no-repeat;
            background-size: contain;
          }
        }
      }
    }
  }

}
</style>
