@pisell/pisellos 0.0.44 → 0.0.46

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.
Files changed (127) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +5 -5
  13. package/dist/modules/Cart/index.js +33 -19
  14. package/dist/modules/Cart/types.d.ts +21 -7
  15. package/dist/modules/Cart/utils.d.ts +29 -5
  16. package/dist/modules/Cart/utils.js +72 -26
  17. package/dist/modules/Date/index.d.ts +6 -6
  18. package/dist/modules/Date/index.js +41 -55
  19. package/dist/modules/Date/types.d.ts +22 -6
  20. package/dist/modules/Date/utils.d.ts +4 -3
  21. package/dist/modules/Date/utils.js +74 -23
  22. package/dist/modules/Discount/index.d.ts +4 -4
  23. package/dist/modules/Discount/index.js +11 -11
  24. package/dist/modules/Order/index.d.ts +10 -5
  25. package/dist/modules/Order/index.js +32 -16
  26. package/dist/modules/Order/types.d.ts +10 -3
  27. package/dist/modules/Product/index.d.ts +4 -1
  28. package/dist/modules/Product/index.js +22 -0
  29. package/dist/modules/Product/types.d.ts +7 -3
  30. package/dist/modules/ProductList/index.js +11 -5
  31. package/dist/modules/Resource/utils.js +1 -1
  32. package/dist/modules/Rules/index.d.ts +4 -4
  33. package/dist/modules/Rules/index.js +11 -11
  34. package/dist/modules/Rules/types.d.ts +1 -1
  35. package/dist/modules/Schedule/index.d.ts +8 -3
  36. package/dist/modules/Schedule/index.js +45 -5
  37. package/dist/modules/Schedule/type.d.ts +7 -7
  38. package/dist/modules/Schedule/types.d.ts +8 -8
  39. package/dist/modules/Schedule/utils.d.ts +9 -3
  40. package/dist/modules/Schedule/utils.js +77 -48
  41. package/dist/modules/Step/index.d.ts +14 -3
  42. package/dist/modules/Step/index.js +54 -2
  43. package/dist/modules/Summary/index.d.ts +5 -5
  44. package/dist/modules/Summary/index.js +7 -7
  45. package/dist/modules/Summary/types.d.ts +2 -2
  46. package/dist/modules/Summary/utils.d.ts +4 -4
  47. package/dist/modules/Summary/utils.js +3 -3
  48. package/dist/plugins/index.d.ts +3 -3
  49. package/dist/plugins/request.d.ts +3 -3
  50. package/dist/plugins/request.js +30 -30
  51. package/dist/plugins/shopStore.d.ts +1 -1
  52. package/dist/solution/BookingByStep/index.d.ts +71 -16
  53. package/dist/solution/BookingByStep/index.js +643 -227
  54. package/dist/solution/BookingByStep/types.d.ts +2 -2
  55. package/dist/solution/BookingByStep/types.js +9 -9
  56. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  57. package/dist/solution/BookingByStep/utils/products.js +3 -0
  58. package/dist/solution/BookingByStep/utils/resources.d.ts +6 -5
  59. package/dist/solution/BookingByStep/utils/resources.js +37 -19
  60. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  61. package/dist/solution/ShopDiscount/index.js +16 -16
  62. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  63. package/dist/solution/ShopDiscount/utils.js +1 -1
  64. package/lib/core/index.js +7 -2
  65. package/lib/modules/Account/index.d.ts +2 -6
  66. package/lib/modules/Account/index.js +15 -30
  67. package/lib/modules/Account/types.d.ts +12 -1
  68. package/lib/modules/AccountList/index.d.ts +20 -1
  69. package/lib/modules/AccountList/index.js +122 -13
  70. package/lib/modules/AccountList/types.d.ts +33 -1
  71. package/lib/modules/AccountList/utils.d.ts +9 -0
  72. package/lib/modules/AccountList/utils.js +39 -0
  73. package/lib/modules/BaseModule.d.ts +2 -2
  74. package/lib/modules/BaseModule.js +14 -3
  75. package/lib/modules/Cart/index.d.ts +5 -5
  76. package/lib/modules/Cart/index.js +28 -6
  77. package/lib/modules/Cart/types.d.ts +21 -7
  78. package/lib/modules/Cart/utils.d.ts +29 -5
  79. package/lib/modules/Cart/utils.js +47 -3
  80. package/lib/modules/Date/index.d.ts +6 -6
  81. package/lib/modules/Date/index.js +6 -6
  82. package/lib/modules/Date/types.d.ts +22 -6
  83. package/lib/modules/Date/utils.d.ts +4 -3
  84. package/lib/modules/Date/utils.js +37 -6
  85. package/lib/modules/Discount/index.d.ts +4 -4
  86. package/lib/modules/Discount/index.js +9 -2
  87. package/lib/modules/Guests/index.js +4 -1
  88. package/lib/modules/Order/index.d.ts +10 -5
  89. package/lib/modules/Order/index.js +11 -1
  90. package/lib/modules/Order/types.d.ts +10 -3
  91. package/lib/modules/Payment/index.js +1 -6
  92. package/lib/modules/Product/index.d.ts +4 -1
  93. package/lib/modules/Product/index.js +16 -0
  94. package/lib/modules/Product/types.d.ts +7 -3
  95. package/lib/modules/ProductList/index.js +21 -7
  96. package/lib/modules/Resource/index.js +4 -1
  97. package/lib/modules/Resource/utils.js +7 -4
  98. package/lib/modules/Rules/index.d.ts +4 -4
  99. package/lib/modules/Rules/types.d.ts +1 -1
  100. package/lib/modules/Schedule/index.d.ts +8 -3
  101. package/lib/modules/Schedule/index.js +33 -2
  102. package/lib/modules/Schedule/type.d.ts +7 -7
  103. package/lib/modules/Schedule/types.d.ts +8 -8
  104. package/lib/modules/Schedule/utils.d.ts +9 -3
  105. package/lib/modules/Schedule/utils.js +32 -4
  106. package/lib/modules/Step/index.d.ts +14 -3
  107. package/lib/modules/Step/index.js +38 -1
  108. package/lib/modules/Summary/index.d.ts +5 -5
  109. package/lib/modules/Summary/types.d.ts +2 -2
  110. package/lib/modules/Summary/utils.d.ts +4 -4
  111. package/lib/plugins/index.d.ts +3 -3
  112. package/lib/plugins/request.d.ts +3 -3
  113. package/lib/plugins/request.js +48 -11
  114. package/lib/plugins/shopStore.d.ts +1 -1
  115. package/lib/solution/BookingByStep/index.d.ts +71 -16
  116. package/lib/solution/BookingByStep/index.js +396 -48
  117. package/lib/solution/BookingByStep/types.d.ts +2 -2
  118. package/lib/solution/BookingByStep/types.js +36 -9
  119. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  120. package/lib/solution/BookingByStep/utils/products.js +3 -0
  121. package/lib/solution/BookingByStep/utils/resources.d.ts +6 -5
  122. package/lib/solution/BookingByStep/utils/resources.js +128 -58
  123. package/lib/solution/BuyTickets/index.js +34 -20
  124. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  125. package/lib/solution/ShopDiscount/index.js +10 -2
  126. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  127. package/package.json +4 -2
