import { findMyTask } from "@/api/publics";

const flowtask = {
  state: {
    awaitTaskNum: 0
  },

  mutations: {
    SET_AWAIT_TASK: (state, number) => {
      state.awaitTaskNum = number
    }
  },

  actions: {
    // 设置代办任务
    settingAwaitNum({ commit }) {
      return new Promise((resolve, reject) => {
        //查询当前登录人的代办任务数量
        findMyTask({}).then(response => {
          let todos = document.querySelectorAll(".tips_Todo");
          let approves = document.querySelectorAll(".tips_Approve");
          let tasks = document.querySelectorAll(".tips_Task");
          let checkDetections = document.querySelectorAll(".tips_CheckDetection");
          let projectMeasures = document.querySelectorAll(".tips_ProjectMeasure");
          let projectCheckings = document.querySelectorAll(".tips_ProjectChecking");
          let materialSeals = document.querySelectorAll(".tips_MaterialSeal");
          let projectFunVerify = document.querySelectorAll(".tips_ProjectFunVerify");
          let surProjects = document.querySelectorAll(".tips_Project");

          //commit('SET_AWAIT_TASK',response.total)
          if (todos.length > 0) {
            todos.forEach(el => {
              el.innerHTML = response.data.todo;
              if (response.data.todo > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (tasks.length > 0) {
            //let sum = parseInt(response.data.todo)+parseInt(response.data.approve);
            tasks.forEach(el => {
              el.innerHTML = response.data.todo;
              if (response.data.todo > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          // if(approves.length>0){
          //   approves.forEach(el=>{
          //     el.innerHTML=response.data.approve;
          //     if(response.data.approve>0){
          //       el.style.display="inline";
          //     }else{
          //       el.style.display="none";
          //     }
          //   });
          // }
          if (checkDetections.length > 0) {
            checkDetections.forEach(el => {
              el.innerHTML = response.data.approveQYFS;
              if (response.data.approveQYFS > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (projectMeasures.length > 0) {
            projectMeasures.forEach(el => {
              el.innerHTML = response.data.approveSCSL;
              if (response.data.approveSCSL > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (projectCheckings.length > 0) {
            projectCheckings.forEach(el => {
              el.innerHTML = response.data.approveJPYS;
              if (response.data.approveJPYS > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (materialSeals.length > 0) {
            materialSeals.forEach(el => {
              el.innerHTML = response.data.approveCLFY;
              if (response.data.approveCLFY > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (projectFunVerify.length > 0) {
            projectFunVerify.forEach(el => {
              el.innerHTML = response.data.approveGCGN;
              if (response.data.approveGCGN > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (surProjects.length > 0) {
            let sum = parseInt(response.data.approveQYFS) + parseInt(response.data.approveSCSL) + parseInt(response.data.approveJPYS) + parseInt(response.data.approveCLFY) + parseInt(response.data.approveGCGN);
            surProjects.forEach(el => {
              el.innerHTML = sum;
              if (sum > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          let Attendance = document.querySelectorAll(".tips_Attendance");
          if (Attendance.length > 0) {
            Attendance.forEach(el => {
              el.innerHTML = response.data.approveLZYJ;
              if (response.data.approveLZYJ > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          let FlowLabourInfo = document.querySelectorAll(".tips_FlowLabourInfo");
          if (FlowLabourInfo.length > 0) {
            FlowLabourInfo.forEach(el => {
              el.innerHTML = response.data.approveLZYJ;
              if (response.data.approveLZYJ > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          let trouble = document.querySelectorAll(".tips_Trouble");
          let pshProblemmodify = document.querySelectorAll(".tips_PshProblemmodify");
          let sspProblemmodify = document.querySelectorAll(".tips_SspProblemmodify");
          if (trouble.length > 0) {
            let sum = parseInt(response.data.zlCount) + parseInt(response.data.aqCount);
            trouble.forEach(el => {
              el.innerHTML = sum;
              if (sum > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (pshProblemmodify.length > 0) {
            pshProblemmodify.forEach(el => {
              el.innerHTML = response.data.aqCount;
              if (response.data.aqCount > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          if (sspProblemmodify.length > 0) {
            sspProblemmodify.forEach(el => {
              el.innerHTML = response.data.zlCount;
              if (response.data.zlCount > 0) {
                el.style.display = "inline";
              } else {
                el.style.display = "none";
              }
            });
          }
          resolve()
        }).catch(error => {
          reject(error)
        });
      })
    }
  }
}

export default flowtask