index.js
11.5 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
/* eslint-disable */
import React, { Component, useState, useEffect } from "react";
import CommonBase from "../../Common/CommonBase"; /* 获取配置及数据 */
import CommonSales from "../../Common/CommonBillEvent"; /* 继承销售模块业务功能 */
import * as commonFunc from "../../Common/commonFunc"; /* 通用单据方法 */ /* 通用单据方法 */
import { Form } from "@ant-design/compatible";
import { Spin, Tree, Select, Input } from "antd-v4";
import styles from "./index.less";
import { ArrowLeftOutlined, FolderFilled, FolderOpenFilled, FileTextFilled, PlusOutlined, MinusOutlined } from "@ant-design/icons";
import SvgBox from "./svg";
import img1 from "../../../assets/paiban1.png";
class BoxProject extends Component {
constructor(props) {
super(props);
this.state = {
boxList: [],
};
}
// 添加一个方法来更新 boxList
updateBoxList = newBoxList => {
this.setState({ boxList: newBoxList });
};
render() {
const { pageLoading, masterData, fastOrderModalVisible } = this.props;
const { boxList } = this.state;
return (
<Spin spinning={pageLoading}>
<BoxProjectContent {...this.props} boxList={boxList} updateBoxList={this.updateBoxList} />
</Spin>
);
}
}
const BoxProjectContent = Form.create({
mapPropsToFields(props) {
const { masterData, masterConfig } = props;
const obj = commonFunc.mapPropsToFields(masterData, Form, masterConfig);
return obj;
},
})(props => {
const { updateBoxList, boxList } = props; // 获取父组件传递的更新方法
// 获取树形节点
const treeData = [
{
title: "parent 1",
key: "0-0",
icon: <FolderOpenFilled />,
children: [
{
title: "leaf",
key: "0-0-0",
icon: <FileTextFilled />,
},
{
title: "leaf",
key: "0-0-1",
icon: ({ selected }) => (selected ? <FileTextFilled /> : <FileTextFilled />),
},
],
},
];
const options = [
{ value: null, label: "", image: null },
{ value: 0, label: "图片1", image: img1 },
{ value: 1, label: "图片2", image: img1 },
// { value: 2, label: "图片3", image: img1 },
];
// 生成盒型输入框数据并更新到父组件的 state
useEffect(
() => {
let list = [];
for (let index = 0; index < 9; index++) {
const data = {
isEditable: false,
value: "",
type: null,
};
list.push(data);
}
updateBoxList(list); // 调用父组件的方法更新 boxList
},
[updateBoxList]
);
const handleFocus = (e, index) => {
if (boxList && boxList.length) {
const updatedBoxList = [...boxList];
updatedBoxList[index].isEditable = true;
updateBoxList(updatedBoxList);
}
};
const handleBlur = (e, index) => {
if (boxList && boxList.length) {
const updatedBoxList = [...boxList];
updatedBoxList[index].isEditable = false;
updateBoxList(updatedBoxList);
}
};
const handleChange = (e, index) => {
const updatedBoxList = [...boxList];
updatedBoxList[index].value = e.target.value;
updateBoxList(updatedBoxList);
};
const handleSelect = (name, selectConfig, index) => {
const updatedBoxList = [...boxList];
updatedBoxList[index].type = name;
updateBoxList(updatedBoxList);
};
const titleList = [
"上方盒舌",
"盒底组件",
"下方盒舌",
"左(上)插位组件",
"左贴边位",
"左(下)插位组件",
"右(上)插位组件",
"右贴边位",
"右(下)插位组件",
];
const svgProps = {
...props,
boxList,
showNew:0
};
// const renderTreeNodes = data => {
// return data.map(item => {
// const { showName, children = [], sId } = item;
// const treeNodeProps = {
// title: showName,
// key: sId,
// treeNode: item,
// selectable: !children.length,
// switcherIcon: params => {
// const { expanded, isLeaf } = params;
// let icon = "";
// if (isLeaf) {
// icon = <FileTextFilled style={{ color: "#f7cc4f", fontSize: 20 }} />;
// } else if (expanded) {
// icon = <FolderOpenFilled style={{ color: "#f7cc4f", fontSize: 20 }} />;
// } else {
// icon = <FolderFilled style={{ color: "#f7cc4f", fontSize: 20 }} />;
// }
// return icon;
// },
// };
// return <Tree.TreeNode {...treeNodeProps}>{!!children.length && renderTreeNodes(children)}</Tree.TreeNode>;
// });
// };
return (
<Form>
<div
style={{
marginTop: "50px",
}}
className={styles.boxDesignContent}
>
<div className={styles.tabs}>111</div>
<div className={styles.content}>
<div className={styles.boxTree}>
<Tree
className={"hide-file-icon"}
onSelect={(e, select) => {
// props.setState(pre => ({ ...pre, selectedNode: select.selectedNodes[0]?.treeNode || {} }));
}}
// defaultSelectedKeys={[activeTree]}
defaultExpandAll={true}
selectedKeys={[1]}
treeData={treeData}
>
{/* {renderTreeNodes(treeData)} */}
</Tree>
</div>
<div className={styles.design}>
{/* 数值输入 */}
{/* 上 */}
{boxList && boxList.length ? (
<div className={styles.boxTop}>
{Array.from({ length: 3 }).map((_, index) => (
<div key={index} className={styles.boxFlex}>
{titleList[index]}
<Select
optionLabelProp="label"
style={{ width: 180 }}
defaultValue={options[0].value}
onSelect={(value, option) => handleSelect(value, option, index)}
>
{options.map(item => (
<Option key={item.value} value={item.value} label={item.label}>
<div style={{ display: "flex", alignItems: "center" }}>
{item.image ? <img src={item.image} alt={item.label} style={{ width: 24, height: 24, marginRight: 8 }} /> : ""}
<span>{item.label}</span>
</div>
</Option>
))}
</Select>
<div>
<div>参数:</div>
<Input
value={boxList[index]?.value}
onChange={e => handleChange(e, index)}
onFocus={e => handleFocus(e, index)}
onBlur={e => handleBlur(e, index)}
readOnly={!boxList[index]?.isEditable}
style={{ width: 180 }}
/>
</div>
</div>
))}
</div>
) : (
""
)}
{/* 左 */}
{boxList && boxList.length ? (
<div className={styles.boxLeft}>
{Array.from({ length: 3 }, (_, i) => i + 3).map(index => (
<div key={index} className={styles.boxFlex}>
{titleList[index]}
<Select
optionLabelProp="label"
style={{ width: 180 }}
defaultValue={options[0].value}
onSelect={(value, option) => handleSelect(value, option, index)}
>
{options.map(item => (
<Option key={item.value} value={item.value} label={item.label}>
<div style={{ display: "flex", alignItems: "center" }}>
{item.image ? <img src={item.image} alt={item.label} style={{ width: 24, height: 24, marginRight: 8 }} /> : ""}
<span>{item.label}</span>
</div>
</Option>
))}
</Select>
<div>
<div>参数:</div>
<Input
value={boxList[index]?.value}
onChange={e => handleChange(e, index)}
onFocus={e => handleFocus(e, index)}
onBlur={e => handleBlur(e, index)}
readOnly={!boxList[index]?.isEditable}
style={{ width: 180 }}
/>
</div>
</div>
))}
</div>
) : (
""
)}
{/* 右 */}
{boxList && boxList.length ? (
<div className={styles.boxRight}>
{Array.from({ length: 3 }, (_, i) => i + 6).map(index => (
<div key={index} className={styles.boxFlex}>
{titleList[index]}
<Select
optionLabelProp="label"
style={{ width: 180 }}
defaultValue={options[0].value}
onSelect={(value, option) => handleSelect(value, option, index)}
>
{options.map(item => (
<Option key={item.value} value={item.value} label={item.label}>
<div style={{ display: "flex", alignItems: "center" }}>
{item.image ? <img src={item.image} alt={item.label} style={{ width: 24, height: 24, marginRight: 8 }} /> : ""}
<span>{item.label}</span>
</div>
</Option>
))}
</Select>
<div>
<div>参数:</div>
<Input
value={boxList[index]?.value}
onChange={e => handleChange(e, index)}
onFocus={e => handleFocus(e, index)}
onBlur={e => handleBlur(e, index)}
readOnly={!boxList[index]?.isEditable}
style={{ width: 180 }}
/>
</div>
</div>
))}
</div>
) : (
""
)}
<SvgConten {...svgProps} />
</div>
</div>
</div>
</Form>
);
});
const SvgConten = props => {
const [length, setLength] = useState(0);
const [width, setWidth] = useState(0);
const [height, setHeight] = useState(0);
const handleChange = (e, index) => {
if (index === 0) {
setLength(e.target.value);
} else if (index === 1) {
setWidth(e.target.value);
} else {
setHeight(e.target.value);
}
};
const svgBoxProps = {
...props,
boxSize:{
length,
width,
height
}
}
return (
<div className={styles.svgContent}>
<div className={styles.svgBox}>
<SvgBox {...svgBoxProps} />
<div>
盒长
<Input value={length} style={{ width: 180 }} onChange={e => handleChange(e, 0)} />
</div>
<div>
盒宽
<Input value={width} style={{ width: 180 }} onChange={e => handleChange(e, 1)} />
</div>
<div>
盒高
<Input value={height} style={{ width: 180 }} onChange={e => handleChange(e, 2)} />
</div>
</div>
</div>
);
};
export default CommonBase(CommonSales(BoxProject));