@pisell/pisellos 0.0.13 → 0.0.14
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/dist/modules/Cart/index.d.ts +21 -7
- package/dist/modules/Cart/index.js +110 -108
- package/dist/modules/Cart/types.d.ts +34 -13
- package/dist/modules/Cart/types.js +3 -3
- package/dist/modules/Cart/utils.d.ts +37 -1
- package/dist/modules/Cart/utils.js +60 -0
- package/dist/modules/Date/index.js +6 -1
- package/dist/modules/Rules/index.js +6 -4
- package/dist/modules/Summary/index.js +6 -1
- package/dist/solution/BookingByStep/index.d.ts +0 -1
- package/dist/solution/BookingByStep/index.js +146 -146
- package/dist/solution/BookingByStep/utils/resources.js +4 -2
- package/lib/modules/Cart/index.d.ts +21 -7
- package/lib/modules/Cart/index.js +50 -45
- package/lib/modules/Cart/types.d.ts +34 -13
- package/lib/modules/Cart/utils.d.ts +37 -1
- package/lib/modules/Cart/utils.js +41 -0
- package/lib/modules/Date/index.js +3 -0
- package/lib/modules/Rules/index.js +6 -4
- package/lib/modules/Summary/index.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +0 -1
- package/lib/solution/BookingByStep/index.js +35 -16
- package/lib/solution/BookingByStep/utils/resources.js +4 -1
- package/package.json +1 -1
|
@@ -5,13 +5,12 @@ export * from "./types";
|
|
|
5
5
|
/**
|
|
6
6
|
* 购物车模块实现
|
|
7
7
|
*/
|
|
8
|
-
export declare class CartModule extends BaseModule implements Module {
|
|
8
|
+
export declare class CartModule extends BaseModule implements Module, CartModuleAPI {
|
|
9
9
|
protected defaultName: string;
|
|
10
10
|
protected defaultVersion: string;
|
|
11
11
|
private request;
|
|
12
12
|
private window;
|
|
13
13
|
private store;
|
|
14
|
-
exports: CartModuleAPI;
|
|
15
14
|
constructor(name?: string, version?: string);
|
|
16
15
|
/**
|
|
17
16
|
* 初始化购物车模块
|
|
@@ -25,17 +24,32 @@ export declare class CartModule extends BaseModule implements Module {
|
|
|
25
24
|
* 更新购物车信息
|
|
26
25
|
*/
|
|
27
26
|
updateItem(params: IUpdateItemParams): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* 格式化数据到购物车
|
|
29
|
+
*/
|
|
30
|
+
formatCartItem(params: IUpdateItemParams): CartItem;
|
|
28
31
|
/**
|
|
29
32
|
* 批量设置购物车数据
|
|
30
33
|
*/
|
|
31
34
|
batchSetItems(items: CartItem[]): Promise<void>;
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
/**
|
|
36
|
+
* 获取购物车商品
|
|
37
|
+
*/
|
|
34
38
|
getItems(): CartItem[];
|
|
39
|
+
/**
|
|
40
|
+
* 移除购物车商品
|
|
41
|
+
*/
|
|
35
42
|
removeItem(id: string): Promise<void>;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
/**
|
|
44
|
+
* 根据账户ID清除购物车
|
|
45
|
+
*/
|
|
39
46
|
clearCartByAccount(account_id: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* 根据账户ID获取购物车
|
|
49
|
+
*/
|
|
40
50
|
getCartByAccount(account_id: string | number): CartItem[];
|
|
51
|
+
/**
|
|
52
|
+
* 清除购物车
|
|
53
|
+
*/
|
|
54
|
+
clear(): void;
|
|
41
55
|
}
|
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(Cart_exports);
|
|
|
26
26
|
var import_BaseModule = require("../BaseModule");
|
|
27
27
|
var import_types = require("./types");
|
|
28
28
|
var import_utils = require("./utils");
|
|
29
|
+
var import_lodash_es = require("lodash-es");
|
|
29
30
|
__reExport(Cart_exports, require("./types"), module.exports);
|
|
30
31
|
var CartModule = class extends import_BaseModule.BaseModule {
|
|
31
32
|
constructor(name, version) {
|
|
@@ -33,15 +34,6 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
33
34
|
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
34
35
|
this.defaultName = "cart";
|
|
35
36
|
this.defaultVersion = "1.0.0";
|
|
36
|
-
// 导出的模块 API
|
|
37
|
-
this.exports = {
|
|
38
|
-
addItem: this.addItem.bind(this),
|
|
39
|
-
getItemCount: this.getItemCount.bind(this),
|
|
40
|
-
getTotalPrice: this.getTotalPrice.bind(this),
|
|
41
|
-
getItems: this.getItems.bind(this),
|
|
42
|
-
updateItem: this.updateItem.bind(this),
|
|
43
|
-
removeItem: this.removeItem.bind(this)
|
|
44
|
-
};
|
|
45
37
|
}
|
|
46
38
|
/**
|
|
47
39
|
* 初始化购物车模块
|
|
@@ -68,10 +60,10 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
68
60
|
const { account, product, bundle, options } = params;
|
|
69
61
|
let cartItem = {
|
|
70
62
|
_id: (0, import_utils.getUniqueId)(),
|
|
71
|
-
_origin: (0, import_utils.createCartItemOrigin)()
|
|
72
|
-
_productOrigin: product
|
|
63
|
+
_origin: (0, import_utils.createCartItemOrigin)()
|
|
73
64
|
};
|
|
74
65
|
if (product) {
|
|
66
|
+
cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
|
|
75
67
|
cartItem = (0, import_utils.formatProductToCartItem)({ cartItem, product, bundle, options });
|
|
76
68
|
}
|
|
77
69
|
if (account) {
|
|
@@ -86,77 +78,90 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
86
78
|
* 更新购物车信息
|
|
87
79
|
*/
|
|
88
80
|
async updateItem(params) {
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
try {
|
|
82
|
+
const tempCartItem = this.formatCartItem(params);
|
|
83
|
+
const items = this.store.list.map((item) => {
|
|
84
|
+
if (item._id === (tempCartItem == null ? void 0 : tempCartItem._id)) {
|
|
85
|
+
return tempCartItem;
|
|
86
|
+
}
|
|
87
|
+
return item;
|
|
88
|
+
});
|
|
89
|
+
this.store.list = [...items];
|
|
90
|
+
await this.core.effects.emit(import_types.CartHooks.OnCartUpdateItem, tempCartItem);
|
|
91
|
+
await this.core.effects.emit(`${this.name}:changed`, items);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error("[CartModule] 更新购物车商品失败", error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 格式化数据到购物车
|
|
98
|
+
*/
|
|
99
|
+
formatCartItem(params) {
|
|
100
|
+
const { _id, cartItem, account, product, discounts, resources, note } = params;
|
|
91
101
|
let tempCartItem = this.store.list.find((i) => i._id === _id);
|
|
92
102
|
if (!tempCartItem) {
|
|
93
|
-
|
|
94
|
-
return;
|
|
103
|
+
throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
|
|
95
104
|
}
|
|
96
105
|
if (cartItem) {
|
|
97
106
|
tempCartItem = cartItem;
|
|
98
107
|
}
|
|
99
108
|
if (product) {
|
|
109
|
+
tempCartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
|
|
100
110
|
tempCartItem = (0, import_utils.formatProductToCartItem)({ cartItem: tempCartItem, product });
|
|
101
111
|
}
|
|
112
|
+
if (discounts) {
|
|
113
|
+
tempCartItem = (0, import_utils.formatDiscountToCartItem)({ cartItem: tempCartItem, discounts });
|
|
114
|
+
}
|
|
102
115
|
if (account) {
|
|
103
116
|
tempCartItem = (0, import_utils.formatAccountToCartItem)({ cartItem: tempCartItem, account });
|
|
104
117
|
}
|
|
105
118
|
if (resources) {
|
|
106
119
|
tempCartItem = (0, import_utils.formatResourceToCartItem)({ cartItem: tempCartItem, resources });
|
|
107
120
|
}
|
|
108
|
-
if (note
|
|
109
|
-
tempCartItem
|
|
110
|
-
tempCartItem._origin.product.note = note;
|
|
121
|
+
if (note) {
|
|
122
|
+
tempCartItem = (0, import_utils.formatNoteToCartItem)({ cartItem: tempCartItem, note });
|
|
111
123
|
}
|
|
112
|
-
|
|
113
|
-
if (item._id === (tempCartItem == null ? void 0 : tempCartItem._id)) {
|
|
114
|
-
return tempCartItem;
|
|
115
|
-
}
|
|
116
|
-
return item;
|
|
117
|
-
});
|
|
118
|
-
this.store.list = items;
|
|
119
|
-
await this.core.effects.emit(`${this.name}:changed`, items);
|
|
124
|
+
return tempCartItem;
|
|
120
125
|
}
|
|
121
126
|
/**
|
|
122
127
|
* 批量设置购物车数据
|
|
123
128
|
*/
|
|
124
129
|
async batchSetItems(items) {
|
|
125
130
|
this.store.list = items || [];
|
|
131
|
+
await this.core.effects.emit(`${this.name}:changed`, items);
|
|
126
132
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
getTotalPrice() {
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
133
|
+
/**
|
|
134
|
+
* 获取购物车商品
|
|
135
|
+
*/
|
|
133
136
|
getItems() {
|
|
134
137
|
return this.store.list;
|
|
135
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* 移除购物车商品
|
|
141
|
+
*/
|
|
136
142
|
async removeItem(id) {
|
|
137
143
|
const items = this.store.list.filter((i) => i._id !== id);
|
|
138
144
|
this.store.list = items;
|
|
139
145
|
await this.core.effects.emit(import_types.CartHooks.OnCartRemove, items);
|
|
140
146
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
getTemp(key) {
|
|
146
|
-
if (!key) {
|
|
147
|
-
return this.store.temp;
|
|
148
|
-
}
|
|
149
|
-
return this.store.temp[key];
|
|
150
|
-
}
|
|
151
|
-
clear() {
|
|
152
|
-
this.store.list = [];
|
|
153
|
-
}
|
|
147
|
+
/**
|
|
148
|
+
* 根据账户ID清除购物车
|
|
149
|
+
*/
|
|
154
150
|
clearCartByAccount(account_id) {
|
|
155
151
|
this.store.list = this.store.list.filter((item) => item.holder_id !== account_id);
|
|
156
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* 根据账户ID获取购物车
|
|
155
|
+
*/
|
|
157
156
|
getCartByAccount(account_id) {
|
|
158
157
|
return this.store.list.filter((item) => item.holder_id === account_id);
|
|
159
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* 清除购物车
|
|
161
|
+
*/
|
|
162
|
+
clear() {
|
|
163
|
+
this.store.list = [];
|
|
164
|
+
}
|
|
160
165
|
};
|
|
161
166
|
// Annotate the CommonJS export names for ESM import in node:
|
|
162
167
|
0 && (module.exports = {
|
|
@@ -7,6 +7,26 @@ export declare enum CartHooks {
|
|
|
7
7
|
OnCartUpdateItem = "card:onCartUpdateItem",
|
|
8
8
|
OnCartRemove = "card:onCartRemove"
|
|
9
9
|
}
|
|
10
|
+
export interface CartModuleAPI {
|
|
11
|
+
/** 添加商品到购物车 */
|
|
12
|
+
addItem: (item: IAddItemParams) => Promise<void>;
|
|
13
|
+
/** 获取购物车商品 */
|
|
14
|
+
getItems: () => CartItem[];
|
|
15
|
+
/** 更新购物车商品 */
|
|
16
|
+
updateItem: (params: IUpdateItemParams) => Promise<void>;
|
|
17
|
+
/** 格式化购物车商品 */
|
|
18
|
+
formatCartItem: (params: IUpdateItemParams) => CartItem;
|
|
19
|
+
/** 批量设置购物车商品 */
|
|
20
|
+
batchSetItems: (items: CartItem[]) => Promise<void>;
|
|
21
|
+
/** 移除购物车商品 */
|
|
22
|
+
removeItem: (id: string) => Promise<void>;
|
|
23
|
+
/** 根据账户ID清除购物车 */
|
|
24
|
+
clearCartByAccount: (account_id: string) => void;
|
|
25
|
+
/** 根据账户ID获取购物车 */
|
|
26
|
+
getCartByAccount: (account_id: string) => CartItem[];
|
|
27
|
+
/** 清除购物车 */
|
|
28
|
+
clear: () => void;
|
|
29
|
+
}
|
|
10
30
|
/**
|
|
11
31
|
* 购物车商品接口
|
|
12
32
|
*/
|
|
@@ -67,7 +87,7 @@ export interface CartItem {
|
|
|
67
87
|
/** 原始数据 */
|
|
68
88
|
_origin: any;
|
|
69
89
|
/** 商品原始数据 */
|
|
70
|
-
_productOrigin
|
|
90
|
+
_productOrigin?: ProductData;
|
|
71
91
|
}
|
|
72
92
|
/**
|
|
73
93
|
* 购物车状态接口
|
|
@@ -77,17 +97,6 @@ export interface CartState {
|
|
|
77
97
|
total: number;
|
|
78
98
|
temp: Record<string, any>;
|
|
79
99
|
}
|
|
80
|
-
/**
|
|
81
|
-
* 购物车模块 API
|
|
82
|
-
*/
|
|
83
|
-
export interface CartModuleAPI {
|
|
84
|
-
addItem: (item: IAddItemParams) => Promise<void>;
|
|
85
|
-
getItemCount: () => number;
|
|
86
|
-
getTotalPrice: () => number;
|
|
87
|
-
getItems: () => CartItem[];
|
|
88
|
-
updateItem: (params: IUpdateItemParams) => Promise<void>;
|
|
89
|
-
removeItem: (id: string) => Promise<void>;
|
|
90
|
-
}
|
|
91
100
|
/**
|
|
92
101
|
* 添加商品到购物车参数
|
|
93
102
|
*/
|
|
@@ -108,13 +117,15 @@ export interface IAddItemParams {
|
|
|
108
117
|
*/
|
|
109
118
|
export interface IUpdateItemParams {
|
|
110
119
|
/** 购物车_id字段 */
|
|
111
|
-
_id
|
|
120
|
+
_id: string;
|
|
112
121
|
/** 购物车商品 */
|
|
113
122
|
cartItem?: CartItem;
|
|
114
123
|
/** 账户 */
|
|
115
124
|
account?: Account;
|
|
116
125
|
/** 商品 */
|
|
117
126
|
product?: ProductData;
|
|
127
|
+
/** 折扣列表 */
|
|
128
|
+
discounts?: IDiscount[];
|
|
118
129
|
/** 数量 */
|
|
119
130
|
quantity?: number;
|
|
120
131
|
/** 资源 */
|
|
@@ -122,3 +133,13 @@ export interface IUpdateItemParams {
|
|
|
122
133
|
/** 备注 */
|
|
123
134
|
note?: string;
|
|
124
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 折扣
|
|
138
|
+
*/
|
|
139
|
+
export interface IDiscount {
|
|
140
|
+
amount?: number;
|
|
141
|
+
type?: string;
|
|
142
|
+
resource_id?: string;
|
|
143
|
+
title?: any;
|
|
144
|
+
original_amount?: number;
|
|
145
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Account } from "../Account";
|
|
2
2
|
import { ProductData } from "../Product/types";
|
|
3
3
|
import { Resource } from "../Resource/types";
|
|
4
|
-
import { CartItem } from "./types";
|
|
4
|
+
import { CartItem, IDiscount } from "./types";
|
|
5
5
|
/**
|
|
6
6
|
* 生成一个唯一的 ID
|
|
7
7
|
*/
|
|
@@ -46,6 +46,24 @@ export declare const formatProductToCartItemOrigin: (params: {
|
|
|
46
46
|
bundle?: any;
|
|
47
47
|
options?: any;
|
|
48
48
|
}) => any;
|
|
49
|
+
/**
|
|
50
|
+
* 格式化折扣到购物车
|
|
51
|
+
* @param params 参数
|
|
52
|
+
* @returns 格式化后的购物车
|
|
53
|
+
*/
|
|
54
|
+
export declare const formatDiscountToCartItem: (params: {
|
|
55
|
+
cartItem: CartItem;
|
|
56
|
+
discounts: IDiscount[];
|
|
57
|
+
}) => CartItem;
|
|
58
|
+
/**
|
|
59
|
+
* 格式化折扣到购物车原始数据
|
|
60
|
+
* @param params 参数
|
|
61
|
+
* @returns 格式化后的购物车原始数据
|
|
62
|
+
*/
|
|
63
|
+
export declare const formatDiscountToCartItemOrigin: (params: {
|
|
64
|
+
cartItem: CartItem;
|
|
65
|
+
discounts: IDiscount[];
|
|
66
|
+
}) => any;
|
|
49
67
|
/**
|
|
50
68
|
* 格式化账户到购物车
|
|
51
69
|
* @param account 账户
|
|
@@ -72,6 +90,24 @@ export declare const formatResourceToCartItemOrigin: (params: {
|
|
|
72
90
|
cartItem: CartItem;
|
|
73
91
|
resources: Resource[];
|
|
74
92
|
}) => any;
|
|
93
|
+
/**
|
|
94
|
+
* 格式化备注到购物车
|
|
95
|
+
* @param params 参数
|
|
96
|
+
* @returns 格式化后的购物车
|
|
97
|
+
*/
|
|
98
|
+
export declare const formatNoteToCartItem: (params: {
|
|
99
|
+
cartItem: CartItem;
|
|
100
|
+
note: string;
|
|
101
|
+
}) => CartItem;
|
|
102
|
+
/**
|
|
103
|
+
* 格式化备注到购物车原始数据
|
|
104
|
+
* @param params 参数
|
|
105
|
+
* @returns 格式化后的购物车原始数据
|
|
106
|
+
*/
|
|
107
|
+
export declare const formatNoteToCartItemOrigin: (params: {
|
|
108
|
+
cartItem: CartItem;
|
|
109
|
+
note: string;
|
|
110
|
+
}) => any;
|
|
75
111
|
/**
|
|
76
112
|
* 格式化套餐规格信息
|
|
77
113
|
* @param options 套餐规格信息
|
|
@@ -34,6 +34,10 @@ __export(utils_exports, {
|
|
|
34
34
|
formatAccountToCartItemOrigin: () => formatAccountToCartItemOrigin,
|
|
35
35
|
formatBundle: () => formatBundle,
|
|
36
36
|
formatBundleToOrigin: () => formatBundleToOrigin,
|
|
37
|
+
formatDiscountToCartItem: () => formatDiscountToCartItem,
|
|
38
|
+
formatDiscountToCartItemOrigin: () => formatDiscountToCartItemOrigin,
|
|
39
|
+
formatNoteToCartItem: () => formatNoteToCartItem,
|
|
40
|
+
formatNoteToCartItemOrigin: () => formatNoteToCartItemOrigin,
|
|
37
41
|
formatOptions: () => formatOptions,
|
|
38
42
|
formatOptionsToOrigin: () => formatOptionsToOrigin,
|
|
39
43
|
formatProductToCartItem: () => formatProductToCartItem,
|
|
@@ -142,6 +146,23 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
142
146
|
}
|
|
143
147
|
return origin;
|
|
144
148
|
};
|
|
149
|
+
var formatDiscountToCartItem = (params) => {
|
|
150
|
+
const { cartItem } = params;
|
|
151
|
+
const oringin = formatDiscountToCartItemOrigin(params);
|
|
152
|
+
cartItem._origin = oringin;
|
|
153
|
+
return cartItem;
|
|
154
|
+
};
|
|
155
|
+
var formatDiscountToCartItemOrigin = (params) => {
|
|
156
|
+
const { cartItem, discounts } = params;
|
|
157
|
+
const origin = cartItem._origin;
|
|
158
|
+
if (discounts && (discounts == null ? void 0 : discounts.length)) {
|
|
159
|
+
if (!origin.product) {
|
|
160
|
+
origin.product = {};
|
|
161
|
+
}
|
|
162
|
+
origin.product.discount_list = discounts;
|
|
163
|
+
}
|
|
164
|
+
return origin;
|
|
165
|
+
};
|
|
145
166
|
var formatAccountToCartItem = (params) => {
|
|
146
167
|
const { cartItem, account } = params;
|
|
147
168
|
if (account) {
|
|
@@ -205,6 +226,22 @@ var formatResourceToCartItemOrigin = (params) => {
|
|
|
205
226
|
}
|
|
206
227
|
return origin;
|
|
207
228
|
};
|
|
229
|
+
var formatNoteToCartItem = (params) => {
|
|
230
|
+
const { cartItem, note } = params;
|
|
231
|
+
cartItem.note = note;
|
|
232
|
+
const oringin = formatNoteToCartItemOrigin(params);
|
|
233
|
+
cartItem._origin = oringin;
|
|
234
|
+
return cartItem;
|
|
235
|
+
};
|
|
236
|
+
var formatNoteToCartItemOrigin = (params) => {
|
|
237
|
+
const { cartItem, note } = params;
|
|
238
|
+
const origin = cartItem._origin;
|
|
239
|
+
if (!origin.product) {
|
|
240
|
+
origin.product = {};
|
|
241
|
+
}
|
|
242
|
+
origin.product.note = note;
|
|
243
|
+
return origin;
|
|
244
|
+
};
|
|
208
245
|
var formatOptions = (options) => {
|
|
209
246
|
if (!(options == null ? void 0 : options.length))
|
|
210
247
|
return [];
|
|
@@ -307,6 +344,10 @@ var getProductOriginTotalPrice = (params) => {
|
|
|
307
344
|
formatAccountToCartItemOrigin,
|
|
308
345
|
formatBundle,
|
|
309
346
|
formatBundleToOrigin,
|
|
347
|
+
formatDiscountToCartItem,
|
|
348
|
+
formatDiscountToCartItemOrigin,
|
|
349
|
+
formatNoteToCartItem,
|
|
350
|
+
formatNoteToCartItemOrigin,
|
|
310
351
|
formatOptions,
|
|
311
352
|
formatOptionsToOrigin,
|
|
312
353
|
formatProductToCartItem,
|
|
@@ -45,6 +45,9 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
45
45
|
this.core = core;
|
|
46
46
|
this.store = options.store;
|
|
47
47
|
this.request = this.core.getPlugin("request");
|
|
48
|
+
if (!this.request) {
|
|
49
|
+
throw new Error("DateModule 需要 request 插件支持");
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
setDateRange(dateRange) {
|
|
50
53
|
this.store.dateRange = dateRange;
|
|
@@ -184,10 +184,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
184
184
|
const discountDetail = {
|
|
185
185
|
amount: product.price,
|
|
186
186
|
type: selectedDiscount.tag,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
discount: {
|
|
188
|
+
resource_id: selectedDiscount.id,
|
|
189
|
+
title: selectedDiscount.format_title,
|
|
190
|
+
original_amount: product.origin_total,
|
|
191
|
+
product_id: selectedDiscount.product_id
|
|
192
|
+
}
|
|
191
193
|
};
|
|
192
194
|
appliedProducts.push(discountDetail);
|
|
193
195
|
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
@@ -34,6 +34,9 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
34
34
|
this.core = core;
|
|
35
35
|
this.store = options.store;
|
|
36
36
|
this.shopStore = this.core.getPlugin("shopStore");
|
|
37
|
+
if (!this.shopStore) {
|
|
38
|
+
throw new Error("SummaryModule 需要 shopStore 插件支持");
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
async getSummary(cartItems) {
|
|
39
42
|
var _a, _b;
|
|
@@ -25,7 +25,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
25
25
|
back(): void;
|
|
26
26
|
gotoStep(index: number): void;
|
|
27
27
|
getStepList(): IStep[];
|
|
28
|
-
getStoreCart(key?: string): Promise<any>;
|
|
29
28
|
loadProducts({ category_ids, product_ids, collection, }: {
|
|
30
29
|
category_ids?: number[];
|
|
31
30
|
product_ids?: number[];
|
|
@@ -107,9 +107,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
107
107
|
return this.store.step.getStepList();
|
|
108
108
|
}
|
|
109
109
|
// 获取购物车里 temp.xxx的方法
|
|
110
|
-
async getStoreCart(key) {
|
|
111
|
-
|
|
112
|
-
}
|
|
110
|
+
// async getStoreCart(key?: string) {
|
|
111
|
+
// return this.store.cart.getTemp(key);
|
|
112
|
+
// }
|
|
113
113
|
// 加载商品,然后导到商品列表里去
|
|
114
114
|
async loadProducts({
|
|
115
115
|
category_ids = [],
|
|
@@ -393,18 +393,24 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
393
393
|
resources_code,
|
|
394
394
|
timeSlots
|
|
395
395
|
}) {
|
|
396
|
-
var _a;
|
|
396
|
+
var _a, _b, _c;
|
|
397
397
|
const dateRange = this.store.date.getDateRange();
|
|
398
398
|
const cartItems = this.store.cart.getItems();
|
|
399
|
-
const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id);
|
|
399
|
+
const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
|
|
400
|
+
if (!accountCartItems.length) {
|
|
401
|
+
return {
|
|
402
|
+
selectedResource: null
|
|
403
|
+
};
|
|
404
|
+
}
|
|
400
405
|
let duration = accountCartItems.reduce((acc, n) => {
|
|
401
|
-
|
|
406
|
+
var _a2, _b2;
|
|
407
|
+
return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
|
|
402
408
|
}, 0);
|
|
403
|
-
let durationType = ((_a = accountCartItems == null ? void 0 :
|
|
409
|
+
let durationType = ((_c = (_b = (_a = accountCartItems[0]) == null ? void 0 : _a._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.type) ?? "minutes";
|
|
404
410
|
const resources = [];
|
|
405
411
|
accountCartItems.forEach((item) => {
|
|
406
|
-
var _a2,
|
|
407
|
-
(
|
|
412
|
+
var _a2, _b2, _c2;
|
|
413
|
+
(_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
|
|
408
414
|
if (n.code === resources_code) {
|
|
409
415
|
resources.push(...n.renderList || []);
|
|
410
416
|
}
|
|
@@ -475,7 +481,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
475
481
|
console.log(this.store.cart.getItems());
|
|
476
482
|
this.store.cart.updateItem({
|
|
477
483
|
_id: item._id,
|
|
478
|
-
|
|
484
|
+
// 这里要做去重,避免出现同样类型的资源被塞进同一个商品
|
|
485
|
+
resources: [
|
|
486
|
+
...(item._origin.resources || []).filter(
|
|
487
|
+
(existingRes) => existingRes.resourceType !== res.selectedResource.resourceType
|
|
488
|
+
),
|
|
489
|
+
res.selectedResource
|
|
490
|
+
]
|
|
479
491
|
});
|
|
480
492
|
console.log(this.store.cart.getItems());
|
|
481
493
|
} else {
|
|
@@ -493,7 +505,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
493
505
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
494
506
|
this.store.cart.updateItem({
|
|
495
507
|
_id: item._id,
|
|
496
|
-
resources: [
|
|
508
|
+
resources: [
|
|
509
|
+
...(item._origin.resources || []).filter(
|
|
510
|
+
(existingRes) => existingRes.resourceType !== targetRenderList[0].resourceType
|
|
511
|
+
),
|
|
512
|
+
targetRenderList[0]
|
|
513
|
+
]
|
|
497
514
|
});
|
|
498
515
|
} else {
|
|
499
516
|
errorList.push(item._id);
|
|
@@ -510,13 +527,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
510
527
|
const cartItems = this.store.cart.getItems();
|
|
511
528
|
const resourceIds = [];
|
|
512
529
|
cartItems.forEach((item) => {
|
|
513
|
-
var _a, _b, _c;
|
|
514
|
-
(_b = (_a = item._productOrigin.product_resource) == null ? void 0 :
|
|
530
|
+
var _a, _b, _c, _d;
|
|
531
|
+
(_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
|
|
515
532
|
if (n.code === resources_code) {
|
|
516
533
|
resources.push(...n.renderList || []);
|
|
517
534
|
}
|
|
518
535
|
});
|
|
519
|
-
(
|
|
536
|
+
(_d = item._origin.resources) == null ? void 0 : _d.forEach((n) => {
|
|
520
537
|
resourceIds.push(n.relation_id);
|
|
521
538
|
});
|
|
522
539
|
});
|
|
@@ -526,7 +543,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
526
543
|
let accountDuration = 0;
|
|
527
544
|
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
528
545
|
cartItems2.forEach((item) => {
|
|
529
|
-
|
|
546
|
+
var _a, _b;
|
|
547
|
+
accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
|
|
530
548
|
});
|
|
531
549
|
if (accountDuration > duration) {
|
|
532
550
|
duration = accountDuration;
|
|
@@ -572,8 +590,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
572
590
|
cartItems.forEach((item) => {
|
|
573
591
|
const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
|
|
574
592
|
newResources.forEach((n) => {
|
|
593
|
+
var _a, _b, _c, _d;
|
|
575
594
|
n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
576
|
-
n.endTime = (0, import_dayjs.default)(n.startTime).add(item._productOrigin.duration.value, item._productOrigin.duration.type).format("YYYY-MM-DD HH:mm");
|
|
595
|
+
n.endTime = (0, import_dayjs.default)(n.startTime).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes").format("YYYY-MM-DD HH:mm");
|
|
577
596
|
delete n.times;
|
|
578
597
|
});
|
|
579
598
|
this.store.cart.updateItem({
|
|
@@ -149,7 +149,10 @@ var getResourcesByProduct = (resourcesMap, cartItem, cartList) => {
|
|
|
149
149
|
}, []);
|
|
150
150
|
item.renderList = optional_resource.concat(default_resource);
|
|
151
151
|
item.renderList = item.renderList.filter((d) => {
|
|
152
|
-
|
|
152
|
+
const latestTime = d.times.reduce((latest, current) => {
|
|
153
|
+
return (0, import_dayjs.default)(current.end_at).isAfter((0, import_dayjs.default)(latest.end_at)) ? current : latest;
|
|
154
|
+
}, d.times[0]);
|
|
155
|
+
return (0, import_dayjs.default)(latestTime.end_at).isAfter((0, import_dayjs.default)());
|
|
153
156
|
});
|
|
154
157
|
item.form_id = form_id;
|
|
155
158
|
acc.push(item);
|