Ben Lin
2024-07-16 5a4d79d9765dfca8812638b57d5f5fe21f7a06ee
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { buildUUID } from '../../../../utils/uuid';
//import { ApiAction, ApiActionPage } from '../../model/baseModel';
import { genAction, Api } from '../../system';
import { useUserStore } from '/@/store/modules/user';
import { defHttp } from '/@/utils/http/axios';
import { isNullOrEmpty } from '/@/utils/is';
import { formatToDateTime } from '/@/utils/dateUtil';
 
/*
 * 获取锡膏胶水信息
 */
 
export const getToolListByPage = async (params: any) => {
  let order = '';
  if (params.order != undefined) {
    order = params.order == 'descend' ? params.field + ' desc' : params.field;
  }
  let sqlcmd = '1=1';
  if (params?.TOOL_CODE != undefined && params?.TOOL_CODE != '') {
    sqlcmd += " And TOOL_CODE like '%" + params?.TOOL_CODE + "%'";
  }
  if (params?.ALARM_TYPE != undefined) {
    sqlcmd += " And ALARM_TYPE like '%" + params?.ALARM_TYPE + "%'";
  }
  if (params?.MANUFACTURER != undefined && params?.MANUFACTURER != '') {
    sqlcmd += " And MANUFACTURER like '%" + params?.MANUFACTURER + "%'";
  }
  if (params?.TOOL_MODEL != undefined && params?.TOOL_MODEL != '') {
    sqlcmd += " And TOOL_MODEL like '%" + params?.TOOL_MODEL + "%'";
  }
 
  const option = {
    UserId: useUserStore().getUserInfo.userId as string,
    ByOrg: true,
    OrgCode: useUserStore().getUserInfo.orgCode as string,
  };
  if (!isNullOrEmpty(params.page)) {
    const usParams = genAction('V_SMT_TOOL', {
      QueryAble_T: '',
      where: sqlcmd,
      order: order,
      page: {
        pageAble_T: 'string',
        draw: 1,
        pageIndex: params.page,
        pageSize: params.pageSize,
      },
    });
    return getToolListByPageAsync(usParams);
  } else {
    const usParams = genAction('V_SMT_TOOL', {
      QueryAble_T: '',
      where: sqlcmd,
    });
    return getToolListByPageAsync(usParams);
  }
  // const rParams = genActionPage('BIZ_ERP_PROD_IN', sqlcmd, params.page, params.pageSize,option);
  // return getFinishedwarehouseListByPageAsync(rParams);
};
async function getToolListByPageAsync(params: any) {
  const data = await defHttp.post(
    { url: Api.QueryUrl, params },
    {
      isTransformResponse: false,
    },
  );
  let model = {};
  if (isNullOrEmpty(data.Data.page)) {
    model = {
      items: data.Data.Items,
    };
  } else {
    model = {
      items: data.Data.page.data,
      total: data.Data.page.totals,
    };
  }
  return model;
}
//新增工具信息
export const SaveTool = async (params: Recordable, isUpdate: boolean, isbaofei: boolean) => {
  const Toolitem: any = {
    ID: params.ID,
    CREATE_TIME: params?.CREATE_TIME,
    CREATE_USER: params?.CREATE_USER,
    UPDATE_TIME: params?.UPDATE_TIME,
    UPDATE_USER: params?.UPDATE_USER,
    GHOST_ROW: params?.GHOST_ROW,
    AUTH_ORG: params?.AUTH_ORG,
    AUTH_PROD: params?.AUTH_PROD,
    AUTH_WH: params?.AUTH_WH,
    TOOL_CODE: params?.TOOL_CODE,
    TOOL_MODEL: params?.TOOL_MODEL,
    TOOL_SPEC: params?.TOOL_SPEC,
    TYPE: params?.TYPE,
    STATUS: params?.STATUS,
    MANUFACTURER: params?.MANUFACTURER,
    PROD_CODE: params?.PROD_CODE,
    USE_LIMIT: params?.USE_LIMIT,
    MT_ALARM_NO: params?.MT_ALARM_NO,
    SCRAP_ALARM_NO: params?.SCRAP_ALARM_NO,
    TOTAL: params?.TOTAL,
    USE_COUNT: params?.USE_COUNT,
    WH_CODE: params?.WH_CODE,
    REGION_CODE: params?.REGION_CODE,
    SHELF_CODE: params?.SHELF_CODE,
    LOCATION_CODE: params?.LOCATION_CODE,
    LINE_CODE: params?.LINE_CODE,
    REMARK: params?.REMARK,
  };
  let data;
 
  if (isUpdate) {
    if (isbaofei) {
      Toolitem.STATUS = 5;
    }
    const time = new Date();
    Toolitem.UPDATE_TIME = formatToDateTime(time);
    Toolitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    // regionitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    // regionitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('SMT_TOOL', Toolitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    // const usParams = genAction(
    //   'SMT_SOLDER',
    //   "REGION_CODE='" + params.REGION_CODE + "'AND AUTH_ORG='" + regionitem.ORG_CODE + "'",
    // );
    //var check = await isExist(usParams);
    //console.log('check',check)
    //if (!check.Data) {
    Toolitem.ID = buildUUID(); //生成GUID
    Toolitem.UPDATE_TIME = formatToDateTime(new Date());
    Toolitem.CREATE_USER = useUserStore().getUserInfo.userId as string;
    Toolitem.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    // regionitem.ORG_CODE = useUserStore().getUserInfo.orgCode as string;
    // regionitem.AUTH_ORG = useUserStore().getUserInfo.orgCode as string;
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('SMT_TOOL', Toolitem) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
    //} else {
    // return check.Message;
    //return '重复了';
    //}
  }
  return data;
};
//删除
export const DeleteTool = async (Tool_Id: string) => {
  const usParams = genAction('SMT_TOOL', `ID='${Tool_Id}'`);
  return await defHttp.post(
    { url: Api.DeleteWhere, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
//下拉列表
// STATUSs 单据状态
export const optionsListApi = async (params: Recordable) => {
  const usParams = genAction('V_SMT_TOOL+ALARM_TYPEs', '');
  return await defHttp.post(
    { url: Api.urlQueryEnum, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      // apiUrl: globSetting.taskApiUrl
    },
  );
};
//类型
export const optionsListApiType = async (params: Recordable) => {
  const usParams = genAction('V_SMT_TOOL+TYPEs', '');
  return await defHttp.post(
    { url: Api.urlQueryEnum, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      // apiUrl: globSetting.taskApiUrl
    },
  );
};