@pisell/pisellos 3.0.26 → 3.0.27

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.
@@ -22,4 +22,5 @@ export declare class AccountModule extends BaseModule implements Module {
22
22
  setAccountInfo(account: Account): void;
23
23
  setActive(active: boolean): void;
24
24
  isActive(): boolean;
25
+ isLogin(): boolean;
25
26
  }
@@ -97,6 +97,10 @@ var AccountModule = class extends import_BaseModule.BaseModule {
97
97
  isActive() {
98
98
  return this.store.active;
99
99
  }
100
+ isLogin() {
101
+ var _a;
102
+ return ((_a = this.store.accountInfo) == null ? void 0 : _a.isLogin) || false;
103
+ }
100
104
  };
101
105
  // Annotate the CommonJS export names for ESM import in node:
102
106
  0 && (module.exports = {
@@ -27,6 +27,8 @@ export interface Account {
27
27
  type?: 'account' | 'holder';
28
28
  /** 账户信息原始数据 */
29
29
  _origin?: Record<string, any>;
30
+ /** 是否是登录账号 */
31
+ isLogin?: boolean;
30
32
  }
31
33
  /**
32
34
  * 账户模块状态
@@ -42,4 +42,5 @@ export declare class AccountListModule extends BaseModule implements Module {
42
42
  * @param params
43
43
  */
44
44
  fetchHolderAccounts(params: IFetchHolderAccountsParams): Promise<void>;
45
+ getLoginAccount(): AccountModule | undefined;
45
46
  }
@@ -312,6 +312,9 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
312
312
  console.error(error);
313
313
  }
314
314
  }
315
+ getLoginAccount() {
316
+ return this.store.accounts.find((n) => n.isLogin());
317
+ }
315
318
  };
316
319
  // Annotate the CommonJS export names for ESM import in node:
