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
8
9
10
11
enum Api {
ORDER_CREATE = '/order/erp/order/add',
UPDATE = '/order/erp/order/edit',
ORDER = '/order/erp/order/list_by_page',
12
ORDER_DELETE = '/order/erp/order/delete_by_id',
sanmu
authored
2 years ago
13
FIELD_AUTH = '/order/erp/order/field_unlock_apply',
14
QUERY_PROJECT_NO_AND_INNER_NO = '/order/erp/order/queryProjectNoAndInnerNo', //查询项目号和内部编号
sanmu
authored
2 years ago
15
EXPORT = '/order/erp/order/export',
sanmu
authored
2 years ago
16
UPLOAD = '/api/localStorage/uploadOss',
sanmu
authored
2 years ago
17
PROFIT_RATE = '/order/erp/profit/calculate', // 编辑订单实时获取利润率
sanmu
authored
2 years ago
18
19
20
21
22
23
24
25
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
26
GRAVITY = '/order/erp/report/analysis',
sanmu
authored
2 years ago
27
28
29
OPT_LOG = '/order/erp/opt/log/list_by_page', // 操作日志
AUDIT_LOG = '/order/erp/audit/log/list_by_page', //审批日志
sanmu
authored
2 years ago
30
31
}
sanmu
authored
2 years ago
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
export const formatSearchData = (params) => {
params.createStartTime = params.createStartTime
? formatToDate(params.createStartTime)
: 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;
};
57
58
59
60
61
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
62
63
64
65
66
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
67
68
69
70
export const getOrderProfitRate = async (data: any) => {
return defHttp.post<any>({ url: Api.PROFIT_RATE, data });
};
71
72
73
74
75
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
76
77
78
79
80
81
82
83
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
2 years ago
84
export const orderUpdate = async (data: any) => {
sanmu
authored
2 years ago
85
const res = await defHttp.post<any>({ url: Api.UPDATE, data }, { message: '操作成功' });
sanmu
authored
2 years ago
86
87
88
89
90
91
92
93
94
95
96
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;
};
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* 查询编号选项
* @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
121
122
123
124
125
126
127
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
128
129
130
131
132
133
134
135
136
137
export const orderExport = async (data: any = {}) => {
// const res = await defHttp.post<any>({ url: Api.EXPORT, data });
const userStore = useUserStoreWithOut();
const token = userStore.getToken;
axios({
url: '/basic-api' + Api.EXPORT,
method: 'post',
responseType: 'blob',
sanmu
authored
2 years ago
138
headers: { Authorization: `${token}` },
sanmu
authored
2 years ago
139
140
141
142
143
144
145
146
147
148
149
150
151
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;
a.download = '订单.xlsx'; // 你可以为文件命名
document.body.appendChild(a);
a.click(); // 模拟点击操作来下载文件
URL.revokeObjectURL(downloadUrl); // 释放掉 blob 对象所占用的内存
document.body.removeChild(a);
sanmu
authored
2 years ago
152
153
message.success('导出成功');
sanmu
authored
2 years ago
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
})
.catch((error) => {
// 处理错误
console.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) => {
sanmu
authored
2 years ago
184
params = formatSearchData(params);
sanmu
authored
2 years ago
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
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;
};