@pisell/pisellos 3.0.16 → 3.0.18

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.
@@ -245,7 +245,11 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
245
245
  return item.default_resource.indexOf(d) == -1;
246
246
  });
247
247
  var optional_resource = item.optional_resource.reduce(function (childAcc, d) {
248
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
248
+ var _resourcesMap$d;
249
+ // 如果其他资源选择过,并且这个资源是单个预约,则不可以选中此资源
250
+ // TODO: 如果容量超了这里怎么处理?
251
+ var isSelectSingleResources = ((_resourcesMap$d = resourcesMap[d]) === null || _resourcesMap$d === void 0 ? void 0 : _resourcesMap$d.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
252
+ if (resourcesMap[d] && !isSelectSingleResources) {
249
253
  // 拼装组合资源的数据
250
254
  var combiningResources = [];
251
255
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -277,7 +281,9 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
277
281
  return childAcc;
278
282
  }, []);
279
283
  var default_resource = item.default_resource.reduce(function (childAcc, d) {
280
- if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
284
+ var _resourcesMap$d2;
285
+ var isSelectSingleResources = ((_resourcesMap$d2 = resourcesMap[d]) === null || _resourcesMap$d2 === void 0 ? void 0 : _resourcesMap$d2.resourceType) === 'single' && selectedResources.includes(resourcesMap[d].id);
286
+ if (resourcesMap[d] && !isSelectSingleResources) {
281
287
  // 拼装组合资源的数据
282
288
  var combiningResources = [];
283
289
  if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
@@ -592,9 +598,9 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
592
598
  return acc;
593
599
  }
594
600
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
595
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
596
- resourcesMap[m].capacity -= n.num;
597
- });
601
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
602
+ // if (resourcesMap[m]) resourcesMap[m].capacity -= d.num || 0;
603
+ // });
598
604
  } else {
599
605
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
600
606
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -602,13 +608,13 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
602
608
  if (m.combined_resource && m.combined_resource.status === 1) {
603
609
  if (m.combined_resource.resource_ids.includes(n.id)) {
604
610
  acc.push(m.id);
605
- resourcesMap[m.id].capacity -= n.num;
611
+ // if (resourcesMap[m.id]) resourcesMap[m.id].capacity -= d.num || 0;
606
612
  }
607
613
  }
608
614
  });
609
615
  }
610
616
  acc.push(n.id);
611
- resourcesMap[n.id].capacity -= n.num;
617
+ // if (resourcesMap[n.id]) resourcesMap[n.id].capacity -= currentCapacity || 0;
612
618
  });
613
619
  }
614
620
  }
@@ -639,9 +645,9 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
639
645
  return acc;
640
646
  }
641
647
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
642
- n.metadata.combined_resource.resource_ids.forEach(function (m) {
643
- resourcesMap[m].capacity -= n.num;
644
- });
648
+ // n.metadata.combined_resource.resource_ids.forEach((m: number) => {
649
+ // resourcesMap[m].capacity -= n.num;
650
+ // });
645
651
  } else {
646
652
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
647
653
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -649,14 +655,14 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
649
655
  if (m.combined_resource && m.combined_resource.status === 1) {
650
656
  if (m.combined_resource.resource_ids.includes(n.id)) {
651
657
  acc.push(m.id);
652
- resourcesMap[m.id].capacity -= n.num;
658
+ // resourcesMap[m.id].capacity -= n.num;
653
659
  }
654
660
  }
655
661
  });
656
662
  }
657
663
  acc.push(n.id);
658
664
  // push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
659
- resourcesMap[n.id].capacity -= n.num;
665
+ // resourcesMap[n.id].capacity -= currentCapacity || 0;
660
666
  });
661
667
  }
662
668
  }
