<template>
  <Bg2 class='ConditionStatistics'>
    <div class="statistics-header">
      <div class="title " ></div>
      <!-- <img class="icon-right " src="@screen/images/icon/icon_right.png" /> -->
    </div>
    <div class="content-box">
      <div class="box-title " style="margin-top: 15px;"><span>天气预报</span></div>
      <div class="box-content0">
        <div class="box-content0-t">
          <div>当前天气</div><div class="sline"></div><img :src="require('./location.svg')" /><div>济南市</div>
        </div>
        <div class="box-content0-m">
          
          <img :src="require(`@screen/images/weather/${cityWeather.icon}.svg`)" class="img" />
          <div class="temp">{{ cityWeather.temp }}</div>
          <div class="wind">
            <div>{{ cityWeather.text }}</div>
            <div>℃</div>
          </div>
          <div class="tags">
            <div class="tagstitle"><img :src="require('./triangle.svg')" /><div class="tagslabel">能见度</div></div>
            <div class="tagsValue">{{ cityWeather.vis }}㎞</div>
          </div>
          <div class="tags">
            <div class="tagstitle"><img :src="require('./triangle.svg')" /><div class="tagslabel">降雨量</div></div>
            <div class="tagsValue">{{ cityWeather.precip }}mm</div>
          </div>
        </div>
      </div>
      <div class="box-title "><span>交通事件</span></div>
      <div class="box-content1">
        <div class="box-content-l">
          <div class="event-item " origin="left">今日：<span>{{ earlyWarningEvents.day }}</span> 起</div>
          <div class="event-item " origin="left">本月：<span>{{ earlyWarningEvents.month }}</span> 起</div>
        </div>
        <div class="box-content-c ">
          <span class="num">{{ earlyWarningEvents.processing }}</span>
          <span class="text">处理中</span>
        </div>
        <div class="box-content-r">
          <div class="event-item " origin="right">本周：<span>{{ earlyWarningEvents.week }}</span> 起</div>
          <div class="event-item " origin="right">本年：<span>{{ earlyWarningEvents.year }}</span> 起</div>
        </div>
      </div>
      <div class="box-title"><span>在途车辆统计</span></div>
      <div class="box-content2">
        <div class="count">
          <div class="charts " ref="carStatisticsEchartBox"></div>
          <div class="count-item cars">
            <span class="icon"></span>
            <span class="label">数量：</span>
            <span class="value">{{p0}}</span>
            <span class="unit">辆</span>
          </div>
        </div>
        <div class="count">
          <div class="charts keep-ratio" ref="focusStatisticsEchartBox"></div>
          <div class="count-item focus">
            <span class="icon"></span>
            <span class="label">数量：</span>
            <span class="value">{{p1}}</span>
            <span class="unit">辆</span>
          </div>
        </div>
        <div class="count">
          <div class="charts keep-ratio" ref="otherStatisticsEchartBox"></div>
          <div class="count-item other">
            <span class="icon"></span>
            <span class="label">数量：</span>
            <span class="value">{{p2}}</span>
            <span class="unit">辆</span>
          </div>
        </div>
      </div>
      <!-- <div class="box-title"><span>今日交通异常</span></div>
      <div class="box-content3">
        <div class="processed">
          <span class="text">处理中：</span>
          <div class="sections">
            <div class="num-box">
              <span>0</span>
            </div>
            <span class="unit">处 /</span>
          </div>
          <div class="kilometer">
            <div class="num-box">
              <span>0</span>
            </div>
            <span class="unit">Km</span>
          </div>
        </div>
        <div class="abnormalList">
          <div class="listItem total">
            <span class="label">日拥堵累计段数：</span>
            <div class="value">
              <span class="num">0</span>
              <span class="unit">处</span>
            </div>
          </div>
          <div class="listItem kilometer">
            <span class="label">日拥堵累计公里数：</span>
            <div class="value">
              <span class="num">13.25</span>
              <span class="unit">Km</span>
            </div>
          </div>
        </div>
      </div> -->
    </div>
  </Bg2>
</template>

<script>
import * as echarts from "echarts";

import carStatistics from "./js/carStatistics.js";
import focusStatistics from "./js/focusStatistics.js";
import otherStatistics from "./js/otherStatistics.js";
import Bg2 from "@screen/components/Decorations/bg-2.vue"
import request from "@/utils/request";
import {toDecimal} from '@screen/utils/common'

