import * as echarts from "echarts";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      FClist: {
        name: "",
        id: "",
      },
      loading:true,
      tableData: [],
      dialogTableVisible: false,
      beginDate: "2021-01-01",
      endDate: "2021-01-01",
      fc: "MHS_FDC",
      selectrowdate: {},
      histogram_Date: [],
      histogram_sers: [],
      h_Date:[],
    };
  },
  methods: {
    /**
     * 查询风场
     */
    query_fc() {
       var newData = new Date();
       this.beginDate = this.BASE.getBzDate(newData.getTime(),-1);
       this.endDate = this.BASE.getBzDate(newData.getTime(),0);
       this.API.get("powercompare/windfarmAjax?").then((res) => {
       this.FClist = res.data;
      }).catch(e=>e);
    },
    /**
     * 获取数据
     */
    query_table() {
      this.API
        .get(
          "leaderboard/fittingtoplist?wpIps=" +
            this.fc +
            "&pageNum=" +
            1 +
            "&pageSize=" +
            10 +
            "&orderByColumn=" +
            "" +
            "&isAsc=" +
            "asc" +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate
        )
        .then((res) => {
          this.tableData = res.data;
          this.loading=false;
        }).catch(e=>e);;
    },
    headStyle() {
      return "text-align:center";
    },
    /**
     * 矩阵选中 获取行数据
     */
    changeFun(val) {
      let wt = [];
      this.histogram_Date = {};
      this.histogram_sers = [];
      for (let i = 0; i < Object.keys(val).length; i++) {
        wt.push(val[i].windturbine);
      }
          this.API
        .get(
          "leaderboard/fittingtopchart?wtIds=" +
            wt +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate
        )
        .then((res) => {
          this.histogram_Date = [];
          this.h_Date = [];
          this.h_Date = res.data;
          this.histogram_sers = res.data.sers;
        }).catch(e=>e);;
      
    },
    // toExcel() {
    //   let that = this;
    //   excelHelper.exportExcel("tableData", "拟合优度排行榜", ".xls", true);
    // },
    /**
     * 转换格式
     */
    filter_bdate(cellValue) {
      let date = new Date(cellValue.beginDate);

      return this.BASE.getBzDate(date,0);
    },
    filter_edate(cellValue) {
      let date = new Date(cellValue.endDate);

      return this.BASE.getBzDate(date,0);
    },
    filter_generatingCapacity(cellValue) {
      return parseFloat(cellValue.power).toFixed(2);
    },
    filter_power(cellValue) {
      return parseFloat(cellValue.power).toFixed(2);
    },
    /**
     * 改变数据格式，调取曲线图
     */
    curveCreation() {
      let that = this;
      let design = [];
      for (let j = 0; j < Object.keys(this.histogram_sers).length; j++) {
        let name1 = that.histogram_sers[j];
        design = that.h_Date[name1];
        that.histogram_Date.push({
          type: "line",
          name: name1,
          stack: "总量",
          data: design,
        });
      }
      this.dialogTableVisible = true;
      this.$nextTick(function () {
        this.ECZM.zzt_cdbqd('histogram' , this.histogram_sers , this.histogram_Date);
      });
    },
  },
  mounted() {
    this.query_fc();
    this.query_table();
  },
};
