import http from "@/utils/http";
import { AppDispatch } from "..";
/**
 * 获取 用户管理 表格列表（存到仓库）
 */
export const C1_APIgetlist = (data: any, falg?: boolean) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("sys/user/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };
      if (falg) {
        dispatch({
          type: "C1/getListAll",
          payload: obj.list.map((v: any) => ({
            value: v.id,
            label: `${v.userName} - ${v.roleName}${
              v.realName ? " - " + v.realName : ""
            }`,
          })),
        });
      } else dispatch({ type: "C1/getList", payload: obj });
    }
  };
};

/**
 * 重置密码
 */
export const C1_APIpassReset = (id: number) => {
  return http.get(`sys/user/resetPass/${id}`);
};

/**
 * 删除用户
 */
export const C1_APIremoves = (id: number) => {
  return http.get(`sys/user/removes/${id}`);
};

/**
 * 新增/编辑
 */
export const C1_APIadd = (data: any) => {
  return http.post("sys/user/save", data);
};

/**
 * 通过id获取详情
 */
export const C1_APIgetInfo = (id: number) => {
  return http.get(`sys/user/detail/${id}`);
};