import { getWeatherFormat }from '../../../perception/meteorologyCheck/data.js'
import moment from "moment";
import { forEach } from "lodash";
export default {
  name: 'ConditionStatistics',
  components: {
    Bg2
  },
  data() {
    return {
      earlyWarningEvents: {
        day: 0,
        processing: 0,
        month: 0,
        week: 0,
        year: 0,
      },
      cityWeather:{
        icon:'0',
        temp:'-',
        text:'-',
        humidity:'-'
      },
      p0:0,
      p1:0,
      p2:0
    }
  },
  methods:{
    bind(){
      this.bindTrafficIncident();
      this.bindWeather();
      this.bindCharts();
    },
    bindCharts(){
      const today = moment().format('YYYY-MM-DD')
      request({
        url: '/business/traffic-statistics/history/realTimeTrafficFlow',
        method: 'get',
        params: {
          startDate: today,
          periodType: 4,
          direction: 1
        }
      }).then(res1=>{
        request({
        url: '/business/traffic-statistics/history/realTimeTrafficFlow',
        method: 'get',
        params: {
          startDate: today,
          periodType: 4,
          direction: 3
          }
        }).then(res3=>{
          // totalPassengerFlow 客车 typeSpecialVehicleFlow//特种车 typeTruckFlow 其他
          let total = 0, p0 = 0, p1=0,p2=0,_p0 = 0, _p1=0,_p2=0;
          res1.data.forEach(x=>{
            total+=(x.totalPassengerFlow+x.typeTruckFlow+x.typeSpecialVehicleFlow)  
            p0 += x.totalPassengerFlow
            p1 += x.typeSpecialVehicleFlow
            p2 += x.typeTruckFlow
          })
          res3.data.forEach(x=>{

            total+=(x.totalPassengerFlow+x.typeTruckFlow+x.typeSpecialVehicleFlow)  
            p0 += x.totalPassengerFlow
            p1 += x.typeSpecialVehicleFlow
            p2 += x.typeTruckFlow
          })
          
          if(total > 0){
            _p0 = parseFloat((p0/total*100).toFixed(1))
            _p1 = parseFloat((p1/total*100).toFixed(1))
            _p2 = parseFloat((p2/total*100).toFixed(1))
          }
          
          this.p0 = p0;
          this.p1 = p1;
          this.p2 = p2;
          carStatistics.series[0].data[0].value = _p0;
          carStatistics.series[2].data[0].value = _p0;
          const myChart1 = echarts.init(this.$refs.carStatisticsEchartBox);
          myChart1.setOption(carStatistics);

          focusStatistics.series[0].data[0].value = _p1;
          focusStatistics.series[2].data[0].value = _p1;
          const myChart2 = echarts.init(this.$refs.focusStatisticsEchartBox);
          myChart2.setOption(focusStatistics);

          otherStatistics.series[0].data[0].value = _p2;
          otherStatistics.series[2].data[0].value = _p2;
          const myChart3 = echarts.init(this.$refs.otherStatisticsEchartBox);
          myChart3.setOption(otherStatistics);

        })
      })
    },
    bindTrafficIncident(){
      // 预警事件
      request({
            url: `/business/trafficIncidents/getTrafficIncidentsNum`,
            method: "get",
          })
            .then(({ code, data }) => {
              if (code != 200) return;

              this.earlyWarningEvents = data;
            })
    },
    bindWeather(){
      request({url: '/weatherForecast/currentWeatherAndForecastInformation',
        method: 'post',
        data: {
          "roadId":"G003537",
          "stakeNum":'K60+000',
          "forecastHour":"0",
          "managerId":"YG10201"
        }
      }).then(res=>{
        if (res.code != 200) return this.$message.error(res?.msg)
        if(res.data.length > 0){
          const data = res.data[0]
          this.cityWeather = getWeatherFormat(data)
        }
      })
    }
  },
  created() {
   
  },
  mounted() {
    this.bind();
  }
}
</script>

