<template>
  <el-container>
    <el-header>
      <el-card style="margin-top: -10px">
        <el-row :gutter="1">
          <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="类型">
              <el-select
                v-model="lx"
                @change="check_lx"
                clearable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in lxlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="风场">
              <el-select v-model="fc" clearable placeholder="请选择">
                <el-option
                  v-for="item in list"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="开始时间">
              <el-date-picker
                v-model="beginDate"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item label="结束时间">
              <el-date-picker
                v-model="endDate"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="query_table" :plain="true"
                >查询</el-button
              >
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="toExcel" :plain="true"
                >导出</el-button
              >
            </el-form-item>
          </el-form>
        </el-row>
      </el-card>
    </el-header>

    <el-main>
      <el-card style=" height: 759px">
        <el-table
          v-loading="loading"
          id="tableData"
          :data="tableData"
          style="width: 100%"
          :cell-style="{ textAlign: 'center' }"
          :header-cell-style="headStyle"
          max-height="739px"
          @selection-change="changeFun"
        >
          >
          <el-table-column label="总发电量排行榜">
            <el-table-column type="index" width="80"> </el-table-column>
            <el-table-column
              type="selection"
              class="selection"
              @selection-change="changeFun"
              width="60"
            >
            </el-table-column>
            <el-table-column sortable prop="windfarm" label="风场" width="310">
            </el-table-column>
            <el-table-column
              sortable
              prop="windturbine"
              label="风机"
              width="310"
            >
            </el-table-column>
            <el-table-column
              sortable
              prop="beginDate"
              :formatter="filter_bdate"
              value-format="yyyy-MM-dd"
              label="起始时间"
              width="310"
            >
            </el-table-column>
            <el-table-column
              sortable
              prop="endDate"
              :formatter="filter_edate"
              value-format="yyyy-MM-dd"
              label="截至日期"
              width="210"
            >
            </el-table-column>
            <el-table-column
              sortable
              prop="speed"
              :formatter="filter_speed"
              label="平均风速"
              width="290"
            >
            </el-table-column>
            <el-table-column
              sortable
              prop="power"
              :formatter="filter_power"
              label="发电量"
              width="280"
            >
            </el-table-column>
          </el-table-column>
        </el-table>
      </el-card>
    </el-main>
  </el-container>
</template>

<script>
import formateDate from "@/utils/date";
import formateDate1 from "@/utils/date_1";
import excelHelper from "@/utils/excelHelper";
export default {
  data() {
    return {
      list:[],
      FClist: [],
      GFlist: [
        
      ],
      loading:true,
      QBlist: [
       
      ],
      lxlist: [
        {
          name: "全部",
          id: "qb",
        },
        {
          name: "风场",
          id: "fc",
        },
        {
          name: "光伏",
          id: "gf",
        },
      ],
      tableData: [],
      beginDate: "2021-01-01",
      endDate: "2021-01-01",
      lx: "qb",
      fc: "",
      selectrowdate: {},
    };
  },
  methods: {
    check_lx() {
      this.fc = "";
      if (this.lx == "fc") {
        this.list={};
        this.list = this.FClist;
      } else if (this.lx == "gf") {
        this.list = {};
        this.list = this.GFlist;
      } else if (this.lx == "qb") {
        this.list = {};
        this.list = this.QBlist;
      }
    },
    query_fc() {
       var newData = new Date();
       this.beginDate = formateDate1(newData.getTime()/1000);
       this.endDate = formateDate(newData.getTime()/1000);
      let that = this;
      let fjj="";
      this.$http.get("powercompare/windfarmAllAjax?").then((res) => {
        this.QBlist = res.data.data;

        for (let i = 0; i < Object.keys(this.QBlist).length; i++) {
          fjj = "";
          fjj = this.QBlist[i].id;
          if (fjj.endsWith("FDC")) {
            that.FClist.push(this.QBlist[i]);
          } else {
            that.GFlist.push(this.QBlist[i]);
          }
        }
        this.list = this.QBlist;
     });
    },
    query_table() {
      this.loading=true;
      this.tableData=[];
      this.$http
        .get(
          "leaderboard/totalPowerCapacityTopList?wpIps=" +
            this.fc +
            "&pageNum=" +
            1 +
            "&pageSize=" +
            10 +
            "&orderByColumn=" +
            "" +
            "&isAsc=" +
            "asc" +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate
        )
        .then((res) => {
          this.tableData = res.data.data;
          this.loading=false;
        });
    },
    toExcel() {
      let that = this;
      excelHelper.exportExcel("tableData", "总发电量排行", ".xls", true);
    },
    headStyle() {
      return "text-align:center";
    },
    changeFun(val) {
      this.selectrowdate = val;
    },
    filter_bdate(cellValue) {
      let date = new Date(cellValue.beginDate);

      return formateDate(date / 1000);
    },
    filter_edate(cellValue) {
      let date = new Date(cellValue.endDate);

      return formateDate(date / 1000);
    },
    filter_power(cellValue) {
      return parseFloat(cellValue.power).toFixed(2);
    },
    filter_speed(cellValue) {
      return parseFloat(cellValue.speed).toFixed(2);
    },
  },
  mounted() {
    this.query_fc();
    this.query_table();
  },
};
</script>
<style scoped>
</style>