import http from '@/api'
import { parseStrEmpty } from '@/utils/common'

/**
 * @name 查询用户列表
 * @param query 参数
 * @returns 返回列表
 */
export const listUserApi = (query: any) => {
  return http.get<any>('/system/user/list', query, { loading: true })
}

/**
 * @name 查询用户详细
 * @param userId userId
 * @returns returns
 */
export const getUserApi = (userId?: string) => {
  return http.get<any>(`/system/user/` + parseStrEmpty(userId))
}

/**
 * @name 查询部门下拉树结构
 * @returns returns
 */
export const deptTreeSelectApi = () => {
  return http.get<any>(`/system/user/deptTree`)
}

/**
 * @name 新增用户
 * @returns returns
 */
export const addUserApi = (data: any) => {
  return http.post<any>('/system/user', data, { loading: false })
}

/**
 * @name 修改用户
 * @returns returns
 */
export const updateUserApi = (data: any) => {
  return http.put<any>('/system/user', data, { loading: false })
}

/**
 * @name 删除用户
 * @returns returns
 */
export const delUserApi = (userId: any) => {
  return http.delete<any>(`/system/user/${userId}`)
}

/**
 * @name 用户状态修改
 * @param userId userId
 * @param status status
 * @returns returns
 */
export const changeUserStatus = (data: any) => {
  return http.put<any>('/system/user/changeStatus', data, { loading: false })
}

/**
 * @name 用户密码重置
 * @param data data
 * @returns returns
 */
export const resetUserPwdApi = (data: any) => {
  return http.put<any>('/system/user/resetPwd', data, { loading: false })
}

/**
 * @name 下载模板
 * @returns returns
 */
export const importTemplateApi = () => {
  return http.downloadPost('/system/user/importTemplate', {})
}

/**
 * @name 导入数据
 * @returns returns
 */
export const importDataApi = (params: FormData) => {
  return http.post('/system/user/importData', params)
}

/**
 * @name 导出数据
 * @returns returns
 */
export const exportApi = (data: any) => {
  return http.downloadPost('/system/user/export', data)
}
