@bit-sun/business-component 4.0.12-alpha.21 → 4.0.12-alpha.23

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.
@@ -0,0 +1,205 @@
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
+ });
@@ -296,7 +296,8 @@ export function commonFun (type?: string, prefixUrl: any, parentProps?:any) {
296
296
  // 商品选择器sku
297
297
  if(type === 'skuCommodity') {
298
298
  requestConfig = {
299
- url: `${prefixUrl.selectPrefix}/sku/doPageBySelect/v3`,
299
+ url: `${prefixUrl.selectPrefix}/sku/doPageBySelect/v4`,
300
+ method: 'post',
300
301
  filter: 'skuCodeAndSkuName', // 过滤参数
301
302
  searchStartLength: 4,
302
303
  mappingTextField: 'name',
@@ -366,6 +367,9 @@ export function commonFun (type?: string, prefixUrl: any, parentProps?:any) {
366
367
  dropdownStyle: { maxHeight: 400, maxWidth: 100, overflow: 'auto' }
367
368
  },
368
369
  } },
370
+ { name: 'UNIQUE_SPEC', label: '属性', field: {
371
+ type: 'proppertySelector',
372
+ } },
369
373
  ]
370
374
  Promise.all([
371
375
  loadSelectSource(`${prefixUrl.formSelectFix}/brand/queryBrandList`, {
@@ -20,7 +20,7 @@
20
20
 
21
21
  .ant-select-dropdown {
22
22
  top: 24px !important;
23
- width: calc(150%) !important;
23
+ width: calc(141%) !important;
24
24
  }
25
25
 
26
26
  // 下拉框清除图标位置调整
@@ -37,7 +37,7 @@
37
37
  &_show.search_select_show_list {
38
38
  .ant-select-dropdown {
39
39
  top: 24px !important;
40
- width: calc(141%) !important;
40
+ width: calc(100% + 110px) !important;
41
41
  }
42
42
  }
43
43
 
@@ -11,6 +11,7 @@ import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
11
  import { handleSourceName, getFormRowInfo, hasMoreQueryFields, defaultVisibleFieldsCount, getRealStr, ColSpan, getTableHeigth, getCurrentSRKs, getRenderSource } from './utils';
12
12
  import { judgeIsRequestError } from '@/utils/requestUtils';
13
13
  import zhankaitiaojian from '../../../assets/zhankaitiaojian-icon.svg';
14
+ import PropertySelector from '@/components/Business/PropertyModal';
14
15
 
15
16
  const { Option } = Select;
16
17
 
@@ -180,7 +181,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
180
181
  }))
181
182
 
182
183
  // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
183
- const getData = (params = {}, type = 1,callback?: any) => {
184
+ const getData = (params = {}, type = 1,callback?: any, bodyParams?: any,) => {
184
185
  if (!requestConfig) return;
185
186
 
186
187
  setFetching(true)
@@ -327,10 +328,112 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
327
328
  if (isNil(queryParams[selectParamsKey])) {
328
329
  queryParams[selectParamsKey] = searchValue;
329
330
  }
331
+
332
+ if (requestConfig?.method === 'post') {
333
+ request
334
+ .post(
335
+ `${url}?${stringify(queryParams)}`,
336
+ bodyParams || null,)
337
+ .then((result: any) => {
338
+ setFetching(false)
339
+ result = result.data;
340
+ if (judgeIsRequestError(result)) {
341
+ message.error(result.msg);
342
+ return;
343
+ }
344
+ const res = result.data;
345
+ let source = [];
346
+ if (isMap) {
347
+ source = Object.keys(res).map((d, i) => {
348
+ return {
349
+ text: Object.values(res)[i],
350
+ value: d,
351
+ };
352
+ });
353
+ } else {
354
+ const keys = res.list ? 'list' : 'items';
355
+ source = res
356
+ ? res[keys]
357
+ ? res[keys].map((item: any, index: number) => {
358
+ let textShowText = item[mappingTextField]
359
+ if (mappingTextShowTextField) {
360
+ textShowText = []
361
+ if (Array.isArray(mappingTextShowTextField)) {
362
+ mappingTextShowTextField.forEach((r: any) => {
363
+ textShowText.push(item[r])
364
+ })
365
+ } else {
366
+ textShowText = item[mappingTextShowTextField]
367
+ }
368
+ }
369
+ if (!item?.children?.length) { delete item?.children };
370
+ return {
371
+ ...item,
372
+ text: specialBracket
373
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
374
+ : item[mappingTextField],
375
+ textShowText,
376
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
377
+ value: item[mappingValueField],
378
+ keyIndex: type != 1 ? ((queryParams?.currentPage - 1) * queryParams?.pageSize + index + 1) : (index + 1),
379
+ };
380
+ })
381
+ : Array.isArray(res) &&
382
+ res?.map((item: Record<string, any>, index: number) => {
383
+ let textShowText = item[mappingTextField]
384
+ if (mappingTextShowTextField) {
385
+ textShowText = []
386
+ if (Array.isArray(mappingTextShowTextField)) {
387
+ mappingTextShowTextField.forEach((r: any) => {
388
+ textShowText.push(item[r])
389
+ })
390
+ } else {
391
+ textShowText = item[mappingTextShowTextField]
392
+ }
393
+ }
394
+ if (!item?.children?.length) { delete item?.children };
395
+ return {
396
+ ...item,
397
+ text: specialBracket
398
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
399
+ : item[mappingTextField],
400
+ textShowText,
401
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
402
+ value: item[mappingValueField],
403
+ keyIndex: type != 1 ? ((queryParams?.currentPage - 1) * queryParams?.pageSize + index + 1) : (index + 1),
404
+ };
405
+ })
406
+ : [];
407
+ }
408
+ // 补充搜索项--选中的数据添加到数据源中去
409
+ const currentSRKs = getCurrentSRKs(selectMode, labelInValue, value)
410
+ if (type === 1 && currentSRKs?.length && currentSRKs?.some(s => !source?.find(r => r.value == s))) {
411
+ const selectedOption = items.filter(option => currentSRKs?.includes(option.value)) || [];
412
+ source = (source || []).concat(selectedOption)
413
+ }
414
+ // 数据源 不可以有重复key
415
+ source = Array.isArray(source) ? _.uniqBy(source, 'value') : [];
416
+
417
+ if (callback) {
418
+ callback(source)
419
+ } else {
420
+ if (type === 1) {
421
+ ctx?.form?.setFieldSource(resultSourceKey, source)
422
+ setSelectDataSource(source, (Number(res?.total || res?.totalCount || source.length)))
423
+ } else {
424
+ setTableData(source)
425
+ setTablePagination({ ...tablePagination, total: Number(res?.total || res?.totalCount || source.length), pageSize: Number(res?.size || res?.pageSize || (params?.pageSize || pageSize)), current: Number(res?.page || res?.currentPage || (params?.currentPage || currentPage)) })
426
+ }
427
+ }
428
+ })
429
+ .catch((err) => { setFetching(false) });
430
+ return;
431
+ }
432
+
433
+
330
434
  request
331
435
  .get(
332
- `${url}?${stringify(queryParams)}`,
333
- {
436
+ `${url}?${stringify(queryParams)}`, {
334
437
  headers: { ...extralHeaders }
335
438
  })
336
439
  .then((result: any) => {
@@ -635,9 +738,14 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
635
738
 
636
739
  // const isHaveParams = params && Object.keys(params).filter(item => params[item]).length > 0;
637
740
  setModalSearched(true);
741
+
742
+ let unique_params = null;
743
+ if (params['UNIQUE_SPEC']) {
744
+ unique_params = params['UNIQUE_SPEC']?.propertyList || [];
745
+ }
638
746
 
639
747
  setTableFormParams(params);
640
- getData({ ...params, pageSize: tableInitPageSize }, 2)
748
+ getData({ ...params, pageSize: tableInitPageSize }, 2, null, unique_params);
641
749
  }
642
750
 
643
751
  const onResetTable = () => {
@@ -817,6 +925,16 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
817
925
  </Col>
818
926
  );
819
927
  }
928
+ if (i?.field?.type === 'proppertySelector') {
929
+ return (
930
+ <Col span={ColSpan} key={i.name}>
931
+ <Form.Item name={i.name} label={i.label} key={i.name}>
932
+ <PropertySelector
933
+ />
934
+ </Form.Item>
935
+ </Col>
936
+ );
937
+ }
820
938
 
821
939
  // 默认type是input
822
940
  return (
@@ -893,10 +1011,10 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
893
1011
  { label: `已选(${selectedRowKeys?.length || 0})`, key: 'selected', children: renderShowTable(selectedRows?.map((s,index)=> ({...s,keyIndex:index+1}))||[],'noPage') },
894
1012
  ];
895
1013
 
896
- const resetSelectDataSource = () => {
1014
+ const resetSelectDataSource = (isClear=false) => {
897
1015
  setSearchValue('');
898
1016
  // 有关联值 不需要清空下拉框数据 也不需要重新去请求了
899
- if(isHaveDependency) return;
1017
+ if(!isClear && isHaveDependency) return; // 清空时需要放开:级联首次回之后,清空数据需要重新查询下拉框的值
900
1018
  clearSelectDataSource();
901
1019
  init && run('init')
902
1020
  }
@@ -908,7 +1026,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
908
1026
  formaData([], items);
909
1027
  onChangeSelectedKeys([], [])
910
1028
  // 重置下拉框数据源
911
- resetSelectDataSource();
1029
+ resetSelectDataSource(true);
912
1030
  }
913
1031
 
914
1032
  const onDeselect = (...arg) => {
package/src/index.ts CHANGED
@@ -35,6 +35,7 @@ export { default as JsonQueryTable } from './components/Business/JsonQueryTable'
35
35
  export { default as TableColumnSetting} from './plugin/TableColumnSetting';
36
36
  export { default as AuthButton } from './components/Functional/AuthButton';
37
37
  export { default as CustomSelector } from './components/Solution/RuleComponent/CustomPlugin/CustomSelector';
38
+ export { default as PropertySelector} from './components/Business/PropertyModal';
38
39
 
39
40
  export { default as EllipsisTooltip} from './components/Functional/EllipsisTooltip';
40
41
  export * from './components/Functional/BsAntdSula/index';