import * as echarts from "echarts";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      loading:true,
      options: [],

      value: [],
      timedate: [],
      multipleSelection: [],
      orderByColumn: "",
      isAsc: "asc",
      fdcLineData: [],
      currentPage2: 1,
      pagesize: 10,
      wpId: "",
      beginDate: "",
      endDate: "",
      dialogTableVisible: false,
      sortInOrder: [],
      sortInOrderTop: [],
      fdcName1: "",
      fdcName2: "",
      sortInOrde2: [],
      getTableData: [],
      wp_n_1: {},
      wp_n_2: {},
    };
  },
  filters: {
    /**
     * 改变格式(取小数点)
     */
    rounding(value) {
      return value.toFixed(2);
    },
  },
  activated() {
    this.timedate = [];
    this.wpId = this.$route.query.wpId;
    this.timedate.push(this.$route.query.beginDate,this.$route.query.endDate); 
    this.queryApData();
  },
  methods: {
    /**
     * 获取当前id
     */
queryApData() {
    this.value = this.$route.query.wpId;
    this.YardTableData();
  },

  queryApDataMx() {
    this.dialogTableVisible = true;
    this.wp_n_1 = {};
    this.wp_n_2 = {};
    this.getTableData = [];
    if (this.multipleSelection.length == 2) {
      this.wp_n_1 = this.multipleSelection[0];
      this.wp_n_2 = this.multipleSelection[1];
      this.fdcName1 = this.multipleSelection[0].wtName;
      this.fdcName2 = this.multipleSelection[1].wtName;
      this.sortInOrder.push(
        this.multipleSelection[0].fnlyl,
        this.multipleSelection[0].xqjsl,
        this.multipleSelection[0].ztzhjsl,
        this.multipleSelection[0].fwjsl,
        this.multipleSelection[0].slssl,
        this.multipleSelection[0].xnssl,
        this.multipleSelection[0].qfl,
        this.multipleSelection[0].jxssl,
        this.multipleSelection[0].gzssl
      );
      this.sortInOrderTop.push(
        this.multipleSelection[1].fnlyl,
        this.multipleSelection[1].xqjsl,
        this.multipleSelection[1].ztzhjsl,
        this.multipleSelection[1].fwjsl,
        this.multipleSelection[1].slssl,
        this.multipleSelection[1].xnssl,
        this.multipleSelection[1].qfl,
        this.multipleSelection[1].jxssl,
        this.multipleSelection[1].gzssl
      );
      this.getTableData.push({
        index: "发电量",
        data1: this.multipleSelection[0].scadafdl,
        data2: this.multipleSelection[1].scadafdl,
      });
      this.getTableData.push({
        index: "故障损失电量",
        data1: this.multipleSelection[0].gzss,
        data2: this.multipleSelection[1].gzss,
      });
      this.getTableData.push({
        index: "检修损失电量",
        data1: this.multipleSelection[0].jxssl,
        data2: this.multipleSelection[1].jxssl,
      });
      this.getTableData.push({
        index: "性能未达标损失电量",
        data1: this.multipleSelection[0].xnsslfraction,
        data2: this.multipleSelection[1].xnsslfraction,
      });
      this.getTableData.push({
        index: "受累损失电量",
        data1: this.multipleSelection[0].slss,
        data2: this.multipleSelection[1].slss,
      });
      this.getTableData.push({
        index: "风能利用率",
        data1: this.multipleSelection[0].fnlyl,
        data2: this.multipleSelection[1].fnlyl,
      });
      this.getTableData.push({
        index: "故障损失率",
        data1: this.multipleSelection[0].gzssl,
        data2: this.multipleSelection[1].gzssl,
      });
      this.getTableData.push({
        index: "检修损失率",
        data1: this.multipleSelection[0].jxssl,
        data2: this.multipleSelection[1].jxssl,
      });
      this.getTableData.push({
        index: "弃风率",
        data1: this.multipleSelection[0].qfl,
        data2: this.multipleSelection[1].qfl,
      });
      this.getTableData.push({
        index: "性能损失率",
        data1: this.multipleSelection[0].xnssl,
        data2: this.multipleSelection[1].xnssl,
      });
      this.getTableData.push({
        index: "受累损失率",
        data1: this.multipleSelection[0].slssl,
        data2: this.multipleSelection[1].slssl,
      });
      this.getTableData.push({
        index: "复位及时率",
        data1: this.multipleSelection[0].fwjsl,
        data2: this.multipleSelection[1].fwjsl,
      });
      this.getTableData.push({
        index: "消缺及时率",
        data1: this.multipleSelection[0].xqjsl,
        data2: this.multipleSelection[1].xqjsl,
      });
      this.getTableData.push({
        index: "状态转换率",
        data1: this.multipleSelection[0].ztzhjsl,
        data2: this.multipleSelection[1].ztzhjsl,
      });
    }
    this.$nextTick(function () {
      this.ECZM.leida_tc("leiDaTu3" , this.sortInOrder,this.fdcName1,this.sortInOrderTop,this.fdcName2);
      this.ECZM.bar_tc("leiDaTu4" , this.wp_n_1 , this.wp_n_2 ,this.wp_n_1.wtId , this.wp_n_2.wtId);
      
    });
  },
  /**
   * 改变格式去小数点
   */
  filter_fdl(cellValue) {
    return parseFloat(cellValue.scadafdl).toFixed(2);
  },
  /**
   * 判断选中条数是否等于2
   */
  ApDataMxcheck() {
    if (this.multipleSelection.length == 2) {
      this.queryApDataMx();
    } else {
      this.$message({
        message: "请选择两个风机！",
        type: "warning",
      });
      return;
    }
  },
  /**
   * 查询场内风机列表信息
   */
  YardTableData() {
    let that = this;
    Object.assign(this.$data.fdcLineData, this.$options.data().fdcLineData);
    this.API.get("/powercompare/windfarmAjax").then((res) => {
      this.options = res.data;
    }).catch(error =>{
      this.$message.error('获取数据失败');
    });
    this.wpId = this.$route.query.wpId;
    if (this.timedate == "") {
      this.beginDate = this.$route.query.beginDate;
      this.endDate = this.$route.query.endDate;
    } else {
      this.beginDate = this.timedate[0];
      this.endDate = this.timedate[1];
    }
    var guilty = new URLSearchParams();
    guilty.append("pageNum", this.currentPage2);
    guilty.append("pageSize", this.pagesize);
    guilty.append("orderByColumn", this.orderByColumn);
    guilty.append("isAsc", this.isAsc);
    if (this.value == []) {
      guilty.append("wpId", this.wpId);
    } else {
      guilty.append("wpId", this.value);
    }
    guilty.append("beginDate", this.beginDate);
    guilty.append("endDate", this.endDate);
    this.API.post("/contrast/benchmarkWpInWtList", guilty).then((res) => {
      this.fdcLineData = res.data;
      this.loading=false;
    }).catch(error =>{
      this.$message.error('获取数据失败');
    });
  },
  headStyle() {
    return "text-align:center";
  },
  /**
   * 选中表格
   */
  handleSelectionChange(val) {
    this.sortInOrder = [];
    this.sortInOrderTop = [];
    this.getTableData = [];
    this.sortInOrde2 = [];
    this.multipleSelection = [];
    this.multipleSelection = val;
  },
  changeTableSort(column) {
    this.orderByColumn = column.prop;
    if (column.order == "descending") {
      this.isAsc = "desc";
    } else if (column.order == "ascending") {
      this.isAsc = "asc";
    }
    this.YardTableData();
  },
  /**
   * 时间格式转化
   */
  filter_date(cellValue) {
    let date = new Date(cellValue.recordDate);
    return this.BASE.getBzDate(date,0);
  },
  /**
   * 返回按钮
   */
  goReturn() {
    this.$router.push("/yardBenchmark");
  },
  /**
   * 导出表格
   */
  toExcel() {
    excelHelper.exportExcel("fdcLineData","损失率对标列表",".xls",true);
  },
},
};