@bit-sun/business-component 4.0.12-alpha.19 → 4.0.12-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,160 +0,0 @@
1
- export const MockPropertyList = [
2
- {
3
- propertyCode: 'year',
4
- propertyName: '年份',
5
- isCommonUse: true,
6
- detailList: [
7
- {
8
- name: '2022',
9
- value: '2022',
10
- isCommonUse: true,
11
- },
12
- {
13
- name: '2023',
14
- value: '2023',
15
- isCommonUse: true,
16
- },
17
- {
18
- name: '2024',
19
- value: '2024',
20
- isCommonUse: true,
21
- },
22
- ]
23
- },
24
- {
25
- propertyCode: 'season',
26
- propertyName: '季节',
27
- isCommonUse: true,
28
- detailList: [
29
- {
30
- name: '春',
31
- value: '1',
32
- isCommonUse: true,
33
- },
34
- {
35
- name: '夏',
36
- value: '2',
37
- isCommonUse: true,
38
- },
39
- {
40
- name: '秋',
41
- value: '3',
42
- isCommonUse: true,
43
- },
44
- {
45
- name: '冬',
46
- value: '4',
47
- isCommonUse: true,
48
- },
49
- ]
50
- },
51
- {
52
- propertyCode: 'color',
53
- propertyName: '色号',
54
- isCommonUse: true,
55
- detailList: [
56
- {
57
- name: '赤',
58
- value: '1',
59
- isCommonUse: true,
60
- },
61
- {
62
- name: '橙',
63
- value: '2',
64
- isCommonUse: true,
65
- },
66
- {
67
- name: '红',
68
- value: '3',
69
- isCommonUse: true,
70
- },
71
- {
72
- name: '绿',
73
- value: '4',
74
- isCommonUse: true,
75
- },
76
- {
77
- name: '青',
78
- value: '5',
79
- isCommonUse: true,
80
- },
81
- {
82
- name: '蓝',
83
- value: '6',
84
- isCommonUse: true,
85
- },
86
- {
87
- name: '紫',
88
- value: '7',
89
- isCommonUse: true,
90
- },
91
- {
92
- name: '橘红',
93
- value: '8',
94
- isCommonUse: false,
95
- },
96
- {
97
- name: '天蓝',
98
- value: '9',
99
- isCommonUse: false,
100
- },
101
- {
102
- name: '银白',
103
- value: '10',
104
- isCommonUse: false,
105
- },
106
- {
107
- name: '紫',
108
- value: '11',
109
- isCommonUse: false,
110
- },
111
- ]
112
- },
113
- {
114
- propertyCode: 'brandCode',
115
- propertyName: '品牌',
116
- isCommonUse: false,
117
- detailList: [
118
- {
119
- name: '品牌2',
120
- value: '2',
121
- isCommonUse: true,
122
- },
123
- {
124
- name: '品牌3',
125
- value: '3',
126
- isCommonUse: true,
127
- },
128
- {
129
- name: '品牌4',
130
- value: '4',
131
- isCommonUse: true,
132
- },
133
-
134
- ]
135
- },
136
- {
137
- propertyCode: 'size',
138
- propertyName: '尺码',
139
- isCommonUse: false,
140
- detailList: [
141
- {
142
- name: 'M',
143
- value: '2',
144
- isCommonUse: true,
145
- },
146
- {
147
- name: 'L',
148
- value: '3',
149
- isCommonUse: true,
150
- },
151
- {
152
- name: 'XL',
153
- value: '4',
154
- isCommonUse: true,
155
- },
156
-
157
- ]
158
- },
159
-
160
- ]
@@ -1,205 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import { Checkbox } from 'antd';
3
- import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons';
4
- import './index.less';
5
- import { set } from "lodash";
6
-
7
- interface PropertyItem {
8
- name: string;
9
- value: string;
10
- isChecked: boolean;
11
- isCommonUse: boolean;
12
- }
13
-
14
- interface propertyInfoProps {
15
- propertyName: string;
16
- propertyCode: string;
17
- detailList: Array<PropertyItem>;
18
- }
19
-
20
- const PropertyGroup = (props: any) => {
21
-
22
- const {
23
- propertyData,
24
- handleProperyItemChange,
25
- modalVisilbe,
26
- itemValue,
27
- } = props;
28
- const [commonUseProperty, setCommonUseProperty] = useState<Array<PropertyItem> | any>([]); // 常用属性值
29
- const [notCommonUseProperty, setNotCommonUseProperty] = useState<Array<PropertyItem> | any>([]); // 非常用属性值
30
- const [indeterminate, setIndeterminate] = useState(false);
31
- const [showNotCommon, setShowNotCommon] = useState(false);
32
-
33
- useEffect(() => {
34
- const proItemValue = (itemValue.propertyList || []).find((item: any) => item.propertyCode === propertyData.propertyCode);
35
- const checkedList = proItemValue?.detailList || [];
36
-
37
- const proDetailList = JSON.parse(JSON.stringify( propertyData?.detailList || []));
38
- proDetailList.forEach((item: any) => {
39
- if (checkedList.some((checkItem: any) => checkItem.value === item.value)){
40
- item.isChecked = true;
41
- }
42
- });
43
- const commonUseProperty = (proDetailList).filter((item: any) => item.isCommonUse);
44
-
45
- const notCommonUseProperty = (proDetailList).filter((item: any) => !item.isCommonUse);
46
- if (checkedList.some((item: any) => !item.isCommonUse)) {
47
- setShowNotCommon(true)
48
- }
49
- setCommonUseProperty(commonUseProperty);
50
- setNotCommonUseProperty(notCommonUseProperty);
51
- }, [modalVisilbe])
52
-
53
- const parseDataToParent = (comUse: any[], notComUse: any[]) => {
54
- let choosedPropertyList = (comUse|| []).filter(item => item.isChecked);
55
- if (showNotCommon) {
56
- choosedPropertyList = [...choosedPropertyList, ...((notComUse|| []).filter(item => item.isChecked))]
57
- }
58
- handleProperyItemChange({
59
- propertyCode: propertyData?.propertyCode,
60
- propertyName: propertyData?.propertyName,
61
- propertyId: propertyData?.propertyId,
62
- isCommonUse: propertyData?.isCommonUse,
63
- detailList: choosedPropertyList
64
- });
65
- }
66
-
67
-
68
- const handleChangeAll = (e: any) => {
69
- if (showNotCommon) {
70
- notCommonUseProperty.map((item: any) => item.isChecked = e.target.checked);
71
- setNotCommonUseProperty([...notCommonUseProperty])
72
- }
73
- commonUseProperty.map((item: any) => item.isChecked = e.target.checked);
74
- parseDataToParent(commonUseProperty, notCommonUseProperty)
75
- setCommonUseProperty([...commonUseProperty])
76
- setIndeterminate(false)
77
- }
78
-
79
- const handleIndeterminate = (commonUseProperty: any[], notCommonUseProperty: any[]) => {
80
- let checkList = [...commonUseProperty];
81
- if (showNotCommon) {
82
- checkList = [...checkList, ...notCommonUseProperty]
83
- }
84
- const indeterminate = !!checkList.filter(item => item.isChecked).length && checkList.filter(item => item.isChecked).length !== checkList.length;
85
- setIndeterminate(indeterminate);
86
- }
87
-
88
- const handleItemChecked = (e: any, item: any, type: number) => {
89
- if (type === 1) { // 常用属性
90
- (commonUseProperty || []).forEach((info: any) => {
91
- if (info.value === item.value) {
92
- info.isChecked = e.target.checked;
93
- }
94
- })
95
- handleIndeterminate(commonUseProperty, notCommonUseProperty)
96
- parseDataToParent(commonUseProperty, notCommonUseProperty)
97
- setCommonUseProperty([...commonUseProperty])
98
- }
99
-
100
- if (type === 2) { // 非常用属性
101
- (notCommonUseProperty || []).forEach((info: any) => {
102
- if (info.value === item.value) {
103
- info.isChecked = e.target.checked;
104
- }
105
- })
106
- handleIndeterminate(commonUseProperty, notCommonUseProperty)
107
- parseDataToParent(commonUseProperty, notCommonUseProperty)
108
- setNotCommonUseProperty([...notCommonUseProperty])
109
- }
110
- }
111
-
112
- const checkAllChecked = () => {
113
- const checkData = showNotCommon ? [...commonUseProperty, ...notCommonUseProperty] : [...commonUseProperty];
114
- return checkData.length && checkData.every(item => item.isChecked) ? true : false;
115
- }
116
-
117
-
118
- return (
119
- <div className={'propertyGroup_container'}>
120
- <div className={'propertyGroup_container_left'}>
121
- <Checkbox
122
- checked={checkAllChecked()}
123
- indeterminate={indeterminate}
124
- onChange={handleChangeAll}
125
- >
126
- <div title={propertyData.name} className="propertyGroup_checkbox_container">{propertyData.propertyName}</div>
127
- </Checkbox>
128
- </div>
129
- <div className={'propertyGroup_container_right'}>
130
- {
131
- (commonUseProperty || []).map((item: any) => (
132
- <Checkbox
133
- checked={item.isChecked}
134
- key={item.value}
135
- onChange={(e) => {
136
- handleItemChecked(e, item, 1)
137
- }}
138
- >
139
- <div title={item.name} className="propertyGroup_checkbox_container">
140
- {item.name}
141
- </div>
142
- </Checkbox>
143
- ))
144
-
145
- }
146
- {
147
- showNotCommon && (notCommonUseProperty || []).map((item: any) => (
148
- <Checkbox
149
- checked={item.isChecked}
150
- key={item.value}
151
- onChange={(e) => {
152
- handleItemChecked(e, item, 2)
153
- }}
154
- >
155
- <div title={item.name} className="propertyGroup_checkbox_container">
156
- {item.name}
157
- </div>
158
- </Checkbox>
159
- ))
160
-
161
- }
162
- {
163
- !!notCommonUseProperty.length && (
164
- <div
165
- style={{
166
- width: '50px',
167
- cursor: 'pointer',
168
- color: '#005cff',
169
- fontSize: '10px',
170
- display: 'flex',
171
- alignItems: 'center',
172
- }}
173
- onClick={() => {
174
- setShowNotCommon(!showNotCommon);
175
- handleIndeterminate(commonUseProperty, notCommonUseProperty)
176
- }}
177
- >
178
- {
179
- showNotCommon && (
180
- <>
181
- <CaretUpOutlined />
182
- 收起
183
- </>
184
- )
185
- }
186
- {
187
- !showNotCommon && (
188
- <>
189
- <CaretDownOutlined />
190
- 展开
191
- </>
192
- )
193
- }
194
- </div>
195
- )
196
- }
197
- </div>
198
- </div>
199
- );
200
- };
201
-
202
- export default React.memo(PropertyGroup, (props, nextProps) => {
203
- if (props.modalVisilbe !== nextProps.modalVisilbe) return false;
204
- return true;
205
- });