import { GenericApi, DwLayout, FileApi, Basicinfo, Mattress } from "@/api/interface/index";
import { PORT1, PORT_DL } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 获取 通用接口：查询
 * @param params 请求参数
 * @param dwname 布局名称
 */
export const CommonDynamicSelect = (params: GenericApi.ReqCommonDynamicSelect, dwname?: string) => {
  return http.postCommonDynamic<GenericApi.ResCommonDynamicSelect>(PORT1 + `/CommonDynamicSelect`, params, dwname);
};

/**
 * @name 数据交互 通用调用uo
 */
export const CommonBill = (params: GenericApi.CommonClass) => {
  return http.postCommonBill<GenericApi.ResCommonBill>(PORT1 + `/CommonBill`, params);
};

/**
 * @name 获取 用户布局习惯
 */
export const GetDwLyoutApi = (params: DwLayout.ReqGetDwLayout) => {
  return http.post<DwLayout.ResGetDwLayout>(PORT1 + `/GetSysUserFileString`, params);
};

/**
 * @name 提交 用户布局习惯
 */
export const SetDwLyoutApi = (params: DwLayout.ReqSetDwLayout) => {
  return http.post(PORT1 + `/SetSysUserFileString`, params);
};

/**
 * @name 获取 文件分类
 */
export const GetFileClass = (params: FileApi.ReqFileClass) => {
  return http.post<FileApi.ResFileClass>(PORT1 + `/GetFileClass`, params);
};

/**
 * @name 获取 附件数据
 */
export const GetFjFile = (params: FileApi.ReqFileData) => {
  return http.post<FileApi.ResFileData>(PORT1 + `/GetFjFile`, params);
};

/**
 * @name 获取 md5转换附件
 */
export const GetCacheFile = (params: FileApi.ReqCacheFile) => {
  return http.post<FileApi.ResCacheFile>(PORT1 + `/GetCacheFile`, params);
};

/**
 * @name 下载 md5转换附件
 */
export const DownloadCacheFile = (params: FileApi.ReqCacheFile) => {
  return http.get<FileApi.ResCacheFile>(PORT_DL + `/GetCacheFile`, params, { responseType: "blob" });
};

/**
 * @name 上传 附件
 */
export const UploadFile = (params: FileApi.ReqUploadFile) => {
  return http.post(PORT1 + `/UploadL1File`, params);
};

export const GetFormulaCompute = (params: GenericApi.ReqFormulaCompute) => {
  return http.post<GenericApi.ResFormulaCompute>(PORT1 + `/GetFormulaCompute`, params);
};

export const GetERPMtrldefList = (params?: GenericApi.ReqGetERPMtrldefList) => {
  return http.post<GenericApi.ResGetERPMtrldefList>(PORT1 + `/GetERPMtrldefList`, params);
};

export const GetERPConfigureList = (params?: GenericApi.ReqGetERPConfigureList) => {
  return http.post<GenericApi.ResGetERPConfigureList>(PORT1 + `/GetERPConfigureList`, params);
};

export const GetERPWrkGrpList = (params?: GenericApi.ReqGetERPWrkGrpList) => {
  return http.post<GenericApi.ResGetERPWrkGrpList>(PORT1 + `/GetERPWrkGrpList`, params);
};

export const GetERPWrkGrpList2 = () => {
  let newParams: any = {};
  newParams.dsname = "_Mapper_wrkgrpcode2";
  newParams.queryparams = {};
  newParams.pageindex = 0;
  newParams.pagesize = 0;
  return CommonDynamicSelect(newParams);
};

export const GetERPMtrlTypeList = () => {
  return http.post<Basicinfo.ResGetMtrlTypeList>(PORT1 + `/GetERPMtrlTypeList`);
};

/**
 * @description 生成L1物料
 * @param params
 * @returns
 */
export const CreatMtrlPf = (params?: Mattress.ReqMultiMattressBcp) => {
  return http.post<Mattress.ResSaveMattressBcp>(PORT1 + `/CreatMtrldef`, params);
};
/**
 * @description 生成L1清单
 * @param params
 * @returns
 */
export const CreatPrdPf = (params?: Mattress.ReqMultiMattressBcp) => {
  return http.post(PORT1 + `/CreatPrdPf`, params);
};

/**
 * @description 删除L1清单
 * @param params
 * @returns
 */
export const DelMtrlPf = (params?: Mattress.ReqMultiMattressBcp) => {
  return http.post(PORT1 + `/DelMtrlPf`, params);
};
/**
 * @description 获取ERP物料资料价格定义
 * @param params
 * @returns
 */
export const GetERPMtrlPriceList = (params?: GenericApi.ReqGetERPMtrldefList) => {
  return http.post<GenericApi.ResGetERPMtrldefList>(PORT1 + `/GetErpMtrlPriceList`, params);
};
/**
 * @description 加锁单据
 * @param params
 * @returns
 */
export const LockBill = (params?: GenericApi.ReqLockBill) => {
  return http.post(PORT1 + `/LockTable`, params);
};
/**
 * @description 解锁单据
 * @param params
 * @returns
 */
export const UnLockBill = (params?: GenericApi.ReqLockBill) => {
  return http.post(PORT1 + `/UnLockTable`, params);
};