<style lang='scss' scoped>
.ConditionStatistics {
  width:100%;
  ::v-deep {
    .BackgroundClip.bg {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
    }
  }
  .statistics-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .icon-right {
      margin-right: 24px;
      margin-top: 36px;
    }

    .title {
      width: 220px;
      height: 40px;
      margin-top: 10px;
      margin-left: 10px;
      display: flex;
      align-items: center;
      background: url("~@screen/images/title/title_bg_001.png") no-repeat;
      background-size: 100% 100%;

      span {
        font-size: 30px;
        font-family: YouSheBiaoTiHei;
        font-weight: 400;
        letter-spacing: 2px;
        text-shadow: 0px 5px 0px rgba(0, 0, 0, 0.25);
        background: linear-gradient(180deg, #ffffff 0%, #4dd4ff 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-left: 24px;
      }
    }

  }

  .box-title {
    width: 100%;
    height: 26px;
    margin: 7px;
    background: url("~@screen/images/title/title_bg_002.png") no-repeat;

    span {
      display: inline-block;
      margin-left: 35px;
      font-size: 16px;
      font-family: Source Han Sans SC, Source Han Sans SC;
      font-weight: 500;
      color: #ffffff;
    }
  }

  .content-box {
    flex: 1;
    display: flex;
    flex-direction: column;
   
  }
  .box-content0{
    background: linear-gradient(180deg,
        #25394a00 0%,
        #25394a00 20%,
        #2AD9FD88 100%);
        border: 1px solid;
    border-image: linear-gradient(360deg,
        rgba(55, 231, 255, 0.42),
        rgba(55, 231, 255, 0.1),
        rgba(55, 231, 255, 0)) 1 1;
        border-top: 0px;
        height: 80px;
        width: 90%;
        margin: 15px 5%;
        padding: 0px 10px 10px 10px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
      .box-content0-t{
        font-size: 12px;
        display: flex;
        align-items: center;
        width: 100%;
        .sline{
          width: 2px;
          background-color: #2AD9FD;
          height: 10px;
          margin:0px 8px;
        }
        img{
          width: 19px;
          height: 14px;
          margin-right: 4px;
        }
      }
      .box-content0-m{
        flex: 1;
        width: 100%;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        .img{
          width: 40px;
          height: 40px;
          background-size: 100% 100%;
        }
        .temp{
          font-size: 30px;
          font-weight: bold;
          margin: 0px 8px 0px 20px;
        }
        .wind{
          display: flex;
          flex-direction: column;
          align-items: flex-start;
          justify-content: flex-end;
          font-size: 10px;
          flex: 1;
          height: 100%;
          padding-bottom: 5px;
        }
        .tags{
          margin-right: 30px;
          height: 45px;
          .tagstitle{
            display: flex;
            margin-bottom: 5px;
          }
          .tagslabel{
            opacity: .5;
            font-size: 14px;
            margin-left: 8px;
          }
          .tagsValue{
            padding-left: 18px;
          }
        }
      }

  }
  .box-content1 {
      display: flex;
      justify-content: space-between;
      
      .box-content-l {
        width: 163px;
        height: 100%;
        margin-top: 21px;
        margin-left: 22px;
        background: url("~@screen/images/bg/box_bg_left.png") no-repeat;
      }

      .box-content-c {
        width: 135px;
        height: 120px;
        background: url("~@screen/images/ybp.png") no-repeat;
        background-size: 100% 100%;
        position: relative;

        .num {
          width: 100%;
          text-align: center;
          position: absolute;
          top: 50px;
          font-size: 18px;
          font-family: 'Hiragino Sans GB', 'Hiragino Sans GB';
          font-weight: 600;
          color: #3de8ff;
          text-shadow: 0px 1px 2px rgba(23, 147, 227, 0.58);
        }

        .text {
          width: 100%;
          text-align: center;
          position: absolute;
          top: 75px;
          // left: 50px;
          margin: auto;
          font-size: 12px;
          font-family: 'Hiragino Sans GB', 'Hiragino Sans GB';
          font-weight: normal;
          color: #ffffff;
        }
      }

      .box-content-r {
        width: 163px;
        height: 80px;
        margin-top: 21px;
        margin-right: 22px;
        background: url("~@screen/images/bg/box_bg_right.png") no-repeat;
        background-size: 100% 100%;
      }

      .event-item {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 124px;
        height: 28px;
        margin-top: 7px;
        margin-left: 12px;
        background: url("~@screen/images/bg/button-bg.png") no-repeat;
        background-size: 100% 100%;
        font-size: 14px;
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 500;
        color: #ffffff;

        span {
          display: inline-block;
          width: 20px;
          margin-right: 12px;
          font-size: 16px;
          font-family: PangMenZhengDao-3, PangMenZhengDao-3;
          font-weight: 400;
          color: #FFCD4D;
          text-align: center;
          font-style: normal;
          text-transform: none;
        }
      }
    }
    .box-content2 {
      width: 85%;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;

      .count {
        .charts {
          width: 120px;
          height: 120px;
          margin: auto;
        }
        .count-item {
          width: 118px;
          height: 26px;
          margin-top: -10px;
          background: url("~@screen/images/bg/button-bg.png") no-repeat;
          background-size: 100% 100%;
          opacity: 1;
          // border: 1px solid;
          display: flex;
          justify-content: center;
          align-items: center;
          .icon {
            width: 6px;
            height: 6px;
            border-radius: 3px 3px 3px 3px;
            opacity: 1;
          }

          .label {
            display: inline-block;
            margin-left: 5px;
            font-size: 12px;
            font-family: PingFang SC, PingFang SC;
            font-weight: 400;
            color: #ffffff;
          }

          .value {
            display: inline-block;
            // margin-left: 10px;
            font-size: 14px;
            font-family: PangMenZhengDao;
            font-weight: 400;
          }

          .unit {
            display: inline-block;
            margin-left: 5px;
            font-size: 12px;
            font-family: PingFang SC, PingFang SC;
            font-weight: 400;
            color: #ffffff;
          }
        }

        .cars {
          .icon {
            background: #3fd7fe;
          }

          .value {
            color: #3fd7fe;
          }
        }

        .focus {
          .icon {
            background: #ff8820;
          }

          .value {
            color: #ff8820;
          }
        }

        .other {
          .icon {
            background: #29deaf;
          }

          .value {
            color: #29deaf;
          }
        }
      }
    }

    .box-content3{
      .processed {
        display: flex;
        justify-content: center;
        align-items: center;

        .text {
          font-size: 14px;
          font-family: PangMenZhengDao;
          font-weight: 400;
          color: #23bee1;
          line-height: 16px;
          letter-spacing: 1px;
        }

        .sections {
          display: flex;
          justify-content: center;
          align-items: center;

          .num-box {
            width: 30px;
            height: 30px;
            background: #047b6e;
            border-radius: 5px 5px 5px 5px;
            opacity: 1;
            border: 1px solid #2fe2cf;
            display: flex;
            justify-content: center;
            align-items: center;

            span {
              font-size: 16px;
              font-family: PangMenZhengDao-3, PangMenZhengDao-3;
              font-weight: 400;
              color: #ffffff;
            }
          }

          .unit {
            display: inline-block;
            margin-left: 10px;
            font-size: 14px;
            font-family: PangMenZhengDao;
            font-weight: 400;
            color: #2fe2cf;
          }
        }

        .kilometer {
          display: flex;
          justify-content: center;
          align-items: center;

          .num-box {
            width: 30px;
            height: 30px;
            background: #583500;
            border-radius: 5px 5px 5px 5px;
            opacity: 1;
            border: 1px solid #f4b149;
            margin-left: 10px;
            display: flex;
            justify-content: center;
            align-items: center;

            span {
              font-size: 16px;
              font-family: PangMenZhengDao-3, PangMenZhengDao-3;
              font-weight: 400;
              color: #ffffff;
            }
          }

          .unit {
            display: inline-block;
            margin-left: 10px;
            font-size: 14px;
            font-family: PangMenZhengDao;
            font-weight: 400;
            color: #f4b149;
          }
        }
      }

      .abnormalList {
        padding-bottom: 20px;

        .listItem {
          width: 410px;
          height: 34px;
          margin: 0 auto;
          margin-top: 10px;
          display: flex;
          justify-content: space-around;
          // align-items: center;
          background: url("~@screen/images/bg/box_total.png") no-repeat;
          font-weight: bold;

          .label {
            width: 220px;
            text-align: right;
            font-size: 12px;
            font-family: 'Hiragino Sans GB', 'Hiragino Sans GB';
            color: #fff;
            line-height: 40px;
            letter-spacing: 7px;
          }

          .value {
            flex: 1;
            width: 0;
            font-family: 'Hiragino Sans GB', 'Hiragino Sans GB';
            line-height: 40px;
            text-align: center;

            .num {
              font-size: 14px;
            }

            .unit {
              font-size: 12px;
              display: inline-block;
              margin-left: 5px;
            }
          }

        }

        .listItem.total {
          .value {
            color: #2fe2cf;
            text-shadow: 0px 1px 4px #2fe2cf;
          }
        }

        .listItem.kilometer {
          .value {
            span {
              font-size: 10px;
            }

            color: #f29600;
            text-shadow: 0px 1px 4px #f29600;
          }
        }

      }
    }
}
</style>
