import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UserForm, UserInfo, UserPageResult, UserQuery } from './types';
//获取企业树 数据
export function getTreelist(queryParams:any) {
  return request({
    url: '/system/organization/getOrgTree',
    method: 'POST',
    params: queryParams
  });
}
//获取用户列表信息
export function gettableData(queryParams:any) {
  return request({
    url: '/system/user/queryUsers',
    method: 'get',
    params: queryParams
  });
}
//用户-禁用，启用
export function DataStatus (queryParams:any) {
  return request({
    url: '/system/user/setStatus',
    method: 'POST',
    params: queryParams
  });
}
//删除用户
export function deltableData (queryParams:any) {
  return request({
    url: '/system/user/deleteById',
    method: 'POST',
    params: queryParams
  });
}
//批量删除
export function delChoise (queryParams:any) {
  return request({
    url: '/system/user/deleteUserByIds',
    method: 'POST',
    params: queryParams
  });
}
//获取角色
export function getRole (queryParams:any) {
  return request({
    url: '/system/role/list',
    method: 'POST',
    params: queryParams
  });
}
//新建用户
export function addUsers (queryParams:any,roleids:any) {
  return request({
    url: '/system/user/addUser?'+'roleids='+roleids,
    method: 'POST',
    data: queryParams,
  });
}
//更改用户
export function updataUser (queryParams:any,roleids:any) {
  return request({
    url: '/system/user/updateUser?'+'roleids='+roleids,
    method: 'POST',
    data: queryParams,
  });
}
//更改用户
export function updatePersonalInfo (queryParams:any) {
  return request({
    url: '/user/updatePersonalInfo',
    method: 'POST',
    data: queryParams,
  });
}
//更改头像
export function updateAvatar (data:any) {
  return request({
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    url: '/system/user/updateAvatar',
    method: 'POST',
    data
  });
}


//重置密码
export function setpass (queryParams:any) {
  return request({
    url: '/system/user/resetPassword',
    method: 'POST',
    params: queryParams,
  });
}

export function updatePassword (queryParams:any) {
  return request({
    url: '/user/updatePassword',
    method: 'GET',
    params: queryParams,
  });
}

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfo(): AxiosPromise<UserInfo> {
  return request({
    url: '/user/me',
    method: 'get'
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function listUserPages(
  queryParams: UserQuery
): AxiosPromise<UserPageResult> {
  return request({
    url: '/api/v1/users/pages',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: number): AxiosPromise<UserForm> {
  return request({
    url: '/api/v1/users/' + userId + '/form',
    method: 'get'
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: '/api/v1/users',
    method: 'post',
    data: data
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(id: number, data: UserForm) {
  return request({
    url: '/api/v1/users/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 修改用户状态
 *
 * @param id
 * @param status
 */
export function updateUserStatus(id: number, status: number) {
  return request({
    url: '/api/v1/users/' + id + '/status',
    method: 'patch',
    params: { status: status }
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: number, password: string) {
  return request({
    url: '/api/v1/users/' + id + '/password',
    method: 'patch',
    params: { password: password }
  });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string) {
  return request({
    url: '/api/v1/users/' + ids,
    method: 'delete'
  });
}

/**
 * 下载用户导入模板
 *
 * @returns
 */
export function downloadTemplate() {
  return request({
    url: '/api/v1/users/template',
    method: 'get',
    responseType: 'arraybuffer'
  });
}

/**
 * 导出用户
 *
 * @param queryParams
 * @returns
 */
export function exportUser(queryParams: UserQuery) {
  return request({
    url: '/api/v1/users/_export',
    method: 'get',
    params: queryParams,
    responseType: 'arraybuffer'
  });
}


//查询用户权限信息
export function queryUserRole (queryParams:any) {
  return request({
    url: '/system/user/queryUserRole',
    method: 'GET',
    params: queryParams,
  });
}
