import request from '@/utils/request'
import { parseStrEmpty } from "@/utils/ruoyi";
import axios from '@/utils/request'
// 查询用户列表
export const listUser = (arg) => {
  if (arg.params) {
    arg.params = {
      'beginTime': arg.params[0],
      'endTime': arg.params[1]
    }
  }
  console.log(arg);
  return axios.request({
    url: '/system/user/list',
    method: 'get',
    params: arg
  })
}

// 查询用户详细
export const getUser = (arg) => {
  return axios.request({
    url: '/system/user/getInfo',
    params: arg,
    method: 'get'
  })
}

// 新增用户
export const addUser = (arg) => {
  return axios.request({
    url: '/system/user/add',
    method: 'post',
    data: arg
  })
}

// 修改用户
export const updateUser = (arg) => {
  return axios.request({
    url: '/system/user',
    method: 'put',
    data: arg
  })
}
// 删除用户
export const delUser = (arg) => {
  return axios.request({
    url: '/system/user/remove',
    method: 'delete',
    params: {userIds: arg.userIds.join(',')},
    dataType: 'json'
  })
}

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

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

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

// 修改用户个人信息
export const updateUserProfile = (arg) => {
  return axios.request({
    url: '/system/user/profile',
    method: 'put',
    data: arg
  })
}

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

// 用户头像上传
export const uploadAvatar = (arg) => {
  return axios.request({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: arg
  })
}

// 查询授权角色
export const getAuthRole = (arg) => {
  return axios.request({
    url: '/system/user/authRole/' + arg,
    method: 'get'
  })
}

// 保存授权角色
export const updateAuthRole = (arg) => {
  return axios.request({
    url: '/system/user/authRole',
    method: 'put',
    params: arg
  })
}

// 查询部门下拉树结构
export const deptTreeSelect = () => {
  return axios.request({
    url: '/system/user/deptTree',
    method: 'get'
  })
}
