import * as echarts from "echarts";
//import FiveLossRatesHistogramChart from "../../views/benchMarking/FiveLossRatesHistogramChart.vue";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      formInline: {
        windfarm: "",
        project: "",
        line: "",
      },
      timedate: [],
      isAsc: "asc",
      beginDate: "",
      endDate: "",
      gridData: [],
      multipleSelection: [],
      sortInOrder: [],
      sortInOrderTop: [],
      sortInOrde2: [],
      getTableData: [],
      sortInOrderTop2: [],
      fdcName1: "",
      fdcName2: "",
      wp_n_1: {},
      wp_n_2: {},
      currentPage2: 1,
      pagesize: 10,
      classification: [
        {
          id: "qf",
          label: "弃风率",
        },
        {
          id: "gz",
          label: "故障损失率",
        },
        {
          id: "jx",
          label: "检修损失率",
        },
        {
          id: "xn",
          label: "性能损失率",
        },
        {
          id: "sl",
          label: "受累损失率",
        },
      ],
      options: [
        {
          value: "MHS_FDC",
          label: "麻黄山风电场",
        },
        {
          value: "NSS_FDC",
          label: "牛首山风电场",
        },
        {
          value: "SBQ_FDC",
          label: "石板泉风电场",
        },
        {
          value: "QS_FDC",
          label: "青山风电场",
        },
        {
          value: "XS_FDC",
          label: "香山风电场",
        },
      ],
      value: "",
      value2: "gz",
      wpId: [],
      wpName: [],
      orderByColumn: "",
      dialogTableVisible: false,
      lineDataOption: [],
      getChartDataValue: [],
      getChartDataValue2: [],
      chartsAName2: "",
      selectrowdate: {},
    };
  },
