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,
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get',
  })
}

// 修改用户个人信息
export function updateUserProfile(data: any) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data,
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword: any, newPassword: any) {
  const data = {
    oldPassword,
    newPassword,
  }
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data,
  })
}

// 用户头像上传
export function uploadAvatar(data: any) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data,
  })
}
