<template>
  <div id="jtaq">
    <div class="panel-left">
      <div class="pl-b1">
        <span class="title1-left">船舶信息</span>
        <div class="plb1-part1">
          <img :src="require('@/assets/imgs/page_jtaq/icon-cbxx.png')" alt="">
          <div>
            <span>当前在港船舶总数</span>
            <div>
              <span>{{ data_cbxx.total }}</span>
              <span>艘次</span>
            </div>
          </div>
        </div>
        <ul class="plb1-part2">
          <li v-for="item in data_cbxx.cata">
            <span>{{ item.name }}</span>
            <span>{{ item.value }}</span>
            <span>艘</span>
            <div>
              <span>{{ cbxxPercent(item.value) }}</span>
              <span>%</span>
            </div>
            <span>占比</span>
          </li>
        </ul>
      </div>
      <div class="pl-b2">
        <span class="title2-left">船舶航行预测</span>
        <ul class="plb2-main">
          <li v-for="item in listData_cbhxyc.value">
            <span>{{ item.dist }}</span>
            <span>{{ item.value }}</span>
            <span>艘</span>
          </li>
        </ul>
      </div>
      <div class="pl-b3">
        <span class="title2-left">船舶功能分类</span>
        <div id="chart-cbgn"></div>
      </div>
      <div class="pl-b4">
        <span class="title2-left">船舶航行状态</span>
        <div v-for="item in data_cbhxzt.value" class="plb4-item">
          <img :src="item.iconUrl" alt="">
          <div>
            <span>{{ item.title }}</span>
            <div>
              <span>{{ item.value }}</span>
              <span>艘</span>
              <span>{{ hxztPercent(item.value) }}</span>
              <span>%</span>
              <span>占比</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="panel-right">
      <div class="pr-b1 pr">
        <span class="title1-right">运行态势</span>
        <span class="title2-right">安全通航信息</span>
        <el-carousel
          trigger="click"
          height="23vh"
          class="prb1-main"
          indicator-position="outside"
          arrow="never"
          :autoplay="!aqthPopupShow"
        >
          <el-carousel-item v-for="page in listData_aqthxx_len" :key="page">
            <div v-for="item,index in listData_aqthxx.value.slice((page-1)*2, (page-1)*2+2)" class="prb1-item" @click="showAqthPopup(index+(page-1)*2)">
              <span class="title3" :class="{'highlight':item.abstract[1]===aqthPopupData.value.code&&aqthPopupShow}">{{ item.title }}</span>
              <span v-for="item2 in item.abstract"> {{ item2 }}</span>
            </div>
          </el-carousel-item>
        </el-carousel>
        <div class="popup-aqth" v-if="aqthPopupShow">
          <i class="btn-close" @click="handleCloseAqthPopup"></i>
          <div class="title-dialog">{{ aqthPopupData.value.title }}</div>
          <p>{{ aqthPopupData.value.des }}</p>
        </div>
      </div>
      
      <div class="pr-b2 pr">
        <span class="title2-right">通航流量监测</span>
        <span class="title3">分时段流量统计</span>
        <div id="chart_fsdll"></div>
        <span class="title3">分航向流量统计</span>
        <div class="prb2-item" v-for="item in data_fhxll.value">
          <div>
            <img :src="require('@/assets/imgs/page_jtaq/icon-zhandian.png')" alt="">
            <span>{{ item.from }}</span>
            <i></i>
            <span>{{ item.to }}</span>
          </div>
          <div>
            <span>分航向流量统计</span>
            <span>{{ item.value }}</span>
            <span>艘次</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

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

