import axios from '@/libs/api.request'

export const getPage = (parmas) => {
  return axios.request({
    url: 'api/v1/rbac/user',
    params: parmas,
    method: 'get',
  })
}

export const editUser = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user',
        method: 'PATCH',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const removeUser = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user/delete/' + id,
        method: 'POST',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const addUser = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const checkLoginName = (loginName) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user/checkLoginName/' + loginName,
        method: 'GET',
        //data: {loginName:loginName},
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const doLockUser = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user/lock/' + id,
        method: 'PATCH',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const doUnLockUser = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/rbac/user/unlock/' + id,
        method: 'PATCH',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const uploadImg = (formData) => {
  return axios.request({
    url: 'api/v1/image/upload',
    data: formData,
  })
}

export const getAllUserByOrgId = (orgId) => {
  return axios.request({
    url: 'cas/api/v1/rbac/user/byOrgId/' + orgId,
    method: 'get',
  })
}

export const getAllUserTreeOrg = () => {
  return axios.request({
    url: 'api/v1/rbac/user/getAllUserTree/org',
    method: 'get',
  })
}

export const getTreeSelectData = () => {
  return axios.request({
    url: 'api/v1/get_tree_select_data',
    method: 'get',
  })
}

export const bindArea = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/basic/userBinding/bindArea',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const bindCompany = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/basic/userBinding/bindCompany',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const removeUserBinding = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/basic/userBinding/unbind/' + id,
        method: 'POST',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
