<template>
  <!-- 安检通道综合效率 -->
  <div class="content-app">
    <div class="up">
      <SecurityCheckHeader
        title="安检通道综合效率"
        :withExportButton="false"
        :withChangeButton="false"
        @search="search"
      />
    </div>
    <div class="comprehensive">
      <div class="header">
        <p>过检效率 - 综合风险等级</p>
        <span>单位：件/小时</span>
      </div>
      <div class="comprehensive_cont">
        <div id="comprehensiveCharts"></div>
      </div>
    </div>
  </div>
</template>
<script>
import { eleCake } from "@/utils/app-ecahrts";
import SecurityCheckHeader from "../components/securityCheckHeader.vue";
import { correlation } from "@/api/statistics/statistics.js";
export default {
  data() {
    return {
      queryData: {},
    };
  },
  components: {
    SecurityCheckHeader,
  },
  mounted() {
    // this.relationDate();
  },
  methods: {
    search(data) {
      this.queryData = {
        startTime: data[0][0],
        endTime: data[0][1],
        proxyId: data[1],
        proxyLevel: data[2],
        type: "日",
      };
      this.relationDate(data);
    },
    //点击跳转
    echar() {
      this.$router.push({
        path: "/waybillTable",
        query: this.queryData,
      });
    },
    change() {
      this.$router.push("./agentTable");
    },
    async relationDate(data) {
      try {
        let params = {
          beginDate: data[0][0],
          endDate: data[0][1],
          proxyId: data[1],
          proxyLevel: data[2],
          querytype: "日",
        };
        const result = await correlation(params);
        if (result.status == 200) {
          let arr = []; //高风险
          let Low = []; //低风险
          let firs = []; //优先级
          let pt = [];
          let strictly = [];
          let arrx = []; //x轴
          result.data.forEach((element) => {
            arrx.push(element.channel);
            element.datas.forEach((res) => {
              if (res.level === "高风险") {
                arr.push(res.count);
              } else if (res.level == "低风险") {
                Low.push(res.count);
              } else if (res.level == "优先") {
                firs.push(res.count);
              } else if (res.level == "普通") {
                pt.push(res.count);
              } else if (res.level == "严控") {
                strictly.push(res.count);
              }
            });
            // console.log(arr);
          });
          this.init(arr, arrx, Low, firs, pt, strictly);
        }
        console.log(result);
      } catch (error) {
        console.log(error);
      }
    },
    init(arr, arrx, Low, firs, pt, strictly) {
      let myChart = this.$echarts.init(
        document.getElementById("comprehensiveCharts")
      ); //统计折线
      eleCake.series[0].data = arr;
      eleCake.series[1].data = Low;
      eleCake.series[2].data = firs;
      eleCake.series[3].data = pt;
      eleCake.series[4].data = strictly;
      eleCake.xAxis.data = arrx;
      myChart.clear();
      myChart.setOption(eleCake, true);
      window.onresize = () => {
        myChart.resize();
      };
      myChart.on("click", (a, b) => {
        this.queryData.riskRating = a.seriesName;
        // this.queryData.openResult = a.value;
        this.echar();
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.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;
  }
}
.comprehensive {
  width: 100%;
  height: 80vh;
  padding: 24px;
  background: #ffffff;
  box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  > .comprehensive_cont {
    width: 100%;
    height: 95%;
    #comprehensiveCharts {
      width: 100%;
      height: 100%;
    }
  }
}
</style>