@@ -16,6 +16,7 @@ export declare class AccountListModule extends BaseModule implements Module {
16
16
  * 创建账号并添加到列表中
17
17
  * @param account 账号信息
18
18
  * @param needEmit 是否需要触发事件
19
+ * @param type 添加类型
19
20
  */
20
21
  private createAccountAndAdd;
21
22
  addAccount(account: Account): Promise<AccountModule>;
@@ -30,10 +31,12 @@ export declare class AccountListModule extends BaseModule implements Module {
30
31
  storeChange(): void;
31
32
  /**
32
33
  * 批量添加holder类型账号
33
- * @param holders 账号信息列表
34
- * @param customerId 账户id
35
34
  */
36
- addHolderAccounts(holders: IHolder[], customerId: number): Promise<AccountModule[]>;
35
+ addHolderAccounts(params: {
36
+ holders: IHolder[];
37
+ customerId: number;
38
+ type?: 'unshift' | 'push';
39
+ }): Promise<AccountModule[]>;
37
40
  /**
38
41
  * 获取holder类型账户列表
39
42
  * @param params
@@ -69,19 +69,30 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
69
69
  * 创建账号并添加到列表中
70
70
  * @param account 账号信息
71
71
  * @param needEmit 是否需要触发事件
72
+ * @param type 添加类型
72
73
  */
73
- async createAccountAndAdd(account, needEmit = true) {
74
+ async createAccountAndAdd(account, needEmit = true, type) {
74
75
  const tempAccountModule = this.store.accounts.find(
75
76
  (a) => a.getId() === account.id
76
77
  );
77
78
  if (tempAccountModule) {
78
79
  return tempAccountModule;
79
80
  }
80
- this.store.accountList.push(account);
81
+ const newAccountList = [...this.store.accountList || []];
82
+ if (type === "unshift") {
83
+ newAccountList.unshift(account);
84
+ } else {
85
+ newAccountList.push(account);
86
+ }
87
+ this.store.accountList = newAccountList;
81
88
  const accountModule = new import_Account.AccountModule(`account_${account.id}`);
82
89
  this.core.registerModule(accountModule);
83
90
  accountModule.setAccountInfo(account);
84
- this.store.accounts = [...this.store.accounts || [], accountModule];
91
+ if (type === "unshift") {
92
+ this.store.accounts = [accountModule, ...this.store.accounts || []];
93
+ } else {
94
+ this.store.accounts = [...this.store.accounts || [], accountModule];
95
+ }
85
96
  if (needEmit) {
86
97
  await this.core.effects.emit(
87
98
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -250,15 +261,22 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
250
261
  }
251
262
  /**
252
263
  * 批量添加holder类型账号
253
- * @param holders 账号信息列表
254
- * @param customerId 账户id
255
264
  */
256
- async addHolderAccounts(holders, customerId) {
265
+ async addHolderAccounts(params) {
266
+ const { holders, customerId, type = "push" } = params;
257
267
  const accountModules = [];
258
268
  for (const holder of holders) {
259
269
  const account = (0, import_utils.createHolderAccount)(holder, customerId);
260
- const accountModule = await this.createAccountAndAdd(account, false);
261
- accountModules.push(accountModule);
270
+ const accountModule = await this.createAccountAndAdd(
271
+ account,
272
+ false,
273
+ type
274
+ );
275
+ if (type === "unshift") {
276
+ accountModules.unshift(accountModule);
277
+ } else {
278
+ accountModules.push(accountModule);
279
+ }
262
280
  }
263
281
  await this.core.effects.emit(
264
282
  import_types.AccountListHooks.OnAccountListUpdate,
@@ -282,8 +300,13 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
282
300
  num: num || 100,
283
301
  skip: skip || 1
284
302
  });
303
+ this.store.accountList = [];
304
+ this.store.accounts = [];
285
305
  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);
306
+ await this.addHolderAccounts({
307
+ holders: res.data.list,
308
+ customerId: customer_id
309
+ });
287
310
  }
288
311
  } catch (error) {
289
312
  console.error(error);
@@ -445,6 +445,7 @@ var getProductDeposit = (params) => {
445
445
  let total = new import_decimal.default(0);
446
446
  const { deposit_fixed, deposit_percentage, deposit_policy_data } = (product == null ? void 0 : product.custom_deposit_data) || {};
447
447
  protocols.push(...deposit_policy_data || []);
448
+ let productHasDeposit = false;
448
449
  if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
449
450
  const { depositTotal, result } = handleProductDeposit({
450
451
  depositData: product == null ? void 0 : product.custom_deposit_data,
@@ -453,6 +454,7 @@ var getProductDeposit = (params) => {
453
454
  });
454
455
  if (result) {
455
456
  total = depositTotal;
457
+ productHasDeposit = true;
456
458
  }
457
459
  } else {
458
460
  if (bundle == null ? void 0 : bundle.length) {
@@ -463,13 +465,17 @@ var getProductDeposit = (params) => {
463
465
  num: currentBundleProduct.num
464
466
  });
465
467
  if (result) {
468
+ productHasDeposit = true;
466
469
  return accumulator.plus(depositTotal);
467
470
  }
468
471
  return accumulator;
469
472
  }, new import_decimal.default(0));
470
473
  }
471
474
  }
472
- return { total: total.toNumber(), protocols };
475
+ if (productHasDeposit) {
476
+ return { total: total.toNumber(), protocols };
477
+ }
478
+ return null;
473
479
  }
474
480
  return null;
475
481
  };
@@ -457,4 +457,6 @@ export interface ProductResourceItem {
457
457
  updated_at: string;
458
458
  /** 可用资源列表 */
459
459
  renderList?: any[];
460
+ /** 资源类型 */
461
+ type: 'single' | 'multiple' | 'capacity';
460
462
  }
@@ -147,6 +147,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
147
147
  checkCartItems(type: ECartItemCheckType): string[];
148
148
  destroy(): void;
149
149
  getResourcesList(): any[];
150
+ checkResourceListForDate(): boolean;
150
151
  getResourcesListByCartItem(id: string | number): {
151
152
  id: number | undefined;
152
153
  _id: string;