import * as echarts from "echarts";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      fj: ["MG01_01"],
      fc: "MHS_FDC",
      leida_list: [],
      Date1: "",
      leida_list_0: [],
      leida_list_1: [],
      leida_list_2: [],
      leida_list_3: [],
      leida_list_4: [],
      tableData: [],
      tableData_y: [],
      tableData_n: [],
      wpIdslist: {
        name: "",
        id: "",
      },
      jfpl: "",
      jfpl0: "",
      jfpl1: "",
      jfpl2: "",
      jfpl3: "",
      jfpl4: "",
      wtIdslist: {
        name: "",
        id: "",
        key: "",
      },
      activeName: "first",
      compareDayList: {},
      lineDate: {
        speed: [],
        value1: [],
        value2: [],
        value3: [],
        value4: [],
        value5: [],
      },
      lineDate_y: {
        speed: [],
        value1: [],
        value2: [],
        value3: [],
        value4: [],
        value5: [],
      },
      lineDate_n: {
        speed: [],
        value1: [],
        value2: [],
        value3: [],
        value4: [],
        value5: [],
      },
    };
  },

  created() {
    this.Date1 = this.BASE.getBzDate(new Date().getTime(),-1);
    this.query_wpid();
  },
  methods: {
    clear() {
      this.fj = [];
    },
    /**
     * 初始化数据 调用查询检查
     */
    handleClick() {
      this.tableData = [];
      this.tableData_n = [];
      this.tableData_y = [];
      this.query_check();
    },
    /**
     * 获取风场
     */
    query_wpid() {
      this.API.get("powercompare/windfarmAjax?").then((res) => {
        this.wpIdslist = res.data;
      }).catch(error =>{
        this.$message.error('获取数据失败');
      });
    },
    /**
     * 清空
     */
    query1() {
      this.clear();
      this.query();
    },
    /**
     * 查询风场
     */
    query() {
      let that = this;
      this.API
        .get("powercompare/windturbineAjax?wpId=" + that.fc)
        .then((res) => {
          this.wtIdslist = res.data;
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 查询检查
     */
    query_check() {
      if (
        this.fc == null ||
        this.fc == undefined ||
        this.fc == "" ||
        this.fj == null ||
        this.fj == undefined ||
        this.fj == ""
      ) {
        Object.assign(this.$data.lineDate, this.$options.data().lineDate);
        Object.assign(this.$data.lineDate_y, this.$options.data().lineDate_y);
        Object.assign(this.$data.lineDate_n, this.$options.data().lineDate_n);
        this.$message({
          showClose: true,
          message: "请选着风机或风场",
          type: "error",
        });
      } else {
        if (this.activeName == "first") {
          Object.assign(this.$data.tableData, this.$options.data().tableData);
          Object.assign(this.$data.lineDate, this.$options.data().lineDate);
          this.query_line();
        } else if (this.activeName == "second") {
          Object.assign(
            this.$data.tableData_y,
            this.$options.data().tableData_y
          );
          Object.assign(this.$data.lineDate_y, this.$options.data().lineDate_y);
          this.query_line_y();
        } else if (this.activeName == "thired") {
          Object.assign(
            this.$data.tableData_n,
            this.$options.data().tableData_n
          );
          Object.assign(this.$data.lineDate_n, this.$options.data().lineDate_n);
          this.query_line_n();
        }
      }
    },
    /**
     * 获取年 曲线数据
     */
    query_line_n() {
      let that = this;
      this.API
        .get(
          "compare/compareYearChat?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          let Date = res.data;
          for (let i = 0; i < Date.length; i++) {
            that.lineDate_n.speed[i] = Date[i].speed;
            that.lineDate_n.value1[i] = Date[i].value1;
            that.lineDate_n.value2[i] = Date[i].value2;
            that.lineDate_n.value3[i] = Date[i].value3;
            that.lineDate_n.value4[i] = Date[i].value4;
            that.lineDate_n.value5[i] = Date[i].value5;
          }
          this.query_daycompare_n();
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 获取年雷达图数据 表格
     */
    query_daycompare_n() {
      this.API
        .get(
          "compare/compareYearList?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          this.tableData_n = res.data;
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });

      this.API
        .get("compare/fzyYear?windturbineid=" + this.fj + "&date=" + this.Date1)
        .then((res) => {
          let that = this;
          Object.assign(
            this.$data.leida_list_0,
            this.$options.data().leida_list_0
          );
          Object.assign(
            this.$data.leida_list_1,
            this.$options.data().leida_list_1
          );
          Object.assign(
            this.$data.leida_list_2,
            this.$options.data().leida_list_2
          );
          Object.assign(
            this.$data.leida_list_3,
            this.$options.data().leida_list_3
          );
          Object.assign(
            this.$data.leida_list_4,
            this.$options.data().leida_list_4
          );
          let len = Object.keys(res.data).length;
          let lenfj = this.fj.length;
          if (len == 2) {
            this.jfpl0 = res.data.jfpl0;
            let value_list_0 = res.data.data0;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
          } else if (len == 4) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
          } else if (len == 6) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
          } else if (len == 8) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            let value_list_3 = res.data.data3;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
            for (let i = 1; i < value_list_3.length; i++) {
              that.leida_list_3.push(value_list_3[i].data1);
            }
          } else if (len == 10) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            this.jfpl4 = res.data.jfpl4;
            for (let i = 1; i < Object.keys(res.data.data0).length; i++) {
              that.leida_list_0.push(res.data.data0[i].data1);
              that.leida_list_1.push(res.data.data1[i].data1);
              that.leida_list_2.push(res.data.data2[i].data1);
              that.leida_list_3.push(res.data.data3[i].data1);
              that.leida_list_4.push(res.data.data4[i].data1);
            }
          }
          if (this.fj.length == 1) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
          } else if (this.fj.length == 2) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
          } else if (this.fj.length == 3) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2);
          } else if (this.fj.length == 4) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3);
          } else if (this.fj.length == 5) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3); 
            this.ECZM.leida_djbhd("fzy5",this.leida_list_4,this.jfpl4); 
          }
          this.ECZM.bar_djbhd("linechar_n",this.fj,this.lineDate);
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 获取月曲线数据
     */
    query_line_y() {
      let that = this;
      this.API
        .get(
          "compare/compareMonthChat?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          let Date = res.data;
          for (let i = 0; i < Date.length; i++) {
            that.lineDate_y.speed[i] = Date[i].speed;
            that.lineDate_y.value1[i] = Date[i].value1;
            that.lineDate_y.value2[i] = Date[i].value2;
            that.lineDate_y.value3[i] = Date[i].value3;
            that.lineDate_y.value4[i] = Date[i].value4;
            that.lineDate_y.value5[i] = Date[i].value5;
          }
          this.query_daycompare_y();
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 获取月雷达图数据 表格
     */
    query_daycompare_y() {
      this.API
        .get(
          "compare/compareMonthList?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          this.tableData_y = res.data;
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
      this.API
        .get(
          "compare/fzyMonth?windturbineid=" + this.fj + "&date=" + this.Date1
        )
        .then((res) => {
          let that = this;
          Object.assign(
            this.$data.leida_list_0,
            this.$options.data().leida_list_0
          );
          Object.assign(
            this.$data.leida_list_1,
            this.$options.data().leida_list_1
          );
          Object.assign(
            this.$data.leida_list_2,
            this.$options.data().leida_list_2
          );
          Object.assign(
            this.$data.leida_list_3,
            this.$options.data().leida_list_3
          );
          Object.assign(
            this.$data.leida_list_4,
            this.$options.data().leida_list_4
          );

          if (Object.keys(res.data).length == 2) {
            this.jfpl0 = res.data.jfpl0;
            let value_list_0 = res.data.data0;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
          } else if (Object.keys(res.data).length == 4) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
          } else if (Object.keys(res.data).length == 6) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
          } else if (Object.keys(res.data).length == 8) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            let value_list_3 = res.data.data3;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
            for (let i = 1; i < value_list_3.length; i++) {
              that.leida_list_3.push(value_list_3[i].data1);
            }
          } else if (Object.keys(res.data).length == 10) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            this.jfpl4 = res.data.jfpl4;
            for (let i = 1; i < Object.keys(res.data.data0).length; i++) {
              that.leida_list_0.push(res.data.data0[i].data1);
              that.leida_list_1.push(res.data.data1[i].data1);
              that.leida_list_2.push(res.data.data2[i].data1);
              that.leida_list_3.push(res.data.data3[i].data1);
              that.leida_list_4.push(res.data.data4[i].data1);
            }
          }
          if (this.fj.length == 1) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
          } else if (this.fj.length == 2) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
          } else if (this.fj.length == 3) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2);
          } else if (this.fj.length == 4) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3);
          } else if (this.fj.length == 5) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3); 
            this.ECZM.leida_djbhd("fzy5",this.leida_list_4,this.jfpl4); 
          }
          this.ECZM.bar_djbhd("linechar_y",this.fj,this.lineDate);
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 获取日曲线数据
     */
    query_line() {
      let that = this;
      this.API
        .get(
          "compare/compareDayChat?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          let Date = res.data;
          for (let i = 0; i < Date.length; i++) {
            that.lineDate.speed[i] = Date[i].speed;
            that.lineDate.value1[i] = Date[i].value1;
            that.lineDate.value2[i] = Date[i].value2;
            that.lineDate.value3[i] = Date[i].value3;
            that.lineDate.value4[i] = Date[i].value4;
            that.lineDate.value5[i] = Date[i].value5;
          }
          this.query_daycompare();
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
    /**
     * 获取日雷达图数据 表格
     */
    query_daycompare() {
      Object.assign(this.$data.tableData, this.$options.data().tableData);
      this.API
        .get(
          "compare/compareDayList?windturbineid=" +
            this.fj +
            "&date=" +
            this.Date1
        )
        .then((res) => {
          this.tableData = res.data;
        });
      this.API
        .get("compare/fzyDay?windturbineid=" + this.fj + "&date=" + this.Date1)
        .then((res) => {
          let that = this;
          Object.assign(
            this.$data.leida_list_0,
            this.$options.data().leida_list_0
          );
          Object.assign(
            this.$data.leida_list_1,
            this.$options.data().leida_list_1
          );
          Object.assign(
            this.$data.leida_list_2,
            this.$options.data().leida_list_2
          );
          Object.assign(
            this.$data.leida_list_3,
            this.$options.data().leida_list_3
          );
          Object.assign(
            this.$data.leida_list_4,
            this.$options.data().leida_list_4
          );

          if (Object.keys(res.data).length == 2) {
            this.jfpl0 = res.data.jfpl0;
            let value_list_0 = res.data.data0;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
          } else if (Object.keys(res.data).length == 4) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
          } else if (Object.keys(res.data).length == 6) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
          } else if (Object.keys(res.data).length == 8) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            let value_list_0 = res.data.data0;
            let value_list_1 = res.data.data1;
            let value_list_2 = res.data.data2;
            let value_list_3 = res.data.data3;
            for (let i = 1; i < value_list_0.length; i++) {
              that.leida_list_0.push(value_list_0[i].data1);
            }
            for (let i = 1; i < value_list_1.length; i++) {
              that.leida_list_1.push(value_list_1[i].data1);
            }
            for (let i = 1; i < value_list_2.length; i++) {
              that.leida_list_2.push(value_list_2[i].data1);
            }
            for (let i = 1; i < value_list_3.length; i++) {
              that.leida_list_3.push(value_list_3[i].data1);
            }
          } else if (Object.keys(res.data).length == 10) {
            this.jfpl0 = res.data.jfpl0;
            this.jfpl1 = res.data.jfpl1;
            this.jfpl2 = res.data.jfpl2;
            this.jfpl3 = res.data.jfpl3;
            this.jfpl4 = res.data.jfpl4;
            for (let i = 1; i < Object.keys(res.data.data0).length; i++) {
              that.leida_list_0.push(res.data.data0[i].data1);
              that.leida_list_1.push(res.data.data1[i].data1);
              that.leida_list_2.push(res.data.data2[i].data1);
              that.leida_list_3.push(res.data.data3[i].data1);
              that.leida_list_4.push(res.data.data4[i].data1);
            }
          }
          if (this.fj.length == 1) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
          } else if (this.fj.length == 2) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
          } else if (this.fj.length == 3) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2);
          } else if (this.fj.length == 4) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3);
          } else if (this.fj.length == 5) {
            this.ECZM.leida_djbhd("fzy1",this.leida_list_0,this.jfpl0); 
            this.ECZM.leida_djbhd("fzy2",this.leida_list_1,this.jfpl1); 
            this.ECZM.leida_djbhd("fzy3",this.leida_list_2,this.jfpl2); 
            this.ECZM.leida_djbhd("fzy4",this.leida_list_3,this.jfpl3); 
            this.ECZM.leida_djbhd("fzy5",this.leida_list_4,this.jfpl4); 
          }
        this.ECZM.bar_djbhd("linechar",this.fj,this.lineDate);
        }).catch(error =>{
          this.$message.error('获取数据失败');
        });
    },
  },
  mounted() {
    this.ECZM.bar_djbhd("linechar",this.fj,this.lineDate);
    this.query();
    this.query_check();
  },
};
