sanmu
authored
2 years ago
1
2
3
4
import axios from 'axios';
import { defHttp } from '/@/utils/http/axios';
import { useUserStoreWithOut } from '/@/store/modules/user';
import { useOrderStoreWithOut } from '/@/store/modules/order';
sanmu
authored
2 years ago
5
import { formatToDate } from '/@/utils/dateUtil';
sanmu
authored
2 years ago
6
import message from '/@/views/form-design/utils/message';
sanmu
authored
2 years ago
7
import { formatToDateTime } from '../../utils/dateUtil';
sanmu
authored
2 years ago
8
9
10
11
12
enum Api {
ORDER_CREATE = '/order/erp/order/add',
UPDATE = '/order/erp/order/edit',
ORDER = '/order/erp/order/list_by_page',
13
ORDER_DELETE = '/order/erp/order/delete_by_id',
sanmu
authored
2 years ago
14
FIELD_AUTH = '/order/erp/order/field_unlock_apply',
15
QUERY_PROJECT_NO_AND_INNER_NO = '/order/erp/order/queryProjectNoAndInnerNo', //查询项目号和内部编号
sanmu
authored
2 years ago
16
EXPORT = '/order/erp/order/export',
sanmu
authored
2 years ago
17
UPLOAD = '/api/localStorage/uploadOss',
柏杨
authored
11 months ago
18
UPLOAD_FILE = '/api/localStorage/upload_file_oss', //上传文件
sanmu
authored
2 years ago
19
PROFIT_RATE = '/order/erp/profit/calculate', // 编辑订单实时获取利润率
sanmu
authored
2 years ago
20
21
22
23
24
25
26
27
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',
sanmu
authored
2 years ago
28
GRAVITY = '/order/erp/report/analysis',
sanmu
authored
2 years ago
29
30
31
OPT_LOG = '/order/erp/opt/log/list_by_page', // 操作日志
AUDIT_LOG = '/order/erp/audit/log/list_by_page', //审批日志
sanmu
authored
2 years ago
32
ORDER_RATE_EXPORT = '/order/erp/report/export', // 所有设计师比重导出
sanmu
authored
about a year ago
33
ORDER_FIELD_CHECK = '/order/erp/order/check', // 校验内部编号是否重复
柏杨
authored
11 months ago
34
35
TRACK_HISTORY = '/order/erp/opinion/log/query_by_id', //跟单结果记录
柏杨
authored
11 months ago
36
PASS_CALCULATE = '/order/erp/order/passRate', //一次性通过率
柏杨
authored
10 months ago
37
38
CREATE_PRODUCT_TEXT = '/order/erp/order/produceReport', //生成生产指示书
EXPORT_PRODUCT_TEXT = '/order/erp/order/send', //导出生产指示书
柏杨
authored
11 months ago
39
40
41
42
43
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', //内部生产净利润分析表_导出
sanmu
authored
2 years ago
44
45
}
sanmu
authored
2 years ago
46
47
48
49
export const formatSearchData = (params) => {
params.createStartTime = params.createStartTime
? formatToDate(params.createStartTime)
: undefined;
sanmu
authored
2 years ago
50
params.createEndTime = params.createEndTime ? formatToDate(params.createEndTime) : undefined;
sanmu
authored
2 years ago
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
};
72
73
74
75
76
export const orderDelete = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ORDER_DELETE, data }, { message: '删除成功' });
return res;
};
sanmu
authored
2 years ago
77
78
79
80
81
export const orderCreate = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.ORDER_CREATE, data }, { message: '保存成功' });
return res;
};
sanmu
authored
2 years ago
82
83
84
85
export const getOrderProfitRate = async (data: any) => {
return defHttp.post<any>({ url: Api.PROFIT_RATE, data });
};
86
87
88
89
90
export const queryProjectNoAndInnerNo = async (data: any) => {
const res = await defHttp.post<any>({ url: Api.QUERY_PROJECT_NO_AND_INNER_NO, data });
return res;
};
sanmu
authored
2 years ago
91
92
93
94
95
96
97
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 });
};
sanmu
authored
about a year ago
98
99
100
101
102
103
104
105
106
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;
};
sanmu
authored
2 years ago
107
sanmu
authored
2 years ago
108
export const orderUpdate = async (data: any) => {
sanmu
authored
2 years ago
109
const res = await defHttp.post<any>({ url: Api.UPDATE, data }, { message: '操作成功' });
sanmu
authored
2 years ago
110
111
112
113
114
115
116
117
118
119
120
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;
};
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* 查询编号选项
* @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;
};
sanmu
authored
2 years ago
145
146
147
148
149
150
151
export const orderGravity = async (data: any) => {
data = formatSearchData(data);
const res = await defHttp.post<any>({ url: Api.GRAVITY, data });
return res;
};
sanmu
authored
2 years ago
152
153
154
export const orderExport = async (data: any = {}) => {
// const res = await defHttp.post<any>({ url: Api.EXPORT, data });
const userStore = useUserStoreWithOut();
sanmu
authored
2 years ago
155
data = formatSearchData(data);
sanmu
authored
2 years ago
156
157
const token = userStore.getToken;
sanmu
authored
2 years ago
158
message.info('正在导出中...');
sanmu
authored
2 years ago
159
sanmu
authored
2 years ago
160
return axios({
sanmu
authored
2 years ago
161
162
163
url: '/basic-api' + Api.EXPORT,
method: 'post',
responseType: 'blob',
sanmu
authored
2 years ago
164
headers: { Authorization: `${token}` },
sanmu
authored
2 years ago
165
166
167
168
169
170
171
172
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;
sanmu
authored
2 years ago
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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`; // 你可以为文件命名
sanmu
authored
2 years ago
196
197
198
199
document.body.appendChild(a);
a.click(); // 模拟点击操作来下载文件
URL.revokeObjectURL(downloadUrl); // 释放掉 blob 对象所占用的内存
document.body.removeChild(a);
sanmu
authored
2 years ago
200
201
message.success('导出成功');
sanmu
authored
2 years ago
202
203
204
})
.catch((error) => {
// 处理错误
sanmu
authored
2 years ago
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
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);
sanmu
authored
2 years ago
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
});
};
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) => {
sanmu
authored
2 years ago
269
params = formatSearchData(params);
sanmu
authored
2 years ago
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
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;
};
柏杨
authored
11 months ago
307
308
309
310
311
312
313
314
315
//订单跟单记录
export const trackHistory = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.TRACK_HISTORY,
data: data,
});
return res;
};
柏杨
authored
11 months ago
316
317
318
319
320
321
322
323
export const passCalculate = async (data: any) => {
const res = await defHttp.post<any>({
url: Api.PASS_CALCULATE,
data: data,
});
return res;
};
柏杨
authored
11 months ago
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
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;
};