@digitalc/drm-dxp-package 0.0.6 → 0.0.7

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,495 @@
1
+ import React from 'react';
2
+ import { formatLocalMessage } from '@utils/utils';
3
+ import { useSelector, useDispatch } from 'react-redux';
4
+ import moment from 'moment';
5
+ import { Form, Input, Row, Col, Select, Tooltip, Icon } from '@whalecloud/fdx';
6
+ import { PARTNER_STATUS, PARTNER_HIERARCHY_STATUS, DATE_TABLE_FORMAT, DEFAULT_DATE_TABLE_FORMAT } from '@/constants';
7
+ import { validatorRule } from '@/utils/getRule';
8
+ import ParentSelect from '../ParentSelect';
9
+ import styles from './index.module.less';
10
+
11
+ const { Option } = Select;
12
+ const BasicInfo = props => {
13
+ const dispatch = useDispatch();
14
+ const { form: { getFieldDecorator, setFieldsValue, getFieldValue, setFields }, isNew } = props;
15
+ const { DRM_DATETIME_FORMAT_UI_NEW = DATE_TABLE_FORMAT } = useSelector(state => state.esalesCommom);
16
+ const {
17
+ partnerStatus, orgBaseInfoDetails = {}, channelTypeList = [], selectedOwner = {},
18
+ subBaseInfoData = {}, orgRegTypes = [],
19
+ basicInfoCom = [], ownerInformationError = {},
20
+ } = useSelector(state => state.partner360);
21
+ const [formDisabled, setFormDisabled] = React.useState(true);
22
+ const [infoData, setInfoData] = React.useState({});
23
+ const [brnPattern, setBrnPattern] = React.useState('');
24
+ const [taxCodeList, setTaxCodeList] = React.useState([]);
25
+ const [regNumData, setRegNumData] = React.useState({});
26
+
27
+ const ruleList = basicInfoCom.find(item => item.componentCode === 'COMMON_PARTNER_BRN')?.componentValidateRuleList || [];
28
+ const serveUrl = ruleList?.find(item => item.validateType === 'S')?.validateRule;
29
+ const ruleBrn = ruleList.find(item => item.validateType === 'R')?.validateRule || '';
30
+
31
+ React.useEffect(() => {
32
+ setInfoData(isNew ? subBaseInfoData : orgBaseInfoDetails);
33
+ }, [JSON.stringify(subBaseInfoData), JSON.stringify(orgBaseInfoDetails)]);
34
+
35
+ React.useEffect(() => {
36
+ if (selectedOwner?.orgSubtype) {
37
+ dispatch({
38
+ type: 'partner360/qryChannelTypeByParentId',
39
+ payload: { channelTypeCode: selectedOwner?.orgSubtype },
40
+ });
41
+ }
42
+ dispatch({
43
+ type: 'partner360/save',
44
+ payload: {
45
+ orgSubtype: infoData.orgSubtype,
46
+ },
47
+ });
48
+ dispatch({
49
+ type: 'partner360/qryTaxCode',
50
+ }).then(res => {
51
+ setTaxCodeList(res);
52
+ });
53
+ }, [selectedOwner?.orgSubtype]);
54
+
55
+ React.useEffect(() => {
56
+ if (partnerStatus === PARTNER_STATUS.NEW && getFieldValue('orgSubtype')) {
57
+ dispatch({
58
+ type: 'partner360/queryFormConfigList',
59
+ payload: getFieldValue('orgSubtype') ?? '',
60
+ });
61
+ }
62
+ if (orgBaseInfoDetails?.orgSubtype) {
63
+ dispatch({
64
+ type: 'partner360/queryFormConfigList',
65
+ payload: orgBaseInfoDetails?.orgSubtype ?? '',
66
+ });
67
+ }
68
+ }, [getFieldValue('orgSubtype'), orgBaseInfoDetails?.orgSubtype]);
69
+
70
+ React.useEffect(() => {
71
+ switch (partnerStatus) {
72
+ case PARTNER_STATUS.DETAIL:
73
+ setFormDisabled(true);
74
+ break;
75
+ default:
76
+ setFormDisabled(false);
77
+ }
78
+ }, [partnerStatus]);
79
+
80
+ React.useEffect(() => {
81
+ dispatch({
82
+ type: 'partner360/qryRegType',
83
+ });
84
+ }, []);
85
+
86
+ const qryComponent = async data => {
87
+ const resp = await dispatch({
88
+ type: 'partner360/componentCheck',
89
+ payload: {
90
+ serveUrl,
91
+ data,
92
+ },
93
+ });
94
+ dispatch({
95
+ type: 'partner360/save',
96
+ payload: {
97
+ ownerInformationError: {
98
+ ...ownerInformationError,
99
+ [data?.key]: {
100
+ message: resp?.code === '200' ? '' : resp?.message || formatLocalMessage('SYSTEM_ERROR'),
101
+ },
102
+ },
103
+ },
104
+ });
105
+ if (resp?.code !== '200') {
106
+ return {
107
+ validateStatus: 'error',
108
+ help: resp?.message,
109
+ };
110
+ }
111
+ return {
112
+ validateStatus: 'success',
113
+ help: null,
114
+ };
115
+ };
116
+
117
+ const changeRegNbr = async (val, ruleAll, isQry, rule) => {
118
+ const msg = validatorRule(val, ruleAll || brnPattern, 'ESALES_ITEM_RULES_BRN_TIPS', false, rule);
119
+ setRegNumData(msg);
120
+ if (msg?.validateStatus === 'error') {
121
+ return;
122
+ }
123
+ const data = { key: 'regNum', regNum: val, regType: getFieldValue('regType'), orgId: orgBaseInfoDetails.orgId };
124
+ if (!isQry) {
125
+ dispatch({
126
+ type: 'partner360/save',
127
+ payload: {
128
+ ownerInformationError: {
129
+ ...ownerInformationError,
130
+ regNum: {
131
+ serveUrl,
132
+ data,
133
+ },
134
+ },
135
+ },
136
+ });
137
+ }
138
+ if (isQry && serveUrl) {
139
+ const qryMsg = await qryComponent(data);
140
+ setRegNumData(qryMsg);
141
+ }
142
+ };
143
+
144
+ const handleParentModalShow = () => {
145
+ dispatch({
146
+ type: 'partner360/save',
147
+ payload: {
148
+ parentModalVisible: true,
149
+ },
150
+ });
151
+ };
152
+
153
+ const clearOrgSubtype = () => {
154
+ setFieldsValue({
155
+ orgSubtype: null,
156
+ });
157
+ };
158
+
159
+ const handleChangeChannelType = val => {
160
+ setFieldsValue({
161
+ orgSubtype: val,
162
+ });
163
+ };
164
+
165
+ const handleChangeRegType = async val => {
166
+ const brnValue = getFieldValue('regNum');
167
+ setFieldsValue({
168
+ regType: val,
169
+ });
170
+ if (ruleBrn) {
171
+ const brnPatterns = {};
172
+ ruleBrn.split('|').forEach(item => {
173
+ const key = item.split('=')[0];
174
+ const value = item.split('=')[1];
175
+ brnPatterns[key] = value;
176
+ });
177
+ const currentBrnPatt = brnPatterns[val];
178
+ setBrnPattern(currentBrnPatt);
179
+ setFields({
180
+ regNum: {
181
+ value: brnValue,
182
+ },
183
+ });
184
+ changeRegNbr(brnValue, null, true, currentBrnPatt);
185
+ }
186
+ };
187
+ const colConfig = {
188
+ sm: 8,
189
+ xs: 24,
190
+ };
191
+
192
+ const FORM_LIST = {
193
+ COMMON_PARTNER_PARENT: selectedOwner?.orgName ? {
194
+ index: 1,
195
+ components: com => (
196
+ <Col {...colConfig}>
197
+ <Form.Item label={formatLocalMessage('PARTNER_PARENT')}>
198
+ {getFieldDecorator('parentOrgId', {
199
+ initialValue: selectedOwner?.orgName,
200
+ rules: [
201
+ {
202
+ required: com.required === 'Y',
203
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
204
+ },
205
+ ],
206
+ })(
207
+ <Input
208
+ disabled={formDisabled || com.editable !== 'Y'}
209
+ placeholder={formatLocalMessage('TRANSFER_DESTINATION')}
210
+ readonly="readonly"
211
+ suffix={<span className="iconfont icon-ic_nav_expand" onClick={handleParentModalShow} />}
212
+ onClick={handleParentModalShow}
213
+ className={styles.orgInput}
214
+ />)}
215
+ </Form.Item>
216
+ </Col>
217
+ ),
218
+ } : {
219
+ index: 1,
220
+ components: () => {},
221
+ },
222
+ COMMON_PARTNER_NAME: {
223
+ index: 2,
224
+ components: com => (
225
+ <Col {...colConfig}>
226
+ <Form.Item label={formatLocalMessage('PARTNER_NAME')}>
227
+ {getFieldDecorator('orgName', {
228
+ initialValue: infoData?.orgName || null,
229
+ rules: [
230
+ {
231
+ required: com.required === 'Y',
232
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
233
+ },
234
+ ],
235
+ })(<Input
236
+ maxLength={100}
237
+ allowClear
238
+ placeholder={formatLocalMessage('COMMON_PLEASE_INPUT')}
239
+ disabled={formDisabled || com.editable !== 'Y'}
240
+ />)}
241
+ </Form.Item>
242
+ </Col>
243
+ ),
244
+ },
245
+ COMMON_PARTNER_CODE: {
246
+ index: 3,
247
+ components: com => (
248
+ <Col {...colConfig}>
249
+ <Form.Item label={formatLocalMessage('PARTNER_CODE')}>
250
+ {getFieldDecorator('orgCode', {
251
+ initialValue: infoData?.orgCode || null,
252
+ rules: [
253
+ {
254
+ required: com.required === 'Y',
255
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
256
+ },
257
+ ],
258
+ })(<Input disabled={formDisabled || com.editable !== 'Y'} />)}
259
+ </Form.Item>
260
+ </Col>
261
+ ),
262
+ },
263
+ COMMON_PARTNER_CATEGORY: {
264
+ index: 4,
265
+ components: com => (
266
+ <Col {...colConfig}>
267
+ <Form.Item label={formatLocalMessage('PARTNER_CATEGORY')}>
268
+ {getFieldDecorator('channelCategoryName', {
269
+ initialValue: selectedOwner?.channelCategoryName || infoData?.channelCategoryName || null,
270
+ rules: [
271
+ {
272
+ required: com.required === 'Y',
273
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
274
+ },
275
+ ],
276
+ })(<Input disabled={formDisabled || com.editable !== 'Y'} />)}
277
+ </Form.Item>
278
+ </Col>
279
+ ),
280
+ },
281
+ COMMON_PARTNER_TYPE: {
282
+ index: 5,
283
+ components: com => (
284
+ <Col {...colConfig}>
285
+ <Form.Item label={formatLocalMessage('PARTNER_TYPE')}>
286
+ {getFieldDecorator('orgSubtype', {
287
+ initialValue: (
288
+ partnerStatus === PARTNER_STATUS.NEW
289
+ ? infoData?.orgSubtype || channelTypeList[0]?.channelTypeCode
290
+ : infoData?.orgSubtypeName
291
+ ),
292
+ rules: [
293
+ {
294
+ required: com.required === 'Y',
295
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
296
+ },
297
+ ],
298
+ })(
299
+ <Select
300
+ onChange={handleChangeChannelType}
301
+ allowClear
302
+ placeholder={formatLocalMessage('COMMON_PLEASE_SELECT')}
303
+ disabled={formDisabled || com.editable !== 'Y'}
304
+ >
305
+ {channelTypeList.map((item, index) => (
306
+ <Option value={item.channelTypeCode} key={index}>
307
+ {item.channelTypeName}
308
+ </Option>
309
+ ))}
310
+ </Select>,
311
+ )}
312
+ </Form.Item>
313
+ </Col>
314
+ ),
315
+ },
316
+ COMMON_PARTNER_REGISTRATION_TYPE: {
317
+ index: 6,
318
+ components: com => (
319
+ <Col {...colConfig}>
320
+ <Form.Item label={formatLocalMessage('PARTNER_REGISTER_TYPE')}>
321
+ {getFieldDecorator('regType', {
322
+ initialValue: infoData?.regType || null,
323
+ rules: [
324
+ {
325
+ required: com.required === 'Y',
326
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
327
+ },
328
+ ],
329
+ })(
330
+ <Select
331
+ onChange={handleChangeRegType}
332
+ placeholder={formatLocalMessage('COMMON_PLEASE_SELECT')}
333
+ allowClear
334
+ disabled={formDisabled || com.editable !== 'Y'}
335
+ >
336
+ {orgRegTypes.map(item => (
337
+ <Option value={item.value} key={item.configValueId}>
338
+ {item.displayName}
339
+ </Option>
340
+ ))}
341
+ </Select>
342
+ )}
343
+ </Form.Item>
344
+ </Col>
345
+ ),
346
+ },
347
+ COMMON_PARTNER_BRN: {
348
+ index: 7,
349
+ components: com => (
350
+ <Col {...colConfig}>
351
+ <Form.Item
352
+ validateStatus={regNumData.validateStatus}
353
+ help={regNumData.help}
354
+ label={(
355
+ <>
356
+ {formatLocalMessage('PARTNER_BRN')}
357
+ <Tooltip trigger="hover/click" title={formatLocalMessage('ESALES_ITEM_RULES_BRN_TIPS')}>
358
+ <Icon className="form-item-required-label-tips" type="info-circle" theme="filled" />
359
+ </Tooltip>
360
+ </>
361
+ )}
362
+ >
363
+ {getFieldDecorator('regNum', {
364
+ initialValue: infoData?.regNum || null,
365
+ rules: [
366
+ {
367
+ required: com.required === 'Y',
368
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
369
+ },
370
+ {
371
+ pattern: brnPattern,
372
+ message: formatLocalMessage('ESALES_ITEM_RULES_BRN_TIPS'),
373
+ },
374
+ ],
375
+ })(<Input
376
+ maxLength={20}
377
+ allowClear
378
+ placeholder={formatLocalMessage('COMMON_PLEASE_INPUT')}
379
+ disabled={formDisabled || com.editable !== 'Y'}
380
+ onChange={e => changeRegNbr(e.target.value, com)}
381
+ onBlur={e => changeRegNbr(e.target.value, com, true)}
382
+ />)}
383
+ </Form.Item>
384
+ </Col>
385
+ ),
386
+ },
387
+ COMMON_PARTNER_STATUS: {
388
+ index: 8,
389
+ components: com => (
390
+ <Col {...colConfig}>
391
+ <Form.Item label={formatLocalMessage('PARTNER_STATUS')}>
392
+ {getFieldDecorator('statusCd', {
393
+ initialValue: PARTNER_HIERARCHY_STATUS[infoData?.statusCd]?.label || null,
394
+ rules: [
395
+ {
396
+ required: com.required === 'Y',
397
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
398
+ },
399
+ ],
400
+ })(<Input disabled={formDisabled || com.editable !== 'Y'} />)}
401
+ </Form.Item>
402
+ </Col>
403
+ ),
404
+ },
405
+ COMMON_PARTNER_CREATED_DATE: {
406
+ index: 9,
407
+ components: com => (
408
+ <Col {...colConfig}>
409
+ <Form.Item label={formatLocalMessage('PARTNER_CREATED_DATE')}>
410
+ {getFieldDecorator('createDate', {
411
+ initialValue: (
412
+ infoData?.createDate && moment(infoData?.createDate, DEFAULT_DATE_TABLE_FORMAT).format(DRM_DATETIME_FORMAT_UI_NEW)
413
+ ) || null,
414
+ rules: [
415
+ {
416
+ required: com.required === 'Y',
417
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
418
+ },
419
+ ],
420
+ })(<Input disabled={formDisabled || com.editable !== 'Y'} />)}
421
+ </Form.Item>
422
+ </Col>
423
+ ),
424
+ },
425
+ COMMON_PARTNER_TAX_CODE: {
426
+ index: 10,
427
+ components: com => (
428
+ <Col {...colConfig}>
429
+ <Form.Item label={formatLocalMessage('PARTNER_TAX_CODE')}>
430
+ {getFieldDecorator('taxCode', {
431
+ initialValue: infoData?.taxCode || null,
432
+ rules: [
433
+ {
434
+ required: com.required === 'Y',
435
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
436
+ },
437
+ ],
438
+ })(
439
+ <Select
440
+ allowClear
441
+ placeholder={formatLocalMessage('COMMON_PLEASE_SELECT')}
442
+ disabled={formDisabled || com.editable !== 'Y'}
443
+ >
444
+ {taxCodeList.map(item => (
445
+ <Option value={item.value} key={item.configValueId}>
446
+ {item.displayName}
447
+ </Option>
448
+ ))}
449
+ </Select>
450
+ )}
451
+ </Form.Item>
452
+ </Col>
453
+ ),
454
+ },
455
+ COMMON_PARTNER_TIN_ID: {
456
+ index: 11,
457
+ components: com => (
458
+ <Col {...colConfig}>
459
+ <Form.Item
460
+ label={formatLocalMessage('PARTNER_TIN_ID')}
461
+ >
462
+ {getFieldDecorator('tinId', {
463
+ initialValue: infoData?.tinId || null,
464
+ rules: [
465
+ {
466
+ required: com.required === 'Y',
467
+ message: formatLocalMessage('ESALES_ITEM_IS_REQUIRED'),
468
+ },
469
+ ],
470
+ })(<Input maxLength={60} disabled={formDisabled || com.editable !== 'Y'} placeholder={formatLocalMessage('COMMON_PLEASE_INPUT')} />)}
471
+ </Form.Item>
472
+ </Col>
473
+ ),
474
+ },
475
+ };
476
+
477
+ return (
478
+ <>
479
+ <div className="secondary-title">{formatLocalMessage('PARTNER_BASIC_INFORMATION')}</div>
480
+ <div className={styles.formContainer}>
481
+ <Row gutter={24}>
482
+ {basicInfoCom.map((item, index) => {
483
+ if ((index + 1) % 3 === 0) {
484
+ return <>{FORM_LIST?.[item.componentCode]?.components(item)}<div style={{ clear: 'both' }} /></>;
485
+ }
486
+ return FORM_LIST?.[item.componentCode]?.components(item);
487
+ })}
488
+ </Row>
489
+ <ParentSelect clearOrgSubtype={clearOrgSubtype} />
490
+ </div>
491
+ </>
492
+ );
493
+ };
494
+
495
+ export default BasicInfo;
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import { useDispatch, useSelector } from 'react-redux';
3
+ import isEmpty from 'lodash/isEmpty';
4
+ import { formatLocalMessage } from '@utils/utils';
5
+ import { EModal, OrgSelect } from '@/components';
6
+ import IMessage from '@/utils/IMessage';
7
+ import styles from './index.module.less';
8
+
9
+ const ParentSelect = prprs => {
10
+ const { clearOrgSubtype } = prprs;
11
+ const dispatch = useDispatch();
12
+ const { parentModalVisible, activeRow } = useSelector(state => state.partner360);
13
+
14
+ const handleOwnerModalClose = () => {
15
+ dispatch({
16
+ type: 'partner360/save',
17
+ payload: {
18
+ parentModalVisible: false,
19
+ },
20
+ });
21
+ };
22
+
23
+ const handleSelect = () => {
24
+ if (isEmpty(activeRow)) {
25
+ IMessage.error(formatLocalMessage('REQUEST_PLEASE_SELECT_ONE_ROW'));
26
+ return;
27
+ }
28
+ dispatch({
29
+ type: 'partner360/save',
30
+ payload: {
31
+ selectedOwner: activeRow,
32
+ },
33
+ });
34
+ clearOrgSubtype();
35
+ handleOwnerModalClose();
36
+ };
37
+
38
+ const handleRowDBClick = row => {
39
+ dispatch({
40
+ type: 'partner360/save',
41
+ payload: {
42
+ selectedOwner: row,
43
+ },
44
+ });
45
+ clearOrgSubtype();
46
+ handleOwnerModalClose();
47
+ };
48
+
49
+ const modalProps = {
50
+ className: styles.parentSelectModal,
51
+ closable: true,
52
+ title: 'Parent',
53
+ width: '80%',
54
+ visible: parentModalVisible,
55
+ okText: 'Select',
56
+ onOk: handleSelect,
57
+ onCancel: handleOwnerModalClose,
58
+ };
59
+
60
+ return (
61
+ <EModal modalProps={{ ...modalProps }}>
62
+ <OrgSelect ownNamespace="partner360" onRowDBClick={handleRowDBClick} modalVisible={parentModalVisible} />
63
+ </EModal>
64
+ );
65
+ };
66
+
67
+ export default ParentSelect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalc/drm-dxp-package",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "files": [