<script setup>
  import { onMounted, reactive, computed, ref } from 'vue';
  import { setCbgn, setFsdll } from '@/echarts/options'
  import { ElCarousel, ElCarouselItem } from 'element-plus'
  import 'element-plus/es/components/carousel/style/css'
  import 'element-plus/es/components/carousel-item/style/css'
  import { GetThlljc, GetCbxx, GetThllByHour } from '../../apis/jtaq'


  onMounted(() => {
    getData()
    setCbgn(document.getElementById('chart-cbgn'), chartData_cbgnfl.value)
    setFsdll(document.getElementById('chart_fsdll'), chartData_fsdll.value)
  })

  function getData() {
    getData_thlljc()
    getData_cbxx()
  }

  function getData_cbxx() {
    GetCbxx().then(res => {
      listData_cbhxyc.value.forEach(i => {
        i.value = res.data.district[i.dist]
      })
      data_cbxx.total = res.data.inport
      data_cbxx.cata.forEach(i => {
        i.value = res.data[i.fieldName]
      })
      data_cbhxzt.value.forEach(i => {
        i.value = res.data[i.fieldName]
      })
      let boatTypeArr = []
      for (let key in res.data.boatType) {
        boatTypeArr.push({name: key, value: res.data.boatType[key]})
      }
      boatTypeArr = boatTypeArr.sort((a,b) => b.value - a.value)
      chartData_cbgnfl.value = [
        ...boatTypeArr.slice(0,4),
        { name: '其它', value: boatTypeArr.slice(4).reduce((sum, i) => sum + i.value, 0)}
      ]
      setCbgn(document.getElementById('chart-cbgn'), chartData_cbgnfl.value)
    })
  }

  const data_cbxx = reactive({
    total: 1157,
    cata: [
      { name: '重点追踪船舶', value: 0, fieldName: 'keyBoat' },
      { name: '载运危货船舶', value: 0, fieldName: 'dangerBoat' }
    ]
  })

  function cbxxPercent(value) {
    return (value / data_cbxx.total *100).toFixed(2)
  }

  const listData_cbhxyc = reactive({value: [
    { dist: '奉贤', value: 0 },
    { dist: '金山', value: 0 },
    { dist: '松江', value: 0 },
    { dist: '嘉定', value: 0 },
    { dist: '闵行', value: 0 },
    { dist: '青浦', value: 0 },
    { dist: '宝山', value: 0 },
    { dist: '崇明', value: 0 },
    { dist: '浦东', value: 0 }
  ]})

  const data_cbhxzt = reactive({value: [
    { title: '航行中船舶', value: 0, iconUrl: require('@/assets/imgs/page_jtaq/icon-cb-hxz.png'), fieldName: 'runningBoatCount'},
    { title: '靠泊中船舶', value: 0, iconUrl: require('@/assets/imgs/page_jtaq/icon-cb-kbz.png'), fieldName: 'stopBoatCount'}
  ]})

  function hxztPercent(value) {
    const sum = data_cbhxzt.value.reduce((total,i) => i.value+total, 0)
    if(sum===0||!value) {
      return '-'
    }
    return Math.round(value / sum *100)
  }

  const chartData_cbgnfl = reactive({value:[
    { name: '--', value: 0 },
    { name: '--', value: 0 },
    { name: '--', value: 0 },
    { name: '--', value: 0 },
    { name: '--', value: 0 }
  ]})

  const listData_aqthxx = reactive({value:[
    {
      title: '黄浦江疏浚作业',
      abstract: [
        '2023年3月20日至2023年4月5日',
        '沪航通〔2023〕0171号'
      ],
      des: `作业地点：\n轮渡其秦线浦东侧码头前沿水域。\n作业方式：\n作业船“中工88”，长25.93米，宽7.6米。作业船顺岸方向布置，采用定位桩方法作业。其他施工船舶: 沪松泖捞4、申浚803、申浚驳802、浙海宁货02139、浙海盐货02083。\n注意事项：\n1、作业船舶应在显明易见处悬挂规定信号；\n2、作业船应加强值班了望和VHF06频道守听，随时采取安全措施和保持通信联络；\n3、航行船舶应距作业船50米外缓速通过；\n4、风力大于6级，作业暂停并顺延1天。`
    },
    {
      title: '黄浦江疏浚作业',
      abstract: [
        '2023年3月20日至2023年4月5日',
        '沪航通〔2023〕0170号'
      ],
      des: '作业地点：\n轮渡其秦线浦西侧码头前沿水域。\n作业方式：\n作业船“中工88”，长25.93米，宽7.6米。作业船顺岸方向布置，采用定位桩方法作业。其他施工船舶: 沪松泖捞4、申浚驳802、浙海宁货02139、浙海盐货02083、申浚803。\n注意事项：\n1、作业船舶应在显明易见处悬挂规定信号；\n2、作业船应加强值班了望和VHF06频道守听，随时采取安全措施和保持通信联络；\n3、航行船舶应距作业船50米外缓速通过；\n4、风力大于6级，作业暂停并顺延1天。'
    },
    {
      title: '黄浦江趸船拆装维修工程',
      abstract: [
        '2023年3月19日至2023年3月31日，白天作业',
        '沪航通〔2023〕0169号'
      ],
      des: '作业地点：\n安记栈码头（杨家渡轮渡上游）前沿水域。\n作业方式：\n作业船“浦江拾号”长41.8米，宽10.80米。作业时船顺靠码头，不抛锚作业。其他作业船:浦江肆号。\n注意事项：\n1、作业船舶应在显明易见处悬挂规定信号；\n2、作业船应加强值班了望和VHF06频道守听，随时采取安全措施和保持通信联络；\n3、航行船舶应距作业船50米外缓速通过；\n4、风力大于6级，作业暂停并顺延1天。'
    },
    {
      title: '黄浦江疏浚作业',
      abstract: [
        '2023年3月20日至2023年4月5日',
        '沪航通〔2023〕0165号'
      ],
      des: '作业地点：\n轮渡杨复线浦西侧码头前沿水域。\n作业方式：\n作业船“中工88”，长25.93米，宽7.6米。作业船顺岸方向布置，采用定位桩方法作业。其他施工船舶: 沪松泖捞4、申浚驳802，申浚 803。\n注意事项：\n1、作业船舶应在显明易见处悬挂规定信号；\n2、作业船应加强值班了望和VHF06频道守听，随时采取安全措施和保持通信联络；\n3、航行船舶应距作业船50米外缓速通过；\n4、风力大于6级，作业暂停并顺延1天。'
    },
    
  ]})

  const listData_aqthxx_len = computed(() => {
    return Math.ceil(listData_aqthxx.value.length/2)
  })
  
  const aqthPopupShow = ref(false)
  const aqthPopupData = reactive({value: {}})
  
  function showAqthPopup(index) {
    aqthPopupShow.value = true
    aqthPopupData.value = {...listData_aqthxx.value[index], code:listData_aqthxx.value[index].abstract[1]}
  }

  function handleCloseAqthPopup() {
    aqthPopupShow.value = false
  }

  function getData_thlljc() {
    GetThlljc().then(res => {
      chartData_fsdll.value = res.data.boatCountList
      let listTemp = JSON.parse(JSON.stringify(res.data.boatCountList))
      listTemp.forEach(i => {
        i.GPSTIME = i.GPSTIME.slice(-2)
      })
      let chartFsdll = setFsdll(document.getElementById('chart_fsdll'), listTemp)
      let lastIndex = res.data.boatCountList.length-1
      chartFsdll.dispatchAction({
        type: 'select',
        seriesIndex: 0,
        dataIndex: lastIndex,
      })
      getData_fhxll(res.data.boatCountList[lastIndex].GPSTIME)
      chartFsdll.getZr().on('click', (params)=> {
        const pointInPixel = [params.offsetX, params.offsetY]
        if (chartFsdll.containPixel('grid', pointInPixel)) {
          let dataIndex = chartFsdll.convertFromPixel({ seriesIndex: 0 }, pointInPixel)[0]
          chartFsdll.dispatchAction({
            type: 'select',
            seriesIndex: 0,
            dataIndex: dataIndex,
          })
          getData_fhxll(chartData_fsdll.value[dataIndex].GPSTIME)
        }
      })
    })
  }

  function getData_fhxll(time) {
    GetThllByHour(time+':00:00').then(res => {
      data_fhxll.value.forEach(i => {
        i.value = res.data[i.fieldName]
      })
    })
  }

  const chartData_fsdll = reactive({value: [
    { GPSTIME: '00', NUM: 0 },
		{ GPSTIME: '06', NUM: 0 },
		{ GPSTIME: '12', NUM: 0 },
		{ GPSTIME: '18', NUM: 0 }
  ]})

  const data_fhxll = reactive({value: [
    { from: '黄浦江上游', to: '黄浦江下游', value: 0, fieldName: 'down' },
    { from: '黄浦江下游', to: '黄浦江上游', value: 0, fieldName: 'up' },
  ]})

