order.ts
11.6 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
import axios from 'axios';
import { defHttp } from '/@/utils/http/axios';
import { useUserStoreWithOut } from '/@/store/modules/user';
import { useOrderStoreWithOut } from '/@/store/modules/order';
import { formatToDate } from '/@/utils/dateUtil';
import message from '/@/views/form-design/utils/message';
import { formatToDateTime } from '../../utils/dateUtil';
enum Api {
ORDER_CREATE = '/order/erp/order/add',
UPDATE = '/order/erp/order/edit',
ORDER = '/order/erp/order/list_by_page',
ORDER_DELETE = '/order/erp/order/delete_by_id',
FIELD_AUTH = '/order/erp/order/field_unlock_apply',
QUERY_PROJECT_NO_AND_INNER_NO = '/order/erp/order/queryProjectNoAndInnerNo', //查询项目号和内部编号
EXPORT = '/order/erp/order/export',
UPLOAD = '/api/localStorage/uploadOss',
UPLOAD_FILE = '/api/localStorage/upload_file_oss', //上传文件
PROFIT_RATE = '/order/erp/profit/calculate', // 编辑订单实时获取利润率
DICT_INIT = '/order/erp/dictionary/get_all',
DICT_ADD = '/order/erp/dictionary/add',
DICT_UPDATE = '/order/erp/dictionary/edit',
DICT_DELETE = '/order/erp/dictionary/delete',
DICT_LIST = '/order/erp/dictionary/list_by_page',
ANALYSIS = '/order/erp/profit/analysis',
GRAVITY = '/order/erp/report/analysis',
OPT_LOG = '/order/erp/opt/log/list_by_page', // 操作日志
AUDIT_LOG = '/order/erp/audit/log/list_by_page', //审批日志
ORDER_RATE_EXPORT = '/order/erp/report/export', // 所有设计师比重导出
ORDER_FIELD_CHECK = '/order/erp/order/check', // 校验内部编号是否重复
TRACK_HISTORY = '/order/erp/opinion/log/query_by_id', //跟单结果记录
PASS_CALCULATE = '/order/erp/order/passRate', //一次性通过率
CREATE_PRODUCT_TEXT = '/order/erp/order/produceReport', //生成生产指示书
EXPORT_PRODUCT_TEXT = '/order/erp/order/send', //导出生产指示书
BUSINESS_PROFIT_RATIO = '/order/erp/calculate_profit/business_profit_ratio', //业务/研发净利润分析
BUSINESS_PROFIT_RATIO_EXPORT = '/order/erp/calculate_profit/business_profit_ratio_export', //业务/研发净利润分析_导出
INNER_PROFIT_RATIO = '/order/erp/calculate_profit/inner_profit_ratio', //内部生产净利润分析表
INNER_PROFIT_RATIO_EXPORT = '/order/erp/calculate_profit/inner_profit_ratio_export', //内部生产净利润分析表_导出
}
export const formatSearchData = (params) => {
params.createStartTime = params.createStartTime
? formatToDate(params.createStartTime)
: undefined;
params.createEndTime = params.createEndTime ? formatToDate(params.createEndTime) : undefined;
params.productionDepartmentConsignStartTime = params.productionDepartmentConsignStartTime
? formatToDate(params.productionDepartmentConsignStartTime)
: undefined;
params.productionDepartmentConsignEndTime = params.productionDepartmentConsignEndTime
? formatToDate(params.productionDepartmentConsignEndTime)
: undefined;
params.orderHodStartTime = params.orderHodStartTime
? formatToDate(params.orderHodStartTime)
: undefined;
params.orderHodEndTime = params.orderHodEndTime
? formatToDate(params.orderHodEndTime)
: undefined;
params.selfTestPassStartTime = params.selfTestPassStartTime
? formatToDate(params.selfTestPassStartTime)
: undefined;
params.selfTestPassEndTime = params.selfTestPassEndTime
? formatToDate(params.selfTestPassEndTime)
: undefined;
return params;
};
export const orderDelete = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ORDER_DELETE, data }, { message: '删除成功' });
return res;
};
export const orderCreate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ORDER_CREATE, data }, { message: '保存成功' });
return res;
};
export const getOrderProfitRate = async (data: any) => {
return defHttp.post<any>({ url: Api.PROFIT_RATE, data });
};
export const queryProjectNoAndInnerNo = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.QUERY_PROJECT_NO_AND_INNER_NO, data });
return res;
};
export const getOrderOptLog = async (data: any) => {
return defHttp.post<any>({ url: Api.OPT_LOG, data });
};
export const getOrderAuditLog = async (data: any) => {
return defHttp.post<any>({ url: Api.AUDIT_LOG, data });
};
export const orderFieldCheck = async (data: any) => {
try {
await defHttp.post<any>({ url: Api.ORDER_FIELD_CHECK, data });
} catch (error) {
// 重复
return error.result === 1000;
}
return false;
};
export const orderUpdate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.UPDATE, data }, { message: '操作成功' });
return res;
};
export const orderAuth = (data: any) =>
defHttp.post<any>({ url: Api.FIELD_AUTH, data }, { message: '操作成功' });
export const orderAnalysis = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ANALYSIS, data });
return res;
};
/**
* 查询编号选项
* @param noType 是项目编号还是内部编号
* @param value keyword
* @returns select的选项
*/
export const queryNoOptions = async (noType: any, value: any) => {
let options = [];
let res;
if (noType === 'projectNo') {
res = await queryProjectNoAndInnerNo({ projectNo: value });
options = res.map((item: any) => {
return { label: item.projectNo, value: item.projectNo };
});
} else {
res = await queryProjectNoAndInnerNo({ innerNo: value });
options = res.map((item: any) => {
return { label: item.innerNo, value: item.innerNo };
});
}
return options;
};
export const orderGravity = async (data: any) => {
data = formatSearchData(data);
const res = await defHttp.post<any>({ url: Api.GRAVITY, data });
return res;
};
export const orderExport = async (data: any = {}) => {
// const res = await defHttp.post<any>({ url: Api.EXPORT, data });
const userStore = useUserStoreWithOut();
data = formatSearchData(data);
const token = userStore.getToken;
message.info('正在导出中...');
return axios({
url: '/basic-api' + Api.EXPORT,
method: 'post',
responseType: 'blob',
headers: { Authorization: `${token}` },
data,
})
.then((response) => {
// 创建一个新的 Blob 对象,它包含了服务器响应的数据(即你的 Excel 文件)
const blob = new Blob([response.data]); // Excel 的 MIME 类型
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
const date = formatToDateTime(Date.now());
const strArr: string[] = [];
Object.keys(data.fieldVO).map((key) => {
switch (key) {
case 'baseFields':
strArr.push('基本信息');
break;
case 'inspectionStageFields':
strArr.push('质量检测');
break;
case 'reportFields':
strArr.push('项目报告');
break;
case 'profitAnalysisFields':
strArr.push('利润分析');
break;
case 'trackStageFields':
strArr.push('跟单');
break;
}
});
a.download = `${strArr.join('_')} ${date}.xlsx`; // 你可以为文件命名
document.body.appendChild(a);
a.click(); // 模拟点击操作来下载文件
console.log(a, '5656a');
URL.revokeObjectURL(downloadUrl); // 释放掉 blob 对象所占用的内存
document.body.removeChild(a);
message.success('导出成功');
})
.catch((error) => {
// 处理错误
message.error('导出错误', error);
});
};
export const orderRateExport = async (data: any = {}) => {
// const res = await defHttp.post<any>({ url: Api.EXPORT, data });
const userStore = useUserStoreWithOut();
data = formatSearchData(data);
const token = userStore.getToken;
message.info('正在导出中...');
return axios({
url: '/basic-api' + Api.ORDER_RATE_EXPORT,
method: 'post',
responseType: 'blob',
headers: { Authorization: `${token}` },
data,
})
.then((response) => {
// 创建一个新的 Blob 对象,它包含了服务器响应的数据(即你的 Excel 文件)
const blob = new Blob([response.data]); // Excel 的 MIME 类型
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
const date = formatToDateTime(Date.now());
a.download = `设计比重报表 ${date}.xlsx`; // 你可以为文件命名
document.body.appendChild(a);
a.click(); // 模拟点击操作来下载文件
URL.revokeObjectURL(downloadUrl); // 释放掉 blob 对象所占用的内存
document.body.removeChild(a);
message.success('导出成功');
})
.catch((error) => {
// 处理错误
message.error('导出错误', error);
});
};
export const getInitDictData = async () => {
const res = await defHttp.post({
url: Api.DICT_INIT,
});
return res;
};
export async function uploadImg(params, onUploadProgress: (progressEvent: ProgressEvent) => void) {
const res = await defHttp.uploadFile(
{
url: Api.UPLOAD,
onUploadProgress,
},
{
file: params.file,
data: { name: params.file.name },
},
);
return Promise.resolve({ data: { thumbUrl: res.data } });
}
export const getOrderList = async (params: DemoParams) => {
params = formatSearchData(params);
const res = await defHttp.post<DemoListGetResultModel>({
url: Api.ORDER,
params,
headers: {
// @ts-ignore
ignoreCancelToken: true,
},
});
const orderStore = useOrderStoreWithOut();
orderStore.setTotal(res.total);
return new Promise((resolve) => {
resolve({
items: res.records,
total: res.total,
});
});
};
export const dictCreate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_ADD, data }, { message: '保存成功' });
return res;
};
export const dictUpdate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_UPDATE, data }, { message: '保存成功' });
return res;
};
export const dictDelete = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_DELETE, data }, { message: '保存成功' });
return res;
};
export const dictList = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.DICT_LIST, data: { ...data, pageSize: 1000 } });
return res;
};
//订单跟单记录
export const trackHistory = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.TRACK_HISTORY,
data: data,
});
return res;
};
export const passCalculate = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.PASS_CALCULATE,
data: data,
});
return res;
};
export const createProductText = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.CREATE_PRODUCT_TEXT,
data: data,
});
return res;
};
export const exportProductText = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.EXPORT_PRODUCT_TEXT,
data: data,
});
return res;
};
export const calculateBusinessProfit = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.BUSINESS_PROFIT_RATIO,
data: data,
});
return res;
};
export const exportBusinessProfit = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.BUSINESS_PROFIT_RATIO_EXPORT,
data: data,
});
return res;
};
export const calculateInnerProfitRatio = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.INNER_PROFIT_RATIO,
data: data,
});
return res;
};
export const exportInnerProfitRatio = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.INNER_PROFIT_RATIO_EXPORT,
data: data,
});
return res;
};