|
1
|
import { postServiceOrderModifiedDiff } from '@/services';
|
|
2
|
import { enumValueToLabel, getAliYunOSSFileNameFromUrl } from '@/utils';
|
|
3
|
import { getReceivingCompanyOptions, isSupplier } from '@/utils/order';
|
|
4
|
import { Button, Divider, Modal, Space, Table, TableProps } from 'antd';
|
|
5
6
|
import { useEffect, useState } from 'react';
import {
|
|
7
|
PAYEE_OPTIONS,
|
|
8
9
|
PAYMENT_CHANNEL_OPTIONS,
PAYMENT_METHOD_OPTIONS,
|
|
10
11
|
PRODUCT_BELONG_DEPARTMENT_OPTIONS,
SHIPPING_WAREHOUSE_OPTIONS,
|
|
12
|
} from '../../constant';
|
|
13
14
|
import '../table.less';
|
|
15
16
|
export default ({ setVisible, subOrders, mainOrder, onClose }) => {
let subIds = subOrders?.map((item: any) => {
|
|
17
18
19
|
return item.id;
});
|
|
20
21
22
23
|
let mainId = mainOrder?.id;
const [subOrderDiffs, setSubOrderDiffs] = useState([]);
const [mainOrderDiffs, setMainOrderDiffs] = useState([]);
|
|
24
|
|
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
function isSupplierUnvisibleField(field: any) {
//主订单字段
let unvisibleFields = [
'receivingCompany',
'invoiceIdentificationNumber',
'bankAccountNumber',
'bank',
'totalPayment',
'institution',
'institutionContactName',
];
//子订单字段
unvisibleFields.push(
...[
'listAnnex',
'shippingWarehouse',
'productBelongBusiness',
'subOrderPayment',
'productPrice',
],
);
|
|
47
|
return isSupplier() && unvisibleFields.includes(field);
|
|
48
49
|
}
|
|
50
51
52
|
async function loadData() {
let res = await postServiceOrderModifiedDiff({
data: {
|
|
53
54
|
subOrderIds: subIds,
mainOrderId: mainId,
|
|
55
56
|
},
});
|
|
57
58
59
60
61
|
let subOrderDiffs = res?.data?.subOrderDiffs;
let mainOrderDiffs = res?.data?.mainOrderDiffs;
setSubOrderDiffs(subOrderDiffs);
setMainOrderDiffs(mainOrderDiffs);
|
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
}
useEffect(() => {
loadData();
}, []);
function toChineseName(key: any, text: any) {
let newText = text;
if (key === '所属事业部') {
newText = enumValueToLabel(text, PRODUCT_BELONG_DEPARTMENT_OPTIONS);
}
if (key === '发货仓库') {
newText = enumValueToLabel(text, SHIPPING_WAREHOUSE_OPTIONS);
}
|
|
76
77
78
79
80
81
|
if (key === '支付渠道') {
newText = enumValueToLabel(text, PAYMENT_CHANNEL_OPTIONS);
}
if (key === '支付方式') {
newText = enumValueToLabel(text, PAYMENT_METHOD_OPTIONS);
}
|
|
82
83
84
|
if (key === '单价' || key === '合计') {
newText = '¥' + newText;
}
|
|
85
86
87
88
89
90
|
if (key === '开票收款单位') {
newText = enumValueToLabel(
text,
getReceivingCompanyOptions(PAYEE_OPTIONS),
);
}
|
|
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
|
return newText;
}
function cellRender(value: any, record: any) {
if (record.fieldName === '附件') {
return (
<Space className="max-w-[300px]" wrap>
{value?.map((item: any, index: any) => {
let fileName = getAliYunOSSFileNameFromUrl(item);
return (
<Button
className="p-0 pr-2"
key={index}
danger={record.isDiff}
type="link"
onClick={() => {
window.open(
'/previewApi/onlinePreview?url=' +
encodeURIComponent(Base64.encode(item)),
);
}}
>
{fileName}
</Button>
);
})}
</Space>
);
}
return (
<div
title={toChineseName(record.fieldName, value)}
|
|
123
|
className="max-w-[250px] whitespace-no-wrap overflow-hidden overflow-ellipsis"
|
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
>
<span className={record.isDiff ? 'text-[red]' : ''}>
{toChineseName(record.fieldName, value)}
</span>
</div>
);
}
interface DataType {
fieldName: string;
oldValue: string;
newValue: string;
isDiff: boolean;
}
const columns: TableProps<DataType>['columns'] = [
{
title: '字段名',
dataIndex: 'fieldName',
key: 'fieldName',
|
|
144
145
146
147
148
149
150
151
152
153
|
render(value) {
return (
<div
title={value}
className="max-w-[80px] whitespace-no-wrap overflow-hidden overflow-ellipsis"
>
{value}
</div>
);
},
|
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
},
{
title: '修改前字段值',
dataIndex: 'oldValue',
key: 'oldValue',
render(value, record) {
return cellRender(value, record);
},
},
{
title: '修改后(当前)字段值',
dataIndex: 'newValue',
key: 'newValue',
render(value, record) {
return cellRender(value, record);
},
},
];
|
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
function loadSubOrderDiffTable(item: any, index: any) {
//转换为表格数据
let oldDatas = item[0];
let curDatas = item[1];
let diffFiledNames = oldDatas?.diffFieldsName;
let tableData = [];
let visibleFields = [
['productName', '商品名称'],
['productCode', '商品编码'],
['parameters', '商品参数'],
['quantity', '数量'],
['productPrice', '单价'],
['unit', '单位'],
['subOrderPayment', '合计'],
['productBelongBusiness', '所属事业部'],
['shippingWarehouse', '发货仓库'],
['notes', '备注'],
|
|
191
192
|
['paymentChannel', '支付渠道'],
['paymentMethod', '支付方式'],
|
|
193
194
195
196
197
|
['listAnnex', '附件'],
];
for (let field of visibleFields) {
let filedKey = field[0];
let filedName = field[1];
|
|
198
199
200
201
202
203
204
205
206
|
if (!isSupplierUnvisibleField(filedKey)) {
tableData.push({
fieldName: filedName,
oldValue: oldDatas[filedKey],
newValue: curDatas[filedKey],
isDiff: diffFiledNames?.includes(filedKey),
});
}
|
|
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
|
}
return (
<>
<Divider orientation="left">商品{index + 1}:</Divider>
<Table
className="myTable"
size="small"
pagination={false}
key={index}
columns={columns}
dataSource={tableData}
/>
</>
);
}
function loadMainOrderDiffTable(item: any, index: any) {
if (!item || item.length <= 0) {
return;
}
//转换为表格数据
let oldDatas = item[0];
let curDatas = item[1];
let diffFiledNames = oldDatas?.diffFieldsName;
let tableData = [];
let visibleFields = [
['salesCode', '销售代号'],
['customerName', '收货人姓名'],
['customerContactNumber', '收货人联系手机号'],
['customerShippingAddress', '收货人地址信息'],
['institutionContactName', '单位联系人'],
['institution', '单位'],
['totalPayment', '支付总金额'],
['notes', '备注'],
['bank', '开户银行'],
['bankAccountNumber', '银行账号'],
['invoiceIdentificationNumber', '开票识别号'],
['receivingCompany', '开票收款单位'],
];
for (let field of visibleFields) {
let filedKey = field[0];
let filedName = field[1];
|
|
250
251
252
253
254
255
256
257
258
|
if (!isSupplierUnvisibleField(filedKey)) {
tableData.push({
fieldName: filedName,
oldValue: oldDatas[filedKey],
newValue: curDatas[filedKey],
isDiff: diffFiledNames?.includes(filedKey),
});
}
|
|
259
260
261
262
263
264
265
266
267
268
269
270
271
|
}
return (
<Table
className="myTable"
size="small"
pagination={false}
key={index}
columns={columns}
dataSource={tableData}
/>
);
}
|
|
272
273
274
275
276
277
278
279
280
281
282
283
|
return (
<>
<Modal
width={700}
open
title="信息对比"
okText="返回"
cancelText={false}
onOk={() => {
setVisible(false);
onClose();
}}
|
|
284
285
286
287
288
289
|
onCancel={() => {
setVisible(false);
}}
cancelButtonProps={{
hidden: true,
}}
|
|
290
291
|
destroyOnClose={true}
>
|
|
292
293
|
<Divider>主订单信息:</Divider>
{loadMainOrderDiffTable(mainOrderDiffs, 0)}
|
|
294
|
|
|
295
296
297
|
<Divider>子订单信息:</Divider>
{subOrderDiffs?.map((item: any, index) => {
return loadSubOrderDiffTable(item, index);
|
|
298
299
300
301
302
|
})}
</Modal>
</>
);
};
|