317
320
  0 && (module.exports = {
@@ -18,6 +18,7 @@ export declare class Product extends BaseModule implements Module {
18
18
  protected otherParams: any;
19
19
  constructor(name?: string, version?: string);
20
20
  initialize(core: PisellCore, options: any): Promise<void>;
21
+ updateData(data: ProductData): void;
21
22
  /**
22
23
  * 获取商品数据
23
24
  */
@@ -38,6 +38,9 @@ var Product = class extends import_BaseModule.BaseModule {
38
38
  this.core = core;
39
39
  this.store = options.store || {};
40
40
  }
41
+ updateData(data) {
42
+ Object.assign(this.store, data);
43
+ }
41
44
  /**
42
45
  * 获取商品数据
43
46
  */
@@ -51,12 +51,15 @@ var ProductList = class extends import_BaseModule.BaseModule {
51
51
  async storeChange(path, value) {
52
52
  var _a;
53
53
  (_a = this.store.list) == null ? void 0 : _a.forEach((product) => {
54
- if (!this.store.productMap.has(`product-${product.id}`)) {
54
+ const productModule = this.store.productMap.get(`product-${product.id}`);
55
+ if (!productModule) {
55
56
  const newProductModule = new import_Product.Product(
56
57
  `product_${product.id.toString()}`
57
58
  );
58
59
  this.core.registerModule(newProductModule, { initialState: product });
59
60
  this.store.productMap.set(product.id.toString(), newProductModule);
61
+ } else {
62
+ productModule.updateData(product);
60
63
  }
61
64
  });
62
65
  }
@@ -78,7 +81,18 @@ var ProductList = class extends import_BaseModule.BaseModule {
78
81
  return void 0;
79
82
  }
80
83
  async addProduct(products) {
81
- this.store.list = [...this.store.list, ...products];
84
+ if (!this.store.list) {
85
+ this.store.list = [];
86
+ }
87
+ products.forEach((n) => {
88
+ const index = this.store.list.findIndex((m) => m.id === n.id);
89
+ if (index === -1) {
90
+ this.store.list.push(n);
91
+ } else {
92
+ this.store.list[index] = n;
93
+ }
94
+ });
95
+ this.storeChange();
82
96
  }
83
97
  async selectProducts(products) {
84
98
  this.store.selectProducts = products;
@@ -0,0 +1,7 @@
1
+ import { Plugin } from '../types';
2
+ /**
3
+ * UserPlugin 接口定义
4
+ */
5
+ export interface UserPlugin extends Plugin {
6
+ get(): Record<string, any>;
7
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/plugins/user.ts
16
+ var user_exports = {};
17
+ module.exports = __toCommonJS(user_exports);
@@ -54,6 +54,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
54
54
  product_ids?: number[];
55
55
  category_ids?: number[];
56
56
  }): Promise<any>;
57
+ updateQuotationPriceAndCart(date: string): Promise<void>;
57
58
  loadAllSchedule(): Promise<void>;
58
59
  loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: {
59
60
  startDate: string;
@@ -161,6 +161,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
161
161
  schedule_ids = [],
162
162
  schedule_date
163
163
  }) {
164
+ var _a;
164
165
  if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
165
166
  const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
166
167
  if (schedule_ids_data.length) {
@@ -169,6 +170,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
169
170
  schedule_ids = [0];
170
171
  }
171
172
  }
173
+ let userPlugin = this.core.getPlugin("user");
174
+ let customer_id = void 0;
175
+ try {
176
+ customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
177
+ } catch (error) {
178
+ console.error(error);
179
+ }
172
180
  const productsData = await this.request.post(
173
181
  `/product/query`,
174
182
  {
@@ -184,6 +192,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
184
192
  status: "published",
185
193
  num: 500,
186
194
  skip: 1,
195
+ customer_id,
187
196
  category_ids,
188
197
  ids: product_ids,
189
198
  collection,
@@ -214,6 +223,51 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
214
223
  schedule_date: date
215
224
  });
216
225
  }
226
+ async updateQuotationPriceAndCart(date) {
227
+ var _a;
228
+ const dateRange = this.store.date.getDateRange();
229
+ const scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
230
+ let scheduleIds = [];
231
+ if (dateRange && dateRange.length) {
232
+ scheduleIds = scheduleList.filter((n) => n.date === dateRange[0].date).flatMap((n) => n.schedule_id);
233
+ } else {
234
+ scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
235
+ }
236
+ await this.loadProducts({
237
+ ...(_a = this.otherParams) == null ? void 0 : _a.productModuleParams,
238
+ scheduleIds,
239
+ schedule_date: date
240
+ });
241
+ const cartItems = this.store.cart.getItems();
242
+ if (cartItems.length) {
243
+ for (const item of cartItems) {
244
+ const targetProduct = await this.store.products.getProduct(item.id);
245
+ const productInfo = (0, import_lodash_es.cloneDeep)(targetProduct == null ? void 0 : targetProduct.getData());
246
+ let bundle = item._bundleOrigin;
247
+ bundle = bundle == null ? void 0 : bundle.map((n) => {
248
+ var _a2;
249
+ const targetBundle = (_a2 = productInfo == null ? void 0 : productInfo.bundle) == null ? void 0 : _a2.find((m) => m.group_id === n.id);
250
+ if (targetBundle) {
251
+ const targetBundleItem = targetBundle.items.find((m) => m.id === n.id);
252
+ if (targetBundleItem) {
253
+ return {
254
+ ...n,
255
+ price: targetBundleItem.price,
256
+ base_price: targetBundleItem.base_price
257
+ };
258
+ }
259
+ }
260
+ return n;
261
+ });
262
+ this.store.cart.updateItem({
263
+ _id: item._id,
264
+ product: productInfo,
265
+ bundle
266
+ });
267
+ }
268
+ ;
269
+ }
270
+ }
217
271
  // 加载当前店铺下所有 schedule
218
272
  async loadAllSchedule() {
219
273
  var _a;
@@ -334,11 +388,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
334
388
  * @param params
335
389
  */
336
390
  async fetchHolderAccountsAsync(params) {
391
+ var _a, _b, _c;
392
+ const cartItems = this.store.cart.getItems();
393
+ if (cartItems.length) {
394
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
395
+ if (!date) {
396
+ date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
397
+ }
398
+ this.updateQuotationPriceAndCart(date);
399
+ }
337
400
  return this.store.accountList.fetchHolderAccounts(params);
338
401
  }
339
402
  // 设置日期范围,注入到日期模块中
340
403
  async setDateRange(dateRange) {
341
404
  this.store.date.setDateRange(dateRange);
405
+ if (dateRange.length && this.store.cart.getItems().length) {
406
+ this.updateQuotationPriceAndCart(dateRange[0].date);
407
+ }
342
408
  }
343
409
  clearDateRange() {
344
410
  this.store.date.clearDateRange();
@@ -414,9 +480,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
414
480
  }
415
481
  // 如果用户登录
416
482
  async setLoginAccount(accountId, accountInfo) {
483
+ var _a, _b, _c;
417
484
  const account = this.store.accountList.getAccount(accountId);
418
485
  if (account) {
419
486
  let stateAccountId = account.getId();
487
+ accountInfo.isLogin = true;
420
488
  account.setAccountInfo(accountInfo);
421
489
  const cartItems = this.store.cart.getItems();
422
490
  cartItems.forEach((item) => {
@@ -428,6 +496,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
428
496
  }
429
497
  });
430
498
  this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
499
+ if (cartItems.length) {
500
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
501
+ if (!date) {
502
+ date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
503
+ }
504
+ this.updateQuotationPriceAndCart(date);
505
+ }
431
506
  } else {
432
507
  throw new Error(`没有找到${accountId}账户`);
433
508
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.26",
4
+ "version": "3.0.27",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",