import * as echarts from "echarts";
export default {
  data() {
    return {
      treeData:[],
      tree: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      loading_line:false,
      fj: "",
      uu:[],
      fc: "MHS_FDC",
      Date1: "",
      Date2: "",
      wpIdslist: {
        name: "",
        id: "",
      },
      wtIdslist: {
        name: "",
        id: "",
        key: "",
      },
      activeName: "serial_1",
      contraryName: "contrary_1",
      dialogTableVisible: false,
      dialogTableVisible_2: false,
      dialogTableVisible_3: false,
      dialogTableVisible_sh: false,
      dialogTableVisible_ls:false,
      jdt: 1,
      jdt_2: 5,
      jdt_3: 1,

      Recommend: [],
      Exceedthreeday: [],
      threeday: [],
      Confirmed: [],
      UnfinishedList: [],
      ParticularsList: [],
      ParticularsList_2: [],
      FinishedList: [],
      LocationTree:[],
      braceletList: {
        PLD: [],
        SSXY: [],
        SZXY: [],
        XTPL: [],
        XYND: [],
        TIMES: [],
      },

      braceletList_ls: [],
      braceletList_ss: [],
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      isAsc: "asc",
      currentPage_fy1: 1,
      pagesize_fy1: 6,
      orderByColumn_fy1: "",
      pages01_fy1: 1,

      currentPage_fy2: 1,
      pagesize_fy2: 6,
      orderByColumn_fy2: "",
      pages01_fy2: 1,
    };
  },
  created() {
    this.Date1 = this.BASE.getBzDate(new Date().getTime(),-1);
    this.Date2 = this.BASE.getBzDate(new Date().getTime(),0);
    this.query_wpid();
    this.query();
  },
  methods: {
    query_wpid() {
      this.API.get("powercompare/windfarmAjax?").then((res) => {
        this.wpIdslist = res.data;
      });
    },
    query1() {
      this.fj = "";
      this.query();
    },
    query() {
      let that = this;
      this.API
        .get("powercompare/windturbineAjax?wpId=" + that.fc)
        .then((res) => {
          this.wtIdslist = res.data;
        });
    },
    query_fc() {
      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.FClist = res.data;
      });
    },
    handleClick() {
      if (this.activeName == "serial_1") {
        this.weekfitness();
      } else if (this.activeName == "serial_2") {
        this.$store.commit("loadingStore",true);
        this.weekfitness();
        this.recommenConfirmedList();
      } else if (this.activeName == "serial_3") {
        this.unfinishedList();
      } else if (this.activeName == "serial_4") {
        this.complateList();
      }
    },
    contraryClick() {
      this.Recommend = [];
      this.Exceedthreeday = [];
      this.threeday = [];
      if (this.contraryName == "contrary_1") {
        this.currentRecommend();
      } else if (this.contraryName == "contrary_2") {
        this.threedayRecommend();
      } else if (this.contraryName == "contrary_3") {
        this.exceedthreedayRecommend();
      }
    },
    filter_pd_date(cellValue) {
      let date = new Date(cellValue.recodedate);
      return this.BASE.getBzDate(date,0);
    },
    filter_tj_date(cellValue) {
      let date = new Date(cellValue.createdate);
      return this.BASE.getBzDate(date,0);
    },
    async weekfitness() {
      let _this = this;
      this.loading_line = true;
      var digital = new URLSearchParams();
      digital.append("wpId", "0");
      digital.append("type", 2);
      const {data} = await this.API.post(
        "/recommen/findAllChartjz",
        digital
      );
      if (this.activeName == "serial_1") {
        this.draw_fitnessRegulate(data);
      } else if (this.activeName == "serial_2") {
        this.draw_fitnessRegulate_2(data);
      }
      this.loading_line = false;
      this.$store.commit("loadingStore",false);
    },
    async monthfitness() {
      this.loading_line = true;
      var digital = new URLSearchParams();
      digital.append("wpId", "0");
      digital.append("type", 3);
      const {data} = await this.API.post(
        "/recommen/findAllChartjz",
        digital
      );
      if (this.activeName == "serial_1") {
        this.draw_fitnessRegulate(data);
      } else if (this.activeName == "serial_2") {
        this.draw_fitnessRegulate_2(data);
      }
      this.loading_line = false;
    },
    affirm_all_check() {
      this.$confirm("此操作将无法撤回, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.affirm_all();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    fj_all_list(){
      this.$router.push({path:"/healthList"})
    },
    async affirm_all() {
      var digital = new URLSearchParams();
      if (this.contraryName == "contrary_1") {
        digital.append("typeid", 1);
      } else if (this.contraryName == "contrary_2") {
        digital.append("typeid", 2);
      } else if (this.contraryName == "contrary_3") {
        digital.append("typeid", 3);
      }
      debugger
      const confir = await this.API.post("/recommen/confirpushAll", digital);
      if (confir.data.code == 200 && this.contraryName == "contrary_1") {
        this.Recommend.splice(0);
        this.success_tj();
      } else if (confir.data.code == 200 && this.contraryName == "contrary_2") {
        this.threeday.splice(0);
        this.success_tj();
      } else if (confir.data.code == 200 && this.contraryName == "contrary_3") {
        this.Exceedthreeday.splice(0);
        this.success_tj();
      } else {
        this.fail_tj();
      }
    },
    ignore_all_check() {
      this.$confirm("此操作将无法撤回, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.ignore_all();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async ignore_all() {
      var digital = new URLSearchParams();
      if (this.contraryName == "contrary_1") {
        digital.append("typeid", 1);
      } else if (this.contraryName == "contrary_2") {
        digital.append("typeid", 2);
      } else if (this.contraryName == "contrary_3") {
        digital.append("typeid", 3);
      }

      const confir = await this.API.post("/recommen/ignorepushAll", digital);
      if (confir.data.code == 200 && this.contraryName == "contrary_1") {
        this.Recommend.splice(0);
        this.success_tj();
      } else if (confir.data.code == 200 && this.contraryName == "contrary_2") {
        this.threeday.splice(0);
        this.success_tj();
      } else if (confir.data.code == 200 && this.contraryName == "contrary_3") {
        this.Exceedthreeday.splice(0);
        this.success_tj();
      } else {
        this.fail_tj();
      }
    },
    confirpush_check(rid, key) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.confirpush(rid, key);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
   confirpush(rid, key) {
      let that = this;
      var digital = new URLSearchParams();
      digital.append("rid", rid);
      this.API.post("/recommen/confirpush", digital).then((res) => {
        if (res.code == 200 && this.contraryName == "contrary_1") {
          this.Recommend.splice(key, 1);
          this.success_tj();
        } else if (res.code == 200 && this.contraryName == "contrary_2") {
          this.threeday.splice(key, 1);
          this.success_tj();
        } else if (res.code == 200 && this.contraryName == "contrary_3") {
          this.Exceedthreeday.splice(key, 1);
          this.success_tj();
        } else {
          this.fail_tj();
        }
       });;
      
      
    },
    async ignorepush(rid, key) {
      var digital = new URLSearchParams();
      digital.append("rid", rid);
      await this.API.post("/recommen/ignorepush", digital).then((res)=>{
        if (res.code == 200 && this.contraryName == "contrary_1") {
          this.Recommend.splice(key, 1);
          this.success_tj();
        } else if (res.code == 200 && this.contraryName == "contrary_2") {
          this.threeday.splice(key, 1);
          this.success_tj();
        } else if (res.code == 200 && this.contraryName == "contrary_3") {
          this.Exceedthreeday.splice(key, 1);
          this.success_tj();
        } else {
          this.fail_tj();
        }
      });
    },
    success_tj() {
      this.$message({
        message: "成功！",
        type: "success",
      });
    },
    fail_tj() {
      this.$message.error("失败！");
    },
    fm_data(row, column, cellValue, index){
      return this.Moment(cellValue).format('yyyy-MM-DD hh:mm:ss a');
    },
    async currentRecommend() {
      const currentRecommend = await this.API.post(
        "/recommen/getRecommenmainDay1"
      );
      this.Recommend = currentRecommend.data;
    },
    async threedayRecommend() {
      const currentRecommend = await this.API.post(
        "/recommen/getRecommenmainDay3"
      );
      this.threeday = currentRecommend.data;
    },
    async exceedthreedayRecommend() {
      const currentRecommend = await this.API.post(
        "/recommen/getRecommenmainDay7"
      );
      this.Exceedthreeday = currentRecommend.data;
    },
    async recommenConfirmedList() {
      this.Confirmed = [];
      await this.API.post(
        "/recommen/recommenConfirmedList"
      ).then((res)=>{
        this.Confirmed = res.data;
      });
      
    },
    async unfinishedList() {
      this.UnfinishedList = [];
      var digital = new URLSearchParams();
      digital.append("pageNum", this.currentPage_fy1);
      digital.append("pageSize", this.pagesize_fy1);
      digital.append("orderByColumn", this.orderByColumn_fy1);
      digital.append("isAsc", this.isAsc);
      digital.append("wpId", this.fc);
      digital.append("wtId", this.fj);
      digital.append("beginDate", this.Date1);
      digital.append("endDate", this.Date2);
      const unfinishedList = await this.API.post(
        "/recommen/unfinishedList",
        digital
      )
      this.UnfinishedList = unfinishedList.data;
    },
    async complateList() {
      this.FinishedList = [];
      var digital = new URLSearchParams();
      digital.append("pageNum", this.currentPage_fy1);
      digital.append("pageSize", this.pagesize_fy1);
      digital.append("orderByColumn", this.orderByColumn_fy1);
      digital.append("isAsc", this.isAsc);
      digital.append("wpId", this.fc);
      digital.append("wtId", this.fj);
      digital.append("beginDate", this.Date1);
      digital.append("endDate", this.Date2);
      const FinishedList = await this.API.post(
        "/recommen/finishedList",
        digital
      );
      this.FinishedList = FinishedList.data;
    },
    async Click_xqgz(date) {
      let that = this;
      this.ParticularsList = [];
      var digital = new URLSearchParams();
      digital.append("rid", date.rid);
      const particulars = await this.API.post(
        "/recommen/findMainTrack",
        digital
      );
      this.dialogTableVisible = true;
      this.ParticularsList = particulars.data;
      var jdt = particulars.data.status;
      if (jdt == null) {
        that.jdt = 0;
      } else if (jdt == "开风机工作票" || jdt == "流程未启用") {
        that.jdt = 1;
      }
    },
    async Click_xqgz_ywc(date) {
      let that = this;
      this.ParticularsList_2 = [];
      var digital = new URLSearchParams();
      digital.append("rid", date.rid);
      const particulars = await this.API.post(
        "/recommen/findMainTrack",
        digital
      );
      this.dialogTableVisible_2 = true;
      this.ParticularsList_2 = particulars.data;
      this.jdt_2 = 5;
    },
    async shxx(rname) {
      let that = this;
      this.braceletList.PLD = [];
      this.braceletList.SSXY = [];
      this.braceletList.SZXY = [];
      this.braceletList.XTPL = [];
      this.braceletList.XYND = [];
      this.braceletList.TIMES = [];
      let list_ls = {};
      this.dialogTableVisible_sh = true;
      var digital = new URLSearchParams();
      digital.append("name", rname);
      digital.append("beginDate", "2021-03-14");
      digital.append("endDate", "2021-03-15");
      const particulars = await this.API.post(
        "/recommen/findShbraceletList",
        digital
      );
      this.braceletList_ss = particulars.data.ss;
      list_ls = particulars.data.ls;
      let len = Object.keys(list_ls.PLD).length;
      for (let i = 0; i < len; i++) {
        this.braceletList.PLD[i] = list_ls.PLD[i].pointValue;
        this.braceletList.SSXY[i] = list_ls.SSXY[i].pointValue;
        this.braceletList.SZXY[i] = list_ls.SZXY[i].pointValue;
        this.braceletList.XTPL[i] = list_ls.XTPL[i].pointValue;
        this.braceletList.XYND[i] = list_ls.XYND[i].pointValue;
        this.braceletList.TIMES[i] = this.BASE.getBztime(list_ls.XYND[i].pointTime);
      }
      this.draw_shouhuan();
    },
    async Click_lscx_ywc(rname){
      
      const {wtid} = rname;
      var digital = new URLSearchParams();
      digital.append("wtId", wtid);
      await this.API.post(
        "/recommen/findLocationTreeByWtId",
        digital
      ).then((res)=>{
        this.tree = res.data;
        this.uu.push(res.data[0].id);
      });
      this.dialogTableVisible_ls = true;
    },
    handleNodeClick(data) {
      this.treeData = [];
      const {id} = data;
      var digital1 = new URLSearchParams();
      digital1.append("pageNum", 1);
      digital1.append("pageSize", 10);
      digital1.append("orderByColumn", "");
      digital1.append("isAsc", "asc");
      digital1.append("location", id);
      this.API.post(
        "/recommen/findWobugeqByLocation",
        digital1
      ).then((res)=>{
        this.treeData = res.data;
      });
    },
    ditu(){
      window.location.href = "http://10.155.32.4:8070/gisweb/ditujiankang.html?LAT="+"106.23507"+"&LNG="+"38.48989"+"&userid="+"1500";
    },
    fjkhd(){
      window.location.href = "http://172.22.85.150";
    },
    handleSizeChange_fy1(val) {
      this.pagesize_fy1 = val;
    },
    handleCurrentChange_fy1(val) {
      this.currentPage2_fy1 = val;
    },
    handleSizeChange_fy2(val) {
      this.pagesize_fy2 = val;
    },
    handleCurrentChange_fy2(val) {
      this.currentPage2_fy2 = val;
    },
    draw_fitnessRegulate(weekDateList) {
      let linearBarDom = echarts.getInstanceByDom(
        document.getElementById("fitnessRegulate")
      );
      if (linearBarDom == null) {
        linearBarDom = echarts.init(document.getElementById("fitnessRegulate"));
      }
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        toolbox: {},
        legend: {
          show: false,
          data: ["优", "良", "差", "健康情况"],
        },
        xAxis: [
          {
            type: "category",
            data: weekDateList.datechart,
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "健康趋势",
            min: 98.5,
            max: 100.5,
            axisLabel: {
              formatter: "{value}",
            },
          },
          {
            type: "value",
            name: "故障风机",
            min: 0,
            max: 1000,
            axisLabel: {
              formatter: "{value}",
            },
          },
        ],
        series: [
          {
            name: "优",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.yslchart,
          },
          {
            name: "良",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.lslchart,
          },
          {
            name: "差",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.cslchart,
          },
          {
            name: "健康情况",
            type: "line",
            data: weekDateList.lvchart,
          },
        ],
      };

      linearBarDom.setOption(option);
    },
    draw_fitnessRegulate_2(weekDateList) {
      let linearBarDom = echarts.getInstanceByDom(
        document.getElementById("fitnessRegulate_2")
      );
      if (linearBarDom == null) {
        linearBarDom = echarts.init(
          document.getElementById("fitnessRegulate_2")
        );
      }
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        toolbox: {},
        legend: {
          show: false,
          data: ["优", "良", "差", "健康情况"],
        },
        xAxis: [
          {
            type: "category",
            data: weekDateList.datechart,
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "健康趋势",
            min: 98.5,
            max: 100.5,
            axisLabel: {
              formatter: "{value}",
            },
          },
          {
            type: "value",
            name: "故障风机",
            min: 0,
            max: 1000,
            axisLabel: {
              formatter: "{value}",
            },
          },
        ],
        series: [
          {
            name: "优",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.yslchart,
          },
          {
            name: "良",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.lslchart,
          },
          {
            name: "差",
            type: "bar",
            stack: "total",
            yAxisIndex: 1,
            data: weekDateList.cslchart,
          },
          {
            name: "健康情况",
            type: "line",
            data: weekDateList.lvchart,
          },
        ],
      };

      linearBarDom.setOption(option);
    },
    draw_shouhuan() {
      let shouhuan = echarts.getInstanceByDom(
        document.getElementById("shxq")
      );
      if (shouhuan == null) {
        shouhuan = echarts.init(document.getElementById("shxq"));
      }
      var option;
      option = {
        title: {
          text: "工作期间检测值",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["疲劳度", "收缩血压", "舒张血压", "心跳频率", "血氧"],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: this.braceletList.TIMES,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "疲劳度",
            type: "line",
            stack: "总量",
            data: this.braceletList.PLD,
          },
          {
            name: "收缩血压",
            type: "line",
            stack: "总量",
            data: this.braceletList.SSXY,
          },
          {
            name: "舒张血压",
            type: "line",
            stack: "总量",
            data: this.braceletList.SZXY,
          },
          {
            name: "心跳频率",
            type: "line",
            stack: "总量",
            data: this.braceletList.XTPL,
          },
          {
            name: "血氧",
            type: "line",
            stack: "总量",
            data: this.braceletList.XYND,
          },
        ],
      };
      shouhuan.setOption(option);
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
  mounted() {
    this.$store.commit("loadingStore",true);
    this.weekfitness();
    this.currentRecommend();
  },
};