
import * as echarts from "echarts";
//import excelHelper from "@/utils/excelHelper";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      len:10,
      fc:"",
      pj:"",
      xl:"",
      autoHeight_fc: 400,
      autoHeight_pj: 800,
      autoHeight_xl: 1200,
      tableHeight_fc:460,
      tableHeight_pj:860,
      tableHeight_xl:1220,
      queryAll_table_lyl:[],
      wpIdslist: {
        name:"",
        id:"",
      },
      projectlist:{
        name:"",
        id:"",
      },
      linelist:{
        name:"",
        id:"",
      },
      fc_date: [],
      pj_date: [],
      xl_date: [],
      beginDate: "",
      endDate: "",
      activeName: "first",
      tableid: "fc",
      styleObject_fc: {
        height: '460px'
      },
      styleObject_pj: {
        height: '860px'
      },
      styleObject_xl: {
        height: '1220px'
      },
      linechar_data:{
        dayspeed:[],
        daydl2:[],
        daynhgzssdl:[],
        daynhcfdl:[],
        daynhqfdl:[],
        daynhxdssdl:[],
        lyl:[],
        wtName:[],
        total:[],
        daynhwhssdl:[]
      }
    };
  },
  methods: {
    created(){
      
      },
    onSubmit() {},
    /**
     * 获取风场
     */
    query_wpid() {
       var newData = new Date();
       this.beginDate = this.BASE.getBzDate(newData.getTime(),-1);
       this.endDate = this.BASE.getBzDate(newData.getTime(),0);
       this.API.get("powercompare/windfarmAjax?").then((res) => {
       this.wpIdslist = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 获取项目
     */
    query_xml(){
      this.pj = "";
      this.xl = "";
      this.API.get("powercompare/projectAjax?wpIds=" + this.fc).then((res) => {
        this.projectlist = res.data;
        
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 获取线路
     */
    query_xl(){
      this.xl = "";
      this.API.get("powercompare/lineAjax?pjIds=" + this.pj).then((res) => {
        this.linelist = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 获取当前卡片状态
     */
    handleClick(tab) {
      Object.assign(this.$data.autoHeight_fc, this.$options.data().autoHeight_fc);
      Object.assign(this.$data.styleObject_fc, this.$options.data().styleObject_fc);
      Object.assign(this.$data.autoHeight_pj, this.$options.data().autoHeight_pj);
      Object.assign(this.$data.styleObject_pj, this.$options.data().styleObject_pj);
      Object.assign(this.$data.autoHeight_xl, this.$options.data().autoHeight_xl);
      Object.assign(this.$data.styleObject_xl, this.$options.data().styleObject_xl);
      Object.assign(this.$data.queryAll_table_lyl, this.$options.data().queryAll_table_lyl);
      if (tab.name === "first") {
        this.tableid = "fc";
        this.query();
      } else if (tab.name === "second") {
        this.tableid = "pj";
        this.query();
      } else if (tab.name === "jdxl") {
        this.tableid = "xl";
        this.query();
      }
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    /**
     * 查询风场、项目、线路列表数据结果
     */
    query() {
      Object.assign(this.$data.autoHeight_fc, this.$options.data().autoHeight_fc);
      Object.assign(this.$data.styleObject_fc, this.$options.data().styleObject_fc);
      Object.assign(this.$data.autoHeight_pj, this.$options.data().autoHeight_pj);
      Object.assign(this.$data.styleObject_pj, this.$options.data().styleObject_pj);
      Object.assign(this.$data.autoHeight_xl, this.$options.data().autoHeight_xl);
      Object.assign(this.$data.styleObject_xl, this.$options.data().styleObject_xl);
      Object.assign(this.$data.queryAll_table_lyl, this.$options.data().queryAll_table_lyl);
      this.styleObject_fc.height = '460px';
      this.autoHeight_fc = '400px';
      this.styleObject_pj.height = '860px';
      this.autoHeight_pj = '800px';
      this.styleObject_xl.height = '1260px';
      this.autoHeight_xl = '1200px';
      this.fc_date = [];
      this.xl_date = [];
      this.pj_date = [];
      //表格数据获取
      this.API
        .get(
          "powercompare/powerAjaxAll?wpIds=" +
            this.fc +
            "&beginDate=" +
            this.beginDate +
            "&endDate=" +
            this.endDate +
            "&queryType=" +
            this.tableid +
            "&sortName=" +
            this.fc +
            "&sortOrder=" +
            "Asc"
        )
        .then((res) => {
          let that = this;
          Object.assign(this.$data.linechar_data, this.$options.data().linechar_data);
          this.linechar_data.dayspeed=[];
          this.linechar_data.daydl2=[];
          this.linechar_data.daynhgzssdl=[];
          this.linechar_data.daynhcfdl=[];
          this.linechar_data.daynhqfdl=[];
          this.linechar_data.daynhxdssdl=[];
          this.linechar_data.lyl=[];
          this.linechar_data.wtName=[];
          this.linechar_data.daynhwhssdl=[];
          let queryAll_table = res.data.list;
          let queryAll_table_lyl = res.data.lyl;
          for(let i = 0;i < Object.keys(queryAll_table).length;i++){
            if(queryAll_table[i].wtName!="合计"){
            that.linechar_data.dayspeed.push(queryAll_table[i].dayspeed.toFixed(2));
            that.linechar_data.daydl2.push(queryAll_table[i].daydl2.toFixed(2));
            that.linechar_data.daynhgzssdl.push(queryAll_table[i].daynhgzssdl.toFixed(2));
            that.linechar_data.daynhcfdl.push(queryAll_table[i].daynhcfdl.toFixed(2));
            that.linechar_data.daynhqfdl.push(queryAll_table[i].daynhqfdl.toFixed(2));
            that.linechar_data.daynhxdssdl.push(queryAll_table[i].daynhxdssdl.toFixed(2));
            that.linechar_data.lyl.push(queryAll_table[i].lyl.toFixed(2));
            that.linechar_data.wtName.push(queryAll_table[i].wtName);
            that.linechar_data.total.push(queryAll_table[i].total.toFixed(2));
             that.linechar_data.daynhwhssdl.push(queryAll_table[i].daynhwhssdl.toFixed(2));
            }
          }
          if (this.tableid === "fc") {
            that.fc_date = queryAll_table;
            that.drawhistogram_fc(this.linechar_data,queryAll_table_lyl);
          } else if (this.tableid === "pj") {
            that.pj_date = queryAll_table;
            that.drawhistogram_pj(this.linechar_data,queryAll_table_lyl);
          } else if (this.tableid === "xl") {
            that.xl_date = queryAll_table;
            that.drawhistogram_xl(this.linechar_data,queryAll_table_lyl);
          }
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 
     * 询风场、项目、线路列表数据结果
     */
    queryPowerAll() {
      Object.assign(this.$data.autoHeight_fc, this.$options.data().autoHeight_fc);
      Object.assign(this.$data.styleObject_fc, this.$options.data().styleObject_fc);
      Object.assign(this.$data.linechar_data, this.$options.data().linechar_data);
      let that = this;
      if (
        this.beginDate == "" ||
        this.endDate == "" ||
        this.beginDate == undefined ||
        this.endDate == undefined
      ) {
        this.query_wpid();
        that.$message.error("请选时间！");
        return;
      }
      this.fc_date = [];
      this.xl_date = [];
      this.pj_date = [];

      if (
        that.fc == "" ||
        that.fc == null ||
        that.fc == undefined
      ) {
        that.query();
      } else {
        this.API
          .get(
            "powercompare/powerAjax?wpIds=" +
              this.fc +
              "&pjIds=" +
              this.pj +
              "&lineIds=" +
              this.xl +
              "&beginDate=" +
              this.beginDate +
              "&endDate=" +
              this.endDate +
              "&sortName=" +
              this.fc +
              "&sortOrder=" +
              "Asc"
          )
          .then((res) => {
            let that = this;
            this.len = Object.keys(res.data.list).length;
            if(this.len <= 10){that.autoHeight_fc = 575; that.styleObject_fc.height = '700px' }
            else if(this.len > 10 && this.len <=20){that.autoHeight_fc = 775; that.styleObject_fc.height = '800px';that.autoHeight_pj = 775; that.styleObject_pj.height = '800px';that.autoHeight_xl = 775; that.styleObject_xl.height = '800px' }
            else if(this.len > 20 && this.len <=30){that.autoHeight_fc = 975; that.styleObject_fc.height = '1000px';that.autoHeight_pj = 975; that.styleObject_pj.height = '1000px';that.autoHeight_xl = 975; that.styleObject_xl.height = '1000px' }
            else if(this.len > 30 && this.len <=40){that.autoHeight_fc = 1175; that.styleObject_fc.height = '1200px';that.autoHeight_pj = 1175; that.styleObject_pj.height = '1200px';that.autoHeight_xl = 1175; that.styleObject_xl.height = '1200px' }
            else if(this.len > 40 && this.len <=50){that.autoHeight_fc = 1375; that.styleObject_fc.height = '1400px';that.autoHeight_pj = 1375; that.styleObject_pj.height = '1400px';that.autoHeight_xl = 1375; that.styleObject_xl.height = '1400px' }
            else if(this.len > 50 && this.len <=60){that.autoHeight_fc = 1575; that.styleObject_fc.height = '1600px';that.autoHeight_pj = 1575; that.styleObject_pj.height = '1600px';that.autoHeight_xl = 1575; that.styleObject_xl.height = '1600px' }
            else if(this.len > 60 && this.len <=70){that.autoHeight_fc = 1775; that.styleObject_fc.height = '1800px';that.autoHeight_pj = 1775; that.styleObject_pj.height = '1800px';that.autoHeight_xl = 1775; that.styleObject_xl.height = '1800px' }
            else if(this.len > 70 && this.len <=80){that.autoHeight_fc = 1975; that.styleObject_fc.height = '2000px';that.autoHeight_pj = 1975; that.styleObject_pj.height = '2000px';that.autoHeight_xl = 1975; that.styleObject_xl.height = '2000px' }
            else{that.autoHeight_fc = 2175; that.styleObject_fc.height = '2200px';that.autoHeight_pj = 2175; that.styleObject_pj.height = '2200px';that.autoHeight_xl = 2175; that.styleObject_xl.height = '2200px' }
             this.tableHeight_fc = this.autoHeight_fc - 20; 
             this.tableHeight_pj = this.autoHeight_pj - 20; 
             this.tableHeight_xl = this.autoHeight_xl - 20; 
          Object.assign(this.$data.linechar_data, this.$options.data().linechar_data);
          this.linechar_data.dayspeed=[];
          this.linechar_data.daydl2=[];
          this.linechar_data.daynhgzssdl=[];
          this.linechar_data.daynhcfdl=[];
          this.linechar_data.daynhqfdl=[];
          this.linechar_data.daynhxdssdl=[];
          this.linechar_data.lyl=[];
          this.linechar_data.wtName=[];
          this.linechar_data.daynhwhssdl=[];
          let queryAll_table = res.data.list;
          let queryAll_table_lyl = res.data.lyl;
          //this.query_lyl(queryAll_table);
          for(let i = 0;i < Object.keys(queryAll_table).length;i++){
            if(queryAll_table[i].wtName!="合计"){
            that.linechar_data.dayspeed.push(queryAll_table[i].dayspeed.toFixed(2));
            that.linechar_data.daydl2.push(queryAll_table[i].daydl2.toFixed(2));
            that.linechar_data.daynhgzssdl.push(queryAll_table[i].daynhgzssdl.toFixed(2));
            that.linechar_data.daynhcfdl.push(queryAll_table[i].daynhcfdl.toFixed(2));
            that.linechar_data.daynhqfdl.push(queryAll_table[i].daynhqfdl.toFixed(2));
            that.linechar_data.daynhxdssdl.push(queryAll_table[i].daynhxdssdl.toFixed(2));
            that.linechar_data.lyl.push(queryAll_table[i].lyl.toFixed(2));
            that.linechar_data.wtName.push(queryAll_table[i].wtName);
            that.linechar_data.total.push(queryAll_table[i].total.toFixed(2));
            that.linechar_data.daynhwhssdl.push(queryAll_table[i].daynhwhssdl.toFixed(2));
            }
            
          }
           if (this.tableid === "fc") {
            that.fc_date = queryAll_table;
            that.drawhistogram_fc(this.linechar_data,queryAll_table_lyl);
          } else if (this.tableid === "pj") {
            that.pj_date = queryAll_table;
            that.drawhistogram_pj(this.linechar_data,queryAll_table_lyl);
          } else if (this.tableid === "xl") {
            that.xl_date = queryAll_table;
            that.drawhistogram_xl(this.linechar_data,queryAll_table_lyl);
          }
          }).catch(error =>{
            this.$message.error('获取数据失败');
          });
      }
    },
    /**
     * 
     * 查询检查
     */
    checkwindfarm() {
      if (this.fc == "") {
        this.$message.error("请选择风场！");
        return;
      }
    },
    checkproject() {
      if (this.fc == "") {
        this.$message.error("请选择项目！");
        return;
      }
      if (new Date(this.timedate) == null) {
        this.$message.error("请选择时间");
        return;
      }
    },
    checktime() {
      if (new Date(this.timedate) == null) {
        this.$message.error("请选择时间");
        return;
      }
    },
    /**
     * 详情跳转
     */
    queryApDataMx() {
      this.$router.push({ path: "/newPerformanceList" ,
      query: {
            beginDate : this.beginDate,
            endDate : this.endDate
          },});
    },

    /**
     * 格式转换
     */
    filter_total(cellValue) {
      return parseFloat(cellValue.total).toFixed(2);
    },

    filter_daydl2(cellValue) {
      return parseFloat(cellValue.daydl2).toFixed(2);
    },
    filter_dayspeed(cellValue) {
      return parseFloat(cellValue.dayspeed).toFixed(2);
    },
    filter_daynhwhssdl(cellValue) {
      return parseFloat(cellValue.daynhwhssdl).toFixed(2);
    },
    filter_daynhcfdl(cellValue) {
      return parseFloat(cellValue.daynhcfdl).toFixed(2);
    },
    filter_daynhxdssdl(cellValue) {
      return parseFloat(cellValue.daynhqfdl).toFixed(2);
    },
    filter_lyl(cellValue) {
      return parseFloat(cellValue.lyl).toFixed(2);
    },
    filter_daynhgzssdl(cellValue) {
      return parseFloat(cellValue.daynhgzssdl).toFixed(2);
    },
    // toExcel() {
    //   let that = this;
    //   if (this.tableid === "fc") {
    //     excelHelper.exportExcel("fc_table", "fc数据", ".xls", true);
    //   } else if (this.tableid === "pj") {
    //     excelHelper.exportExcel("pj_table", "pj数据", ".xls", true);
    //   } else if (this.tableid === "xl") {
    //     excelHelper.exportExcel("xl_table", "xl数据", ".xls", true);
    //   }
    // },
    drawhistogram_fc(date,date2) {
      this.chartLine = echarts.init(document.getElementById("histogram_fc"));
      this.chartLine.clear();
      this.chartLine.resize({ height: this.autoHeight_fc });

      var option;
      option = {
        color: [
          "#64E572",
          "#24CBE5",
          "#DDDF00",
          "#ED561B",
          "#50B432",
          "#058DC7",
        ],
        title: {
          text: "风机绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "-",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          max: Math.ceil(Math.max.apply(null, date.total))+ Math.ceil((Math.max.apply(null, date.total))*0.08)
        },
        yAxis: {
          type: "category",
          data: date.wtName,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daydl2,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhwhssdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhgzssdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhxdssdl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhcfdl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhqfdl,
          },
          //曲线
          {
            name: "-",
            data: date.total,
            markPoint: {
                data: date2,
                        },
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
    drawhistogram_pj(date,date2) {
      this.chartLine = echarts.init(document.getElementById("histogram_xm"));
      this.chartLine.clear();
      this.chartLine.resize({ height: this.autoHeight_pj });

      var option;

      var option;
      option = {
        color: [
          "#64E572",
          "#24CBE5",
          "#DDDF00",
          "#ED561B",
          "#50B432",
          "#058DC7",
        ],
        title: {
          text: "项目绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "-",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          max: Math.ceil(Math.max.apply(null, date.total))+ Math.ceil((Math.max.apply(null, date.total))*0.08)
         },
        yAxis: {
          type: "category",
          data: date.wtName,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daydl2,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhwhssdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhgzssdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhxdssdl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhcfdl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhqfdl,
          },
          //曲线
          {
            name: "-",
            data: date.total,
            markPoint: {
                data: date2,
                        },
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
    drawhistogram_xl(date,date2) {
      this.chartLine = echarts.init(document.getElementById("histogram_jdxl"));
      this.chartLine.clear();
      this.chartLine.resize({ height: this.autoHeight_xl });
      var option;

      var option;
      option = {
        color: [
          "#64E572",
          "#24CBE5",
          "#DDDF00",
          "#ED561B",
          "#50B432",
          "#058DC7",
        ],
        title: {
          text: "路线绩效榜单",
          left: 300,
          top: -5,
          textStyle: {
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
          left: 15,
          top: 30,
          data: [
            "实发电量",
            "计划检修损失",
            "非计划检修损失",
            "限电损失",
            "受累损失",
            "性能损失",
            "-",
          ],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          max: Math.ceil(Math.max.apply(null, date.total))+ Math.ceil((Math.max.apply(null, date.total))*0.08)
        },
        yAxis: {
          type: "category",
          data: date.wtName,
        },
        series: [
          {
            name: "实发电量",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daydl2,
          },
          {
            name: "计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhwhssdl,
          },
          {
            name: "非计划检修损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhgzssdl,
          },
          {
            name: "限电损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhxdssdl,
          },
          {
            name: "受累损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhcfdl,
          },
          {
            name: "性能损失",
            type: "bar",
            stack: "total",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            data: date.daynhqfdl,
          },
          //曲线
          {
            name: "-",
            data: date.total,
            markPoint: {
                data: date2,
                        },
            type: "line",
            symbol: "circle",
            symbolSize: 20,
            lineStyle: {
              color: "#5470C6",
              width: 4,
              type: "dashed",
            },
            itemStyle: {
              borderWidth: 3,
              borderColor: "#EE6666",
              color: "yellow",
            },
          },
        ],
      };
      this.chartLine.setOption(option);
    },
  },
  mounted() {
    this.$nextTick(() => {
               
            //后面的50：根据需求空出的高度，自行调整
        });
       
    this.query_wpid();
    this.query();
  },
};
