@pisell/private-materials 6.12.160 → 6.12.162
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.
- package/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/preview.js +1 -1
- package/build/lowcode/render/default/view.js +18 -18
- package/build/lowcode/view.js +18 -18
- package/es/components/bigSale/components/ProductList/index.js +30 -19
- package/es/components/bigSale/index.js +3 -3
- package/es/plus/saleDetail/components/CartItems/Editable/index.js +1 -0
- package/es/plus/salesSdk/context/SalesSdkCartContext.js +25 -12
- package/es/plus/salesSdk/context/SalesSdkProvider.js +9 -5
- package/es/plus/salesSdk/hosts/BookingEditHostRenderer.js +12 -7
- package/es/plus/salesSdk/utils/resolvePreviousService.js +28 -0
- package/es/plus/salesSdk/utils/runAddProductFlow.js +8 -4
- package/es/plus/skuOptionsSelection/components/NormalCard/index.js +18 -12
- package/es/plus/skuOptionsSelection/docs/skuOptionsSelection.$tab-dev.md +66 -2
- package/es/plus/skuOptionsSelection/types.d.ts +50 -1
- package/es/plus/skuOptionsSelection/utils/normalizers.js +17 -0
- package/es/plus/skuOptionsSelection/utils/transformOptionGroup.js +17 -7
- package/es/plus/skuOptionsSelection/utils/transformSelectorValueToValue.js +89 -15
- package/es/plus/skuOptionsSelection/utils/transformValueToSelectorValue.js +31 -19
- package/es/pro/Selector/Selector.js +11 -6
- package/es/pro/Selector/hooks/useSelectionController.js +54 -61
- package/es/pro/Selector/locales.js +10 -0
- package/es/pro/Selector/types.d.ts +5 -0
- package/es/pro/skuDetailModal/index.js +4 -4
- package/es/pro/skuDetailModal/types.d.ts +1 -0
- package/lib/components/bigSale/components/ProductList/index.js +30 -19
- package/lib/components/bigSale/index.js +3 -3
- package/lib/plus/saleDetail/components/CartItems/Editable/index.js +1 -0
- package/lib/plus/salesSdk/context/SalesSdkCartContext.js +25 -12
- package/lib/plus/salesSdk/context/SalesSdkProvider.js +9 -5
- package/lib/plus/salesSdk/hosts/BookingEditHostRenderer.js +12 -7
- package/lib/plus/salesSdk/utils/resolvePreviousService.js +30 -0
- package/lib/plus/salesSdk/utils/runAddProductFlow.js +8 -4
- package/lib/plus/skuOptionsSelection/components/NormalCard/index.js +18 -12
- package/lib/plus/skuOptionsSelection/docs/skuOptionsSelection.$tab-dev.md +66 -2
- package/lib/plus/skuOptionsSelection/types.d.ts +50 -1
- package/lib/plus/skuOptionsSelection/utils/normalizers.js +19 -0
- package/lib/plus/skuOptionsSelection/utils/transformOptionGroup.js +17 -7
- package/lib/plus/skuOptionsSelection/utils/transformSelectorValueToValue.js +89 -15
- package/lib/plus/skuOptionsSelection/utils/transformValueToSelectorValue.js +31 -19
- package/lib/pro/Selector/Selector.js +11 -6
- package/lib/pro/Selector/hooks/useSelectionController.js +54 -61
- package/lib/pro/Selector/locales.js +10 -0
- package/lib/pro/Selector/types.d.ts +5 -0
- package/lib/pro/skuDetailModal/index.js +4 -4
- package/lib/pro/skuDetailModal/types.d.ts +1 -0
- package/package.json +3 -3
|
@@ -15,7 +15,7 @@ category: plus
|
|
|
15
15
|
## 2. 版本
|
|
16
16
|
|
|
17
17
|
**当前版本**: `1.0.0`
|
|
18
|
-
**最后更新**:
|
|
18
|
+
**最后更新**: 2026-08-12
|
|
19
19
|
|
|
20
20
|
## 3. 相关文档
|
|
21
21
|
|
|
@@ -51,6 +51,10 @@ SKUOptionsSelection
|
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
export interface DataSource {
|
|
54
|
+
/** 商品id */
|
|
55
|
+
id?: number;
|
|
56
|
+
/** 生产编码 */
|
|
57
|
+
production_code?: string;
|
|
54
58
|
/** 单规格组数据 */
|
|
55
59
|
option_group?: Array<OptionGroupItem>;
|
|
56
60
|
/** 组合规格组装后的数据 */
|
|
@@ -58,7 +62,17 @@ export interface DataSource {
|
|
|
58
62
|
/** 组合规格组数据 */
|
|
59
63
|
variant_group?: Array<VariantGroupItem>;
|
|
60
64
|
/** 套餐商品组数据 */
|
|
61
|
-
bundle_group?: Array<
|
|
65
|
+
bundle_group?: Array<BundleGroupItem>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface OptionGroupMetadata {
|
|
69
|
+
advanced_settings_enabled?: 0 | 1;
|
|
70
|
+
option_types_config?: {
|
|
71
|
+
min?: number;
|
|
72
|
+
max?: number;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
};
|
|
75
|
+
[key: string]: unknown;
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
/**
|
|
@@ -88,6 +102,8 @@ export interface OptionGroupItem {
|
|
|
88
102
|
max_quantity?: number;
|
|
89
103
|
/** 最小选择数量 */
|
|
90
104
|
min_quantity?: number;
|
|
105
|
+
/** 高级设置元数据 */
|
|
106
|
+
metadata?: OptionGroupMetadata;
|
|
91
107
|
/** 单规格组名称 */
|
|
92
108
|
name?: string;
|
|
93
109
|
/** 单规格组下规格数据 */
|
|
@@ -133,6 +149,8 @@ export interface OptionItem {
|
|
|
133
149
|
is_enabled?: 0 | 1;
|
|
134
150
|
/** 最大选择数量 */
|
|
135
151
|
max_quantity?: number;
|
|
152
|
+
/** 最小选择数量 */
|
|
153
|
+
min_quantity?: number;
|
|
136
154
|
/** 规格名称 */
|
|
137
155
|
name?: string;
|
|
138
156
|
/** 规格组id */
|
|
@@ -141,6 +159,8 @@ export interface OptionItem {
|
|
|
141
159
|
original_price?: string;
|
|
142
160
|
/** 商品id */
|
|
143
161
|
product_id?: number;
|
|
162
|
+
/** 生产编码 */
|
|
163
|
+
production_code?: string;
|
|
144
164
|
/** 店铺id */
|
|
145
165
|
shop_id?: number;
|
|
146
166
|
/** 排序 */
|
|
@@ -268,6 +288,8 @@ export interface VariantProductItem {
|
|
|
268
288
|
price?: string;
|
|
269
289
|
/** 商品id */
|
|
270
290
|
product_id?: number;
|
|
291
|
+
/** 生产编码 */
|
|
292
|
+
production_code?: string;
|
|
271
293
|
/** 折扣类型 */
|
|
272
294
|
rebate_type?: string;
|
|
273
295
|
/** 折扣值 */
|
|
@@ -350,6 +372,8 @@ export interface BundleItem {
|
|
|
350
372
|
price_type_ext?: '' | 'product_price';
|
|
351
373
|
/** 商品id */
|
|
352
374
|
product_id?: number;
|
|
375
|
+
/** 生产编码 */
|
|
376
|
+
production_code?: string;
|
|
353
377
|
/** 商品价格 */
|
|
354
378
|
product_price?: string;
|
|
355
379
|
/** 商品副标题 */
|
|
@@ -370,6 +394,8 @@ export interface SkuValue {
|
|
|
370
394
|
product_variant_id: number;
|
|
371
395
|
/** 多规格商品选项字符串 */
|
|
372
396
|
product_option_string?: string;
|
|
397
|
+
/** 当前商品或组合规格商品的生产编码 */
|
|
398
|
+
production_code?: string;
|
|
373
399
|
/** 套餐商品组数据 */
|
|
374
400
|
bundle: Array<any>;
|
|
375
401
|
/** 单规格组数据 */
|
|
@@ -666,6 +692,44 @@ const App = () => {
|
|
|
666
692
|
/>
|
|
667
693
|
```
|
|
668
694
|
|
|
695
|
+
### 6.7 Option 高级限制与 Production Code
|
|
696
|
+
|
|
697
|
+
多选 Option Group 在 `metadata.advanced_settings_enabled=1` 时支持种类数限制:
|
|
698
|
+
|
|
699
|
+
```typescript
|
|
700
|
+
{
|
|
701
|
+
is_multiple: 1,
|
|
702
|
+
min_quantity: 1, // 总份数下限
|
|
703
|
+
max_quantity: 4, // 总份数上限,0 表示不限
|
|
704
|
+
metadata: {
|
|
705
|
+
advanced_settings_enabled: 1,
|
|
706
|
+
option_types_config: {
|
|
707
|
+
min: 1, // 最少种类数,0 表示不限
|
|
708
|
+
max: 2, // 最多种类数,0 表示不限
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
option_item: [
|
|
712
|
+
{
|
|
713
|
+
id: 1,
|
|
714
|
+
min_quantity: 2, // 选择该项后的最少份数
|
|
715
|
+
max_quantity: 0, // 单项份数不限
|
|
716
|
+
production_code: 'OPTION-1',
|
|
717
|
+
},
|
|
718
|
+
],
|
|
719
|
+
}
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
达到最多种类数后,组件只禁用尚未选择的 Option Item;已选项仍可在总份数和单项规则允许的范围内调整。Item `min_quantity` 仅对已选项生效,首次选择会从该最小数量开始。
|
|
723
|
+
|
|
724
|
+
`getTransformValues()` 和 `onChange` 输出会明确携带以下编码:
|
|
725
|
+
|
|
726
|
+
- `production_code`:Product 或当前 Variant 编码。
|
|
727
|
+
- `option[*].production_code`:Option Item 编码。
|
|
728
|
+
- `bundle[*].production_code`:Bundle Item 编码。
|
|
729
|
+
- `bundle[*].option[*].production_code`:套餐嵌套 Option Item 编码。
|
|
730
|
+
|
|
731
|
+
显式空字符串表示“无编码”,不会回退到 Product 或其他节点编码。
|
|
732
|
+
|
|
669
733
|
## 7. 注意事项
|
|
670
734
|
|
|
671
735
|
1. **数据格式**:确保传入的 `dataSource` 和 `value` 格式正确,否则可能导致组件渲染异常
|
|
@@ -90,6 +90,10 @@ interface IProps {
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
interface DataSource {
|
|
93
|
+
/** 商品id */
|
|
94
|
+
id?: number;
|
|
95
|
+
/** 生产编码 */
|
|
96
|
+
production_code?: string;
|
|
93
97
|
/** 单规格组数据 */
|
|
94
98
|
option_group?: Array<OptionGroupItem>;
|
|
95
99
|
/** 组合规格组装后的数据 */
|
|
@@ -97,7 +101,19 @@ interface DataSource {
|
|
|
97
101
|
/** 组合规格组数据 */
|
|
98
102
|
variant_group?: Array<VariantGroupItem>;
|
|
99
103
|
/** 套餐商品组数据 */
|
|
100
|
-
bundle_group?: Array<
|
|
104
|
+
bundle_group?: Array<BundleGroupItem>;
|
|
105
|
+
}
|
|
106
|
+
interface OptionGroupMetadata {
|
|
107
|
+
/** 是否启用高级设置 */
|
|
108
|
+
advanced_settings_enabled?: 0 | 1;
|
|
109
|
+
/** Option 种类数限制 */
|
|
110
|
+
option_types_config?: {
|
|
111
|
+
min?: number;
|
|
112
|
+
max?: number;
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
};
|
|
115
|
+
/** 保留后端返回的其他元数据 */
|
|
116
|
+
[key: string]: unknown;
|
|
101
117
|
}
|
|
102
118
|
/**
|
|
103
119
|
* 单规格组数据
|
|
@@ -125,6 +141,8 @@ interface OptionGroupItem {
|
|
|
125
141
|
max_quantity?: number;
|
|
126
142
|
/** 最小选择数量 */
|
|
127
143
|
min_quantity?: number;
|
|
144
|
+
/** 高级设置元数据 */
|
|
145
|
+
metadata?: OptionGroupMetadata;
|
|
128
146
|
/** 单规格组名称 */
|
|
129
147
|
name?: string;
|
|
130
148
|
/** 单规格组下规格数据 */
|
|
@@ -168,6 +186,8 @@ interface OptionItem {
|
|
|
168
186
|
is_enabled?: 0 | 1;
|
|
169
187
|
/** 最大选择数量 */
|
|
170
188
|
max_quantity?: number;
|
|
189
|
+
/** 最小选择数量 */
|
|
190
|
+
min_quantity?: number;
|
|
171
191
|
/** 规格名称 */
|
|
172
192
|
name?: string;
|
|
173
193
|
/** 规格组id */
|
|
@@ -176,6 +196,8 @@ interface OptionItem {
|
|
|
176
196
|
original_price?: string;
|
|
177
197
|
/** 商品id */
|
|
178
198
|
product_id?: number;
|
|
199
|
+
/** 生产编码 */
|
|
200
|
+
production_code?: string;
|
|
179
201
|
/** 店铺id */
|
|
180
202
|
shop_id?: number;
|
|
181
203
|
/** 排序 */
|
|
@@ -297,6 +319,8 @@ interface VariantProductItem {
|
|
|
297
319
|
price?: string;
|
|
298
320
|
/** 商品id */
|
|
299
321
|
product_id?: number;
|
|
322
|
+
/** 生产编码 */
|
|
323
|
+
production_code?: string;
|
|
300
324
|
/** 折扣类型 */
|
|
301
325
|
rebate_type?: string;
|
|
302
326
|
/** 折扣值 */
|
|
@@ -312,6 +336,27 @@ interface VariantProductItem {
|
|
|
312
336
|
/** 重量值 */
|
|
313
337
|
weight_value?: string;
|
|
314
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* 套餐商品组数据
|
|
341
|
+
*/
|
|
342
|
+
interface BundleGroupItem {
|
|
343
|
+
/** 店铺id */
|
|
344
|
+
shop_id?: number;
|
|
345
|
+
/** 排序 */
|
|
346
|
+
sort?: number;
|
|
347
|
+
/** 套餐id */
|
|
348
|
+
id?: number;
|
|
349
|
+
/** 最大选择数量 */
|
|
350
|
+
max_quantity?: number;
|
|
351
|
+
/** 最小选择数量 */
|
|
352
|
+
min_quantity?: number;
|
|
353
|
+
/** 套餐名称 */
|
|
354
|
+
name?: string;
|
|
355
|
+
/** 商品id */
|
|
356
|
+
product_id?: number;
|
|
357
|
+
/** 套餐商品组数据 */
|
|
358
|
+
bundle_item?: Array<BundleItem>;
|
|
359
|
+
}
|
|
315
360
|
/**
|
|
316
361
|
* 套餐商品组下选项数据
|
|
317
362
|
*/
|
|
@@ -354,6 +399,8 @@ interface BundleItem {
|
|
|
354
399
|
price_type_ext?: '' | 'product_price';
|
|
355
400
|
/** 商品id */
|
|
356
401
|
product_id?: number;
|
|
402
|
+
/** 生产编码 */
|
|
403
|
+
production_code?: string;
|
|
357
404
|
/** 商品价格 */
|
|
358
405
|
product_price?: string;
|
|
359
406
|
/** 商品副标题 */
|
|
@@ -373,6 +420,8 @@ interface SkuValue {
|
|
|
373
420
|
product_variant_id: number;
|
|
374
421
|
/** 多规格商品选项字符串 */
|
|
375
422
|
product_option_string?: string;
|
|
423
|
+
/** 当前商品或组合规格商品的生产编码 */
|
|
424
|
+
production_code?: string;
|
|
376
425
|
/** 套餐商品组数据 */
|
|
377
426
|
bundle: Array<any>;
|
|
378
427
|
/** 价格 */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/plus/skuOptionsSelection/utils/normalizers.ts
|
|
2
|
+
const normalizeNonNegativeInteger = (value, fallback = 0) => {
|
|
3
|
+
const normalizedFallback = Math.max(0, Math.trunc(Number(fallback) || 0));
|
|
4
|
+
if (value === null || value === void 0 || typeof value === "string" && value.trim() === "") return normalizedFallback;
|
|
5
|
+
const normalizedValue = Number(value);
|
|
6
|
+
if (!Number.isFinite(normalizedValue)) return normalizedFallback;
|
|
7
|
+
return Math.max(0, Math.trunc(normalizedValue));
|
|
8
|
+
};
|
|
9
|
+
const hasOwnProductionCode = (value) => !!value && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, "production_code");
|
|
10
|
+
const normalizeProductionCode = (value) => value === null || value === void 0 ? "" : String(value).trim();
|
|
11
|
+
const resolveProductionCode = (snapshotValue, currentValue) => {
|
|
12
|
+
if (hasOwnProductionCode(snapshotValue)) return normalizeProductionCode(snapshotValue.production_code);
|
|
13
|
+
if (hasOwnProductionCode(currentValue)) return normalizeProductionCode(currentValue.production_code);
|
|
14
|
+
return "";
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { hasOwnProductionCode, normalizeNonNegativeInteger, resolveProductionCode };
|
|
@@ -3,6 +3,7 @@ import store from "../store/store.js";
|
|
|
3
3
|
import NormalCard from "../components/NormalCard/index.js";
|
|
4
4
|
import TitleExtra from "../components/TitleExtra/index.js";
|
|
5
5
|
import { checkSkuDisabled, checkSkuStockCanSell } from "./checkSkuStatus.js";
|
|
6
|
+
import { normalizeNonNegativeInteger } from "./normalizers.js";
|
|
6
7
|
import React from "react";
|
|
7
8
|
//#region src/plus/skuOptionsSelection/utils/transformOptionGroup.tsx
|
|
8
9
|
const transformOptionGroup = (optionGroup, translationOriginal) => {
|
|
@@ -11,11 +12,19 @@ const transformOptionGroup = (optionGroup, translationOriginal) => {
|
|
|
11
12
|
const getDisplayText = (value) => typeof value === "string" ? value : (translationOriginal === null || translationOriginal === void 0 ? void 0 : translationOriginal(value)) || "";
|
|
12
13
|
const selectorLayout = ((_store$getState$custo = store.getState().customConfig) === null || _store$getState$custo === void 0 ? void 0 : _store$getState$custo.selectorLayout) || null;
|
|
13
14
|
return optionGroup.map((item) => {
|
|
14
|
-
var _item$option_item, _item$name;
|
|
15
|
+
var _item$metadata, _item$metadata2, _item$metadata3, _item$option_item, _item$name;
|
|
16
|
+
const isMultiple = (item === null || item === void 0 ? void 0 : item.is_multiple) == 1;
|
|
17
|
+
const groupMin = normalizeNonNegativeInteger(item === null || item === void 0 ? void 0 : item.min_quantity, 0);
|
|
18
|
+
const groupMax = normalizeNonNegativeInteger(item === null || item === void 0 ? void 0 : item.max_quantity, 0);
|
|
19
|
+
const advancedEnabled = isMultiple && (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.advanced_settings_enabled) === 1;
|
|
20
|
+
const minTypes = advancedEnabled ? normalizeNonNegativeInteger(item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 || (_item$metadata2 = _item$metadata2.option_types_config) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.min, 0) : 0;
|
|
21
|
+
const maxTypes = advancedEnabled ? normalizeNonNegativeInteger(item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 || (_item$metadata3 = _item$metadata3.option_types_config) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.max, 0) : 0;
|
|
15
22
|
const selectorOptionsDataSource = item === null || item === void 0 || (_item$option_item = item.option_item) === null || _item$option_item === void 0 ? void 0 : _item$option_item.map((optionItem) => {
|
|
16
23
|
var _optionItem$name;
|
|
17
24
|
const { canSell, hasStock } = checkSkuStockCanSell(optionItem);
|
|
18
25
|
const disabled = checkSkuDisabled(optionItem, canSell);
|
|
26
|
+
const itemMin = normalizeNonNegativeInteger(optionItem === null || optionItem === void 0 ? void 0 : optionItem.min_quantity, 0);
|
|
27
|
+
const itemMax = normalizeNonNegativeInteger(optionItem === null || optionItem === void 0 ? void 0 : optionItem.max_quantity, 1);
|
|
19
28
|
return {
|
|
20
29
|
_original: _objectSpread2(_objectSpread2({}, optionItem || {}), {}, { product_option_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id }),
|
|
21
30
|
id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id,
|
|
@@ -23,8 +32,8 @@ const transformOptionGroup = (optionGroup, translationOriginal) => {
|
|
|
23
32
|
value: optionItem === null || optionItem === void 0 ? void 0 : optionItem.id,
|
|
24
33
|
disabled,
|
|
25
34
|
ruleConfig: {
|
|
26
|
-
min:
|
|
27
|
-
max:
|
|
35
|
+
min: itemMin,
|
|
36
|
+
max: itemMax,
|
|
28
37
|
autoValidate: true
|
|
29
38
|
},
|
|
30
39
|
_extra: {
|
|
@@ -34,7 +43,6 @@ const transformOptionGroup = (optionGroup, translationOriginal) => {
|
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
45
|
});
|
|
37
|
-
const isMultiple = (item === null || item === void 0 ? void 0 : item.is_multiple) == 1;
|
|
38
46
|
const selectorDataSource = {
|
|
39
47
|
id: item.id,
|
|
40
48
|
title: getDisplayText((_item$name = item === null || item === void 0 ? void 0 : item.name) !== null && _item$name !== void 0 ? _item$name : item === null || item === void 0 ? void 0 : item.title),
|
|
@@ -47,10 +55,12 @@ const transformOptionGroup = (optionGroup, translationOriginal) => {
|
|
|
47
55
|
dataSource: selectorOptionsDataSource || [],
|
|
48
56
|
disabled: (item === null || item === void 0 ? void 0 : item.is_enabled) === 0,
|
|
49
57
|
ruleConfig: {
|
|
50
|
-
min: isMultiple ?
|
|
51
|
-
max: isMultiple
|
|
58
|
+
min: isMultiple ? groupMin : void 0,
|
|
59
|
+
max: isMultiple && groupMax > 0 ? groupMax : void 0,
|
|
60
|
+
minTypes: isMultiple && minTypes > 0 ? minTypes : void 0,
|
|
61
|
+
maxTypes: isMultiple && maxTypes > 0 ? maxTypes : void 0,
|
|
52
62
|
autoValidate: true,
|
|
53
|
-
required: isMultiple ?
|
|
63
|
+
required: isMultiple ? groupMin > 0 || minTypes > 0 : (item === null || item === void 0 ? void 0 : item.required) === 1
|
|
54
64
|
},
|
|
55
65
|
headerProps: { renderExtra: (props) => {
|
|
56
66
|
return /* @__PURE__ */ React.createElement(TitleExtra, props || {});
|
|
@@ -1,9 +1,45 @@
|
|
|
1
1
|
import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
2
2
|
import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
|
|
3
3
|
import store from "../store/store.js";
|
|
4
|
+
import { hasOwnProductionCode, resolveProductionCode } from "./normalizers.js";
|
|
4
5
|
import Decimal from "decimal.js";
|
|
5
6
|
//#region src/plus/skuOptionsSelection/utils/transformSelectorValueToValue.ts
|
|
6
7
|
const _excluded = ["_data"];
|
|
8
|
+
const isSameNodeId = (left, right) => left !== null && left !== void 0 && right !== null && right !== void 0 && String(left) === String(right);
|
|
9
|
+
const getOptionItemId = (value) => {
|
|
10
|
+
var _value$id;
|
|
11
|
+
return (_value$id = value === null || value === void 0 ? void 0 : value.id) !== null && _value$id !== void 0 ? _value$id : value === null || value === void 0 ? void 0 : value.product_option_item_id;
|
|
12
|
+
};
|
|
13
|
+
const getBundleItemId = (value) => {
|
|
14
|
+
var _value$id2;
|
|
15
|
+
return (_value$id2 = value === null || value === void 0 ? void 0 : value.id) !== null && _value$id2 !== void 0 ? _value$id2 : value === null || value === void 0 ? void 0 : value.bundle_id;
|
|
16
|
+
};
|
|
17
|
+
const getBundleGroupId = (value) => {
|
|
18
|
+
var _value$group_id;
|
|
19
|
+
return (_value$group_id = value === null || value === void 0 ? void 0 : value.group_id) !== null && _value$group_id !== void 0 ? _value$group_id : value === null || value === void 0 ? void 0 : value.bundle_group_id;
|
|
20
|
+
};
|
|
21
|
+
const createOutputOption = (params) => {
|
|
22
|
+
var _ref, _ref2, _selectorItem$quantit, _selectorItem$value, _currentGroup$id, _currentGroup$option_, _currentOptionItem$id;
|
|
23
|
+
const { selectorItem, optionGroupId, currentOptionGroups = [], snapshotOptions = [] } = params;
|
|
24
|
+
const itemData = (selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.data) || {};
|
|
25
|
+
const quantity = Number((_ref = (_ref2 = (_selectorItem$quantit = selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.quantity) !== null && _selectorItem$quantit !== void 0 ? _selectorItem$quantit : itemData === null || itemData === void 0 ? void 0 : itemData.quantity) !== null && _ref2 !== void 0 ? _ref2 : itemData === null || itemData === void 0 ? void 0 : itemData.num) !== null && _ref !== void 0 ? _ref : 0);
|
|
26
|
+
if (!(quantity > 0)) return null;
|
|
27
|
+
const optionItemId = (_selectorItem$value = selectorItem === null || selectorItem === void 0 ? void 0 : selectorItem.value) !== null && _selectorItem$value !== void 0 ? _selectorItem$value : getOptionItemId(itemData);
|
|
28
|
+
const requestedGroupId = optionGroupId !== null && optionGroupId !== void 0 ? optionGroupId : itemData === null || itemData === void 0 ? void 0 : itemData.option_group_id;
|
|
29
|
+
const currentGroup = currentOptionGroups.find((group) => isSameNodeId(group === null || group === void 0 ? void 0 : group.id, requestedGroupId));
|
|
30
|
+
const resolvedGroupId = (_currentGroup$id = currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.id) !== null && _currentGroup$id !== void 0 ? _currentGroup$id : requestedGroupId;
|
|
31
|
+
const currentOptionItem = currentGroup === null || currentGroup === void 0 || (_currentGroup$option_ = currentGroup.option_item) === null || _currentGroup$option_ === void 0 ? void 0 : _currentGroup$option_.find((item) => isSameNodeId(item === null || item === void 0 ? void 0 : item.id, optionItemId));
|
|
32
|
+
const resolvedOptionItemId = (_currentOptionItem$id = currentOptionItem === null || currentOptionItem === void 0 ? void 0 : currentOptionItem.id) !== null && _currentOptionItem$id !== void 0 ? _currentOptionItem$id : optionItemId;
|
|
33
|
+
const snapshotOption = snapshotOptions.find((item) => isSameNodeId(getOptionItemId(item), optionItemId) && ((item === null || item === void 0 ? void 0 : item.option_group_id) === null || (item === null || item === void 0 ? void 0 : item.option_group_id) === void 0 || isSameNodeId(item === null || item === void 0 ? void 0 : item.option_group_id, resolvedGroupId)));
|
|
34
|
+
return _objectSpread2(_objectSpread2({}, itemData), {}, {
|
|
35
|
+
id: resolvedOptionItemId,
|
|
36
|
+
product_option_item_id: resolvedOptionItemId,
|
|
37
|
+
option_group_id: resolvedGroupId,
|
|
38
|
+
production_code: currentOptionItem ? resolveProductionCode(snapshotOption, currentOptionItem) : "",
|
|
39
|
+
quantity,
|
|
40
|
+
num: quantity
|
|
41
|
+
});
|
|
42
|
+
};
|
|
7
43
|
/**
|
|
8
44
|
* 将SelectorValue转换为Value
|
|
9
45
|
*/
|
|
@@ -11,6 +47,8 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
11
47
|
var _dataSource$bundle_gr, _dataSource$option_gr, _dataSource$variant_g;
|
|
12
48
|
if (!selectorValue) return {};
|
|
13
49
|
const dataSource = store.getState().dataSource;
|
|
50
|
+
const originalValue = store.getState().value;
|
|
51
|
+
let selectedVariant = null;
|
|
14
52
|
const transformValue = {
|
|
15
53
|
bundle: [],
|
|
16
54
|
option: [],
|
|
@@ -25,37 +63,65 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
25
63
|
const groupItemValue = selectorValue === null || selectorValue === void 0 ? void 0 : selectorValue[groupId];
|
|
26
64
|
if (!groupId || !groupItemValue) return;
|
|
27
65
|
(Array.isArray(groupItemValue) ? groupItemValue : [groupItemValue]).forEach((item) => {
|
|
28
|
-
|
|
66
|
+
var _item$value, _bundleGroupItem$bund;
|
|
67
|
+
const bundleItemId = (_item$value = item === null || item === void 0 ? void 0 : item.value) !== null && _item$value !== void 0 ? _item$value : getBundleItemId(item === null || item === void 0 ? void 0 : item.data);
|
|
68
|
+
const currentBundleItem = bundleGroupItem === null || bundleGroupItem === void 0 || (_bundleGroupItem$bund = bundleGroupItem.bundle_item) === null || _bundleGroupItem$bund === void 0 ? void 0 : _bundleGroupItem$bund.find((bundleItem) => isSameNodeId(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.id, bundleItemId));
|
|
69
|
+
const bundleSnapshots = ((originalValue === null || originalValue === void 0 ? void 0 : originalValue.bundle) || []).filter((bundleItem) => isSameNodeId(getBundleItemId(bundleItem), bundleItemId) && (getBundleGroupId(bundleItem) === null || getBundleGroupId(bundleItem) === void 0 || isSameNodeId(getBundleGroupId(bundleItem), groupId)));
|
|
70
|
+
const bundleSnapshot = bundleSnapshots.find((bundleItem) => hasOwnProductionCode(bundleItem));
|
|
71
|
+
const _ref3 = (item === null || item === void 0 ? void 0 : item.data) || {}, { _data } = _ref3, rest = _objectWithoutProperties(_ref3, _excluded);
|
|
29
72
|
if (_data) _data === null || _data === void 0 || _data.forEach((_item) => {
|
|
30
73
|
if (_item === null || _item === void 0 ? void 0 : _item.data) {
|
|
31
|
-
|
|
74
|
+
const bundleQuantity = Number((_item === null || _item === void 0 ? void 0 : _item.quantity) || 0);
|
|
75
|
+
if (!(bundleQuantity > 0)) return;
|
|
76
|
+
let _newData = _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
77
|
+
option: [],
|
|
78
|
+
production_code: currentBundleItem ? resolveProductionCode(bundleSnapshot, currentBundleItem) : ""
|
|
79
|
+
});
|
|
32
80
|
let totalPrice = new Decimal(0);
|
|
33
81
|
Object.keys(_item === null || _item === void 0 ? void 0 : _item.data).forEach((key) => {
|
|
34
82
|
var _item$data;
|
|
35
83
|
const _itemDataItem = _item === null || _item === void 0 || (_item$data = _item.data) === null || _item$data === void 0 ? void 0 : _item$data[key];
|
|
36
84
|
if (Array.isArray(_itemDataItem)) _itemDataItem.forEach((_itemDataItem_item) => {
|
|
37
|
-
|
|
85
|
+
const outputOption = createOutputOption({
|
|
86
|
+
selectorItem: _itemDataItem_item,
|
|
87
|
+
optionGroupId: key,
|
|
88
|
+
currentOptionGroups: (currentBundleItem === null || currentBundleItem === void 0 ? void 0 : currentBundleItem.option_group) || [],
|
|
89
|
+
snapshotOptions: bundleSnapshots.flatMap((bundleItem) => (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option) || [])
|
|
90
|
+
});
|
|
91
|
+
if (!outputOption) return;
|
|
38
92
|
totalPrice = totalPrice.plus(new Decimal((_itemDataItem_item === null || _itemDataItem_item === void 0 ? void 0 : _itemDataItem_item.totalPrice) || 0));
|
|
39
|
-
_newData.option.push(
|
|
93
|
+
_newData.option.push(outputOption);
|
|
40
94
|
});
|
|
41
95
|
else {
|
|
42
|
-
|
|
96
|
+
const outputOption = createOutputOption({
|
|
97
|
+
selectorItem: _itemDataItem,
|
|
98
|
+
optionGroupId: key,
|
|
99
|
+
currentOptionGroups: (currentBundleItem === null || currentBundleItem === void 0 ? void 0 : currentBundleItem.option_group) || [],
|
|
100
|
+
snapshotOptions: bundleSnapshots.flatMap((bundleItem) => (bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option) || [])
|
|
101
|
+
});
|
|
102
|
+
if (!outputOption) return;
|
|
43
103
|
totalPrice = totalPrice.plus(new Decimal((_itemDataItem === null || _itemDataItem === void 0 ? void 0 : _itemDataItem.totalPrice) || 0));
|
|
44
|
-
_newData.option.push(
|
|
104
|
+
_newData.option.push(outputOption);
|
|
45
105
|
}
|
|
46
106
|
});
|
|
47
107
|
const _restPricePrefix = (rest === null || rest === void 0 ? void 0 : rest.price_type) === "markdown" ? -1 : 1;
|
|
48
108
|
_newData.price = totalPrice.plus(new Decimal((rest === null || rest === void 0 ? void 0 : rest.price) || 0).times(_restPricePrefix)).toString();
|
|
49
109
|
_newData.original_price = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
50
110
|
_newData.original_total = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
51
|
-
_newData.quantity =
|
|
52
|
-
_newData.num =
|
|
111
|
+
_newData.quantity = bundleQuantity;
|
|
112
|
+
_newData.num = bundleQuantity;
|
|
53
113
|
_newData._bundle_product_id = _newData === null || _newData === void 0 ? void 0 : _newData.bundle_product_id;
|
|
54
114
|
transformValue.bundle.push(_newData);
|
|
55
115
|
}
|
|
56
116
|
});
|
|
57
117
|
else {
|
|
118
|
+
var _ref4, _ref5, _item$quantity;
|
|
58
119
|
const _newData = _objectSpread2({}, (item === null || item === void 0 ? void 0 : item.data) || {});
|
|
120
|
+
const bundleQuantity = Number((_ref4 = (_ref5 = (_item$quantity = item === null || item === void 0 ? void 0 : item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : _newData === null || _newData === void 0 ? void 0 : _newData.quantity) !== null && _ref5 !== void 0 ? _ref5 : _newData === null || _newData === void 0 ? void 0 : _newData.num) !== null && _ref4 !== void 0 ? _ref4 : 0);
|
|
121
|
+
if (!(bundleQuantity > 0)) return;
|
|
122
|
+
_newData.production_code = currentBundleItem ? resolveProductionCode(bundleSnapshot, currentBundleItem) : "";
|
|
123
|
+
_newData.quantity = bundleQuantity;
|
|
124
|
+
_newData.num = bundleQuantity;
|
|
59
125
|
const _pricePrefix = (_newData === null || _newData === void 0 ? void 0 : _newData.price_type) === "markdown" ? -1 : 1;
|
|
60
126
|
_newData.price = new Decimal((_newData === null || _newData === void 0 ? void 0 : _newData.price) || 0).times(_pricePrefix).toString();
|
|
61
127
|
_newData.original_price = _newData === null || _newData === void 0 ? void 0 : _newData.price;
|
|
@@ -77,8 +143,13 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
77
143
|
else _groupItemValue = [groupItemValue];
|
|
78
144
|
_groupItemValue === null || _groupItemValue === void 0 || _groupItemValue.forEach((item) => {
|
|
79
145
|
if (item === null || item === void 0 ? void 0 : item.data) {
|
|
80
|
-
|
|
81
|
-
|
|
146
|
+
const outputOption = createOutputOption({
|
|
147
|
+
selectorItem: item,
|
|
148
|
+
optionGroupId: groupId,
|
|
149
|
+
currentOptionGroups: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.option_group) || [],
|
|
150
|
+
snapshotOptions: (originalValue === null || originalValue === void 0 ? void 0 : originalValue.option) || []
|
|
151
|
+
});
|
|
152
|
+
if (outputOption) transformValue.option.push(outputOption);
|
|
82
153
|
}
|
|
83
154
|
});
|
|
84
155
|
});
|
|
@@ -96,9 +167,9 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
96
167
|
else _groupItemValue = [groupItemValue];
|
|
97
168
|
_groupItemValue === null || _groupItemValue === void 0 || _groupItemValue.forEach((item) => {
|
|
98
169
|
if (item === null || item === void 0 ? void 0 : item.data) {
|
|
99
|
-
var _item$
|
|
100
|
-
selectedVariantIds.push(`${item === null || item === void 0 || (_item$
|
|
101
|
-
selectedVariantOptionString.push(`${variantGroupItem === null || variantGroupItem === void 0 ? void 0 : variantGroupItem.name}:${item === null || item === void 0 || (_item$
|
|
170
|
+
var _item$data2, _item$data3, _item$data4;
|
|
171
|
+
selectedVariantIds.push(`${item === null || item === void 0 || (_item$data2 = item.data) === null || _item$data2 === void 0 ? void 0 : _item$data2.variant_group_id}:${item === null || item === void 0 || (_item$data3 = item.data) === null || _item$data3 === void 0 ? void 0 : _item$data3.id}`);
|
|
172
|
+
selectedVariantOptionString.push(`${variantGroupItem === null || variantGroupItem === void 0 ? void 0 : variantGroupItem.name}:${item === null || item === void 0 || (_item$data4 = item.data) === null || _item$data4 === void 0 ? void 0 : _item$data4.name}`);
|
|
102
173
|
}
|
|
103
174
|
});
|
|
104
175
|
});
|
|
@@ -110,12 +181,15 @@ const transformSelectorValueToValue = (selectorValue) => {
|
|
|
110
181
|
return selectedVariantIds.every((idItem) => ids.includes(idItem));
|
|
111
182
|
});
|
|
112
183
|
if (filteredVariant === null || filteredVariant === void 0 ? void 0 : filteredVariant.length) {
|
|
113
|
-
|
|
114
|
-
transformValue.product_variant_id =
|
|
184
|
+
selectedVariant = filteredVariant[0];
|
|
185
|
+
transformValue.product_variant_id = selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.id;
|
|
115
186
|
transformValue.product_option_string = selectedVariantOptionString.join(", ");
|
|
116
187
|
}
|
|
117
188
|
}
|
|
118
189
|
}
|
|
190
|
+
if (selectedVariant) transformValue.production_code = resolveProductionCode(isSameNodeId(originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id, selectedVariant === null || selectedVariant === void 0 ? void 0 : selectedVariant.id) ? originalValue : void 0, selectedVariant);
|
|
191
|
+
else transformValue.production_code = resolveProductionCode((originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === null || (originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === void 0 || Number(originalValue === null || originalValue === void 0 ? void 0 : originalValue.product_variant_id) === 0 ? originalValue : void 0, dataSource);
|
|
192
|
+
console.log("transformSelectorValueToValue>>>>>", transformValue);
|
|
119
193
|
return transformValue;
|
|
120
194
|
};
|
|
121
195
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
2
|
+
import { hasOwnProductionCode, normalizeNonNegativeInteger, resolveProductionCode } from "./normalizers.js";
|
|
2
3
|
import Decimal from "decimal.js";
|
|
3
4
|
//#region src/plus/skuOptionsSelection/utils/transformValueToSelectorValue.ts
|
|
4
5
|
/** 接口详情与订单行可能分别返回 number/string,SKU 回填按业务 ID 比较。 */
|
|
@@ -13,16 +14,17 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
13
14
|
if (value === null || value === void 0 ? void 0 : value.bundle) {
|
|
14
15
|
var _value$bundle, _newBundle$forEach;
|
|
15
16
|
const newBundle = value === null || value === void 0 || (_value$bundle = value.bundle) === null || _value$bundle === void 0 ? void 0 : _value$bundle.reduce((acc, v) => {
|
|
16
|
-
|
|
17
|
+
var _v$id;
|
|
18
|
+
const _bundleItemId = (_v$id = v === null || v === void 0 ? void 0 : v.id) !== null && _v$id !== void 0 ? _v$id : v === null || v === void 0 ? void 0 : v.bundle_id;
|
|
17
19
|
const idx = acc === null || acc === void 0 ? void 0 : acc.findIndex((v1) => (v1 === null || v1 === void 0 ? void 0 : v1.id) === _bundleItemId);
|
|
18
20
|
if (idx !== -1) {
|
|
19
21
|
var _acc$idx, _acc$idx$push;
|
|
20
22
|
(_acc$idx = acc[idx]) === null || _acc$idx === void 0 || (_acc$idx = _acc$idx.bundleOptions) === null || _acc$idx === void 0 || (_acc$idx$push = _acc$idx.push) === null || _acc$idx$push === void 0 || _acc$idx$push.call(_acc$idx, v);
|
|
21
23
|
} else {
|
|
22
|
-
var _acc$push;
|
|
24
|
+
var _acc$push, _v$group_id;
|
|
23
25
|
acc === null || acc === void 0 || (_acc$push = acc.push) === null || _acc$push === void 0 || _acc$push.call(acc, {
|
|
24
26
|
id: _bundleItemId,
|
|
25
|
-
groupId: v === null || v === void 0 ? void 0 : v.group_id,
|
|
27
|
+
groupId: (_v$group_id = v === null || v === void 0 ? void 0 : v.group_id) !== null && _v$group_id !== void 0 ? _v$group_id : v === null || v === void 0 ? void 0 : v.bundle_group_id,
|
|
26
28
|
bundleOptions: [v]
|
|
27
29
|
});
|
|
28
30
|
}
|
|
@@ -31,6 +33,7 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
31
33
|
newBundle === null || newBundle === void 0 || (_newBundle$forEach = newBundle.forEach) === null || _newBundle$forEach === void 0 || _newBundle$forEach.call(newBundle, (v1) => {
|
|
32
34
|
const _bundleGroupId = v1 === null || v1 === void 0 ? void 0 : v1.groupId;
|
|
33
35
|
const _bundleValue = createBundleValue(v1, dataSource);
|
|
36
|
+
if (!_bundleValue) return;
|
|
34
37
|
if (transformValue[_bundleGroupId]) transformValue[_bundleGroupId] = [...transformValue[_bundleGroupId] || [], _bundleValue];
|
|
35
38
|
else transformValue[_bundleGroupId] = [_bundleValue];
|
|
36
39
|
});
|
|
@@ -77,7 +80,7 @@ const transformValueToSelectorValue = (value, dataSource) => {
|
|
|
77
80
|
* 创建套餐商品数据
|
|
78
81
|
*/
|
|
79
82
|
const createBundleValue = (v, dataSource) => {
|
|
80
|
-
var _dataSource$bundle_gr, _v$
|
|
83
|
+
var _dataSource$bundle_gr, _v$bundleOptions2, _v$bundleOptions2$for;
|
|
81
84
|
let _createdValue = null;
|
|
82
85
|
const bundleGroupItem = dataSource === null || dataSource === void 0 || (_dataSource$bundle_gr = dataSource.bundle_group) === null || _dataSource$bundle_gr === void 0 ? void 0 : _dataSource$bundle_gr.find((v1) => {
|
|
83
86
|
return isSameId(v1 === null || v1 === void 0 ? void 0 : v1.id, v === null || v === void 0 ? void 0 : v.groupId);
|
|
@@ -88,29 +91,34 @@ const createBundleValue = (v, dataSource) => {
|
|
|
88
91
|
findedBundleItem = bundleGroupItem === null || bundleGroupItem === void 0 || (_bundleGroupItem$bund = bundleGroupItem.bundle_item) === null || _bundleGroupItem$bund === void 0 ? void 0 : _bundleGroupItem$bund.find((v1) => {
|
|
89
92
|
return isSameId(v1 === null || v1 === void 0 ? void 0 : v1.id, v === null || v === void 0 ? void 0 : v.id);
|
|
90
93
|
});
|
|
91
|
-
if (!!findedBundleItem)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
if (!!findedBundleItem) {
|
|
95
|
+
var _v$bundleOptions;
|
|
96
|
+
const bundleSnapshot = v === null || v === void 0 || (_v$bundleOptions = v.bundleOptions) === null || _v$bundleOptions === void 0 ? void 0 : _v$bundleOptions.find((item) => hasOwnProductionCode(item));
|
|
97
|
+
_createdValue = {
|
|
98
|
+
value: findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.id,
|
|
99
|
+
data: _objectSpread2(_objectSpread2({}, findedBundleItem || {}), {}, { production_code: resolveProductionCode(bundleSnapshot, findedBundleItem) })
|
|
100
|
+
};
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
if (!_createdValue) return null;
|
|
97
104
|
let totalQuantity = 0;
|
|
98
|
-
v === null || v === void 0 || (_v$
|
|
99
|
-
var _v1$option;
|
|
105
|
+
v === null || v === void 0 || (_v$bundleOptions2 = v.bundleOptions) === null || _v$bundleOptions2 === void 0 || (_v$bundleOptions2$for = _v$bundleOptions2.forEach) === null || _v$bundleOptions2$for === void 0 || _v$bundleOptions2$for.call(_v$bundleOptions2, (v1) => {
|
|
106
|
+
var _v1$option, _v1$quantity2;
|
|
100
107
|
if (v1 === null || v1 === void 0 || (_v1$option = v1.option) === null || _v1$option === void 0 ? void 0 : _v1$option.length) {
|
|
101
|
-
var _createdValue$data;
|
|
108
|
+
var _createdValue$data, _v1$quantity;
|
|
102
109
|
const _data = (_createdValue === null || _createdValue === void 0 || (_createdValue$data = _createdValue.data) === null || _createdValue$data === void 0 ? void 0 : _createdValue$data._data) || [];
|
|
103
110
|
const _createdValueData = createOptionValue({}, v1, findedBundleItem);
|
|
104
111
|
_data.push({
|
|
105
|
-
value:
|
|
112
|
+
value: findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.id,
|
|
106
113
|
data: _createdValueData,
|
|
107
|
-
quantity: (v1 === null || v1 === void 0 ? void 0 : v1.quantity) || 1
|
|
114
|
+
quantity: normalizeNonNegativeInteger((_v1$quantity = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity !== void 0 ? _v1$quantity : v1 === null || v1 === void 0 ? void 0 : v1.num, 1)
|
|
108
115
|
});
|
|
109
116
|
_createdValue.data._data = _data;
|
|
110
117
|
}
|
|
111
|
-
|
|
118
|
+
const itemQuantity = normalizeNonNegativeInteger((_v1$quantity2 = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity2 !== void 0 ? _v1$quantity2 : v1 === null || v1 === void 0 ? void 0 : v1.num, 1);
|
|
119
|
+
totalQuantity = totalQuantity + itemQuantity;
|
|
112
120
|
const _price = (v1 === null || v1 === void 0 ? void 0 : v1.price) || (findedBundleItem === null || findedBundleItem === void 0 ? void 0 : findedBundleItem.price) || 0;
|
|
113
|
-
_createdValue.totalPrice = new Decimal(_createdValue.totalPrice || 0).plus(new Decimal(_price).times(
|
|
121
|
+
_createdValue.totalPrice = new Decimal(_createdValue.totalPrice || 0).plus(new Decimal(_price).times(itemQuantity)).toNumber();
|
|
114
122
|
});
|
|
115
123
|
_createdValue.quantity = totalQuantity;
|
|
116
124
|
_createdValue.data.quantity = totalQuantity;
|
|
@@ -124,21 +132,25 @@ const createOptionValue = (initValue, value, dataSource) => {
|
|
|
124
132
|
var _value$option, _value$option$forEach;
|
|
125
133
|
let _createdValue = initValue || {};
|
|
126
134
|
value === null || value === void 0 || (_value$option = value.option) === null || _value$option === void 0 || (_value$option$forEach = _value$option.forEach) === null || _value$option$forEach === void 0 || _value$option$forEach.call(_value$option, (v1) => {
|
|
127
|
-
var _dataSource$option_gr, _matchedGroup$option_;
|
|
135
|
+
var _v1$id, _dataSource$option_gr, _matchedGroup$option_, _v1$quantity3;
|
|
128
136
|
const _optionGroupId = v1 === null || v1 === void 0 ? void 0 : v1.option_group_id;
|
|
137
|
+
const optionItemId = (_v1$id = v1 === null || v1 === void 0 ? void 0 : v1.id) !== null && _v1$id !== void 0 ? _v1$id : v1 === null || v1 === void 0 ? void 0 : v1.product_option_item_id;
|
|
129
138
|
const matchedGroup = dataSource === null || dataSource === void 0 || (_dataSource$option_gr = dataSource.option_group) === null || _dataSource$option_gr === void 0 ? void 0 : _dataSource$option_gr.find((v2) => isSameId(v2 === null || v2 === void 0 ? void 0 : v2.id, _optionGroupId));
|
|
130
|
-
const matchedOptionItem = matchedGroup === null || matchedGroup === void 0 || (_matchedGroup$option_ = matchedGroup.option_item) === null || _matchedGroup$option_ === void 0 ? void 0 : _matchedGroup$option_.find((v3) => isSameId(v3 === null || v3 === void 0 ? void 0 : v3.id,
|
|
131
|
-
const _num = (v1 === null || v1 === void 0 ? void 0 : v1.quantity)
|
|
139
|
+
const matchedOptionItem = matchedGroup === null || matchedGroup === void 0 || (_matchedGroup$option_ = matchedGroup.option_item) === null || _matchedGroup$option_ === void 0 ? void 0 : _matchedGroup$option_.find((v3) => isSameId(v3 === null || v3 === void 0 ? void 0 : v3.id, optionItemId));
|
|
140
|
+
const _num = normalizeNonNegativeInteger((_v1$quantity3 = v1 === null || v1 === void 0 ? void 0 : v1.quantity) !== null && _v1$quantity3 !== void 0 ? _v1$quantity3 : v1 === null || v1 === void 0 ? void 0 : v1.num, 1);
|
|
132
141
|
const _price = (matchedOptionItem === null || matchedOptionItem === void 0 ? void 0 : matchedOptionItem.add_price) || 0;
|
|
133
142
|
const _tempOptionValue = {
|
|
134
143
|
data: _objectSpread2(_objectSpread2(_objectSpread2({}, matchedOptionItem || {}), v1 || {}), {}, {
|
|
144
|
+
id: optionItemId,
|
|
145
|
+
product_option_item_id: optionItemId,
|
|
146
|
+
production_code: matchedOptionItem ? resolveProductionCode(v1, matchedOptionItem) : "",
|
|
135
147
|
num: _num,
|
|
136
148
|
price: _price,
|
|
137
149
|
original_price: _price,
|
|
138
150
|
original_total: _price
|
|
139
151
|
}),
|
|
140
152
|
quantity: _num,
|
|
141
|
-
value:
|
|
153
|
+
value: optionItemId,
|
|
142
154
|
totalPrice: new Decimal((matchedOptionItem === null || matchedOptionItem === void 0 ? void 0 : matchedOptionItem.add_price) || 0).times(_num).toNumber()
|
|
143
155
|
};
|
|
144
156
|
if (_createdValue[_optionGroupId]) _createdValue[_optionGroupId] = [..._createdValue[_optionGroupId] || [], _tempOptionValue];
|