@@ -26,6 +26,7 @@ var import_lodash_es = require("lodash-es");
26
26
  var import_Account = require("../Account");
27
27
  var import_BaseModule = require("../BaseModule");
28
28
  var import_types = require("./types");
29
+ var import_utils = require("./utils");
29
30
  var AccountListModule = class extends import_BaseModule.BaseModule {
30
31
  constructor(name, version) {
31
32
  super(name, version);
@@ -45,6 +46,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
45
46
  var _a, _b, _c;
46
47
  this.core = core;
47
48
  this.store = options == null ? void 0 : options.store;
49
+ this.request = this.core.getPlugin("request");
48
50
  if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.accountList)) {
49
51
  const recordList = (0, import_lodash_es.cloneDeep)(options.initialState.accountList || []);
50
52
  this.store.accounts = [];
@@ -63,13 +65,41 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
63
65
  this.fatherModule = options.otherParams.fatherModule;
64
66
  }
65
67
  }
68
+ /**
69
+ * 创建账号并添加到列表中
70
+ * @param account 账号信息
71
+ * @param needEmit 是否需要触发事件
72
+ */
73
+ async createAccountAndAdd(account, needEmit = true) {
74
+ const tempAccountModule = this.store.accounts.find(
75
+ (a) => a.getId() === account.id
76
+ );
77
+ if (tempAccountModule) {
78
+ return tempAccountModule;
79
+ }
80
+ this.store.accountList.push(account);
81
+ const accountModule = new import_Account.AccountModule(`account_${account.id}`);
82
+ this.core.registerModule(accountModule);
83
+ accountModule.setAccountInfo(account);
84
+ this.store.accounts = [...this.store.accounts || [], accountModule];
85
+ if (needEmit) {
86
+ await this.core.effects.emit(
87
+ import_types.AccountListHooks.OnAccountListUpdate,
88
+ this.store
89
+ );
90
+ }
91
+ return accountModule;
92
+ }
66
93
  async addAccount(account) {
94
+ let currentAccountModule;
67
95
  try {
68
96
  this.store.isLoading = true;
69
97
  this.store.error = null;
70
98
  if (this.store.accounts.some((a) => a.getId() === account.id)) {
99
+ currentAccountModule = this.store.accounts.find(
100
+ (n) => n.getId() === account.id
101
+ );
71
102
  throw new Error(`Account with id ${account.id} already exists`);
72
- return;
73
103
  }
74
104
  this.store.accountList.push(account);
75
105
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
@@ -79,13 +109,21 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
79
109
  if (this.store.accounts.length === 1) {
80
110
  this.setActiveAccount(accountModule.getId());
81
111
  }
82
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
112
+ currentAccountModule = accountModule;
113
+ await this.core.effects.emit(
114
+ import_types.AccountListHooks.OnAccountListUpdate,
115
+ this.store
116
+ );
83
117
  } catch (error) {
84
118
  console.error(error);
85
119
  this.store.error = error instanceof Error ? error.message : "Failed to add account";
86
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
120
+ await this.core.effects.emit(
121
+ import_types.AccountListHooks.OnAccountListError,
122
+ this.store.error
123
+ );
87
124
  } finally {
88
125
  this.store.isLoading = false;
126
+ return currentAccountModule;
89
127
  }
90
128
  }
