doubleLayer.js
15.9 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/* eslint-disable */
import React, { useRef, useState, useEffect } from "react";
import styles from "../index.less";
import SvgBox from "../svg";
import { Select, Button, message, Input, Spin } from "antd-v4";
import { CompressOutlined, ExpandOutlined } from "@ant-design/icons";
import * as commonUtils from "@/utils/utils";
import * as commonFunc from "@/components/Common/commonFunc";
import * as commonBusiness from "@/components/Common/commonBusiness";
import * as commonServices from "@/services/services";
import CommonBase from "@/components/Common/CommonBase";
import AntdDraggableModal from "@/components/Common/AntdDraggableModal";
import CommonViewTable from "@/components/Common/CommonViewTable";
import StaticEditTable from "@/components/Common/CommonTable";
import jsPreviewPdf from "@js-preview/pdf";
import commonConfig from "@/utils/config";
const DoubleLayerBox = props => {
const { onCancel, onOk, title, loading, masterConfig, bFullScreen, tableData, options = [] } = props;
const { slaveData = {}, masterData = {} } = props.state;
const [boxList, setBoxList] = useState([]);
const [tableColum, setTableColum] = useState([]); // 盒身类型
const [tableDataList, setTableDataList] = useState([]); // 盒长
const [boxBodyList, setBoxBodyList] = useState([]); // 盒身信息
const [isDefaultValue, setIsDefaultValue] = useState(true); // 是否默认值
const [topBoxList, setTopBoxList] = useState([]); // 盒身信息
const [leftBoxList, setLeftBoxList] = useState([]); // 左边
const [rightBoxList, setRightBoxList] = useState([]);
// useEffect(() => {
// if (tableData && tableData.length) {
// const newTableColum = tableData.map(item => {
// return {
// ...item,
// isEditable: true,
// isSelect: false,
// selectImage: null,
// value: "",
// };
// });
// const newList = newTableColum.filter(
// item => item.showName.includes("盒长") || item.showName.includes("盒高") || item.showName.includes("盒宽")
// );
// const newLists = newTableColum.filter(
// item =>
// !(item.showName.includes("盒长") || item.showName.includes("盒高") || item.showName.includes("盒宽") || item.showName.includes("盒身"))
// );
// const bodyList = newTableColum.filter(item => item.showName.includes("盒身"));
// newLists.forEach(x => {
// if (x.showName === "盒型类别") {
// x.showName = "盒型名称";
// }
// });
// setTableColum(newLists);
// setBoxBodyList(bodyList);
// newList.forEach(item => {
// let name = "";
// if (item.showName === "盒长") {
// name = item.showName + "(L)";
// } else if (item.showName === "盒宽") {
// name = item.showName + "(W)";
// } else if (item.showName === "盒高") {
// name = item.showName + "(D)";
// }
// item.sName = name;
// });
// setTableDataList(newList);
// }
// }, [tableData]);
const titleList = [
"左(上)插位组件",
"上插位组件",
"右(上)插位组件",
"左偏移",
"左插位组件",
"左(下)插位组件",
"右偏移",
"右插位组件",
"右(下)插位组件",
"盒型名称",
"盒身",
"个数",
"首盒长(L)",
"首盒宽(W)",
"次盒长(L)",
"次盒宽(W)",
];
const titleList1 = [
{ name: "左(上)插位组件", value: "dZSCW" },
{ name: "上插位组件", value: "dSCW" },
{ name: "右(上)插位组件", value: "dYSCW" },
{ name: "左偏移", value: "dZPY" },
{ name: "左插位组件", value: "dZCW" },
{ name: "左(下)插位组件", value: "dZXCW" },
{ name: "右偏移", value: "dYPY" },
{ name: "右插位组件", value: "dYCW" },
{ name: "右(下)插位组件", value: "dYXCW" },
];
// tableColum.forEach(item => {
// titleList.push(item.showName);
// });
// boxBodyList.forEach(item => {
// titleList.push(item.showName);
// });
// tableDataList.forEach(item => {
// titleList.push(item.showName);
// });
const newBoxList = [];
// 盒身信息
titleList.forEach((item, index) => {
newBoxList.push({
value: "",
sName: item,
isEditable: true,
isSelect: false,
selectValue: null,
selectLabel: "",
selectImage: null,
type: null,
show: true,
showName: item, // 参数名称
sAssignFormula: null,
});
});
if (slaveData && slaveData.length) {
slaveData.forEach((item, index) => {
const i = titleList1.findIndex(i => {
return i.value === item.sCode;
});
if (i !== -1) {
const x = newBoxList.findIndex(z => z.sName === titleList1[i].name);
newBoxList[x].value = item.iValue;
newBoxList[x].type = item.sTypes;
newBoxList[x].showName = item.sName;
newBoxList[x].selectImage = item.sMakeUpPath;
newBoxList[x].sName = titleList1[i].name;
newBoxList[x].sAssignFormula = item.sAssignFormula;
newBoxList[x].bVisible = item.bVisible;
}
});
}
// 盒身信息
if (masterData) {
newBoxList.forEach((item, index) => {
if (item.sName === "盒身") {
newBoxList[index].value = masterData.sBoxBody;
newBoxList[index].selectImage = masterData.sMakeUpPath;
newBoxList[index].type = masterData.sTypes;
} else if (item.sName === "盒长") {
newBoxList[index].value = masterData.dBoxLength;
} else if (item.sName === "盒宽") {
newBoxList[index].value = masterData.dBoxWidth;
} else if (item.sName === "盒高") {
newBoxList[index].value = masterData.dBoxHeight;
} else if (item.sName === "盒型名称") {
newBoxList[index].value = masterData.sName;
}
});
}
const arraysAreEqual = (arr1, arr2) => {
if (arr1.length !== arr2.length) return false;
return arr1.every((item, index) => item.sName === arr2[index].sName);
};
// 有数据的时候 盒型设计需要赋值
useEffect(() => {
if (newBoxList.length > 0 && !arraysAreEqual(boxList, newBoxList)) {
setBoxList(newBoxList);
}
}, [newBoxList]);
const getImage = fileName => {
// const imageUrl = `${commonConfig.file_host}file/download?savePathStr=${fileName}&sModelsId=100&token=${props.token}`;
const imageUrl = `${commonConfig.file_host}file/download?savePathStr=${fileName}&scale=0.1&sModelsId=100&token=${props.token}`;
return imageUrl;
};
// 下来框
const renderOptionWithImage = option => {
return (
<Select.Option key={option.sId} value={option.sCode} label={option.sName} image={getImage(option.sMakeUpPath)}>
<div style={{ display: "flex", alignItems: "center" }}>
{option.sMakeUpPath ? <img src={getImage(option.sMakeUpPath)} style={{ width: 24, height: 24, marginRight: 8 }} /> : ""}
<span>{option.sName}</span>
</div>
</Select.Option>
);
};
const svgBoxProps = {
...props,
boxList,
showNew: 0,
};
useEffect(() => {
if (!boxList.length) return;
const slicedArray = boxList.slice(9, 12);
// 处理盒型部分
setBoxBodyList(slicedArray);
}, [boxList]);
console.log(tableDataList, "boxList");
return (
<div className={styles.boxBody}>
<div className={styles.boxTop}>
{topBoxList.map((topItem, index) => (
<div key={index} className={styles.boxFlex} style={{ display: topItem.show ? "block" : "none" }}>
<div className={styles.boxTitle}>{topItem.sName}</div>
{topItem?.selectImage ? (
<img
src={topItem?.selectImage}
alt={topItem.value}
style={{ width: 40, height: 30, marginRight: 8, position: "absolute", left: 20, top: 24, zIndex: 10 }}
/>
) : (
""
)}
<Select
optionLabelProp="label"
className="mySelects"
style={{ width: 180 }}
defaultValue={options.length ? options[0].value : ""}
onSelect={(value, option) => handleSelect(value, option, index, 0)}
onDropdownVisibleChange={async open => {
if (open) {
props.getSqlOptions(index + 1); // 在下拉菜单打开时调用 getSqlOptions
}
}}
>
{!loading ? options.map(option => renderOptionWithImage(option)) : ""}
</Select>
<div className={styles.boxInput}>
{/* <div className={styles.text}>参数:</div> */}
<Input
value={topItem?.showName}
onChange={e => handleChangeName(e, index)}
onFocus={e => handleFocus(e, index)}
onBlur={e => handleBlur(e, index)}
readOnly={!topItem?.isEditable}
className={styles.text}
/>
<Input
value={topItem?.value}
onChange={e => handleChange(e, index)}
onFocus={e => handleFocus(e, index)}
onBlur={e => handleBlur(e, index)}
readOnly={!topItem?.isEditable}
style={{ width: " 80%" }}
/>
</div>
</div>
))}
</div>
<div className={styles.boxLeft}>
{leftBoxList.map((item, index) => (
<div key={index + 3} className={styles.boxFlex} style={{ display: item?.show ? "block" : "none" }}>
<div className={styles.boxTitle}>{titleList[index + 3]}</div>
<Select
optionLabelProp="label"
className="mySelects"
style={{ width: 180 }}
defaultValue={options.length ? options[0].value : ""}
onSelect={(value, option) => handleSelect(value, option, findIndexBySname(item.sName), 0)}
onDropdownVisibleChange={async open => {
if (open) {
props.getSqlOptions(findIndexBySname(item.sName) + 1); // 在下拉菜单打开时调用 getSqlOptions
}
}}
>
{!loading ? options.map(option => renderOptionWithImage(option)) : ""}
</Select>
<div className={styles.boxInput}>
{item?.selectImage ? (
<img
src={item?.selectImage}
alt={item.value}
style={{
width: 40,
height: 30,
marginRight: 8,
position: "absolute",
left: 20,
top: -35,
zIndex: 10,
}}
/>
) : (
""
)}
<Input
value={item?.showName}
onChange={e => handleChangeName(e, findIndexBySname(item.sName))}
onFocus={e => handleFocus(e, findIndexBySname(item.sName))}
onBlur={e => handleBlur(e, findIndexBySname(item.sName))}
readOnly={!item?.isEditable}
className={styles.text}
/>
<Input
value={item?.value}
onChange={e => handleChange(e, findIndexBySname(item.sName))}
onFocus={e => handleFocus(e, findIndexBySname(item.sName))}
onBlur={e => handleBlur(e, findIndexBySname(item.sName))}
readOnly={!item?.isEditable}
style={{ width: " 80%" }}
/>
</div>
</div>
))}
</div>
<div className={styles.boxRight}>
{rightBoxList.map((item, index) => (
<div key={findIndexBySname(item.sName)} className={styles.boxFlex} style={{ display: item?.show ? "block" : "none" }}>
<div className={styles.boxTitle}>{titleList[findIndexBySname(item.sName)]}</div>
<Select
optionLabelProp="label"
className="mySelects"
style={{ width: 180 }}
defaultValue={options.length ? options[0].value : ""}
onSelect={(value, option) => handleSelect(value, option, findIndexBySname(item.sName), 0)}
onDropdownVisibleChange={async open => {
if (open) {
props.getSqlOptions(findIndexBySname(item.sName) + 1); // 在下拉菜单打开时调用 getSqlOptions
}
}}
>
{!loading ? options.map(option => renderOptionWithImage(option)) : ""}
</Select>
<div className={styles.boxInput}>
{item?.selectImage ? (
<img
src={item?.selectImage}
alt={item.value}
style={{
width: 40,
height: 30,
marginRight: 8,
position: "absolute",
left: 20,
top: -35,
zIndex: 10,
}}
/>
) : (
""
)}
<Input
value={item?.showName}
onChange={e => handleChangeName(e, findIndexBySname(item.sName))}
onFocus={e => handleFocus(e, findIndexBySname(item.sName))}
onBlur={e => handleBlur(e, findIndexBySname(item.sName))}
readOnly={!item?.isEditable}
className={styles.text}
/>
<Input
value={item?.value}
onChange={e => handleChange(e, findIndexBySname(item.sName))}
onFocus={e => handleFocus(e, findIndexBySname(item.sName))}
onBlur={e => handleBlur(e, findIndexBySname(item.sName))}
readOnly={!item?.isEditable}
style={{ width: " 80%" }}
/>
</div>
</div>
))}
</div>
<div className={styles.boxBottom}>
<div className={styles.svgBox}>
<SvgBox {...svgBoxProps} />
</div>
<div className={styles.content}>
<div className={styles.content}>
{boxBodyList && boxBodyList.length
? boxBodyList.map((item, index) => {
const uniqueIndex = index + 9;
return (
<div key={uniqueIndex} className={styles.boxFlex}>
<div className={styles.boxInput}>
<div className={styles.text} style={{ width: "120px" }}>
{item.showName}
</div>
{boxList[uniqueIndex]?.selectImage ? (
<img
src={boxList[uniqueIndex]?.selectImage}
alt={boxList[uniqueIndex].value}
style={{ width: 40, height: 30, marginRight: 8, position: "absolute", left: 120, top: 6, zIndex: 10 }}
/>
) : (
""
)}
{isDefaultValue ? <div className={styles.defaultValue}>{boxList[uniqueIndex]?.value}</div> : ""}
<Select
optionLabelProp="label"
className="mySelects"
style={{ width: "80%" }}
defaultValue={boxList[uniqueIndex]?.value}
onSelect={(value, option) => handleSelect(value, option, uniqueIndex, 1)}
onDropdownVisibleChange={async open => {
if (open) {
props.getSqlOptions(10); // 盒身
}
}}
>
{!loading ? options.map(option => renderOptionWithImage(option)) : ""}
</Select>
</div>
</div>
);
})
: ""}
</div>
</div>
</div>
</div>
);
};
export default DoubleLayerBox;