//   components: {
//     FiveLossRatesHistogramChart: FiveLossRatesHistogramChart,
//   },
  created() {
    this.FiveLossInformation();
  },
  methods: {
    headStyle() {
      return "text-align:center";
    },
    onSubmit() {
    },
    handleClick() {},
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    queryApData() {
      this.FiveLossInformation();
    },
    /**
     * 
     * 检查是否选择两个项目
     */
    querycheck(){
      if(this.selectrowdate.length == 2){
        this.queryApDataMx();
      }else{
        this.$message({
          message:"请选择两个项目！",
          type:'error'
        });
        return
      }
    },
    /**
     * 获取表格数据
     */
    handleEdit(a, b) {
      this.wpId = [];
      this.lineDataOption = [];
        this.lineDataOption.push({ id: b.wpId, name: b.wpName });
        this.$router.push({
          path: "/propertBenchmarkParticulars",
          query: {
            wpId: b.wpId,
            beginDate: this.beginDate,
            endDate: this.endDate,
            wpName: b.wpName,
            select: this.lineDataOption,
          },
        });
    },
    /**
     * 查询检查
     */
    checkwindfarm() {
      if (this.formInline.windfarm == "") {
        this.$message.error("请选择风场！");
        return;
      }
    },
    checkproject() {
      if (this.formInline.project == "") {
        this.$message.error("请选择项目！");
        return;
      }
      if (new Date(this.timedate) == null) {
        this.$message.error("请选择时间");
        return;
      }
    },
    /**
     * 弹出控制
     */
    queryApDataMx() {
      this.dialogTableVisible = true;
      this.check_wpid();
      this.$nextTick(function () {
      this.ECZM.bar_tc("leiDaTu8" , this.wp_n_1 , this.wp_n_2 , this.wp_n_1.wpId , this.wp_n_2.wpId);
      this.ECZM.leida_tc("leiDatu6" , this.sortInOrder,this.fdcName1,this.sortInOrderTop,this.fdcName2);
      });
    },
    handleSelectionChange(val) {
      this.selectrowdate = val;
    },
    /**
     * 数据转换
     */
     check_wpid() {
      this.wp_n_1 = {};
      this.wp_n_2 = {};
      this.sortInOrder = [];
      this.sortInOrderTop = [];
      this.getTableData = [];
      this.sortInOrde2 = [];
      this.fdcName1 = "";
      this.fdcName2 = "";
     
        this.wp_n_1 = this.selectrowdate[0];
        this.wp_n_2 = this.selectrowdate[1];
        this.fdcName1 = this.selectrowdate[0].wpName;
        this.fdcName2 = this.selectrowdate[1].wpName;
        this.sortInOrder.push(
          this.selectrowdate[0].fnlyl,
          this.selectrowdate[0].xqjsl,
          this.selectrowdate[0].ztzhjsl,
          this.selectrowdate[0].fwjsl,
          this.selectrowdate[0].slssl,
          this.selectrowdate[0].xnssl,
          this.selectrowdate[0].qfl,
          this.selectrowdate[0].jxssl,
          this.selectrowdate[0].gzssl
        );
        this.sortInOrderTop.push(
          this.selectrowdate[1].fnlyl,
          this.selectrowdate[1].xqjsl,
          this.selectrowdate[1].ztzhjsl,
          this.selectrowdate[1].fwjsl,
          this.selectrowdate[1].slssl,
          this.selectrowdate[1].xnssl,
          this.selectrowdate[1].qfl,
          this.selectrowdate[1].jxssl,
          this.selectrowdate[1].gzssl
        );
        this.getTableData.push({
          index: "发电量",
          data1: this.selectrowdate[0].fdl,
          data2: this.selectrowdate[1].fdl,
        });
        this.getTableData.push({
          index: "故障损失电量",
          data1: this.selectrowdate[0].gzss,
          data2: this.selectrowdate[1].gzss,
        });
        this.getTableData.push({
          index: "检修损失电量",
          data1: this.selectrowdate[0].jxssl,
          data2: this.selectrowdate[1].jxssl,
        });
        this.getTableData.push({
          index: "性能未达标损失电量",
          data1: this.selectrowdate[0].xnsslfraction,
          data2: this.selectrowdate[1].xnsslfraction,
        });
        this.getTableData.push({
          index: "受累损失电量",
          data1: this.selectrowdate[0].slss,
          data2: this.selectrowdate[1].slss,
        });
        this.getTableData.push({
          index: "风能利用率",
          data1: this.selectrowdate[0].fnlyl,
          data2: this.selectrowdate[1].fnlyl,
        });
        this.getTableData.push({
          index: "故障损失率",
          data1: this.selectrowdate[0].gzssl,
          data2: this.selectrowdate[1].gzssl,
        });
        this.getTableData.push({
          index: "检修损失率",
          data1: this.selectrowdate[0].jxssl,
          data2: this.selectrowdate[1].jxssl,
        });
        this.getTableData.push({
          index: "弃风率",
          data1: this.selectrowdate[0].qfl,
          data2: this.selectrowdate[1].qfl,
        });
        this.getTableData.push({
          index: "性能损失率",
          data1: this.selectrowdate[0].xnssl,
          data2: this.selectrowdate[1].xnssl,
        });
        this.getTableData.push({
          index: "受累损失率",
          data1: this.selectrowdate[0].slssl,
          data2: this.selectrowdate[1].slssl,
        });
        this.getTableData.push({
          index: "复位及时率",
          data1: this.selectrowdate[0].fwjsl,
          data2: this.selectrowdate[1].fwjsl,
        });
        this.getTableData.push({
          index: "消缺及时率",
          data1: this.selectrowdate[0].xqjsl,
          data2: this.selectrowdate[1].xqjsl,
        });
        this.getTableData.push({
          index: "状态转换率",
          data1: this.selectrowdate[0].ztzhjsl,
          data2: this.selectrowdate[1].ztzhjsl,
        });
    },
    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.FiveLossInformation();
    },
    /**
     * 查询风机列表信息
     */
    FiveLossInformation() {
      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.options = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
      if (this.timedate == "") {
        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/benchmarkLossList", fiveLossData)
        .then((res) => {
          that.gridData = res.data;
          that.getPackageData(that.gridData, that.value2);
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    getPackageData(gridData, value2) {
      for (let i = 0; i < gridData.length; i++) {
        this.getChartDataValue.push({
          value: gridData[i].fdl,
          name: gridData[i].wpName,
        });
        if (value2 == "gz") {
          this.chartsAName2 = "故障损失占比";
          this.getChartDataValue2.push({
            value: gridData[i].gzss,
            name: gridData[i].wpName,
          });
        } else if (value2 == "xn") {
          this.chartsAName2 = "性能损失占比";
          this.getChartDataValue2.push({
            value: gridData[i].qfss,
            name: gridData[i].wpName,
          });
        } else if (value2 == "qf") {
          this.chartsAName2 = "弃风率占比";
          this.getChartDataValue2.push({
            value: gridData[i].qfl,
            name: gridData[i].wpName,
          });
        } else if (value2 == "jx") {
          this.chartsAName2 = "检修损失占比";
          this.getChartDataValue2.push({
            value: gridData[i].whss,
            name: gridData[i].wpName,
          });
        } else if (value2 == "sl") {
          this.chartsAName2 = "受累损失占比";
          this.getChartDataValue2.push({
            value: gridData[i].slss,
            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: this.chartsAName2,
          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);
    },
  },
};