91
129
  async updateAccount(id, updates) {
@@ -97,14 +135,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
97
135
  throw new Error(`Account with id ${id} not found`);
98
136
  }
99
137
  account.setAccountInfo(updates);
100
- const index = this.store.accountList.findIndex((account2) => account2.id === id);
138
+ const index = this.store.accountList.findIndex(
139
+ (account2) => account2.id === id
140
+ );
101
141
  if (index !== -1) {
102
142
  this.store.accountList[index] = updates;
103
143
  }
104
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
144
+ await this.core.effects.emit(
145
+ import_types.AccountListHooks.OnAccountListUpdate,
146
+ this.store
147
+ );
105
148
  } catch (error) {
106
149
  this.store.error = error instanceof Error ? error.message : "Failed to update account";
107
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
150
+ await this.core.effects.emit(
151
+ import_types.AccountListHooks.OnAccountListError,
152
+ this.store.error
153
+ );
108
154
  } finally {
109
155
  this.store.isLoading = false;
110
156
  }
@@ -116,7 +162,10 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
116
162
  }
117
163
  return account;
118
164
  });
119
- this.core.effects.emit(`${this.name}:changed`, { path: "accounts", value: this.store.accountList });
165
+ this.core.effects.emit(`${this.name}:changed`, {
166
+ path: "accounts",
167
+ value: this.store.accountList
168
+ });
120
169
  }
121
170
  async removeAccount(id) {
122
171
  try {
@@ -131,11 +180,19 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
131
180
  ...(this.store.accounts || []).slice(0, index),
132
181
  ...(this.store.accounts || []).slice(index + 1)
133
182
  ];
134
- this.store.accountList = this.store.accountList.filter((account) => account.id !== id);
135
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
183
+ this.store.accountList = this.store.accountList.filter(
184
+ (account) => account.id !== id
185
+ );
186
+ await this.core.effects.emit(
187
+ import_types.AccountListHooks.OnAccountListUpdate,
188
+ this.store
189
+ );
136
190
  } catch (error) {
137
191
  this.store.error = error instanceof Error ? error.message : "Failed to remove account";
138
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
192
+ await this.core.effects.emit(
193
+ import_types.AccountListHooks.OnAccountListError,
194
+ this.store.error
195
+ );
139
196
  } finally {
140
197
  this.store.isLoading = false;
141
198
  }
@@ -151,10 +208,16 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
151
208
  this.store.isLoading = true;
