<template>
  <div class="sewage">
    <div class="reply" :style="{ color: color }">污水监测</div>
    <div class="sewage-box">
      <div class="box" v-for="item in echartList" :key="item.id">
        <chart-sewage-corona :config-obj="item"></chart-sewage-corona>
      </div>
    </div>
    <br>
    <div class="echarts-line">
      <div class="reply1" :style="{ color: color }">污水监测</div>
      <div class="echarts-box" v-for="item in lineList" :key="item.id">
        <template v-if= "item.data.length > 0">
          <chart-sewage-line :line-config="item"></chart-sewage-line>
        </template>
       <template v-else>
         <el-empty description="设备暂无数据"></el-empty>
       </template>
      </div>
    </div>
  </div>
</template>

<script>
import ChartSewageCorona from "@/views/Zoology/chart/ChartSewageCorona";
import ChartSewageLine from "@/views/Zoology/chart/ChartSewageLine";
import { mapState } from 'vuex'
import { getEnvList, getSevenEnv } from "../../utils/api";

export default {
  name: "Sewage",
  components: {
    ChartSewageCorona,
    ChartSewageLine
  },
  computed: {
    ...mapState(['color'])
  },
  data() {
    return {
      echartList: [
        {
          id: 1,
          data: 0,
          unit: '',
          max: 14,
          name: 'ph'
        },
        {
          id: 2,
          data: 0,
          unit: 'mg/L',
          max: 500,
          name: 'COD'
        },
        {
          id: 3,
          data: 0,
          unit: 'mg/L',
          max: 200,
          name: '总磷'
        },
        {
          id: 4,
          data: 0,
          unit: 'mg/L',
          max: 2,
          name: '氨氮量'
        },
        {
          id: 5,
          data: 0,
          unit: 'L/s',
          max: 1,
          name: '污水'
        },
      ],
      lineList: [
        {
          id: 1,
          unit: '',
          time: [],
          data: [],
          name: 'ph'
        },
        {
          id: 2,
          unit: 'mg/L',
          time: [],
          data: [],
          name: 'COD'
        },
        {
          id: 3,
          unit: 'T',
          time: [],
          data: [],
          name: '流量'
        },
        {
          id: 4,
          unit: 'mg/L',
          time: [],
          data: [],
          name: '氨氮量'
        },
      ]
    }
  },
  methods: {
    init() {
      getEnvList({}).then(res => {
        if(res.code === 10000) {
          this.echartList[0].data = res.data.phPj;
          this.echartList[1].data = res.data.hxxylPj;
          this.echartList[3].data = res.data.adPj;
          this.echartList[4].data = res.data.wsPj;
        }
      })
      getSevenEnv({days: 7}).then(res => {
        if(res.code === 10000) {
          this.lineList.forEach(item => {
            item.time = res.data.date
          })
          this.lineList[0].data = res.data.ph;
          this.lineList[1].data = res.data.cod;
          this.lineList[2].data = res.data.ws;
          this.lineList[3].data = res.data.ad
        }
      })
    }
  },
  mounted() {
    this.init()
  }
}
</script>

<style scoped>
  .sewage{
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 20px 20px 0 20px;
  }
  .reply {
    width: 100%;
    border: 1px solid #ddd;
    height: 50px;
    background-color: #F3F3F3;
    line-height: 50px;
    font-size: 18px;
    box-sizing: border-box;
    padding-left: 20px;
  }
  .sewage-box {
    width: 100%;
    height: 300px;
    display: flex;
    justify-content: space-between;
    border: 1px solid #ddd;
    border-top: 0;
  }
  .box {
    width: 19%;
    height: 100%;
  }
  .echarts-line {
    width: 100%;
    border: 1px solid #ddd;
  }
  .reply1 {
    width: 100%;
    height: 50px;
    background-color: #F3F3F3;
    line-height: 50px;
    font-size: 18px;
    box-sizing: border-box;
    padding-left: 20px;
  }
  .echarts-box {
    width: 100%;
    height: 400px;
    border-top: 1px solid #ddd;
  }
</style>
