@pisell/pisellos 0.0.96 → 0.0.97

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,8 @@ 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 = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
172
175
  const productsData = await this.request.post(
173
176
  `/product/query`,
174
177
  {
@@ -184,6 +187,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
184
187
  status: "published",
185
188
  num: 500,
186
189
  skip: 1,
190
+ customer_id,
187
191
  category_ids,
188
192
  ids: product_ids,
189
193
  collection,
@@ -214,6 +218,49 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
214
218
  schedule_date: date
215
219
  });
216
220
  }
221
+ async updateQuotationPriceAndCart(date) {
222
+ var _a;
223
+ const dateRange = this.store.date.getDateRange();
224
+ let scheduleIds = [];
225
+ if (dateRange.length) {
226
+ const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
227
+ scheduleIds = scheduleList.filter((n) => n.date === dateRange[0].date).flatMap((n) => n.schedule_id);
228
+ }
229
+ await this.loadProducts({
230
+ ...(_a = this.otherParams) == null ? void 0 : _a.productModuleParams,
231
+ scheduleIds,
232
+ schedule_date: date
233
+ });
234
+ const cartItems = this.store.cart.getItems();
235
+ if (cartItems.length) {
236
+ for (const item of cartItems) {
237
+ const targetProduct = await this.store.products.getProduct(item.id);
238
+ const productInfo = (0, import_lodash_es.cloneDeep)(targetProduct == null ? void 0 : targetProduct.getData());
239
+ let bundle = item._bundleOrigin;
240
+ bundle = bundle == null ? void 0 : bundle.map((n) => {
241
+ var _a2;
242
+ const targetBundle = (_a2 = productInfo == null ? void 0 : productInfo.bundle) == null ? void 0 : _a2.find((m) => m.group_id === n.id);
243
+ if (targetBundle) {
244
+ const targetBundleItem = targetBundle.items.find((m) => m.id === n.id);
245
+ if (targetBundleItem) {
246
+ return {
247
+ ...n,
248
+ price: targetBundleItem.price,
249
+ base_price: targetBundleItem.base_price
250
+ };
251
+ }
252
+ }
253
+ return n;
254
+ });
255
+ this.store.cart.updateItem({
256
+ _id: item._id,
257
+ product: productInfo,
258
+ bundle
259
+ });
260
+ }
261
+ ;
262
+ }
263
+ }
217
264
  // 加载当前店铺下所有 schedule
218
265
  async loadAllSchedule() {
219
266
  var _a;
@@ -334,11 +381,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
334
381
  * @param params
335
382
  */
336
383
  async fetchHolderAccountsAsync(params) {
384
+ var _a, _b, _c;
385
+ const cartItems = this.store.cart.getItems();
386
+ if (cartItems.length) {
387
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
388
+ if (!date) {
389
+ date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
390
+ }
391
+ this.updateQuotationPriceAndCart(date);
392
+ }
337
393
  return this.store.accountList.fetchHolderAccounts(params);
338
394
  }
339
395
  // 设置日期范围,注入到日期模块中
340
396
  async setDateRange(dateRange) {
341
397
  this.store.date.setDateRange(dateRange);
398
+ if (dateRange.length && this.store.cart.getItems().length) {
399
+ this.updateQuotationPriceAndCart(dateRange[0].date);
400
+ }
342
401
  }
343
402
  clearDateRange() {
344
403
  this.store.date.clearDateRange();
@@ -414,9 +473,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
414
473
  }
415
474
  // 如果用户登录
416
475
  async setLoginAccount(accountId, accountInfo) {
476
+ var _a, _b, _c;
417
477
  const account = this.store.accountList.getAccount(accountId);
418
478
  if (account) {
419
479
  let stateAccountId = account.getId();
480
+ accountInfo.isLogin = true;
420
481
  account.setAccountInfo(accountInfo);
421
482
  const cartItems = this.store.cart.getItems();
422
483
  cartItems.forEach((item) => {
@@ -428,6 +489,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
428
489
  }
429
490
  });
430
491
  this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
492
+ if (cartItems.length) {
493
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
494
+ if (!date) {
495
+ date = ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.start_date) || "";
496
+ }
497
+ this.updateQuotationPriceAndCart(date);
498
+ }
431
499
  } else {
432
500
  throw new Error(`没有找到${accountId}账户`);
433
501
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.96",
4
+ "version": "0.0.97",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",