//import FiveLossRatesHistogramChart from "../../views/benchMarking/FiveLossRatesHistogramChart.vue";
import * as echarts from "echarts";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      timedate: [],
      isAsc: "asc",
      beginDate: "",
      endDate: "",
      gridData: [],
      multipleSelection: [],
      sortInOrder: [],
      sortInOrderTop: [],
      sortInOrde2: [],
      getTableData: [],
      sortInOrderTop2: [],
      fdcName1: "",
      fdcName2: "",
      currentPage2: 1,
      pagesize: 10,
      FClist: {
        name: "",
        id: "",
      },
      value: "",
      wpId: [],
      wpName: [],
      orderByColumn: "",
      dialogTableVisible: false,
      lineDataOption: [],
      getChartDataValue: [],
      getChartDataValue2: [],
      getChartData:[],
      wp_n_1: {},
      wp_n_2: {},
    };
  },
  components: {
  },
  created() {
    this.Inquire_tableDate();
  },
  methods: {
    changeFun(val) {
      this.selectrowdate = val;
    },
    /**
     * 日期转换
     */
    filter_date(cellValue) {
      let date = new Date(cellValue.recordDate);

      return this.BASE.getBzDate(date,0);
    },
    headStyle() {
      return "text-align:center";
    },
    onSubmit() {
    },
    handleClick() {},
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    queryApData() {
      this.Inquire_tableDate();
    },
    /**
     * 转换格式(去小数点)
     */
    simplification(cellValue){
      return parseFloat(cellValue.fdl).toFixed(2);
    },
    /**
     * 详情跳转
     */
    handleEdit(a, b) {
      this.wpId = [];
      this.lineDataOption = [];
     
        this.lineDataOption.push({ id: b.wpId, name: b.wpName });
        this.$router.push({
          path: "/innationBenchmarkParticulars",
          query: {
            wpId: b.wpId,
            beginDate: this.beginDate,
            endDate: this.endDate,
            wpName: b.wpName,
            select: this.lineDataOption,
          },
        });
    },
    /**
     * 对标分析
     */
    queryApDataMx() {
      this.dialogTableVisible = true;
      this.$nextTick(function () {
        
        this.ECZM.leida_tc("leiDaTu" , this.sortInOrder,this.fdcName1,this.sortInOrderTop,this.fdcName2);
        this.ECZM.bar_tc("leiDaTu2" , this.wp_n_1 , this.wp_n_2 , this.wp_n_1.wpId , this.wp_n_2.wpId);
      });
    },
    /**
     * 数据格式转换
     */
    handleSelectionChange(val) {
      this.wp_n_1 = "";
      this.wp_n_2 = "";
      this.sortInOrder = [];
      this.sortInOrderTop = [];
      this.getTableData = [];
      this.sortInOrde2 = [];
      this.multipleSelection = val;
      if (this.multipleSelection.length == 2) {
        this.wp_n_1 = this.multipleSelection[0];
        this.wp_n_2 = this.multipleSelection[1];
        this.fdcName1 = this.multipleSelection[0].wpName;
        this.fdcName2 = this.multipleSelection[1].wpName;
        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].fdl,
          data2: this.multipleSelection[1].fdl,
        });
        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,
        });
      }
    },
    handleCurrentChange(val) {
    },
    /**
     * 分页功能
     */
    handleSizeChange(val) {
      this.pagesize = val;
    },
    /**
     * 分页功能
     */
    changeTableSort(column) {
      this.orderByColumn = column.prop;
      if (column.order == "descending") {
        this.isAsc = "desc";
      } else if (column.order == "ascending") {
        this.isAsc = "asc";
      }
      this.Inquire_tableDate();
    },
    /**
     * 查询场际对标列表信息
     */
    Inquire_tableDate() { 
      var newData = new Date();
       this.timedate[0] = this.BASE.getBzDate(newData.getTime(),-1);
       this.timedate[1] = this.BASE.getBzDate(newData.getTime(),0);
      let that = this;
      this.API.get("/powercompare/windfarmAjax").then((res) => {
        that.FClist = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
      if (this.timedate == "") {
        this.timedate[0] = "2021-01-01";
        this.timedate[1] = "2021-01-01";
        this.beginDate = this.timedate[0];
        this.endDate = this.timedate[1];
      } else {
        this.beginDate = this.timedate[0];
        this.endDate = this.timedate[1];
      }
      var fiveLossData = new URLSearchParams();
      fiveLossData.append("pageNum", this.currentPage2);
      fiveLossData.append("pageSize", this.pagesize);
      fiveLossData.append("orderByColumn", this.orderByColumn);
      fiveLossData.append("isAsc", this.isAsc);
      fiveLossData.append("wpId", this.value);
      fiveLossData.append("beginDate", this.beginDate);
      fiveLossData.append("endDate", this.endDate);
      this.API
        .post("/contrast/benchmarkWpOutList", fiveLossData)
        .then((res) => {
          that.gridData = res.data;
          that.getPackageData(that.gridData);
          that.getPackageData2(that.gridData);
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    toExcel() {},
    getPackageData(gridData) {
      for (let i = 0; i < gridData.length; i++) {
        this.getChartDataValue.push({
          value: gridData[i].fdl,
          name: gridData[i].wpName,
        });
        this.getChartDataValue2.push({
          value: gridData[i].gzss,
          name: gridData[i].wpName,
        });
      }
      this.getChartDataImport();
      this.getChartDataValue = [];
      this.getChartDataValue2 = [];
    },
    getChartDataImport() {
      var charts = echarts.init(document.getElementById("chartPie"));
      let option = {
        title: {
          text: "发电量占比",
          left: "center",
        },
        color: ["#90ED7D", "#F7A35C", "#7CB5EC", "#434348", "#8085E9"],
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            type: "pie",
            radius: "50%",
            data: this.getChartDataValue,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      charts.setOption(option);

      var charts2 = echarts.init(document.getElementById("chartPieRight"));
      let option2 = {
        title: {
          text: "损失电量占比",
          left: "center",
        },
        color: ["#90ED7D", "#F7A35C", "#7CB5EC", "#434348", "#8085E9"],
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            type: "pie",
            radius: "50%",
            data: this.getChartDataValue2,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      charts2.setOption(option2);
    },
    getPackageData2(gridData){
            this.getChartData = [];
            for(let i=0;i<gridData.length;i++){
                this.getChartData.push({product:gridData[i].wpName,'限电损失电量单位:万KWh':gridData[i].xdss,
                '故障损失电量单位:万KWh':gridData[i].gzss,'检修损失电量单位:万KWh':gridData[i].jxssl,
                '性能损失电量单位:万KWh':gridData[i].xnssl,'受累损失电量单位:万KWh':gridData[i].slss})
            }
            this.getChartDataImport2();
        },
    getChartDataImport2(){
            var charts =echarts.init(document.getElementById("chartHistogram"));
            let option = {
            title: {
                text: '损失电量分析',
                left: 'center'
            },
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            tooltip: {},
            dataset: {
                 dimensions: ['product', '限电损失电量单位:万KWh', '故障损失电量单位:万KWh', '检修损失电量单位:万KWh', '性能损失电量单位:万KWh', '受累损失电量单位:万KWh'],
                 source: this.getChartData
            },
            xAxis: {type: 'category'},
            yAxis: {},
            // Declare several bar series, each will be mapped
            // to a column of dataset.source by default.
            series: [
                {
                    // barGap:'100%',/*多个并排柱子设置柱子之间的间距*/
                    type: 'bar',
                    barWidth : 30,
                    itemStyle:{
                        normal:{
                            color:'#D201D8'
                        }
                    }
                },
                {
                    
                    type: 'bar',
                    barWidth : 30,
                    itemStyle:{
                        normal:{
                            color:'#FD0100'
                        }
                    }
                },
                {
                    
                    type: 'bar',
                    barWidth : 30,
                    itemStyle:{
                        normal:{
                            color:'#FF7B16'
                        }
                    }
                },
                {
                    
                    type: 'bar',
                    barWidth : 30,
                    itemStyle:{
                        normal:{
                            color:'#8085E9'
                        }
                    }
                },
                {
                    
                    type: 'bar',
                    barWidth : 30,
                    itemStyle:{
                        normal:{
                            color:'#A6A6A6'
                        }
                    }
                },
                
            ]
        };
        charts.setOption(option);
        }
  },
};