@pisell/pisellos 0.0.13 → 0.0.15

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.
@@ -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
- return this.store.cart.getTemp(key);
112
- }
110
+ // async getStoreCart(key?: string) {
111
+ // return this.store.cart.getTemp(key);
112
+ // }
113
113
  // 加载商品,然后导到商品列表里去
114
114
  async loadProducts({
115
115
  category_ids = [],
@@ -272,7 +272,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
272
272
  this.store.cart.updateItem(params);
273
273
  }
274
274
  // 删除购物车里某个商品
275
- deleteCart(product_id) {
275
+ deleteCart(cartItemId) {
276
+ this.store.cart.removeItem(cartItemId);
276
277
  }
277
278
  // 清空购物车
278
279
  clearCart() {
@@ -282,6 +283,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
282
283
  clearCartByAccount(account_id) {
283
284
  this.store.cart.clearCartByAccount(account_id);
284
285
  }
286
+ /**
287
+ * 批量更新购物车
288
+ */
289
+ batchUpdateCart(paramsList) {
290
+ const cartItems = [];
291
+ paramsList.forEach((params) => {
292
+ const cartItem = this.store.cart.formatCartItem(params);
293
+ cartItems.push(cartItem);
294
+ });
295
+ this.store.cart.batchSetItems(cartItems);
296
+ }
297
+ /**
298
+ * 从购物车中按类别删除信息
299
+ */
300
+ deleteCartItemInfo(types) {
301
+ this.store.cart.deleteCartItemInfo(types);
302
+ }
285
303
  destory() {
286
304
  var _a, _b, _c, _d, _e, _f;
287
305
  (_a = this.store.cart) == null ? void 0 : _a.destory();
@@ -305,11 +323,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
305
323
  const cartItems = this.store.cart.getItems();
306
324
  const arr = [];
307
325
  cartItems.forEach((cartItem) => {
308
- const productResources = (0, import_resources.getResourcesByProduct)(
309
- resourcesMap,
310
- cartItem,
311
- cartItems
312
- );
326
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
313
327
  arr.push({
314
328
  id: cartItem.id,
315
329
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -393,18 +407,24 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
393
407
  resources_code,
394
408
  timeSlots
395
409
  }) {
396
- var _a;
410
+ var _a, _b, _c;
397
411
  const dateRange = this.store.date.getDateRange();
398
412
  const cartItems = this.store.cart.getItems();
399
- const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id);
413
+ const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
414
+ if (!accountCartItems.length) {
415
+ return {
416
+ selectedResource: null
417
+ };
418
+ }
400
419
  let duration = accountCartItems.reduce((acc, n) => {
401
- return acc + n._productOrigin.duration.value;
420
+ var _a2, _b2;
421
+ return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
402
422
  }, 0);
403
- let durationType = ((_a = accountCartItems == null ? void 0 : accountCartItems[0]) == null ? void 0 : _a._productOrigin.duration.type) || "minutes";
423
+ let durationType = ((_c = (_b = (_a = accountCartItems[0]) == null ? void 0 : _a._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.type) ?? "minutes";
404
424
  const resources = [];
405
425
  accountCartItems.forEach((item) => {
406
- var _a2, _b;
407
- (_b = (_a2 = item._productOrigin.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b.forEach((n) => {
426
+ var _a2, _b2, _c2;
427
+ (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
408
428
  if (n.code === resources_code) {
409
429
  resources.push(...n.renderList || []);
410
430
  }
@@ -475,25 +495,30 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
475
495
  console.log(this.store.cart.getItems());
476
496
  this.store.cart.updateItem({
477
497
  _id: item._id,
478
- resources: [...item._origin.resources || [], res.selectedResource]
498
+ // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
499
+ resources: [
500
+ ...(item._origin.resources || []).filter(
501
+ (existingRes) => existingRes.form_id !== res.selectedResource.form_id
502
+ ),
503
+ res.selectedResource
504
+ ]
479
505
  });
480
506
  console.log(this.store.cart.getItems());
481
507
  } else {
482
508
  errorList.push(item._id);
483
509
  }
484
510
  } else {
485
- const productResources = (0, import_resources.getResourcesByProduct)(
486
- resourcesMap,
487
- item,
488
- allCartItems
489
- );
490
- const targetRenderList = (_a = productResources.find(
491
- (n) => n.code === resources_code
492
- )) == null ? void 0 : _a.renderList;
511
+ const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
512
+ const targetRenderList = (_a = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _a.renderList;
493
513
  if (targetRenderList && targetRenderList.length > 0) {
494
514
  this.store.cart.updateItem({
495
515
  _id: item._id,
496
- resources: [...item._origin.resources || [], targetRenderList[0]]
516
+ resources: [
517
+ ...(item._origin.resources || []).filter(
518
+ (existingRes) => existingRes.resourceType !== targetRenderList[0].resourceType
519
+ ),
520
+ targetRenderList[0]
521
+ ]
497
522
  });
498
523
  } else {
499
524
  errorList.push(item._id);
@@ -510,13 +535,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
510
535
  const cartItems = this.store.cart.getItems();
511
536
  const resourceIds = [];
512
537
  cartItems.forEach((item) => {
513
- var _a, _b, _c;
514
- (_b = (_a = item._productOrigin.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach((n) => {
538
+ var _a, _b, _c, _d;
539
+ (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
515
540
  if (n.code === resources_code) {
516
541
  resources.push(...n.renderList || []);
517
542
  }
518
543
  });
519
- (_c = item._origin.resources) == null ? void 0 : _c.forEach((n) => {
544
+ (_d = item._origin.resources) == null ? void 0 : _d.forEach((n) => {
520
545
  resourceIds.push(n.relation_id);
521
546
  });
522
547
  });
@@ -526,7 +551,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
526
551
  let accountDuration = 0;
527
552
  const cartItems2 = this.store.cart.getCartByAccount(account.getId());
528
553
  cartItems2.forEach((item) => {
529
- accountDuration += item._productOrigin.duration.value;
554
+ var _a, _b;
555
+ accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
530
556
  });
531
557
  if (accountDuration > duration) {
532
558
  duration = accountDuration;
@@ -572,8 +598,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
572
598
  cartItems.forEach((item) => {
573
599
  const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
574
600
  newResources.forEach((n) => {
601
+ var _a, _b, _c, _d;
575
602
  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");
603
+ n.endTime = (0, import_dayjs.default)(n.startTime).add(
604
+ ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
605
+ ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
606
+ ).format("YYYY-MM-DD HH:mm");
577
607
  delete n.times;
578
608
  });
579
609
  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
- return (0, import_dayjs.default)(d.times[0].end_at).isAfter((0, import_dayjs.default)());
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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",