import axios from '@/common/services/axios-instance'

class AuditService {
  // 获取审计计划流程实例ID
  getPlanInstId(params) {
    return axios({
      url: 'api/xcoa-mobile/v1/iamauditplan/getPlanInstId',
      method: 'get',
      params: params,
    }).then((res) => {
      return res.data
    })
  }

  // 检查指定年份年度计划是否已经存在
  existYearPlan(id, planYear, orgid, operNum) {
    return axios({
      url:
        `api/xcoa-mobile/v1/iamauditplan/existYearPlan?id=` +
        id +
        `&planYear=` +
        planYear +
        `&auditOrgId=` +
        orgid +
        '&operNum=' +
        operNum,
    })
  }

  // 自动预排
  autoPrequeue(id, unitCode, planYear, unitIdList) {
    return axios({
      url:
        `api/xcoa-mobile/v1/iamauditplan/autoPrequeue?id=` +
        id +
        `&unitCode=` +
        unitCode +
        `&planYear=` +
        planYear +
        `&unitIdList=` +
        unitIdList,
    })
  }

  // 检查表单是否作废
  isWaste(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/checkDept?id=` + id,
    })
  }

  // 删除前校验
  beforeDeleteCheck(ids) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/beforeDeleteCheck?ids=` + ids,
    })
  }

  // 删除计划变更信息
  deleteProjectChange(ids) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditprojectchange/deleteProjectChange?ids=` + ids,
    })
  }

  // 根据已办获取代办
  findTodoId(instId) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-common/query/todo?instId=` + instId,
    })
  }

  // 获取计划年度
  getPlanYear() {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/getPlanYear`,
    })
  }

  // 获取项目信息
  getProjectInfoById(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditproject/getProjectInfoById?id=` + id,
    })
  }

  // 校验项目是否已启动
  checkProjectIsStart(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditproject/checkProjectIsStart?id=` + id,
    })
  }

  // 取消项目
  cancelProject(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditproject/cancelProject?id=` + id,
    })
  }

  // 计划项目变更批量提交
  projectChangeBatchSubmit(params, srcTrustId) {
    const headers = {
      'Content-Type': 'application/json',
    }
    if (srcTrustId) {
      headers['X-RUN-AS'] = srcTrustId
    }
    return axios
      .post(`api/xcoa-mobile/v1/iamauditprojectchange/projectChangeBatchSubmit`, params, {
        headers,
      })
      .then(function(res) {
        return res.data
      })
  }

  // 通过计划年度获取计划信息
  getPlanByPlanYear(planYear) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/getPlanByPlanYear?planYear=` + planYear,
    })
  }

  // 获取审计计划信息
  getAuditPlanById(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/getAuditPlanById?id=` + id,
    })
  }

  // 校验权限
  checkPermission() {
    return axios({
      url: `api/xcoa-mobile/v1/iamauditplan/checkPermission`,
    })
  }

  // 获取用户所在机构
  getCurrentUserGroup() {
    return axios({
      url: `api/xcoa-mobile/v1/iamorg/getCurrentUserGroup`,
      method: 'get',
    }).then((res) => {
      return res
    })
  }

  // 获取用户所在机构
  findIamOrgId(params) {
    return axios({
      url: 'api/xcoa-mobile/v1/iamorg/findIamOrgId',
      method: 'post',
      params,
    })
  }
}

export default new AuditService()
