// import excelHelper from "@/utils/excelHelper";
import * as echarts from "echarts";
export default {
  data() {
    return {
      //风场选择器
      options: [],
      //风机日信息等级评估管理表格数据
      gridData: [],
      //风机月信息等级评估管理表格数据
      gridDataMonth: [],
      //风机年信息等级评估管理表格数据
      gridDataYear: [],
      value: "NSS_FDC",
      value1: "",
      value2: "",
      value3: "",
      yearvalue: "",
      monthvalue: "",
      //风机日信息等级评估管理对比框开关
      dialogTableVisible: false,
      //风机月信息等级评估管理对比框开关
      dialogTableVisibleMonth: false,
      //风机年信息等级评估管理对比框开关
      dialogTableVisibleYear: false,
      //elementui组件多选数据包
      multipleSelection: [],
      //分页起始页
      currentPage2: 1,
      //每页显示数据个数
      pagesize: 10,
      //等级评估对标雷达图1数据
      radarChartData1: [],
      //等级评估对标雷达图2数据
      radarChartData2: [],
      //等级评估雷达图标题名称
      radarChartName: "",
      //雷达图数据名称1
      radatChartWindturbineid1: "",
      //雷达图数据名称2
      radatChartWindturbineid2: "",
      fan1: "",
      fan2: "",
      //对比框表格风机编号数据1
      fanNumber1: "",
      //对比框表格风机编号数据2
      fanNumber2: "",
      //风机日信息等级评估管理页面表格显示开关
      dailyInformation: true,
      //风机月信息等级评估管理页面表格显示开关
      monthlyInformation: false,
      //风机年信息等级评估管理页面表格显示开关
      annualInformation: false,
      activeName: "first",
      //对比框表格右侧数据
      sortInOrder: [],
      //对比框表格左侧数据
      sortInOrderTop: [],
      ranking1: "",
      ranking2: "",
      score1: "",
      score2: "",
      //所需排序值
      orderByColumn: "windturbineid",
      //排序，默认为升序asc
      isAsc: "asc",
      //获取日信息分页数据
      total: 0,
      //获取月信息分页数据
      totalMonth: "",
      //获取年信息分页数据
      totalYear: "",
      //日期昨天
      updateTime: "",
    };
  },
  created() {
    //获取风场信息数据
    this.API.get("/powercompare/windfarmAjax").then((res) => {
      this.options = res.data;
    });
    //获取昨日日期时间
    var newData = new Date();
    this.updateTime = this.BASE.getBzDate(newData.getTime(), -1);
  },
  mounted() {
    this.gradeByDaygData();
    this.gamonthlistByPage();
    this.gayearlistByPage();
    
  },
  methods: {
    headStyle() {
      //表格文字居中显示
      return "text-align:center";
    },
    currentSel() {
      this.gradeByDaygData();
      this.gamonthlistByPage();
      this.gayearlistByPage();
    },
    //排序方法
    changeTableSort(column) {
      //排序方法 column.prop为点击要排序列的数据，将需要排序的值赋给orderByColumn
      this.orderByColumn = column.prop;
      //如果column.order为descending（点击排序上箭头），则为降序，若为ascending（点击排序下箭头），则为升序，并将值赋给isAsc
      if (column.order == "descending") {
        this.isAsc = "desc";
      } else if (column.order == "ascending") {
        this.isAsc = "asc";
      }
      this.gradeByDaygData();
    },
    //处理对比框表格数据方法val为点击多选框的数据
    handleSelectionChange(val) {
      this.sortInOrder = [];
      this.sortInOrderTop = [];
      this.multipleSelection = val;
      //如果多选框中的数据有两个，那么对其对比框表格赋值并显示
      if (this.multipleSelection.length == 2) {
        this.fan1 = this.multipleSelection[0].windturbineid;
        this.fanNumber1 = "风机编号：" + this.fan1;
        this.fan2 = this.multipleSelection[1].windturbineid;
        this.fanNumber2 = "风机编号：" + this.fan2;
        this.ranking1 = "排名：" + this.fan1.slice(5);
        this.ranking2 = "排名：" + this.fan2.slice(5);
        this.score1 = "评分：" + this.fan1.slice(5);
        this.score2 = "评分：" + this.fan2.slice(5);
        this.sortInOrderTop.push({
          lhpj: "量化评级：" + this.multipleSelection[0].level,
          zhpm: "量化评级：" + this.multipleSelection[1].level,
        });
        this.sortInOrderTop.push({
          lhpj: "综合排名：" + this.multipleSelection[0].rank,
          zhpm: "综合排名：" + this.multipleSelection[1].rank,
        });
        this.sortInOrder.push({
          lx: "",
          index: "发电量",
          data1: this.multipleSelection[0].dayfdl,
          data2: this.multipleSelection[1].dayfdl,
          ranking1: this.multipleSelection[0].monthfdl,
          ranking2: this.multipleSelection[1].monthfdl,
          score1: this.multipleSelection[0].yearfdl,
          score2: this.multipleSelection[1].yearfdl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "理论发电量",
          data1: this.multipleSelection[0].dayllfdl,
          data2: this.multipleSelection[1].dayllfdl,
          ranking1: this.multipleSelection[0].monthllfdl,
          ranking2: this.multipleSelection[1].monthllfdl,
          score1: this.multipleSelection[0].yearllfdl,
          score2: this.multipleSelection[1].yearllfdl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "平均功率",
          data1: this.multipleSelection[0].daygl,
          data2: this.multipleSelection[1].daygl,
          ranking1: this.multipleSelection[0].monthgl,
          ranking2: this.multipleSelection[1].monthgl,
          score1: this.multipleSelection[0].yeargl,
          score2: this.multipleSelection[1].yeargl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "故障损失电量",
          data1: this.multipleSelection[0].daygzssdl,
          data2: this.multipleSelection[1].daygzssdl,
          ranking1: this.multipleSelection[0].monthgzssdl,
          ranking2: this.multipleSelection[1].monthgzssdl,
          score1: this.multipleSelection[0].yeargzssdl,
          score2: this.multipleSelection[1].yeargzssdl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "限电损失电量",
          data1: this.multipleSelection[0].dayxdssdl,
          data2: this.multipleSelection[1].dayxdssdl,
          ranking1: this.multipleSelection[0].monthxdssdl,
          ranking2: this.multipleSelection[1].monthxdssdl,
          score1: this.multipleSelection[0].yearxdssdl,
          score2: this.multipleSelection[1].yearxdssdl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "维护损失电量",
          data1: this.multipleSelection[0].daywhssdl,
          data2: this.multipleSelection[1].daywhssdl,
          ranking1: this.multipleSelection[0].monthwhssdl,
          ranking2: this.multipleSelection[1].monthwhssdl,
          score1: this.multipleSelection[0].yearwhssdl,
          score2: this.multipleSelection[1].yearwhssdl,
        });
        this.sortInOrder.push({
          lx: "",
          index: "故障时间",
          data1: this.multipleSelection[0].daygzsj,
          data2: this.multipleSelection[1].daygzsj,
          ranking1: this.multipleSelection[0].monthgzsj,
          ranking2: this.multipleSelection[1].monthgzsj,
          score1: this.multipleSelection[0].yeargzsj,
          score2: this.multipleSelection[1].yeargzsj,
        });
        this.sortInOrder.push({
          lx: "",
          index: "维护时间",
          data1: this.multipleSelection[0].daywhsj,
          data2: this.multipleSelection[1].daywhsj,
          ranking1: this.multipleSelection[0].monthwhsj,
          ranking2: this.multipleSelection[1].monthwhsj,
          score1: this.multipleSelection[0].yearwhsj,
          score2: this.multipleSelection[1].yearwhsj,
        });
        this.sortInOrder.push({
          lx: "",
          index: "运行时间",
          data1: this.multipleSelection[0].dayyxsj,
          data2: this.multipleSelection[1].dayyxsj,
          ranking1: this.multipleSelection[0].monthyxsj,
          ranking2: this.multipleSelection[1].monthyxsj,
          score1: this.multipleSelection[0].yearyxsj,
          score2: this.multipleSelection[1].yearyxsj,
        });
        this.sortInOrder.push({
          lx: "",
          index: "停机时间",
          data1: this.multipleSelection[0].daytjsj,
          data2: this.multipleSelection[1].daytjsj,
          ranking1: this.multipleSelection[0].monthtjsj,
          ranking2: this.multipleSelection[1].monthtjsj,
          score1: this.multipleSelection[0].yeartjsj,
          score2: this.multipleSelection[1].yeartjsj,
        });
        this.sortInOrder.push({
          lx: "性能",
          index: "平均切入风速",
          data1: this.multipleSelection[0].dayxfqr,
          data2: this.multipleSelection[1].dayxfqr,
          ranking1: this.multipleSelection[0].monthxfqr,
          ranking2: this.multipleSelection[1].monthxfqr,
          score1: this.multipleSelection[0].yearxfqr,
          score2: this.multipleSelection[1].yearxfqr,
        });
        this.sortInOrder.push({
          lx: "性能",
          index: "性能损失电量",
          data1: this.multipleSelection[0].dayxnssdl,
          data2: this.multipleSelection[1].dayxnssdl,
          ranking1: this.multipleSelection[0].monthxnssdl,
          ranking2: this.multipleSelection[1].monthxnssdl,
          score1: this.multipleSelection[0].yearxnssdl,
          score2: this.multipleSelection[1].yearxnssdl,
        });
        this.sortInOrder.push({
          lx: "性能",
          index: "拟合优度",
          data1: this.multipleSelection[0].daynhyd,
          data2: this.multipleSelection[1].daynhyd,
          ranking1: this.multipleSelection[0].monthnhyd,
          ranking2: this.multipleSelection[1].monthnhyd,
          score1: this.multipleSelection[0].yearnhyd,
          score2: this.multipleSelection[1].yearnhyd,
        });
        this.sortInOrder.push({
          lx: "性能",
          index: "功率一致性系数",
          data1: this.multipleSelection[0].dayglyzxxs,
          data2: this.multipleSelection[1].dayglyzxxs,
          ranking1: this.multipleSelection[0].monthglyzxxs,
          ranking2: this.multipleSelection[1].monthglyzxxs,
          score1: this.multipleSelection[0].yearglyzxxs,
          score2: this.multipleSelection[1].yearglyzxxs,
        });
        this.sortInOrder.push({
          lx: "可靠性管理",
          index: "利用小时",
          data1: this.multipleSelection[0].daylyxs,
          data2: this.multipleSelection[1].daylyxs,
          ranking1: this.multipleSelection[0].monthlyxs,
          ranking2: this.multipleSelection[1].monthlyxs,
          score1: this.multipleSelection[0].yearlyxs,
          score2: this.multipleSelection[1].yearlyxs,
        });
        this.sortInOrder.push({
          lx: "可靠性管理",
          index: "设备可利用率",
          data1: this.multipleSelection[0].daysbklyl,
          data2: this.multipleSelection[1].daysbklyl,
          ranking1: this.multipleSelection[0].monthsbklyl,
          ranking2: this.multipleSelection[1].monthsbklyl,
          score1: this.multipleSelection[0].yearsbklyl,
          score2: this.multipleSelection[1].yearsbklyl,
        });
        this.sortInOrder.push({
          lx: "可靠性管理",
          index: "等效可利用系数",
          data1: this.multipleSelection[0].daydxkyxs,
          data2: this.multipleSelection[1].daydxkyxs,
          ranking1: this.multipleSelection[0].monthdxkyxs,
          ranking2: this.multipleSelection[1].monthdxkyxs,
          score1: this.multipleSelection[0].yeardxkyxs,
          score2: this.multipleSelection[1].yeardxkyxs,
        });
        this.sortInOrder.push({
          lx: "可靠性管理",
          index: "有效风时速",
          data1: this.multipleSelection[0].dayyxfss,
          data2: this.multipleSelection[1].dayyxfss,
          ranking1: this.multipleSelection[0].monthyxfss,
          ranking2: this.multipleSelection[1].monthyxfss,
          score1: this.multipleSelection[0].yearyxfss,
          score2: this.multipleSelection[1].yearyxfss,
        });
        this.sortInOrder.push({
          lx: "资源",
          index: "平均风速",
          data1: this.multipleSelection[0].dayfs,
          data2: this.multipleSelection[1].dayfs,
          ranking1: this.multipleSelection[0].monthfs,
          ranking2: this.multipleSelection[1].monthfs,
          score1: this.multipleSelection[0].yearfs,
          score2: this.multipleSelection[1].yearfs,
        });
        this.sortInOrder.push({
          lx: "资源",
          index: "静风频率",
          data1: this.multipleSelection[0].daygl,
          data2: this.multipleSelection[1].daygl,
          ranking1: this.multipleSelection[0].monthgl,
          ranking2: this.multipleSelection[1].monthgl,
          score1: this.multipleSelection[0].yeargl,
          score2: this.multipleSelection[1].yeargl,
        });
        this.radarChartData();
      }
    },
    //点击分页调用方法刷新页面
    handleSizeChange(val) {
      this.pagesize = val;
      this.gradeByDaygData();
      this.gamonthlistByPage();
      this.gayearlistByPage();
    },
    //刷新分页显示当前页数目
    handleCurrentChange(val) {
      this.gradeByDaygData();
      this.gamonthlistByPage();
      this.gayearlistByPage();
    },
    //导出excel风机等级评估日数据
    exportDayData() {
      excelHelper.exportExcel("daytable", "等级评估日数据", ".xls", true);
    },
    //导出excel风机等级评估月数据
    exportMonthData() {
      excelHelper.exportExcel("monthtable", "等级评估月数据", ".xls", true);
    },
    //导出excel风机等级评估年数据
    exportYearData() {
      excelHelper.exportExcel("yeartable", "等级评估年数据", ".xls", true);
    },
    //点击打开日对比框方法
    dialogTableVisibleOpen() {
      this.dialogTableVisible = true;
      //多选风机id赋值给radatChartWindturbineid1为雷达图数据1名称
      this.radatChartWindturbineid1 = this.multipleSelection[0].windturbineid;
      //多选风机id赋值给radatChartWindturbineid1为雷达图数据2名称
      this.radatChartWindturbineid2 = this.multipleSelection[1].windturbineid;
      //调用对应EChart热力图
      this.$nextTick(function () {
        this.drawPie("leiDaTu");
      });
    },
    //点击打开月对比框方法
    dialogTableVisibleOpenMonth() {
      this.dialogTableVisibleMonth = true;
      this.radatChartWindturbineid1 = this.multipleSelection[0].windturbineid;
      this.radatChartWindturbineid2 = this.multipleSelection[1].windturbineid;
      this.$nextTick(function () {
        this.drawPie2("leiDaTu2");
      });
    },
    //点击打开年对比框方法
    dialogTableVisibleOpenYear() {
      this.dialogTableVisibleYear = true;
      this.radatChartWindturbineid1 = this.multipleSelection[0].windturbineid;
      this.radatChartWindturbineid2 = this.multipleSelection[1].windturbineid;
      this.$nextTick(function () {
        this.drawPie3("leiDaTu2");
      });
    },
    handleClick(tab) {
      //根据点击切换判断打开哪个表格的div,tab.name包含所有的切换页面名，根据名字判断打开了哪页。
      if (tab.name === "first") {
        this.dailyInformation = true;
        this.monthlyInformation = false;
        this.annualInformation = false;
        this.gradeByDaygData();
        this.gamonthlistByPage();
        this.gayearlistByPage();
      } else if (tab.name === "second") {
        this.dailyInformation = false;
        this.monthlyInformation = true;
        this.annualInformation = false;
        this.gradeByDaygData();
        this.gamonthlistByPage();
        this.gayearlistByPage();
      } else if (tab.name === "cord") {
        this.dailyInformation = false;
        this.monthlyInformation = false;
        this.annualInformation = true;
        this.gradeByDaygData();
        this.gamonthlistByPage();
        this.gayearlistByPage();
      }
    },
    gradeByDaygData() {
      //风机日信息等级评估管理数据
      let that = this;
      var page = new URLSearchParams();
      //页数
      page.append("pageNum", this.currentPage2);
      //页面数据个数
      page.append("pageSize", this.pagesize);
      //需要排序的参数
      page.append("orderByColumn", this.orderByColumn);
      //升序还是降序
      page.append("isAsc", this.isAsc);
      //风场id
      page.append("wpId", this.value);
      if (this.value1 == "") {
        this.value1 = this.updateTime;
      }
      page.append("recorddate", this.value1);
      this.API.post("/benchmarking/gadaylistByPage", page).then((res) => {
        //gridData日表格数据
        that.gridData = res.data.list;
        //total日分页数据
        that.total = res.data.total;
      });
    },
    gamonthlistByPage() {
      //风机月信息等级评估管理数据
      let that = this;
      var pagemonth = new URLSearchParams();
      pagemonth.append("pageNum", this.currentPage2);
      pagemonth.append("pageSize", this.pagesize);
      pagemonth.append("wpId", this.value);
      if (this.yearvalue == "") {
        this.yearvalue = this.updateTime.substring(0, 4);
      }
      //年份
      pagemonth.append("year", this.yearvalue);
      if (this.value2 == "") {
        this.value2 = this.updateTime;
        //判断数据长度是否为2位数，若为2位数截取两位数，一位数则截取一位数
        if (this.value2.substring(5, 7) < 10) {
          this.monthvalue = this.value2.substring(6, 7);
        } else {
          this.monthvalue = this.value2.substring(5, 7);
        }
      } else {
        if (this.value2.substring(5, 7) < 10) {
          this.monthvalue = this.value2.substring(6, 7);
        } else {
          this.monthvalue = this.value2.substring(5, 7);
        }
      }
      //月份
      pagemonth.append("month", this.monthvalue);
      this.API
        .post("/benchmarking/gamonthlistByPage", pagemonth)
        .then((res) => {
          //gridDataMonth月表格数据
          that.gridDataMonth = res.data.list;
          //totalMonth月分页数据
          that.totalMonth = res.data.total;
        });
    },
    gayearlistByPage() {
      //风机年信息等级评估管理数据
      let that = this;
      this.yearvalue = this.value3.toString();
      var pageyear = new URLSearchParams();
      pageyear.append("pageNum", this.currentPage2);
      pageyear.append("pageSize", this.pagesize);
      pageyear.append("wpId", this.value);
      if (this.value3 == "") {
        this.value3 = this.updateTime.substring(0, 4);
      }
      pageyear.append("year", this.value3);
      this.API
        .post("/benchmarking/gayearlistByPage", pageyear)
        .then((res) => {
          //gridDataYear年表格数据
          that.gridDataYear = res.data.list;
          //totalYear年分页数据
          that.totalYear = res.data.total;
        });
    },
    radarChartData() {
      //获取EChart雷达图数据
      let that = this;
      this.API
        .get(
          "/benchmarking/wtchart?gaid1=" +
          this.multipleSelection[0].id +
          "&gaid2=" +
          this.multipleSelection[1].id
        )
        .then((res) => {
          var arr1 = [];
          var name = [];
          res.data.gaid1.forEach(function (item) {
            arr1.push({
              //雷达图数据
              data1: item.data1,
            });
            name.push({
              //雷达图数据命名
              name: item.name,
            });
          });
          that.radarChartName = name;
          //将target雷达图显示容量加入数组中。
          var target = {
            max: 15,
          };
          //循环遍历数据
          for (let v = 0; v < that.radarChartName.length; v++) {
            const returnedTarget = Object.assign(
              that.radarChartName[v],
              target
            );
          }
          for (let i = 0; i < arr1.length; i++) {
            that.radarChartData1.push(arr1[i].data1);
          }
          var arr2 = [];
          res.data.gaid2.forEach(function (item) {
            arr2.push({
              data1: item.data1,
            });
          });
          for (let j = 0; j < arr2.length; j++) {
            that.radarChartData2.push(arr2[j].data1);
          }
        });
    },
    //风机日信息等级评估管理Echart图
    drawPie() {
      this.ECLZX.getGradeEvaluationChartData("leiDaTu",
      [
        {
          value: this.radarChartData1,
          name: this.radatChartWindturbineid1,
        },
        {
          value: this.radarChartData2,
          name: this.radatChartWindturbineid2,
        },
      ],this.radarChartName,[this.radatChartWindturbineid1, this.radatChartWindturbineid2]);
    },
    //风机月信息等级评估管理Echart图
    drawPie2() {
      var charts2;
      if (charts2 != null && charts2 != "" && charts2 != undefined) {
        charts2.dispose();
      }
      charts2 = this.$echarts.init(document.getElementById("leiDaTu2"));
      let option2 = {
        tooltip: {},
        legend: {
          x: "center", //可设定图例在左、右、居中
          y: "bottom",
          data: [this.radatChartWindturbineid1, this.radatChartWindturbineid2],
        },
        radar: {
          // shape: 'circle',
          name: {
            textStyle: {
              color: "#fff",
              backgroundColor: "#999",
              borderRadius: 3,
              padding: [3, 5],
            },
          },
          indicator: this.radarChartName,
        },
        series: [
          {
            name: "预算 vs 开销（Budget vs spending）",
            type: "radar",
            // areaStyle: {normal: {}},
            data: [
              {
                value: this.radarChartData1,
                name: this.radatChartWindturbineid1,
              },
              {
                value: this.radarChartData2,
                name: this.radatChartWindturbineid2,
              },
            ],
          },
        ],
      };
      charts2.clear();
      charts2.setOption(option2);
    },
    //风机年信息等级评估管理Echart图
    drawPie3() {
      var charts3;
      if (charts3 != null && charts3 != "" && charts3 != undefined) {
        charts3.dispose();
      }

      charts3 = this.$echarts.init(document.getElementById("leiDaTu3"));
      let option3 = {
        tooltip: {},
        legend: {
          x: "center", //可设定图例在左、右、居中
          y: "bottom",
          data: [this.radatChartWindturbineid1, this.radatChartWindturbineid2],
        },
        radar: {
          // shape: 'circle',
          name: {
            textStyle: {
              color: "#fff",
              backgroundColor: "#999",
              borderRadius: 3,
              padding: [3, 5],
            },
          },
          indicator: this.radarChartName,
        },
        series: [
          {
            name: "预算 vs 开销（Budget vs spending）",
            type: "radar",
            // areaStyle: {normal: {}},
            data: [
              {
                value: this.radarChartData1,
                name: this.radatChartWindturbineid1,
              },
              {
                value: this.radarChartData2,
                name: this.radatChartWindturbineid2,
              },
            ],
          },
        ],
      };
      charts3.clear();
      charts3.setOption(option3);
    },
  },
};