import * as echarts from "echarts";
export default {
  data() {
    return {
     
      FClist: {
        name: "",
        id: "",
      },
      fdcName1: "",
      fdcName2: "",
      date1: "2021-01-01",
      date2: "2020-01-03",
      wp_n_1: {},
      wp_n_2: {},
      selectrowdate: {},
      histogram: {
        date: [],
        xdss: [],
        gzss: [],
        jxss: [],
        xnss: [],
        slss: [],
      },
      wpId: [],
      wpName: [],
      lineDataOption: [],
      beginDate: "2021-01-01",
      endDate: "2021-01-03",
      fc: "",
      tableData: [],
      dialogTableVisible: false,
      getChartDataValue: [],
      getChartDataValue2: [],
      getTableData: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
    };
  },
  methods: {
    
    /**
     * 控制弹出
     */
    dialog() {
      this.dialogTableVisible = true;
      this.check_wpid();
      this.$nextTick(function () {
        this.ECZM.leida_tc("leidatu" , this.getChartDataValue,this.fdcName1,this.getChartDataValue2,this.fdcName2);
        this.ECZM.bar_tc("histogram_n" , this.wp_n_1 , this.wp_n_2 , this.wp_n_1.wpId , this.wp_n_2.wpId);
      });
    },
    headStyle() {
      return "text-align:left";
    },
    /**
     * 
     *  风场检查
     */
    check_wpid() {
      this.wp_n_1 = {};
      this.wp_n_2 = {};
      this.fdcName1 = "";
      this.fdcName2 = "";
      this.getChartDataValue = [];
      this.getChartDataValue2 = [];
      this.getTableData = [];
      if (Object.keys(this.selectrowdate).length != 2) {
        this.alert_jg();
        return;
      } else {
        this.wp_n_1 = this.selectrowdate[0];
        this.wp_n_2 = this.selectrowdate[1];
        this.fdcName1 = this.wp_n_1.wpId;
        this.fdcName2 = this.wp_n_2.wpId;
        this.getChartDataValue.push(
          this.wp_n_1.fnlyl,
          this.wp_n_1.gzssl,
          this.wp_n_1.jxssl,
          this.wp_n_1.qfl,
          this.wp_n_1.xnssl,
          this.wp_n_1.slssl,
          this.wp_n_1.fwjsl,
          this.wp_n_1.ztzhl,
          this.wp_n_1.xqjsl
        );
        this.getChartDataValue2.push(
          this.wp_n_2.fnlyl,
          this.wp_n_2.gzssl,
          this.wp_n_2.jxssl,
          this.wp_n_2.qfl,
          this.wp_n_2.xnssl,
          this.wp_n_2.slssl,
          this.wp_n_2.fwjsl,
          this.wp_n_2.ztzhl,
          this.wp_n_2.xqjsl
        );
        this.getTableData.push({
          index: "发电量",
          data1: this.wp_n_1.scadafdl,
          data2: this.wp_n_2.scadafdl,
        });
        this.getTableData.push({
          index: "故障损失电量",
          data1: this.wp_n_1.gzss,
          data2: this.wp_n_2.gzss,
        });
        this.getTableData.push({
          index: "检修损失电量",
          data1: this.wp_n_1.jxssl,
          data2: this.wp_n_2.jxssl,
        });
        this.getTableData.push({
          index: "性能未达标损失电量",
          data1: this.wp_n_1.xnsslfraction,
          data2: this.wp_n_2.xnsslfraction,
        });
        this.getTableData.push({
          index: "受累损失电量",
          data1: this.wp_n_1.slss,
          data2: this.wp_n_2.slss,
        });
        this.getTableData.push({
          index: "风能利用率",
          data1: this.wp_n_1.fnlyl,
          data2: this.wp_n_2.fnlyl,
        });
        this.getTableData.push({
          index: "故障损失率",
          data1: this.wp_n_1.gzssl,
          data2: this.wp_n_2.gzssl,
        });
        this.getTableData.push({
          index: "检修损失率",
          data1: this.wp_n_1.jxssl,
          data2: this.wp_n_2.jxssl,
        });
        this.getTableData.push({
          index: "弃风率",
          data1: this.wp_n_1.qfl,
          data2: this.wp_n_2.qfl,
        });
        this.getTableData.push({
          index: "性能损失率",
          data1: this.wp_n_1.xnssl,
          data2: this.wp_n_2.xnssl,
        });
        this.getTableData.push({
          index: "受累损失率",
          data1: this.wp_n_1.slssl,
          data2: this.wp_n_2.slssl,
        });
        this.getTableData.push({
          index: "复位及时率",
          data1: this.wp_n_1.fwjsl,
          data2: this.wp_n_2.fwjsl,
        });
        this.getTableData.push({
          index: "消缺及时率",
          data1: this.wp_n_1.xqjsl,
          data2: this.wp_n_2.xqjsl,
        });
        this.getTableData.push({
          index: "状态转换率",
          data1: this.wp_n_1.ztzhjsl,
          data2: this.wp_n_2.ztzhjsl,
        });
      }
    },
    /**
     * 获取表格行值
     * 
     */
    changeFun(val) {
      this.selectrowdate = val;
    },
    /**
     * 获取风场列表
     */
    query_fc() {
      let that = this ;
      var newData = new Date();
       this.beginDate = this.BASE.getBzDate(newData,-1);
       this.endDate = this.BASE.getBzDate(newData,0);
       this.API.get("powercompare/windfarmAjax?").then((res) => {
        that.FClist = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 
     * 弹出提示信 息
     */
    alert_jg() {
      this.$message({
        message: "只能选择两条数据",
        type: "warning",
      });
      return;
    },
    /**
     * 
     * 跳转详情页面
     */
    handleEdit(a, b) {
        this.lineDataOption.push({ id: b.wpId, name: b.wpName });
        this.$router.push({
          path: "/yardBenchmarkParticulars",
          query: {
            wpId: b.wpId,
            beginDate: this.beginDate,
            endDate: this.endDate,
            wpName: b.wpName,
            select: this.lineDataOption,
          },
        });
    },
    /**
     * 查询场内对标列表信息
     */
    query_benchmarkWpList() {
      Object.assign(this.$data.histogram, this.$options.data().histogram);
      let that = this;
      var page = new URLSearchParams();
      page.append("wpId", this.fc);
      page.append("beginDate", this.beginDate);
      page.append("endDate", this.endDate);
      this.API.post("/contrast/benchmarkWpList", page).then((res) => {
        this.tableData = res.data;
        let len = this.tableData.length;
        for (let i = 0; i < len; i++) {
          that.histogram.date[i] = this.BASE.getBzDate(
            new Date(res.data[i].recordDate),0
          );
          
            that.histogram.xdss[i] = res.data[i].xdss;
          

          
            that.histogram.gzss[i] = res.data[i].gzss;
          

          
            that.histogram.jxss[i] = res.data[i].whss;
         
            that.histogram.xnss[i] = res.data[i].qfss;
          
            that.histogram.slss[i] = res.data[i].slss;
          
        }

        this.ECZM.getBar_fdd("histogram",this.histogram);
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 
     * 日期类型转换
     */
    filter_date(cellValue) {
      let date = new Date(cellValue.recordDate);

      return this.BASE.getBzDate(date,0);
    },
  },
  mounted() {
    this.query_fc();
    this.query_benchmarkWpList();
  },
};