ModifiedDiffModal.tsx
4.54 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
import { postServiceOrderModifiedDiff } from '@/services';
import { enumValueToLabel, getAliYunOSSFileNameFromUrl } from '@/utils';
import { Button, Modal, Space, Table, TableProps } from 'antd';
import Base64 from 'base-64';
import { useEffect, useState } from 'react';
import {
PRODUCT_BELONG_DEPARTMENT_OPTIONS,
SHIPPING_WAREHOUSE_OPTIONS,
} from '../constant';
import '../table.less';
export default ({ setVisible, subOrders, onClose }) => {
let ids = subOrders?.map((item: any) => {
return item.id;
});
const [diffDatas, setDiffDatas] = useState([]);
async function loadData() {
let res = await postServiceOrderModifiedDiff({
data: {
subOrderIds: ids,
},
});
let datas = res?.data;
setDiffDatas(datas);
}
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);
}
if (key === '单价' || key === '合计') {
newText = '¥' + newText;
}
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)}
className="max-w-[300px] whitespace-no-wrap overflow-hidden overflow-ellipsis"
>
<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',
},
{
title: '修改前字段值',
dataIndex: 'oldValue',
key: 'oldValue',
render(value, record) {
return cellRender(value, record);
},
},
{
title: '修改后(当前)字段值',
dataIndex: 'newValue',
key: 'newValue',
render(value, record) {
return cellRender(value, record);
},
},
];
return (
<>
<Modal
width={700}
open
title="信息对比"
okText="返回"
cancelText={false}
onOk={() => {
setVisible(false);
onClose();
}}
destroyOnClose={true}
>
{diffDatas?.map((item: any, index) => {
//转换为表格数据
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', '备注'],
['listAnnex', '附件'],
];
for (let field of visibleFields) {
let filedKey = field[0];
let filedName = field[1];
tableData.push({
fieldName: filedName,
oldValue: oldDatas[filedKey],
newValue: curDatas[filedKey],
isDiff: diffFiledNames?.includes(filedKey),
});
}
return (
<Table
className="myTable"
size="small"
pagination={false}
key={index}
columns={columns}
dataSource={tableData}
/>
);
})}
</Modal>
</>
);
};