<template>
  <div id="yyjg">
    <div class="panel-left">
      <div class="pl-b1">
        <span class="title1-left">企业概况</span>
        <ul class="plb1-content">
          <!-- <li v-for="item in listData_qygk.data" @click="handleOpenEntList(item)"> -->
          <li v-for="item in listData_qygk.data">
            <img :src="item.icon" alt="">
            <div>
              <span>{{ item.showName||item.name }}</span>
              <span>{{item.count}}</span>
            </div>
          </li>
        </ul>
      </div>
      <div class="pl-b2">
        <span class="title1-left">作业申报</span>
        <div v-for="item in listData_zysb.data" class="list-item">
          <span>{{ item.name }}</span>
          <span>{{ item.count }}</span>
          <span>{{ item.unit }}</span>
        </div>
        <span class="top5">企业货物吞吐量TOP5</span>
        <div id="chart-top5"></div>
      </div>
      <EntInfoList :list-data="listData_entInfo.data" v-if="entInfoListShow" @closeEntList="entInfoListShow=false"/>
    </div>
    <div class="panel-right">
      <div class="pr pr-b1">
        <span class="title1-right">装卸监测</span>
        <el-carousel
          trigger="click"
          height="21vh"
          class="prb1-main"
          indicator-position="outside"
          arrow="never"
          :autoplay="true"
        >
          <el-carousel-item v-for="page in listData_zxjc_len" :key="page">
            <div v-for="item,index in listData_zxjc.data.slice((page-1)*2, (page-1)*2+2)" class="prb1-main-item">
              <i></i>
              <div>
                <div>
                  <span>{{ item.shipName }}</span>
                  <span>{{ item.state }}</span>
                </div>
                <span v-if="item.startWorkTime!=='--'">
                  {{ item.startWorkTime + ' - ' + item.endWorkTime }}
                </span>
                <span v-else>--</span>
                <div>
                  <div>
                    <span>货物: </span>
                    <span :title="item.cargoName">{{ item.cargoName }}</span>
                  </div>
                  <div>
                    <span>申报量(吨): </span>
                    <span>{{ item.declareTon }}</span>
                  </div>
                </div>
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="pr pr-b2">
        <span class="title1-right">运行动态</span>
        <div class="prb2-main">
          <div v-for="item in cataData_yxdt.data">
            <span>{{ item.value }}</span>
            <span>艘次</span>
            <i></i>
            <div><i></i><span>{{ item.title }}</span></div>
          </div>
        </div>
      </div>
      <div class="pr pr-b3">
        <span class="title1-right">违规告警</span>
        <div class="prb3-item" v-for="item in listData_wggj.data">
          <i></i>
          <div>
            <span>{{ item.type }}</span>
            <span>{{ item.value }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

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

<script setup>
  import { onMounted, reactive, nextTick, ref, computed } from 'vue';
  import { setEntThroughput5 } from '@/echarts/options';
  import EntInfoList from './cpns/EntInfoList'
  import { GetQygk, GetYxdt, GetZysb, GetZxjc, GetWggj } from '@/apis/yyjg'
  import { useDateFormat } from '@vueuse/core'
  import { ElCarousel, ElCarouselItem } from 'element-plus'
  import 'element-plus/es/components/carousel/style/css'
  import 'element-plus/es/components/carousel-item/style/css'

  onMounted(() => {
    getData()
    nextTick(() => {
      setEntThroughput5(document.getElementById('chart-top5'), chartData_entThroughput5.data)
    })
  })

  function getData() {
    getData_qygk()
    getData_yxdt()
    getData_zysb()
    getData_zxjc()
    getData_wggj()
  }

  function getData_qygk() {
    GetQygk().then(res => {
      res.data.forEach(i => {
        listData_qygk.data.forEach(j => {
          if(i.certtype === j.name) {
            j.count = i.id
          }
        })
      })
    })
  }

  const entInfoListShow = ref(false)

  const listData_qygk = reactive({data: [
    { name: '港口经营企业', count: 0, icon: require('../../assets/imgs/page_yyjg/icon-gkjy.png') },
    { name: '港口经营备案企业', count: 0, icon: require('../../assets/imgs/page_yyjg/icon-gkjy.png') },
    { name: '水路运输管理企业', showName: '国内水运企业', count: 0, icon: require('../../assets/imgs/page_yyjg/icon-gnsy.png') },
    { name: '国内船舶管理企业', count: 0, icon: require('../../assets/imgs/page_yyjg/icon-gnsy.png') }
  ]})

  function getData_zysb() {
    GetZysb().then(res => {
      listData_zysb.data.forEach(i => {
        if(i.fieldName==='ton') {
          let valLen = Math.round(+res.data['ton']).toString().length
          if(valLen<5) {
            i.count = +res.data['ton'].toFixed(2)
            i.unit = '吨'
          } else {
            i.count = (+res.data['ton']/10000).toFixed(2)
            i.unit = '万吨'
          }
        } else {
          i.count = res.data[i.fieldName]
        }
      })
      chartData_entThroughput5.data = res.data.topList.sort((a,b) => b.ton - a.ton)
      setEntThroughput5(document.getElementById('chart-top5'), chartData_entThroughput5.data)
    })
  }

  const listData_zysb = reactive({data: [
    { name: '当天货物装卸申报数', fieldName:'count', count: 0, unit: '件' },
    { name: '当天散货装卸吞吐量', fieldName:'ton', count: 0, unit: '吨' }
  ]})

  const chartData_entThroughput5 = reactive({data: [
    { unitName: '', ton: 0 },
		{ unitName: '', ton: 0 },
		{ unitName: '', ton: 0 },
		{ unitName: '', ton: 0 },
		{ unitName: '', ton: 0 }
  ]})

  function getData_zxjc() {
    GetZxjc().then(res => {
      listData_zxjc.data = res.data.Rows.sort((a,b) => b.startWorkTime - a.startWorkTime)
      setTimeout(() => {
        getData_zxjc()
      }, 10000);
    })
  }

  const listData_zxjc = reactive({data: [
    { shipName: '--', state: '--', startWorkTime: '--', endWorkTime: '--', cargoName: '--', declareTon: 0 },
    { shipName: '--', state: '--', startWorkTime: '--', endWorkTime: '--', cargoName: '--', declareTon: 0 }
  ]})

  const listData_zxjc_len = computed(() => {
    return Math.ceil(listData_zxjc.data.length/2)
  })

  function getData_yxdt() {
    GetYxdt().then(res => {
      cataData_yxdt.data.forEach(i => {
        i.value = res.data[i.fieldName]
      })
    })
  }

  const cataData_yxdt = reactive({data: [
    { title: '即将作业船舶数', fieldName: 'willWorkCount', value: 0 },
    { title: '作业完成船舶数', fieldName: 'finishWorkCount', value: 0 },
    { title: '作业中船舶数', fieldName: 'workingCount', value: 0 },
  ]})

  function getData_wggj() {
    GetWggj().then(res => {
      listData_wggj.data.forEach(i => {
        i.value = res.data[i.fieldName]
      })
    })
  }

  const listData_wggj = reactive({data: [
    { type: '超等级靠泊', fieldName: 'overGrade', value: 0 },
    { type: '港口经营许可证到期', fieldName: 'portExpire', value: 0 },
    { type: '危险货物作业附证到期', fieldName: 'dangerExpire', value: 0 },
  ]})

  const listData_entInfo = reactive({data: [
    
  ]})

  function handleOpenEntList(item) {
    let temp = []
    for(let i=0; i<item.count; i++) {
      if(i%5===0) {
        temp.push({ entName: '上海闵行房屋建筑材料材料料料有限公司' })
      } else {
        temp.push({ entName: '上海闵行房屋建筑材料有限公司' })
      }
      
    }
    listData_entInfo.data = temp
    entInfoListShow.value = true
  }


</script>

<style lang="scss" scoped>
#yyjg {
  
  .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 20px 30px;
  }

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

  .pl-b1 {
    .plb1-content {
      li {
        width: fit-content;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        cursor: pointer;
        &>img {
          margin: 0 20px 0 -10px;
        }
        &>div {
          display: flex;
          flex-direction: column;
          span:nth-child(1) {
            position: relative;
            display: inline-block;
            width: 153px;
            height: 26px;
            margin-top: 12px;
            font-size: 16px;
            font-weight: bold;
            font-style: italic;
            color: transparent;
            line-height: 26px;
            background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
            -webkit-background-clip: text;
            &::after {
              content: '';
              position: absolute;
              left: 0;
              top: 0;
              width: 100%;
              height: 100%;
              background: url('@/assets/imgs/page_yyjg/bg-text1.png') no-repeat;
              background-size: 100% 100%;
              z-index: -1;
            }

          }
          span:nth-child(2) {
            font-size: 30px;
            font-family: BarlowBold;
            font-style: italic;
            color: transparent;
            background: linear-gradient(180deg, #FFFFFF 30%, #47D5F7 100%);
            -webkit-background-clip: text;
          }
        }
      }
      li:nth-child(3), li:nth-child(4)  {
        &>div>span:nth-child(2) {
          background: linear-gradient(180deg, #FFFFFF 30%, #48F7C3 100%);
          -webkit-background-clip: text;
        }
      }
    }
  }

  .pl-b2 {
    .list-item {
      box-sizing: border-box;
      width: 290px;
      height: 28px;
      margin-bottom: 18px;
      padding: 0 10px 7px 26px;
      background: url('@/assets/imgs/page_yyjg/bg-zysb.png') no-repeat;
      background-size: 100% 100%;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      span:nth-child(1) {
        font-size: 16px;
        line-height: 16px;
        font-style: italic;
        color: transparent;
        background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
        -webkit-background-clip: text;
      }
      span:nth-child(2) {
        box-sizing: border-box;
        display: inline-block;
        padding: 0 5px;
        flex: 1;
        text-align: right;
        font-size: 20px;
        line-height: 20px;
        font-family: BarlowBold;
        color: transparent;
        background: linear-gradient(180deg, #08D8BC 0%, #10ECDE 100%);
        -webkit-background-clip: text;
      }
      span:nth-child(3) {
        font-size: 14px;
        line-height: 14px;
        color: #FFFFFF;
        background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
        -webkit-background-clip: text;
      }
    }

    .top5 {
      display: block;
      box-sizing: border-box;
      width: 143px;
      height: 26px;
      background: url('@/assets/imgs/page_yyjg/bg-top5.png') no-repeat;
      background-size: 100% 100%;
      line-height: 26px;
      text-align: center;
      font-size: 12px;
      font-weight: bold;
      color: #FFFFFF;
    }

    #chart-top5 {
      width: 100%;
      height: 30vh;
    }
  }

  .pr-b1 {
    .prb1-main {
      width: 90%;
    }
    .prb1-main-item {
      display: flex;
      align-items: center;
      margin: 10px 0 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 5px;
          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;
          }
          span:nth-child(2) {
            font-size: 14px;
            font-weight: 400;
            font-style: italic;
            color: #FF0000;
          }
        }
        &>span:nth-child(2) {
          box-sizing: border-box;
          padding: 0 5px;
          display: block;
          margin: 10px 0;
          font-size: 14px;
          font-family: BarlowBold;
          color: rgba($color: #fff, $alpha: 0.6);
        }
        &>div:nth-child(3) {
          box-sizing: border-box;
          padding: 0 5px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          &>div {
            display: flex;
            align-items: center;
          }
          div>span:nth-child(1) {
            font-size: 14px;
            font-weight: 400;
            color: #FFFFFF;
          }
          div:nth-child(1)>span:nth-child(2) {
            display: inline-block;
            max-width: 57px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-size: 14px;
            color: #66E6FF;
          }
          div:nth-child(2)>span:nth-child(2) {
            font-size: 16px;
            font-family: BarlowBold;
            color: #66E6FF;
          }
        }
      }
    }
    ::v-deep {
      .el-carousel__indicator--horizontal {
        margin: 0 4px;
        padding: 8px 4px;
      }
      .el-carousel__indicator button {
        width: 5px;
        height: 5px;
        border-radius: 50%;
      }
    }
  }

  .pr-b2 {
    .prb2-main {
      position: relative;
      width: 95%;
      height: 25vh;
      &>div {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: absolute;
        &>span:nth-child(1) {
          font-size: 24px;
          font-family: BarlowBold;
          color: #A5D2FF;
        }
        &>span:nth-child(2) {
          font-size: 12px;
          font-weight: 400;
          color: rgba($color: #FAFCFF, $alpha: 0.8);
        }
        &>i {
          display: block;
          width: 98px;
          height: 98px;
          background: url('@/assets/imgs/page_yyjg/icon-yxdt2.png') no-repeat;
          background-size: 100% 100%;
          margin-top: -30px;
        }
        &>div:nth-child(4) {
          position: relative;
          width: 60px;
          text-align: center;
          span {
            font-size: 14px;
            font-weight: 400;
            color: #FFFFFF;
          }
          i {
            position: absolute;
            left: -15px;
            top: 2px;
            display: inline-block;
            width: 13px;
            height: 13px;
            transform: translateY(2px);
            margin-right: 3px;
            background: url('@/assets/imgs/page_yyjg/dot-blue.png') no-repeat;
            background-size: 100% 100%;
          }
        }
      }
      &>div:nth-child(1) {
        top: 30px;
        left: 0;
      }
      &>div:nth-child(2) {
        top: 30px;
        right: 0;
      }
      &>div:nth-child(3) {
        top: 90px;
        left: 50%;
        transform: translateX(-50%);
        &>i {
          background: url('@/assets/imgs/page_yyjg/icon-yxdt1.png') no-repeat;
          background-size: 100% 100%;
          margin-top: -20px;
        }
        &>div:nth-child(4) {
          width: fit-content;
          i {
            background: url('@/assets/imgs/page_yyjg/dot-green.png') no-repeat;
            background-size: 100% 100%;
          }
        }
      }
    }
  }

  .pr-b3 {
    .prb3-item {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      i {
        display: block;
        width: 83px;
        height: 81px;
        background: url('@/assets/imgs/page_yyjg/icon-wg.png') no-repeat;
        background-size: 100% 100%;
      }
      &>div {
        margin-right: 20px;
        span:nth-child(1) {
          position: relative;
          display: block;
          width: 153px;
          height: 26px;
          padding-left: 8px;
          font-size: 14px;
          font-weight: bold;
          font-style: italic;
          color: transparent;
          line-height: 26px;
          background: linear-gradient(0deg, #ACDDFF 0%, #FFFFFF 100%);
          -webkit-background-clip: text;
          &::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: url('@/assets/imgs/page_yyjg/bg-wggj.png') no-repeat;
            background-size: 100% 100%;
            z-index: -1;
          }
        }
        span:nth-child(2) {
          display: block;
          width: 100%;
          margin-top: 10px;
          font-size: 26px;
          line-height: 26px;
          font-family: BarlowBold;
          font-style: italic;
          color: transparent;
          background: linear-gradient(0deg, #FFFFFF 30%, #47D5F7 100%);
          -webkit-background-clip: text;
        }
      }
    }
  }

}
</style>
