import { parseStrEmpty } from '/@/utils/index'
import request from '/@/utils/request'

export function getList(params?: any) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params,
  })
}

export const doAdd = (data: any) => {
  return request({
    url: '/system/user',
    method: 'post',
    data,
  })
}

export const doEdit = (data: any) => {
  return request({
    url: '/system/user',
    method: 'put',
    data,
  })
}

export const doDelete = (userId: any) => {
  return request({
    url: `/system/user/${userId}`,
    method: 'delete',
  })
}

// 查询用户详细
export function getUser(userId: any) {
  return request({
    url: `/system/user/${parseStrEmpty(userId)}`,
    method: 'get',
  })
}

// 用户状态修改
export function changeUserStatus(userId: any, status: any) {
  const data = {
    userId,
    status,
  }
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data,
  })
}

// 用户密码重置
export function resetUserPwd(userId: any, password: any) {
  const data = {
    userId,
    password,
  }
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data,
  })
}

// 查询授权角色
export function getAuthRole(userId: any) {
  return request({
    url: `/system/user/authRole/${userId}`,
    method: 'get',
  })
}

// 保存授权角色
export function updateAuthRole(data: any) {
  return request({
    url: '/system/user/authRole',
    method: 'put',
    params: data,
  })
}