152
209
  this.store.error = null;
153
210
  this.store.accounts = [];
154
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListUpdate, this.store);
211
+ await this.core.effects.emit(
212
+ import_types.AccountListHooks.OnAccountListUpdate,
213
+ this.store
214
+ );
155
215
  } catch (error) {
156
216
  this.store.error = error instanceof Error ? error.message : "Failed to clear accounts";
157
- await this.core.effects.emit(import_types.AccountListHooks.OnAccountListError, this.store.error);
217
+ await this.core.effects.emit(
218
+ import_types.AccountListHooks.OnAccountListError,
219
+ this.store.error
220
+ );
158
221
  } finally {
159
222
  this.store.isLoading = false;
160
223
  }
@@ -177,7 +240,53 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
177
240
  store.accountList = store.accountList.filter(
178
241
  (account, index, self) => index === self.findIndex((t) => t.id === account.id)
179
242
  );
180
- this.checkSaveCache({ cacheId: this.cacheId, fatherModule: this.fatherModule, store, cacheKey: ["accountList"] });
243
+ this.checkSaveCache({
244
+ cacheId: this.cacheId,
245
+ fatherModule: this.fatherModule,
246
+ store,
247
+ cacheKey: ["accountList"]
248
+ });
249
+ }
250
+ }
251
+ /**
252
+ * 批量添加holder类型账号
253
+ * @param holders 账号信息列表
254
+ * @param customerId 账户id
255
+ */
256
+ async addHolderAccounts(holders, customerId) {
257
+ const accountModules = [];
258
+ for (const holder of holders) {
259
+ const account = (0, import_utils.createHolderAccount)(holder, customerId);
260
+ const accountModule = await this.createAccountAndAdd(account, false);
261
+ accountModules.push(accountModule);
262
+ }
263
+ await this.core.effects.emit(
264
+ import_types.AccountListHooks.OnAccountListUpdate,
265
+ this.store
266
+ );
267
+ return accountModules;
268
+ }
269
+ /**
270
+ * 获取holder类型账户列表
271
+ * @param params
272
+ */
273
+ async fetchHolderAccounts(params) {
274
+ var _a, _b;
275
+ const url = params.url || "/account/holder";
276
+ const { form_id, shop_id, num, skip, customer_id } = (params == null ? void 0 : params.query) || {};
277
+ try {
278
+ const res = await this.request.get(url, {
279
+ customer_id,
280
+ form_id,
281
+ shop_id,
282
+ num: num || 100,
283
+ skip: skip || 1
284
+ });
285
+ if ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) == null ? void 0 : _b.length) {
286
+ await this.addHolderAccounts(res.data.list, customer_id);
287
+ }
288
+ } catch (error) {
289
+ console.error(error);
181
290
  }
182
291
  }
183
292
  };
