Ben Lin
2024-11-08 3d2c48733b86a03fc2e5a1f12ac3667ab0863b80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { buildUUID } from '../../../utils/uuid';
import { ApiActionPage } from '../../model/baseModel';
import {
  SupplierInfoListItem,
  SupplierInfoPageParams,
  SupplierInfoPageListGetResultModel,
} from '../model/basModel';
import { genAction, Api, genActionPage, isExist } from '../system';
import { defHttp } from '/@/utils/http/axios';
import { useUserStore } from '../../../store/modules/user';
 
/*
 * 获取储位分页列表
 */
export const getSupplierListByPage = async (params: SupplierInfoPageParams) => {
  let sqlcmd = '';
  if (params?.SUPP_CODE != undefined && params?.SUPP_CODE != '') {
    sqlcmd += "And SUPP_CODE like '%" + params?.SUPP_CODE + "%'";
  }
  if (params?.SUPP_NAME_CN != undefined && params?.SUPP_NAME_CN != '') {
    sqlcmd += "And SUPP_NAME_CN like '%" + params?.SUPP_NAME_CN + "%'";
  }
  const rParams = genActionPage('BAS_SUPPLIER', sqlcmd, params.page, params.pageSize);
  return getSupplierListByPageAsync(rParams);
};
async function getSupplierListByPageAsync(params: ApiActionPage) {
  const data = await defHttp.post<ApiActionPage>(
    { url: Api.EntityPageList, params },
    {
      isTransformResponse: false,
    },
  );
  const model: SupplierInfoPageListGetResultModel = {
    items: data.Data.data,
    total: data.Data.totals,
  };
  return model;
}
//检查
export function isAccountExist(params: string) {
  const usParams = genAction('BAS_SUPPLIER', "SUPP_CODE='" + params + "'");
  return isExist(usParams);
}
//保存
export const SaveRegion = async (params: SupplierInfoListItem, isUpdate: boolean) => {
  let data;
  if (isUpdate) {
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('BAS_SUPPLIER', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    isAccountExist(params.SUPP_CODE);
    params.ID = buildUUID(); //生成GUID
    params.CREATE_USER = useUserStore().getUserInfo.userId;
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('BAS_SUPPLIER', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
};
//删除
export const DeleteSupplier = async (params: Recordable) => {
  const usParams = genAction('BAS_SUPPLIER', [params]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};