import { request, upload } from "@/utils/request.js";
import { getDeptId } from "@/utils/auth";

export const getAllDataDictList = () =>
  request({
    url: "/system/dict-data/simple-list",
    method: "GET",
  });

export const getAllDeptList = (name) =>
  request({
    url: "/system/dept/simple-list",
    method: "GET",
    params: {
      name,
    },
  });

export const getAllDeviceList = (deptId) =>
  request({
    url: "/rq/iot-device/simple-list",
    method: "GET",
    params: {
      deptId,
    },
  });

/**
 * 获取工厂、成本中心、库存地点列表
 * @param type 1-工厂 2-成本中心 3-库存地点
 */
export const getAllCostCenterOrFactoryOrStorageLocationList = (type) =>
  request({
    url: "/system/sap-org/simple-list",
    method: "GET",
    params: {
      type,
    },
  });
/**
 * 获取工厂、成本中心列表 - 新
 * @param type 1-工厂 2-成本中心
 */
export const filteredSimpleSapOrgList = (type) =>
  request({
    url: "/system/sap-org/filteredSimpleSapOrgList",
    method: "GET",
    params: {
      type,
      deptId: getDeptId(), // 获取当前部门ID
    },
  });

/**
 * 供应商分页数据
 * @param params 筛选参数
 */
export const getSupplierList = (params) =>
  request({
    url: "/supplier/base/page",
    method: "GET",
    params,
  });

/**
 * 获取字典分页数据
 * @param params
 */
export const getDataDictList = (params) =>
  request({
    url: "/system/dict-data/page",
    method: "GET",
    params,
  });

/**
 * 上传文件
 * @param filePath
 */
export const uploadFile = (filePath) =>
  upload("/infra/file/upload/path", {
    // #ifdef MP-ALIPAY
    fileType: "image/video/audio", // 仅支付宝小程序，且必填。
    // #endif
    filePath: filePath, // 要上传文件资源的路径。
    name: "file", // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
  });

/**
 * 获取用户列表
 * @param userId
 */
export const getUserList = (userId) =>
  request({
    url: "/system/user/dept/users",
    method: "GET",
    params: {
      userId,
    },
  });

export const selectedDeptsEmployee = (params) =>
  request({
    url: "/system/user/selectedDeptsEmployee",
    method: "GET",
    params,
  });

export const getDept = (deptId) =>
  request({
    url: "/system/dept/get?id=" + deptId,
    method: "GET",
  });

// 获取用户信息
export const getUserInfo = (params) =>
  request({
    url: "/system/user/get",
    method: "GET",
    params,
  });

// 获取用户部门信息
export const getUserDeptInfo = (params) =>
  request({
    url: "/system/dept/get",
    method: "GET",
    params,
  });

/**
 * 获取部门下用户列表
 * @param deptId
 */
export const getUserListByDeptId = (deptId) =>
  request({
    url: "/system/user/simpleUserList",
    method: "GET",
    params: { deptId },
  });

export const specifiedSimpleDepts = (deptId) =>
  request({
    url: "/system/dept/specifiedSimpleDepts",
    method: "GET",
    params: { deptId },
  });
