<!-- 江河水查看数据页面-->
<template>
  <div class="ele-body">
    <a-card :bordered="false">
      <!-- 搜索表单 -->
      <a-form :model="where" :label-col="{ md: { span: 8 }, sm: { span: 24 } }"
        :wrapper-col="{ md: { span: 16 }, sm: { span: 24 } }">
        <a-row>
          <a-form-item label="断面名称">
           <a-select allow-clear mode="multiple" placeholder="请选择断面名称" v-model:value="where.name">
              <a-select-option v-for="item in sectionInfo" :key="item.stationName" :value="item.stationName">
                {{ item.stationName }}
              </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="时间:">
              <a-month-picker
              v-model:value="where.time"
              :disabled-date="disabledDate"
              valueFormat="YYYY-MM"
            />
          </a-form-item>
          <a-form-item label="类型:" style="width:100px"> 
            <a-select v-model:value="where.type" allowClear showSearch>
              <a-select-option value="0">上半月</a-select-option>
              <a-select-option value="1">下半月</a-select-option>
              <a-select-option value="2">整月</a-select-option>
            </a-select>
          </a-form-item>
          <a-col :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-item class="ele-text-right" :wrapper-col="{ span: 24 }">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
                <a-button @click="exportFile">导出Excel</a-button>
              </a-space>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <!-- 表格 -->
      <a-spin :spinning="loading">
      <ele-pro-table ref="table" :datasource="momData" :columns="columnsMom" :where="where"
        :scroll="{ x: 'max-content' }" @done="(d) => (data = d.data)">
      </ele-pro-table>

      <ele-pro-table ref="table" :datasource="yoyData" :columns="columnsYoy" :where="where"
        :scroll="{ x: 'max-content' }" @done="(d) => (data = d.data)">
      </ele-pro-table>
    </a-spin>
    </a-card>
  </div>
  <!-- 编辑弹窗 -->
</template>

<script>
 import {
  listWaterSiteYoy
  } from "@/api/ecology/river-statis";
  import {
    listInfo
  } from "@/api/ecology/water/river-water";
  import locale from "ant-design-vue/es/date-picker/locale/zh_CN";
  // import {
  //   tableColumns
  // } from "./colums";
  import XLSX from "xlsx";
  export default {
    name: "RiverCollectWater",
    components: {},
    data() {
      return {
        data: [],
        momData:[],
        yoyData:[],
        datasource: {},
        columnsMom: [{
            title: '所在河流名称',
            dataIndex: 'riverName',
            key: 'riverName',
          },
          {
            title: '自动站名称',
            dataIndex: 'stationName',
            key: 'stationName',
          },
          {
            title: "溶解氧（mg/L）", children: [
              {title: "本半月", dataIndex: "oxygenMonth"},
              {title: "上期", dataIndex: "oxygenLast"},
              {title: "增减", dataIndex: "oxygenLastvalue"},
            ]
          },
          {
            title: "高锰酸盐指数（mg/L）", children: [
              {title: "本半月", dataIndex: "permanganateMonth"},
              {title: "上期", dataIndex: "permanganateLast"},
              {title: "增减", dataIndex: "permanganateLastValue"},
            ]
          },
          {
            title: "氨氮（mg/L）", children: [
              {title: "本半月", dataIndex: "ammoniaMonth"},
              {title: "上期", dataIndex: "ammoniaLast"},
              {title: "增减", dataIndex: "ammoniaLastValue"},
            ]
          },
          {
            title: "总磷（mg/L）", children: [
              {title: "本半月", dataIndex: "phosphorusMonth"},
              {title: "上期", dataIndex: "phosphorusLast"},
              {title: "增减", dataIndex: "phosphorusLastValue"},
            ]
          },
        ],
        columnsYoy: [
        {
            title: '所在河流名称',
            dataIndex: 'riverName',
            key: 'riverName',
          },
          {
            title: '自动站名称',
            dataIndex: 'stationName',
            key: 'stationName',
          },
          {
            title: "溶解氧（mg/L）", children: [
              {title: "本半月", dataIndex: "oxygenMonth"},
              {title: "去年同期", dataIndex: "oxygenLastYearStage"},
              {title: "增减", dataIndex: "oxygenYearvalue"},
            ]
          },
          {
            title: "高锰酸盐指数（mg/L）", children: [
              {title: "本半月", dataIndex: "permanganateMonth"},
              {title: "去年同期", dataIndex: "permanganateLastYearStage"},
              {title: "增减", dataIndex: "permanganateYearValue"},
            ]
          },
          {
            title: "氨氮（mg/L）", children: [
              {title: "本半月", dataIndex: "ammoniaMonth"},
              {title: "去年同期", dataIndex: "ammoniaLastYearStage"},
              {title: "增减", dataIndex: "ammoniaYearValue"},
            ]
          },
          {
            title: "总磷（mg/L）", children: [
              {title: "本半月", dataIndex: "phosphorusMonth"},
              {title: "去年同期", dataIndex: "phosphorusLastYearStage"},
              {title: "增减", dataIndex: "phosphorusYearValue"},
            ]
          },
        ],
        locale,
        bill: {},
        // 表格数据接口
        // url: nationalWaterFunctionTotalUrl,
        selection: [],
        // tableColumns,
        // // 表格列配置
        // columns: [
        //   ...tableColumns,
        // ],
        // 表格搜索条件
        where: {},
        sectionInfo: {},
        loading: false,
        rules: {},
      };
    },
    created() {
      listInfo().then((res) => {
        if (res.data.code == 0) {
          console.log(res.data.data)
          this.visibleWater = true;
          this.sectionInfo = res.data.data
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
    methods: {
      /* 刷新表格 */
      reload() {
        this.loading = true;
        this.momData = [];
        this.yoyData = [];
        listWaterSiteYoy(this.where).then((res) => {
          console.log(res.data.data);
          if (res.data.code == 0) {
              this.$message.success(res.data.msg);
              res.data.data.momData.forEach((m)=> {
                this.momData.push(m);
              })
              res.data.data.yoyData.forEach((y)=> {
                this.yoyData.push(y);
              })
            } else {
              this.$message.error(res.data.msg);
            }
            this.loading = false;
        });
      },
      /* 重置搜索 */
      reset() {
        this.where = {};
        this.reload();
      },
      /* 导出 */
      exportFile() {
        const columns = this.columns.filter(item => item.dataIndex);
        const arr = [];
        const th = columns.map((item) => item.title);
        arr.push(th);
        this.data.forEach((d) => {
          const td = columns.map((item) => d[item.dataIndex]);
          arr.push(td);
        });

        let sheet = XLSX.utils.aoa_to_sheet(arr);
        this.$util.exportSheet(XLSX, sheet, new Date().getTime().toString());
      }

    },
  };

</script>

<style scoped lang="less">
</style>
