<template>
  <msg-card class="item-trafficEvent" title="交通事件">
    <div class="full-h trafficEvent" v-loading="eventLoading"
         element-loading-spinner="el-icon-loading"
         element-loading-text="数据加载中..."
         element-loading-background="rgba(3, 11, 25, 0.8)">
      <div class="event-list-container full-w-h">
        <div
            class="trafficItem"
            :class="`event${i.eventType}`"
            v-for="(i,index) of eventList"
            :key="index"
        >
          <div class="leftImg" :class="`event${i.eventType}`"></div>
          <div class="right">
            <div>{{ i.eventNumber }}</div>
            <div :title="i.eventLabel">{{ i.eventLabel }}</div>
          </div>
        </div>
      </div>
    </div>
  </msg-card>
</template>

<script>
import {eventAnalysis, eventAnalysisV2} from "../../../../dao/situation";
import msgCard from "../../../../components/Standard/msg-card.vue";

export default {
  name: "trafficEventV2",
  components: {
    msgCard,
  },
  data() {
    return {
      eventLoading: true,
      chart: null,
      // 交通事件
      trafficEvents: [],
      eventList: [],
    };
  },
  methods: {
    getEventAnalysis() {
      eventAnalysisV2({eventType:'1,401,701,702,703,704,502,503,504'}).then((res) => {
        console.log('events...',res)
        this.eventLoading = false
        this.eventList = res.content.reduce((a, b) => {
          if(['502','503','504'].includes(b.eventType)){
            let containFlag = false
            for(let aItem of a){
              if(aItem.eventType === 'yd'){
                containFlag = true
                aItem.eventNumber += Number(b.eventNumber)
              }
            }
            if(!containFlag){
              a.push({
                eventType:'yd',
                eventNumber: b.eventNumber,
                eventLabel:'拥堵事件'
              })
            }
          }else if(['1','401'].includes(b.eventType)){
            let containFlag = false
            for(let aItem of a){
              if(aItem.eventType === 'tcsj'){
                containFlag = true
                aItem.eventNumber += Number(b.eventNumber)
              }
            }
            if(!containFlag){
              a.push({
                eventType:'tcsj',
                eventNumber: b.eventNumber,
                eventLabel:'停车事件'
              })
            }
          }
          else{
            a.push(b)
          }
          return a
        }, [])
      });
    },
  },
  mounted() {
    this.getEventAnalysis();
  },
};
</script>

<style lang="less" scoped>
.item-trafficEvent {
  //::-webkit-scrollbar {
  //  width: 0;
  //  height: 0;
  //  background-color: #f5f7fa;
  //}

  ::v-deep .el-tabs__item {
    color: white;
    height: 28px;
    line-height: 24px;
    font-size: 16px;
    font-weight: 500;
    padding: 0 12px;
  }

  ::v-deep .el-tabs__active-bar {
    background: linear-gradient(90deg,
    transparent 0%,
    rgba(41, 110, 194, 1) 50%,
    transparent 100%);
  }

  ::v-deep .el-tabs__header {
    margin: 0;
    height: 30px;
  }

  ::v-deep .el-tabs__nav {
    transform: translateX(-50%) !important;
    left: 50%;
  }

  ::v-deep .el-tabs__nav-wrap::after {
    background-color: transparent;
  }

  ::v-deep .el-tabs__content {
    background-color: #010613;
    padding: 12px;
    overflow: auto;
    height: calc(100% - 30px);
  }

  .head {
    display: flex;
    width: 100%;
    height: 100%;

    .name {
      height: 100%;
      width: 90%;
      line-height: normal;
    }

    .number {
      line-height: normal;
    }
  }

  .trafficEvent {
    overflow: hidden;
  }

  .event-list-container {
    color: rgba(155, 177, 212, 1);
    display: flex;
    height: 100%;
    justify-content: space-between;
    flex-flow: row wrap;
    align-items: center;

    .trafficItem {
      width: 49%;
      font-size: 14px;
      height:29%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      background-color: #012546;
      padding: 6px 10px 6px 0;

      .leftImg{
        width: 36%;
        height: 100%;
        background-position-x: right;
        background-size: auto 100%;
        background-repeat: no-repeat;

      }
      .eventtcsj{
        background-image: url("../../../../assets/images/smartCityMain/event1.png");
      }
      .eventyd{
        background-image: url("../../../../assets/images/smartCityMain/event222.png");
      }
      .event701{
        background-image: url("../../../../assets/images/smartCityMain/event701.png");
      }
      .event702{
        background-image: url("../../../../assets/images/smartCityMain/event702.png");
      }
      .event703{
        background-image: url("../../../../assets/images/smartCityMain/event703.png");
      }
      .event704{
        background-image: url("../../../../assets/images/smartCityMain/event704.png");
      }

      .right {
        width: 55%;
        max-width: 60%;
        color: rgba(255,255,255,0.9);
        font-size: 16px;
        display: inline-block;

        text-align: left;
        // max-width: 80%;
        white-space: nowrap;
        div{
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        div:first-child{
          font-size: 18px;

          color:#0cd2ff;
          font-weight: bold;
        }
      }
    }
    .trafficItem:nth-child(5){
      margin-bottom: 0;
    }
    .trafficItem:nth-child(6){
      margin-bottom: 0;
    }
  }
}
</style>
