<template>
  <div class="content-app">
    <div class="up">
      <SecurityCheckHeader
        title="安检通道综合效率"
        :withExportButton="false"
        :withChangeButton="false"
        @search="search"
      />
    </div>
    <div class="comprehensive_cont">
      <div class="comprehensive_top">
        <div class="header">
          <p>月过检件数统计</p>
          <span>单位：件</span>
        </div>
        <div id="comprehensive-month"></div>
      </div>
      <div class="comprehensive_bootom">
        <div class="header">
          <p>日过检件数统计</p>
          <span>单位：件</span>
        </div>
        <div id="comprehensive-day"></div>
      </div>
    </div>
  </div>
</template>
<script>
import { discoloration, discolorationcops } from '@/utils/app-ecahrts'
import SecurityCheckHeader from '../components/securityCheckHeader.vue'
import { emergency } from '@/api/statistics/statistics.js'
export default {
  data() {
    return {
      queryData: {},
    }
  },
  components: {
    SecurityCheckHeader,
  },
  // mounted() {
  // },
  methods: {
    search(data) {
      this.queryData = {
        startTime: data[0][0],
        endTime: data[0][1],
        riskRating: data[1],
        agentCode: data[2],
      }
      this.relationDate(data)
    },
    //点击跳转
    echar() {
      this.$router.push({
        path: '/securityCheck/waybillTable',
        query: this.queryData,
      })
    },
    async relationDate(data) {
      try {
        let params = {
          beginDate: data[0][0],
          endDate: data[0][1],
          proxyId: data[1],
          proxyLevel: data[2],
          querytype: '月',
        }
        let paramspoy = {
          beginDate: data[0][0],
          endDate: data[0][1],
          proxyId: data[1],
          proxyLevel: data[2],
          querytype: '日',
        }
        const result = await emergency(params)
        const resultcopy = await emergency(paramspoy)
        if (result.status == 200) {
          let arr = [] //高风险
          let Low = [] //低风险
          let firs = [] //优先级
          let pt = []
          let arrx = [] //x轴
          result.data.forEach((element) => {
            arrx.push(element.date)
            element.datas.forEach((res) => {
              if (res.level === 'A') {
                arr.push(res.count)
              } else if (res.level == 'B') {
                Low.push(res.count)
              } else if (res.level == 'C') {
                firs.push(res.count)
              } else if (res.level == 'D') {
                pt.push(res.count)
              }
            })
            // console.log(arr);
          })
          this.init(arr, arrx, Low, firs, pt)
        }
        if (resultcopy.status == 200) {
          let arr = [] //高风险
          let Low = [] //低风险
          let firs = [] //优先级
          let pt = []
          let arrx = [] //x轴
          resultcopy.data.forEach((element) => {
            arrx.push(element.date)
            element.datas.forEach((res) => {
              if (res.level === 'A') {
                arr.push(res.count)
              } else if (res.level == 'B') {
                Low.push(res.count)
              } else if (res.level == 'C') {
                firs.push(res.count)
              } else if (res.level == 'D') {
                pt.push(res.count)
              }
            })
            // console.log(arr);
          })
          this.inits(arr, arrx, Low, firs, pt)
        }
        console.log(result)
      } catch (error) {
        console.log(error)
      }
    },
    //月
    init(arr, arrx, Low, firs, pt) {
      let myChart = this.$echarts.init(document.getElementById('comprehensive-month')) //统计折线
      let myChartcopy = this.$echarts.init(document.getElementById('comprehensive-day')) //统计折线
      discoloration.series[0].data = arr
      discoloration.series[1].data = Low
      discoloration.series[2].data = firs
      discoloration.series[3].data = pt
      discoloration.xAxis.data = arrx
      myChart.clear()
      myChart.setOption(discoloration)
      window.onresize = () => {
        this.queryData.agentLevel = a.seriesName
        myChart.resize()
      }
      myChart.on('click', (a, b) => {
        this.queryData.startTime = a.name + '-01'
        this.queryData.endTime = a.name + '-31'
        this.queryData.agentLevel = a.seriesName
        this.echar()
      })
    },
    //日
    inits(arr, arrx, Low, firs, pt) {
      let myChart = this.$echarts.init(document.getElementById('comprehensive-day')) //统计折线
      discolorationcops.series[0].data = arr
      discolorationcops.series[1].data = Low
      discolorationcops.series[2].data = firs
      discolorationcops.series[3].data = pt
      discolorationcops.xAxis.data = arrx
      myChart.clear()
      myChart.setOption(discolorationcops)
      window.onresize = () => {
        myChart.resize()
      }
      myChart.on('click', (a, b) => {
        this.queryData.startTime = a.name
        this.queryData.endTime = a.name
        this.queryData.agentLevel = a.seriesName
        // this.queryData.openResult = a.value;
        this.echar()
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.comprehensive_cont {
  width: 100%;
  > .comprehensive_top {
    width: 100%;
    height: 38vh;
    background: #ffffff;
    box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 24px;
  }
  > .comprehensive_bootom {
    margin-top: 16px;
    width: 100%;
    height: 38vh;
    background: #ffffff;
    box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 24px;
  }
}
#comprehensive-month {
  width: 100%;
  height: 90%;
}
#comprehensive-day {
  width: 100%;
  height: 90%;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  > p {
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #101116;
    margin: 0 0 24px 0;
  }
  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #101116;
  }
}
</style>