/*
 * @Author: your name
 * @Date: 2022-01-12 09:55:49
 * @LastEditTime: 2024-07-11 18:13:46
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/service/user.ts
 */

import { request } from 'umi';

//获取用户列表

export type getUsersParams = {
  current: number;
  pageSize: number;
  keyword?: string;
  departmentId?: string;
};

type paginationDefaultType = {
  current: number;
  pageSize: number;
  totalCount: number;
  totalPage: number;
};

export const getUsers = async (params: getUsersParams) => {
  return request<
    {
      list: any[];
    } & paginationDefaultType
  >('/centerSys/user/list', {
    method: 'GET',
    params: { ...params },
  });
};

export type AddUsersDataType = {
  hospId: number;
  name: string;
  account: number;
  phoneNum?: number;
  idCardNum?: number;
  isOnService?: number; //是否在职0.默认，1.离职
};
export const addUsers = async (data: AddUsersDataType) => {
  return request('/centerSys/user/addUser', {
    method: 'POST',
    data: data,
  });
};

export type EditUsersDataType = {
  id: number;
  hospId?: number;
  name?: string;
  account?: number;
  password?: string;
  phoneNum?: number;
  idCardNum?: number;
  isOnService?: number; //是否在职0.默认，1.离职
};
export const editUsers = async (data: EditUsersDataType) => {
  return request('/centerSys/user/editUser', {
    method: 'POST',
    data: data,
  });
};

export const delUsers = async (data: number[]) => {
  return request('/centerSys/user/removeUser', {
    method: 'POST',
    data: data,
  });
};

//修改用户密码
export const editUsersPsd = async (params: { id: number; password: string }) => {
  return request('/centerSys/user/updatePassword', {
    method: 'POST',
    params: params,
  });
};

//获取用户模板
export const getUsertemplate = async () => {
  return request<string>('/centerSys/user/exportUserTemplate', {
    method: 'GET',
  });
};

//导入用户
export const importUserData = async (formData: any) => {
  return request('/centerSys/user/importUserInfo', {
    method: 'POST',
    data: formData,
  });
};

//重置用户密码
export const resetUserPwd = async (data: { userId: number }) => {
  return request('/centerSys/user/resetPwd', {
    method: 'POST',
    data: data,
  });
};

//上传头像
export const uploadAvatar = async (data:any) => {
  return request('/centerSys/user/uploadAvatar', {
    method: 'POST',
    data: data,
  });
};

//获取有数用户列表
export type GetYoushuUsersRepType = {
  id: number;
  name: string;
  // account: string;
  // password: string;
  // isDefault: number;
};

export const getYoushuUsers = async () => {
  return request<GetYoushuUsersRepType[]>('/centerSys/role/getYoushuUsersByHospId', {
    method: 'GET',
  });
};

//获取用户相关的字典表

export type UserRelaSeletDataListType = {
  name: any;
  code: string;
  value: string;
  sort: number;
  defaultValue: number;
};
export interface UserRelaSeletDataType {
  code: string;
  dataVoList: UserRelaSeletDataListType[];
  value: string;
}

export const getUserRelaSeletData = async (key?: string) => {
  return request<UserRelaSeletDataType[]>('/centerSys/sysdictdata/getDictData', {
    method: 'GET',
    params: { dictType: key },
  });
};

//刷新token

export const updateTokenReq = async (data: any) => {
  return request('/oauth2/refreshToken', {
    method: 'POST',
    data,
  });
};