@@ -1,4 +1,4 @@
1
- import { Account, AccountModule } from "../Account";
1
+ import { Account, AccountModule } from '../Account';
2
2
  export declare enum AccountListHooks {
3
3
  OnAccountListUpdate = "accountList:onUpdate",
4
4
  OnAccountListError = "accountList:onError"
@@ -27,11 +27,43 @@ export interface AccountListState {
27
27
  * 账户列表模块 API
28
28
  */
29
29
  export interface AccountListModuleAPI {
30
+ /** 添加账户 */
30
31
  addAccount: (account: Account) => Promise<void>;
32
+ /** 更新账户 */
31
33
  updateAccount: (id: string, updates: Partial<AccountModule>) => Promise<void>;
34
+ /** 删除账户 */
32
35
  removeAccount: (id: string) => Promise<void>;
36
+ /** 获取账户列表 */
33
37
  getAccounts: () => AccountModule[];
38
+ /** 获取单个账户 */
34
39
  getAccount: (id: string) => AccountModule | null;
40
+ /** 清空账户列表 */
35
41
  clearAccounts: () => Promise<void>;
42
+ /** 批量添加账户 */
36
43
  addAccounts: (accounts: AccountModule[]) => Promise<void>;
44
+ /** 获取holder类型账户列表 */
45
+ fetchHolderAccounts: (params: IFetchHolderAccountsParams) => Promise<void>;
46
+ }
47
+ /**
48
+ * 获取holder类型账户列表参数
49
+ */
50
+ export interface IFetchHolderAccountsParams {
51
+ url?: string;
52
+ query: {
53
+ customer_id: number;
54
+ form_id: string | number;
55
+ shop_id: string | number;
56
+ num?: number;
57
+ skip?: number;
58
+ };
59
+ }
60
+ /**
61
+ * holder类型数据
62
+ */
63
+ export interface IHolder {
64
+ created_at: string;
65
+ form_id: number;
66
+ form_record_id: number;
67
+ main_field: string;
68
+ customer_cover?: string;
37
69
  }
@@ -0,0 +1,9 @@
1
+ import { Account } from '../Account/types';
2
+ import { IHolder } from './types';
3
+ /**
4
+ * 创建holder类型账号
5
+ * @param holder
6
+ * @param customer_id 账户id
7
+ * @returns
8
+ */
9
+ export declare const createHolderAccount: (holder: IHolder, customerId: number) => Account;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/AccountList/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ createHolderAccount: () => createHolderAccount
23
+ });
24
+ module.exports = __toCommonJS(utils_exports);
25
+ var createHolderAccount = (holder, customerId) => {
26
+ const account = {
27
+ id: holder.form_record_id,
28
+ name: holder.main_field,
29
+ username: holder.main_field,
30
+ avatar: (holder == null ? void 0 : holder.customer_cover) || "",
31
+ type: "holder",
32
+ _origin: { ...holder, customer_id: customerId }
33
+ };
34
+ return account;
35
+ };
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ createHolderAccount
39
+ });
@@ -1,4 +1,4 @@
1
- import { PisellCore } from "../types";
1
+ import { PisellCore } from '../types';
2
2
  export declare class BaseModule {
3
3
  protected defaultName: string;
4
4
  protected defaultVersion: string;
@@ -8,7 +8,7 @@ export declare class BaseModule {
8
8
  protected core: PisellCore;
9
9
  constructor(name?: string, version?: string);
10
10
  destroy(): void;
11
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }: {
11
+ checkSaveCache({ cacheId, fatherModule, store, cacheKey, }: {
12
12
  cacheId: string | undefined;
13
13
  fatherModule: string | undefined;
14
14
  store: any;
@@ -35,7 +35,12 @@ var BaseModule = class {
35
35
  this.core.unregisterModule(this);
36
36
  }
37
37
  // 提供统一的缓存 module 里的数据的方法
38
- checkSaveCache({ cacheId, fatherModule, store, cacheKey }) {
38
+ checkSaveCache({
39
+ cacheId,
40
+ fatherModule,
41
+ store,
42
+ cacheKey
43
+ }) {
39
44
  const window = this.core.getPlugin("window");
40
45
  if (cacheId) {
41
46
  if (fatherModule) {
@@ -54,7 +59,10 @@ var BaseModule = class {
54
59
  cacheKey.forEach((key) => {
55
60
  currentCacheDataObj[cacheId][this.name][key] = store == null ? void 0 : store[key];
56
61
  });
57
- window.sessionStorage.setItem(fatherModule, JSON.stringify(currentCacheDataObj));
62
+ window.sessionStorage.setItem(
63
+ fatherModule,
64
+ JSON.stringify(currentCacheDataObj)
65
+ );
58
66
  } else {
59
67
  let currentCacheData = window.sessionStorage.getItem(cacheId);
60
68
  let currentCacheDataObj = JSON.parse(currentCacheData || "{}");
@@ -67,7 +75,10 @@ var BaseModule = class {
67
75
  cacheKey.forEach((key) => {
68
76
  currentCacheDataObj[this.name][key] = store[key];
69
77
  });
70
- window.sessionStorage.setItem(cacheId, JSON.stringify(currentCacheDataObj));
78
+ window.sessionStorage.setItem(
79
+ cacheId,
80
+ JSON.stringify(currentCacheDataObj)
81
+ );
71
82
  }
72
83
  }
73
84
  }
@@ -1,7 +1,7 @@
1
- import { Module, PisellCore, ModuleOptions } from "../../types";
2
- import { BaseModule } from "../BaseModule";
3
- import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from "./types";
4
- export * from "./types";
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from './types';
4
+ export * from './types';
5
5
  /**
6
6
  * 购物车模块实现
7
7
  */
@@ -58,7 +58,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
58
58
  /**
59
59
  * 清除购物车商品中的信息
60
60
  */
61
- deleteCartItemInfo(types: "resource" | "time"): void;
61
+ deleteCartItemInfo(types: 'resource' | 'time'): void;
62
62
  /**
63
63
  * 清除购物车
64
64
  */
@@ -23,9 +23,9 @@ __export(Cart_exports, {
23
23
  CartModule: () => CartModule
24
24
  });
25
25
  module.exports = __toCommonJS(Cart_exports);
26
- var import_lodash_es = require("lodash-es");
27
26
  var import_BaseModule = require("../BaseModule");
28
27
  var import_utils = require("./utils");
28
+ var import_lodash_es = require("lodash-es");
29
29
  __reExport(Cart_exports, require("./types"), module.exports);
30
30
  var CartModule = class extends import_BaseModule.BaseModule {
31
31
  constructor(name, version) {
@@ -69,13 +69,14 @@ var CartModule = class extends import_BaseModule.BaseModule {
69
69
  * 添加商品到购物车
70
70
  */
71
71
  async addItem(params) {
72
- const { account, product, bundle, options } = params;
72
+ const { account, product, bundle, options, date } = params;
73
73
  let cartItem = {
74
74
  _id: (0, import_utils.getUniqueId)(),
75
75
  _origin: (0, import_utils.createCartItemOrigin)()
76
76
  };
77
77
  if (product) {
78
78
  cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
79
+ cartItem._productInit = (0, import_lodash_es.cloneDeep)(product);
79
80
  cartItem = (0, import_utils.formatProductToCartItem)({
80
81
  cartItem,
81
82
  product,
@@ -86,6 +87,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
86
87
  if (account) {
87
88
  cartItem = (0, import_utils.formatAccountToCartItem)({ cartItem, account });
88
89
  }
90
+ if (date) {
91
+ cartItem = (0, import_utils.formatDateToCartItem)({ cartItem, date });
92
+ }
89
93
  const items = [...this.store.list, cartItem];
90
94
  this.store.list = items;
91
95
  await this.core.effects.emit(`${this.name}:onAddItem`, cartItem);
@@ -112,7 +116,16 @@ var CartModule = class extends import_BaseModule.BaseModule {
112
116
  * 格式化数据到购物车
113
117
  */
114
118
  formatCartItem(params) {
115
- const { _id, cartItem, account, product, discounts, resources, note } = params;
119
+ const {
120
+ _id,
121
+ cartItem,
122
+ account,
123
+ product,
124
+ discounts,
125
+ resources,
126
+ note,
127
+ date
128
+ } = params;
116
129
  let tempCartItem = this.store.list.find((i) => i._id === _id);
117
130
  if (!tempCartItem) {
118
131
  throw new Error("[CartModule] 格式化数据到购物车失败,商品不存在");
@@ -145,6 +158,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
145
158
  resources
146
159
  });
147
160
  }
161
+ if (date) {
162
+ tempCartItem = (0, import_utils.formatDateToCartItem)({ cartItem: tempCartItem, date });
163
+ }
148
164
  if (note) {
149
165
  tempCartItem = (0, import_utils.formatNoteToCartItem)({ cartItem: tempCartItem, note });
150
166
  }
@@ -172,7 +188,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
172
188
  * 根据账户ID获取购物车
173
189
  */
174
190
  getCartByAccount(account_id) {
175
- return this.store.list.filter((item) => item.holder_id === account_id);
191
+ return this.store.list.filter(
192
+ (item) => item.holder_id === account_id
193
+ );
176
194
  }
177
195
  /**
178
196
  * 移除购物车商品
@@ -186,7 +204,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
186
204
  * 根据账户ID清除购物车
187
205
  */
188
206
  clearCartByAccount(account_id) {
189
- const items = this.store.list.filter((item) => item.holder_id !== account_id);
207
+ const items = this.store.list.filter(
208
+ (item) => item.holder_id !== account_id
209
+ );
190
210
  this.store.list = [...items || []];
191
211
  }
192
212
  /**
@@ -212,7 +232,9 @@ var CartModule = class extends import_BaseModule.BaseModule {
212
232
  storeChange() {
213
233
  if (this.openCache) {
214
234
  const store = (0, import_lodash_es.cloneDeep)(this.store);
215
- store.list = store.list.filter((item, index, self) => index === self.findIndex((t) => t._id === item._id));
235
+ store.list = store.list.filter(
236
+ (item, index, self) => index === self.findIndex((t) => t._id === item._id)
237
+ );
216
238
  this.checkSaveCache({
217
239
  cacheId: this.cacheId,
218
240
  fatherModule: this.fatherModule,
@@ -1,6 +1,6 @@
1
- import { ProductData } from "../Product/types";
2
- import { Account } from "../Account/types";
3
- import { Resource } from "../Resource/types";
1
+ import { ProductData } from '../Product/types';
2
+ import { Account } from '../Account/types';
3
+ import { Resource } from '../Resource/types';
4
4
  export declare enum CartHooks {
5
5
  OnAddItem = "card:onAddItem",
6
6
  OnCartChange = "card:onCartChange",
@@ -57,7 +57,7 @@ export interface CartItem {
57
57
  /** 备注 */
58
58
  note?: string;
59
59
  /** 点赞状态 */
60
- like_status?: "like" | "common";
60
+ like_status?: 'like' | 'common';
61
61
  /** 用户名称 */
62
62
  holder_title?: string;
63
63
  /** 用户ID */
@@ -96,16 +96,16 @@ export interface CartItem {
96
96
  title: string;
97
97
  }[];
98
98
  } | null;
99
- /** 原始数据 */
99
+ /** 接口原始数据 */
100
100
  _origin: any;
101
+ /** 商品加入购物车时初始数据 */
102
+ _productInit?: ProductData;
101
103
  /** 商品原始数据 */
102
104
  _productOrigin?: ProductData;
103
105
  /** 资源原始数据 */
104
106
  _resourceOrigin?: Resource[];
105
107
  /** 容量 */
106
108
  capacity?: any;
107
- /** 商品套餐 */
108
- product_bundle?: any;
109
109
  }
110
110
  /**
111
111
  * 购物车状态接口
@@ -127,6 +127,13 @@ export interface IAddItemParams {
127
127
  bundle?: any[];
128
128
  /** 商品规格信息 */
129
129
  options?: any[];
130
+ /** 日期 */
131
+ date?: {
132
+ /** 开始时间 */
133
+ startTime: string;
134
+ /** 结束时间 */
135
+ endTime: string;
136
+ };
130
137
  }
131
138
  /**
132
139
  * 更新购物车信息参数
@@ -148,6 +155,13 @@ export interface IUpdateItemParams {
148
155
  resources?: Resource[];
149
156
  /** 备注 */
150
157
  note?: string;
158
+ /** 日期 */
159
+ date?: {
160
+ /** 开始时间 */
161
+ startTime: string;
162
+ /** 结束时间 */
163
+ endTime: string;
164
+ };
151
165
  }
152
166
  /**
153
167
  * 折扣
@@ -1,8 +1,8 @@
1
- import { Account } from "../Account";
2
- import { ProductData } from "../Product/types";
3
- import { Resource } from "../Resource/types";
4
- import { CartItem, IDiscount } from "./types";
5
- import Decimal from "decimal.js";
1
+ import { Account } from '../Account';
2
+ import { ProductData } from '../Product/types';
3
+ import { Resource } from '../Resource/types';
4
+ import { CartItem, IDiscount } from './types';
5
+ import Decimal from 'decimal.js';
6
6
  /**
7
7
  * 生成一个唯一的 ID
8
8
  */
@@ -90,6 +90,30 @@ export declare const formatResourceToCartItemOrigin: (params: {
90
90
  cartItem: CartItem;
91
91
  resources: Resource[];
92
92
  }) => any;
93
+ /**
94
+ * 格式化日期到购物车
95
+ * @param date 开始时间和结束时间
96
+ * @returns 格式化后的日期
97
+ */
98
+ export declare const formatDateToCartItem: (params: {
99
+ cartItem: CartItem;
100
+ date: {
101
+ startTime: string;
102
+ endTime: string;
103
+ };
104
+ }) => CartItem;
105
+ /**
106
+ * 格式化日期到购物车原始数据
107
+ * @param date 开始时间和结束时间
108
+ * @returns 格式化后的日期原始数据
109
+ */
110
+ export declare const formatDateToCartItemOrigin: (params: {
111
+ cartItem: CartItem;
112
+ date: {
113
+ startTime: string;
114
+ endTime: string;
115
+ };
116
+ }) => any;
93
117
  /**
94
118
  * 从购物车中删除资源相关信息
95
119
  * @param cartItem 购物车