import request from '../utils/request'

export function toLogin(params) {
  const { username, password,device,version,versions } = params
  return new Promise((resolve, reject) => {
    request.post("/Token/Gen", params, false).then((result)=>{
      const { access_token, refreshToken, orgId, Tenant,userid ,userName} = result
      uni.setStorageSync('accessToken', access_token)
      uni.setStorageSync('refreshToken', refreshToken)
      uni.setStorageSync('orgId', orgId)
      uni.setStorageSync('Tenant', Tenant)
	   uni.setStorageSync('Userid', userid)
	    uni.setStorageSync('Username', userName)
      request.post('/PF/Login/Login', {
        Parameter1: username,
        Parameter2: password,
        Parameter3: '2',
        Parameter4: orgId,
        Parameter7: true,
		Parameter20:version,
		Parameter21:device,
      }).then((res) => {
        if (res.IsSuccessful) {
          uni.setStorageSync('appInfo', res.Data)
          uni.switchTab({
            url: '/pages/index/index2'
          })
        }
      })
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getOrgList(params) {
  return new Promise((resolve, reject) => {
    request.post("/OP/TenantInfo/GetOrgList", params).then((result)=>{
      console.log('org list app', result)
      if (result.IsSuccessful) {
        resolve(result);//.Data
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getTodoData(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/FMNotificationTask/HomeOrderPaged", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function searchSame(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BITask/searchSamePost", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function userToDo(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BITask/userToDo", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}


export function handleTaskStatus(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/FMNotificationTask/ChangeStatus", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

///wyw 首页待办 获取 审批信息
export function FullGet(params) {
  return new Promise((resolve, reject) => {
    request.post("/PF/PFApprove/FullGet", params).then((result)=>{
      console.log('result', result)
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}


export function GetApproveInfo(params) {
  return new Promise((resolve, reject) => {
    request.post("/PF/Approve/GetApproveInfo", params).then((result)=>{
      console.log('result', result)
      if (result.IsSuccessful) {
        resolve(result.Data);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getDepartmentLists(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/Department/OrderPaged", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function saveSnapShot(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/FMSnapshot/FullUpdate", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getTasksUpdate(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/FMNotificationTask/UserNotificationCount", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getChartData(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BIStatiscialAnalysisController/GetPersonAnalyze", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function getStandardScore(params) {
  return new Promise((resolve, reject) => {
    request.post("/PE/PESafetyEvaluationRecord/HomeGet", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function getRiskLevel(params) {
  return new Promise((resolve, reject) => {
    request.post("/FM/RiskLevelProportion/OrderPaged", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function getClassActive(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BIStatiscialAnalysisController/GetDepartmentCompletionSort", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function getWorkTicket(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BIStatiscialAnalysisController/GetJobCompletionSort", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}
export function getDangerTotal(params) {
  return new Promise((resolve, reject) => {
    request.post("/BI/BIHome/GetHomeInfo", params, true, false).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

export function getTrainHours(params) {
  return new Promise((resolve, reject) => {
    request.post("/SE/SETrainRecord/GetTrainHours", params).then((result)=>{
      if (result.IsSuccessful) {
        resolve(result);
      }
    }).catch((error)=>{
      reject(error);
    })
  })
}

// get请求
// export function getBannerList(params) {
//   return new Promise((resolve, reject)=>{
//     request.get("/banner/getList", params).then((result)=>{
//       resolve(result)
//     }).catch(err=>{
//       reject(err)
//     });
//   });
// }

// post请求
// export function addBanner(params) {
//   return new Promise((resolve, reject) => {
//     request.post("/banner/add", params).then((result)=>{
//       resolve(result);
//     }).catch((error)=>{
//       reject(error);
//     });
//   });
// }

