import upload from '@/utils/upload'
import request from '@/utils/request'

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

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

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

// 用户头像上传
export function uploadAvatar(data) {
  return upload({
    url: '/system/user/profile/avatar',
    name: data.name,
    filePath: data.filePath
  })
}

// 查询用户列表
export function getUserList() {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: {
      pageNum: 1,
      pageSize: 500
    }
  })
}

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

//获取全部用户
export function listAllUser() {
  return request({
    url: '/system/user/listAll',
    method: 'get',
  })
}

//根据用户ID查询用户信息
export function getUserInfoById(userId) {
  return request({
    url: `/system/user/${userId}`,
    method: 'get',
  })
}

//根据用户ID获取岗位选择框列表
export function getPostListsByUserId(userId) {
  return request({
    url: `/system/user/getPostListsByUserId/${userId}`,
    method: 'get',
  })
}

//获取所有部门和班组下人员
export function getDeptUserTree(params) {
  return request({
    url: '/system/user/deptUserTree',
    method: 'get',
    params: params
  })
}

//根据角色ID查询应用列表
export function getAppListByRoleId(roleId) {
  return request({
    url: `/system/app/roleAppSelect/${roleId}`, 
    method: 'get',
  })
}

//查询移动端全部应用列表
export function getAppList(params) {
  return request({
    url: '/system/app/listBy',
    method: 'get',
    params: params
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/system/user',
    method: 'put',
    data: data
  })
}

//查询所有岗位
export function getPostAllList() {
  return request({
    url: '/system/post/listAllTree',
    method: 'get',
  })
}