import { get, post, put, del } from "@/utils/requestMethod";

/**
 * 获取用户列表
 * @param {*} status 账户状态0为正常，1为禁用
 * @param {*} page
 * @param {*} page_size
 * @name 对user_name进行模糊查询
 * @returns
 */
const getUserList = (
    status,
    page,
    page_size = 20,
    name=""
) => {
    return get(
        `/users/user_list?status=${status}&page=${page}&page_size=${page_size}&name=${name}`
    );
}
//添加用户
const addUser = (options) => {
    let params = new FormData();
    options.username !== '' && params.append('username', options.username);
    options.password !== '' && params.append('password', options.password);
    params.append('photograph', options.photograph);
    params.append('name', options.name);
    params.append('phone', options.phone);
    params.append('email', options.email);
    params.append('role', options.role);
    params.append('permission', options.permission);
    params.append('company', options.corporation);
    params.append('department', options.department);
    params.append('on_job_status', options.working_status);
    params.append('duty', options.post);
    params.append('nationality', options.nationality);
    return post(`/users/user`, params);
}
//获取用户详情
const getUserDetail = (
    id
) => {
    return get(`/users/user?id=${id}`);
}
//导出用户数据
const exportUserData = () => {
    return get(`/users/export_data`);
}
//删除用户
const deleteSingleUser = (options) => {
    let params = new FormData();
    params.append('id', options.id);
    params.append('username', options.username);
    params.append('password', options.password);
    return del(`/users/user`, params);
}
//批量删除用户
const delUserByBatched = () => {
    return del(`/users/batch_delete_user`);
}
//更新用户详情
const updateUserDetail = (options) => {
    let params = new FormData();
    options.username !== '' && params.append('username', options.username);
    options.password !== '' && params.append('password', options.password);
    params.append('photograph', options.photograph);
    params.append('name', options.name);
    params.append('phone', options.phone);
    params.append('email', options.email);
    params.append('role', options.role);
    params.append('permission', options.permission);
    params.append('company', options.corporation);
    params.append('department', options.department);
    params.append('on_job_status', options.working_status);
    params.append('duty', options.psot);
    params.append('nationality', options.nationality);
    return put(`/users/user`, params);
}
//修改用户状态等
const alterUserStatus = () => {
    return put(`/users/user_status`);
}
//批量修改用户状态等
const alterUserStatusByBatched = () => {
    return put(`/users/batch_modify_user_status`);
}
export {
    getUserList,
    addUser,
    getUserDetail,
    exportUserData,
    deleteSingleUser,
    delUserByBatched,
    updateUserDetail,
    alterUserStatus,
    alterUserStatusByBatched
}