</script>

<style lang="scss" scoped>
#jtaq {
  
  .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;
    justify-content: space-between;
  }
  .panel-left {
    left: 0;
    padding: 0 30px 30px;
  }

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

  .pl-b1 {
    .plb1-part1 {
      display: flex;
      align-items: center;
      margin: 0 0 15px 10px;
      &>img {
        width: 100px;
        height: 71px;
      }
      &>div {
        display: flex;
        flex-direction: column;
        &>span {
          font-size: 14px;
          color: #FFFFFF;
        }
        &>div {
          margin-top: 3px;
          span:nth-child(1) {
            width: 57px;
            height: 21px;
            font-size: 28px;
            font-family: BarlowBold;
            color: transparent;
            background: linear-gradient(180deg, rgba(224,244,255,0.9) 0%, rgba(89,102,128,0.9) 100%);
            -webkit-background-clip: text;
            letter-spacing: 2px;
          }
          span:nth-child(2) {
            margin-left: 6px;
            font-size: 13px;
            color: rgba($color: #fff, $alpha: 0.6);
          }
        }
      }
    }
    .plb1-part2 {
      margin-left: 10px;
      li {
        display: flex;
        align-items: flex-end;
        margin-bottom: 20px;
        &>span:nth-child(1) {
          font-size: 14px;
          color: #D9EAF5;
        }
        &>span:nth-child(2), &>div>span:nth-child(1) {
          display: inline-block;
          font-size: 22px;
          font-family: BarlowBold;
          color: #00EAFF;
          line-height: 22px;
        }
        &>span:nth-child(2) {
          width: 50px;
          margin: 0 5px;
          text-align: center;
        }
        &>span:nth-child(3), &>span:nth-child(5){
          font-size: 13px;
          color: #D9EAF5;
        }
        &>div {
          display: flex;
          align-items: flex-end;
          width: 60px;
          margin-left: 15px;
          &>span:nth-child(2) {
            font-size: 14px;
            font-family: BarlowBold;
            color: #00EAFF;
            line-height: 14px;
          }
        }
          
      }
    }
  }

  .pl-b2 {
    .plb2-main {
      width: 90%;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      &>li {
        width: 91px;
        height: 25px;
        margin: 15px 0;
        display: flex;
        justify-content: center;
        align-items: flex-end;
        background: url('@/assets/imgs/page_jtaq/bg-cbyc.png') no-repeat;
        background-size: 100% 100%;
        span {
          margin-bottom: 8px;
          font-size: 14px;
          color: transparent;
          background: linear-gradient(180deg, rgba(255,255,255,1) 0%, rgba(175, 231, 255, 0.8) 80%, rgba(0,179,255,0.8) 100%);
          text-shadow: 0 6px 0 rgba(175, 231, 255, 0.2);
          -webkit-background-clip: text;
          line-height: 14px;
        }
        span:nth-child(2) {
          margin: 0 4px 7px;
          font-family: BarlowBold;
          font-size: 24px;
          line-height: 24px;
        }
      }
    }
  }

  .pl-b3 {
    #chart-cbgn {
      height: 18vh;
      width: 90%;
    }
  }

  .pl-b4 {
    .plb4-item {
      display: flex;
      align-items: center;
      margin: 10px 0;
      &>img {
        width: 85px;
        height: 85px;
      }
      &>div {
        box-sizing: border-box;
        width: 200px;
        height: 66px;
        padding-left: 15px;
        transform: translateX(-10px);
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: url('@/assets/imgs/page_jtaq/bg-hxzt.png') no-repeat;
        background-size: 100% 100%;
        &>span {
          font-size: 16px;
          font-weight: bold;
          font-style: italic;
          color: transparent;
          text-shadow: 0px 0px 5px rgba($color: #9EC7FF, $alpha: 0.3);
          background: linear-gradient(0deg, #6FC2FF 0%, #CCDAE6 35%, #FFFFFF 60%);
          -webkit-background-clip: text;
        }
        &>div {
          display: flex;
          align-items: flex-end;
          margin-top: 5px;
          span:nth-child(1), span:nth-child(3), span:nth-child(4) {
            padding-right: 3px;
            font-size: 22px;
            line-height: 22px;
            font-family: YSBTH;
            font-weight: 400;
            font-style: italic;
            color: transparent;
            text-shadow: 0px 0px 5px rgba($color: #9EC7FF, $alpha: 0.3);
            background: linear-gradient(-1deg, #9EC7FF 0%, #DCEBFF 40%, #FFFFFF 100%);
            -webkit-background-clip: text;
          }
          span:nth-child(2), span:nth-child(5) {
            margin: 0 5px;
            font-size: 14px;
            line-height: 22px;
            color: #FFFFFF;
          }
          span:nth-child(4) {
            font-size: 16px;
            line-height: 20px;
          }
        }
      }
    }
  }

  .pr-b1 {
    position: relative;
    .prb1-main {
      width: 82%;
      .prb1-item {
        margin: 15px 0;
        cursor: pointer;
        &>span:not(:first-child) {
          position: relative;
          display: block;
          padding-left: 26px;
          height: 21px;
          margin: 10px 0;
          font-size: 14px;
          font-family: BarlowBold;
          color: rgba($color: #fff, $alpha: 0.6);
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          &::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            display: inline-block;
            width: 21px;
            height: 21px;
            background: url('@/assets/imgs/page_jtaq/icon-aqth.png') no-repeat;
            background-size: 100% 100%;
          }
        }
        .highlight {
          color: #FFE874;
        }
      }

      :deep(.el-carousel__indicator--horizontal) {
        margin: 0 4px;
      }
      :deep(.el-carousel__indicator button) {
        width: 5px;
        height: 5px;
        border-radius: 50%;
      }
    }

    .popup-aqth {
      position: absolute;
      box-sizing: border-box;
      padding: 20px 10px 20px 20px;
      top: 5vh;
      left: -320px;
      width: 320px;
      height: 364px;
      background: url('@/assets/imgs/page_jtaq/bg-popup.png') no-repeat;
      background-size: 100% 100%;

      .btn-close {
        position: absolute;
        right: 18px;
        top: 15px;
        display: block;
        width: 12px;
        height: 12px;
        padding: 4px;
        background: url('@/assets/imgs/common/btn-close.png') no-repeat;
        background-size: 12px 12px;
        background-position: center;
        cursor: pointer;
      }

      p:nth-child(3) {
        height: calc(100% - 34px);
        padding-right: 10px;
        margin-top: 10px;
        overflow-y: auto;
        font-size: 14px;
        color: #eee;
        line-height: 22px;
        white-space: pre-wrap;
      }
    }
  }

  .pr-b2 {
    #chart_fsdll {
      width: 90%;
      height: 16vh;
      margin: 5px 0 10px;
    }

    .title2-right {
      margin-bottom: 25px;
    }

    .prb2-item {
      margin: 16px 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      &>div {
        display: flex;
      }
      &>div:first-child {
        align-items: center;
        width: fit-content;
        height: 32px;
        margin-bottom: 20px;
        padding-right: 14px;
        background: url('@/assets/imgs/page_jtaq/bg-fhx-1.png');
        background-size: 100% 100%;
        &>img {
          width: 47px;
          height: 51px;
          margin-right: 5px;
        }
        &>i {
          display: inline-block;
          width: 51px;
          height: 19px;
          margin: 0 6px 0 10px;
          background: url('@/assets/imgs/page_jtaq/icon-arrow.png') repeat-x;
          background-size: 17px 19px;
        }
        &>span {
          font-size: 14px;
          font-weight: bold;
          font-style: italic;
          color: #FFFFFF;
        }
      }
      &>div:last-child {
        box-sizing: border-box;
        justify-content: center;
        align-items: flex-end;
        width: 290px;
        height: 34px;
        padding-bottom: 13px;
        background: url('@/assets/imgs/page_jtaq/bg-fhx-2.png');
        background-size: 100% 100%;
        span:nth-child(1), span:nth-child(3) {
          font-size: 14px;
          color: #FFFFFF;
        }
        span:nth-child(2) {
          margin: 0 13px;
          font-size: 32px;
          font-family: BarlowBold;
          color: transparent;
          line-height: 32px;
          background: linear-gradient(0deg, rgba(148, 239, 255, 1) 0%, rgba(85, 226, 255, 1) 100%);
          -webkit-background-clip: text;
        }
      }
    } 
  }
}
</style>
