<template>
  <div class="renyuan">
    <div class="block1">
      <layout-title title="边界入侵统计"/>
      <div class="options">
        <div v-for="(item,index) in block1OptionsList" :key="index" class="option">
          <div class="imger">
            <img :src="item.img" alt="">
          </div>
          <div class="info">
            <div class="label">{{ item.title }}</div>
            <div class="text">{{ item.count }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="block2">
      <layout-title title="区域摄像头数量"/>
      <div class="options">
        <div id="main1"/>
      </div>
    </div>
    <div class="block4">
      <layout-title title="报警列表"/>
      <div class="content">
        <div class="table">
          <div class="tr">
            <div class="td">区域名称</div>
            <div class="td">报警设备编号</div>
            <div class="td">状态告警</div>
          </div>
          <div v-for="(item,index) in block4List" :key="index" class="tr">
            <div class="td">{{ item.alarmName }}</div>
            <div class="td">{{ item.equipmentName }}</div>
            <div class="td">{{ item.statusName }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import layoutTitle from './title.vue'
import CountTo from 'vue-count-to'
import { requestFN } from '@/utils/request'
import * as echarts from 'echarts'

let Echarts1
export default {
  components: {
    CountTo,
    layoutTitle
  },
  props: {
    corpInfoId: {
      type: String,
      default: ''
    },
    area: {
      type: String,
      default: ''
    },
    gangkou: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      block1OptionsList: [
        {
          title: '报警数量',
          img: require('../../../assets/map/zhongdian/ico1.png'),
          count: '-'
        },
        {
          title: '监控数量',
          img: require('../../../assets/map/zhongdian/ico2.png'),
          count: '-'
        }
      ],
      block2OptionsList: [
        {
          img: require('../../../assets/map/zhongdian/ico5.png'),
          label: '处罚次数',
          count: 0
        },
        {
          img: require('../../../assets/map/zhongdian/ico6.png'),
          label: '处罚金额',
          count: 0
        }
      ],
      block3OptionsList: ['风险区域统计', '组织机构统计'],
      block3OptionsIndex: 0,
      block3List: [
        {
          CORP_NAME: '-',
          OUTSOURCED_COUNT: '-',
          CHECK_COUNT: '-',
          HIDDEN_COUNT: '-'
        }
      ],
      block4List: []
    }
  },
  mounted() {
    this.initNum()
    this.initgetTable()
    window.onresize = function() {
      Echarts1 && Echarts1.resize()
    }
  },
  beforeDestroy() {
    Echarts1 = null
  },
  methods: {
    getCount() {
      requestFN(
        '/map/keyProject/findFormCount',
        {
          CORPINFO_ID: this.corpInfoId,
          AREA: this.area,
          GANGKOU: this.gangkou
        }
      ).then((data) => {
        // 第一个数组
        this.block1OptionsList[0].count = data.pd.STATE_COUNT
        this.block1OptionsList[1].count = data.pd.VIDEO_COUNT
        this.block1OptionsList[2].count = data.pd.CHECK_COUNT
        this.block1OptionsList[3].count = data.pd.HIDDEN_COUNT
        // 第二个数组
        this.block2OptionsList[0].count = data.pd.PUNISH_COUNT
        this.block2OptionsList[1].count = data.pd.AMOUT_SUM
      })
    },
    initNum() {
      requestFN('/map/getAllDwMessage', { corpId: this.corpInfoId, source: '0' }
      ).then((data0) => {
        this.block1OptionsList[0].count = data0.alarmList.page.total
        requestFN('/map/mapPlatformelectronic/listAllLocation', { corpId: this.corpInfoId, TYPE: 'bianjieruqin' }
        ).then((data1) => {
          this.block4List = data0.alarmList.list
          this.block1OptionsList[1].count = data1.varList.length
          this.initEcharts1(data1.iconData)
        }).catch((e) => {
          this.$message.error(e)
        })
      }).catch((e) => {
        this.$message.error(e)
      })
    },
    initgetTable() {
      requestFN(
        '/map/keyProject/list?showCount=10&currentPage=1',
        {
          CORPINFO_ID: this.corpInfoId,
          AREA: this.area,
          GANGKOU: this.gangkou
        }
      ).then((data) => {
        this.block3List = data.varList
      })
    },
    initEcharts1(data) {
      console.log(data)
      const XaxisData = []
      const seriesData1 = []
      for (const optionKey in data) {
        console.log(data[optionKey])
        for (let i = 0; i < data[optionKey].length; i++) {
          console.log(data[optionKey][i])
          XaxisData.push(data[optionKey][i].NAME)
          seriesData1.push(data[optionKey][i].num)
        }
      }

      // eslint-disable-next-line no-undef
      Echarts1 = echarts.init(document.querySelector('#main1'))
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '2%',
          right: '4%',
          bottom: '5%',
          top: '12%',
          containLabel: true
        },
        legend: {
          top: '0%',
          right: '0%',
          textStyle: {
            color: '#fff',
            fontSize: 14
          },
          itemWidth: 12,
          itemHeight: 10
        },
        xAxis: {
          type: 'category',
          data: XaxisData,
          axisLine: {
            lineStyle: {
              color: '#fff'
            }
          },
          axisLabel: {
            textStyle: {
              fontSize: 12
            }
          }
        },
        yAxis: {
          type: 'value',
          max: '50',
          axisLine: {
            show: false,
            lineStyle: {
              color: '#fff'
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#8c9493'
            }
          },
          axisLabel: {
            textStyle: {
              fontSize: 14
            }
          }
        },
        series: [
          {
            name: '摄像头',
            type: 'bar',
            barWidth: '10%',
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: '#00f0ff'
                    },
                    {
                      offset: 1,
                      color: '#0066ff'
                    }
                  ],
                  false
                )
              }
            },
            data: seriesData1
          }
        ]
      }
      Echarts1.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.renyuan {
  .title {
    background-image: url("../../../assets/map/menjin/title_on.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 113px;
    height: 26px;
    font-size: 14px;
    line-height: 26px;
    text-align: center;
    color: #fff;

    &.active {
      background-image: url("../../../assets/map/menjin/title.png");
    }
  }

  .block1 {
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    .options {
      padding: 10px 15px;
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      display: flex;
      flex-wrap: wrap;

      .option {
        display: flex;
        width: 50%;
        align-items: center;
        margin-top: 10px;

        &:nth-child(-n+2) {
          margin-top: 0;
        }

        .imger {
          width: 50px;
          height: 50px;
          background-image: url("../../../assets/map/menjin/img1.png");
          background-size: 100% 100%;
          background-repeat: no-repeat;
          text-align: center;
          margin-left: 20px;

          img {
            width: 30px;
            height: 30px;
            animation: scale 2s infinite;
            margin-top: 10px;
          }
        }

        .info {
          color: #FFFFFF;
          margin-left: 10px;

          .label {
            font-size: 12px;
            height: 25px;
            line-height: 25px;
          }

          .text {
            font-size: 24px;
            background: linear-gradient(to top, #48bbf0, #ffffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: bold;
            font-family: "PingFang SC", "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", "微软雅黑", sans-serif;
            margin-top: -5px;
          }
        }
      }
    }
  }

  .block2 {
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
    margin-top: 10px;

    .options {
      padding: 10px 15px;
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;

      #main1 {
        width: 100%;
        height: 250px;
      }
    }
  }

  .block3 {
    margin-top: 10px;
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    .content {
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      padding: 10px;

      .options {
        display: flex;
        justify-content: flex-end;

        .title {
          cursor: pointer;
        }
      }

      .table {
        margin-top: 5px;

        .tr {
          display: flex;

          &:nth-child(odd) {
            background-color: rgba(42, 86, 158, 0.53);
          }

          .td {
            flex: 1;
            text-align: center;
            font-size: 12px;
            color: #fff;
            padding: 5px;
          }
        }
      }
    }
  }

  .block4 {
    margin-top: 10px;
    width: 410px;
    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));

    .content {
      border: 1px solid;
      border-image: linear-gradient(to bottom, rgba(58, 122, 149, 0), rgba(58, 122, 149, 1)) 1;
      border-top: none;
      padding: 10px;

      .options {
        display: flex;
        justify-content: flex-end;

        .title {
          cursor: pointer;
        }
      }

      .table {
        margin-top: 5px;

        .tr {
          display: flex;

          &:nth-child(odd) {
            background-color: rgba(42, 86, 158, 0.53);
          }

          .td {
            flex: 1;
            text-align: center;
            font-size: 12px;
            color: #fff;
            padding: 5px;
          }
        }
      }
    }
  }
}

@keyframes scale {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(0.9);
  }
}

@keyframes slideY {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(5px);
  }
  100% {
    transform: translateY(0);
  }
}
</style>
