<template>
  <div class="">
    <a-form :model="where" :rules="whereRules" :labelCol="{ offset: 1 }">
      <a-row>
        <a-col :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-item label="昼夜:">
            <a-select
              :options="timeSlotOptions"
              v-model:value="where.timeSlot"
              placeholder="昼夜"
            >
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :lg="12" :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>
    <ele-pro-table
      v-if="hisYears.length > 0"
      ref="table"
      row-key="id"
      :datasource="url"
      :columns="columns"
      :where="where"
      :needPage="false"
      :initLoad="false"
      :scroll="{ x: 'max-content' }"
      :method="'POST'"
      @done="(d) => (data = d.data)"
    >
      <template #toolbar> </template>
    </ele-pro-table>
  </div>
</template>

<script>
// import _ from "lodash";
import XLSX from "xlsx";
import {
  pageFunctionNoiseCompare,
  getHistoryyears,
} from "@/api/ecology/noise/function-sound";
export default {
  name: "StatisticSoundFunctionCompare",
  components: {},
  data() {
    const whereRules = {};
    return {
      url: pageFunctionNoiseCompare,
      data: [],
      where: {},
      timeRange: [],
      whereRules,
      hisYears: [],
      timeScope: [],
      columns: [{ title: "年", dataIndex: "year" }],
    };
  },
  mounted() {
    getHistoryyears().then((res) => {
      this.hisYears = res.data.data;
      this.$nextTick(() => {
        this.reload();
      });
    });
  },
  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({
        where: this.where,
      });
    },
    /* 重置搜索 */
    reset() {
      this.reload();
    },
    exportFile() {
      const arr = [];
      const th = this.columns.map((item) => item.title);
      arr.push(th);
      this.data.forEach((d) => {
        const td = this.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>
</style>