@pisell/pisellos 0.0.29 → 0.0.31

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.
@@ -848,9 +848,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
848
848
  var dateRange = this.store.date.getDateRange();
849
849
  if (timeSlots) {
850
850
  // 如果 start_time 存在,则直接根据 start_time 算出商品总共需要的时长,然后根据时长去匹配资源
851
- var duration = resourceProductData.product.duration.value;
852
- var start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
853
- var end_time = dayjs("".concat(dateRange[0].date, " ").concat(start_time)).add(duration, resourceProductData.product.duration.type).format("HH:mm");
851
+ // const duration = resourceProductData.product.duration.value;
852
+ // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
853
+ // const end_time = dayjs(`${dateRange[0].date} ${start_time}`)
854
+ // .add(duration, resourceProductData.product.duration.type)
855
+ // .format("HH:mm");
854
856
  // 根据 start_time 和 end_time 去匹配资源
855
857
  var targetResource = null;
856
858
  var _iterator = _createForOfIteratorHelper(resources),
@@ -860,11 +862,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
860
862
  var n = _step.value;
861
863
  var canUseTime = n.times.find(function (item) {
862
864
  return getIsUsableByTimeItem({
863
- timeSlice: item,
864
- time: {
865
- start_time: start_time,
866
- end_time: end_time
867
- },
865
+ timeSlice: timeSlots,
866
+ time: item,
868
867
  resource: n,
869
868
  currentCount: 1
870
869
  });
@@ -887,7 +886,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
887
886
  };
888
887
  } else {
889
888
  // 如果没有传递 timeSlots,证明是第一个资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
890
- var _duration = resourceProductData.product.duration.value;
889
+ var duration = resourceProductData.product.duration.value;
891
890
  var resourcesMap = getResourcesMap(resources);
892
891
  var resourceIds = resources.map(function (n) {
893
892
  return n.id;
@@ -895,7 +894,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
895
894
  var _timeSlots = getTimeSlicesByResources({
896
895
  resourceIds: resourceIds,
897
896
  resourcesMap: resourcesMap,
898
- duration: _duration,
897
+ duration: duration,
899
898
  currentDate: dateRange[0].date,
900
899
  split: 10
901
900
  });
@@ -950,9 +949,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
950
949
  });
951
950
 
952
951
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
952
+ // 每个商品
953
953
  if (timeSlots) {
954
- var start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
955
- var end_time = dayjs("".concat(dateRange[0].date, " ").concat(start_time)).add(duration, durationType).format("HH:mm");
954
+ // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
955
+ // const end_time = dayjs(`${dateRange[0].date} ${timeSlots.start_time}`)
956
+ // .add(duration, durationType as dayjs.ManipulateType)
957
+ // .format("HH:mm");
956
958
  // 根据 start_time 和 end_time 去匹配资源
957
959
  var targetResource = null;
958
960
  var _iterator2 = _createForOfIteratorHelper(resources),
@@ -963,11 +965,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
963
965
  var recordCount = countMap[n.id] || 0;
964
966
  var canUseTime = n.times.find(function (item) {
965
967
  return getIsUsableByTimeItem({
966
- timeSlice: item,
967
- time: {
968
- start_time: start_time,
969
- end_time: end_time
970
- },
968
+ timeSlice: timeSlots,
969
+ time: item,
971
970
  resource: n,
972
971
  currentCount: recordCount + 1
973
972
  });
@@ -1029,15 +1028,39 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1029
1028
  var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1030
1029
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1031
1030
  var allCartItems = _this7.store.cart.getItems();
1032
- cartItems.forEach(function (item) {
1031
+ var recordTimeSlots = cloneDeep(timeSlots);
1032
+ // timeSlots 传进来的只是用户选中的时间片,但是实际上需要根据多个商品时间进行累加
1033
+ // 假设 timeSlots.start_time 是15:40 duration 是 30min
1034
+ // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1035
+
1036
+ cartItems.forEach(function (item, index) {
1033
1037
  if (timeSlots) {
1038
+ var _item$_origin$resourc2;
1039
+ if (index !== 0 && recordTimeSlots) {
1040
+ var _item$_productOrigin$, _item$_productOrigin2, _ref8, _item$_productOrigin3, _item$_productOrigin$2, _item$_productOrigin4, _ref9, _item$_productOrigin5;
1041
+ var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.duration) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref8 = (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.type) !== null && _ref8 !== void 0 ? _ref8 : "minutes");
1042
+ var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref9 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref9 !== void 0 ? _ref9 : "minutes");
1043
+ recordTimeSlots = {
1044
+ start_time: start_at.format("HH:mm"),
1045
+ end_time: end_at.format("HH:mm"),
1046
+ start_at: start_at,
1047
+ end_at: end_at
1048
+ };
1049
+ }
1034
1050
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1035
1051
  var res = _this7.autoSelectAccountResources({
1036
1052
  holder_id: item.holder_id,
1037
1053
  resources_code: resources_code,
1038
- timeSlots: timeSlots,
1054
+ timeSlots: recordTimeSlots,
1039
1055
  countMap: selectResourcesMap
1040
1056
  });
1057
+ // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1058
+ if ((_item$_origin$resourc2 = item._origin.resources) !== null && _item$_origin$resourc2 !== void 0 && _item$_origin$resourc2.some(function (n) {
1059
+ var _res$selectedResource;
1060
+ return n.form_id === (res === null || res === void 0 || (_res$selectedResource = res.selectedResource) === null || _res$selectedResource === void 0 ? void 0 : _res$selectedResource.form_id);
1061
+ })) {
1062
+ return;
1063
+ }
1041
1064
  if (res !== null && res !== void 0 && res.selectedResource) {
1042
1065
  if (!selectResourcesMap[res.selectedResource.id]) {
1043
1066
  selectResourcesMap[res.selectedResource.id] = 1;
@@ -1067,6 +1090,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1067
1090
  return n.code === resources_code;
1068
1091
  })) === null || _productResources$fin === void 0 ? void 0 : _productResources$fin.renderList;
1069
1092
  if (targetRenderList && targetRenderList.length > 0) {
1093
+ var _item$_origin$resourc3;
1094
+ // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1095
+ if ((_item$_origin$resourc3 = item._origin.resources) !== null && _item$_origin$resourc3 !== void 0 && _item$_origin$resourc3.some(function (n) {
1096
+ return n.form_id === targetRenderList[0].form_id;
1097
+ })) {
1098
+ return;
1099
+ }
1070
1100
  var targetResource = targetRenderList[0];
1071
1101
  targetResource.capacity = 1;
1072
1102
  _this7.store.cart.updateItem({
@@ -1097,8 +1127,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1097
1127
  var cartItems = this.store.cart.getItems();
1098
1128
  var resourceIds = [];
1099
1129
  cartItems.forEach(function (item) {
1100
- var _item$_productOrigin2;
1101
- (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 || _item$_productOrigin2.forEach(function (n) {
1130
+ var _item$_productOrigin6;
1131
+ (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.product_resource) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.resources) === null || _item$_productOrigin6 === void 0 || _item$_productOrigin6.forEach(function (n) {
1102
1132
  if (n.code === resources_code) {
1103
1133
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1104
1134
  }
@@ -1117,8 +1147,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1117
1147
  var accountDuration = 0;
1118
1148
  var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1119
1149
  cartItems.forEach(function (item) {
1120
- var _item$_productOrigin$, _item$_productOrigin3;
1121
- accountDuration += (_item$_productOrigin$ = (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0;
1150
+ var _item$_productOrigin$3, _item$_productOrigin7;
1151
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1122
1152
  });
1123
1153
  if (accountDuration > duration) {
1124
1154
  duration = accountDuration;
@@ -1158,9 +1188,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1158
1188
  accountItems.forEach(function (item, index) {
1159
1189
  var newResources = cloneDeep(item._origin.resources);
1160
1190
  newResources.forEach(function (resource) {
1161
- var _item$_productOrigin$2, _item$_productOrigin4, _ref8, _item$_productOrigin5;
1191
+ var _item$_productOrigin$4, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1162
1192
  resource.startTime = currentStartTime;
1163
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$2 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref8 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref8 !== void 0 ? _ref8 : "minutes").format("YYYY-MM-DD HH:mm");
1193
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : "minutes").format("YYYY-MM-DD HH:mm");
1164
1194
  delete resource.times;
1165
1195
  });
1166
1196
  _this9.store.cart.updateItem({
@@ -432,15 +432,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
432
432
  }) {
433
433
  const dateRange = this.store.date.getDateRange();
434
434
  if (timeSlots) {
435
- const duration = resourceProductData.product.duration.value;
436
- const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
437
- const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, resourceProductData.product.duration.type).format("HH:mm");
438
435
  let targetResource = null;
439
436
  for (const n of resources) {
440
437
  const canUseTime = n.times.find(
441
438
  (item) => (0, import_resources.getIsUsableByTimeItem)({
442
- timeSlice: item,
443
- time: { start_time, end_time },
439
+ timeSlice: timeSlots,
440
+ time: item,
444
441
  resource: n,
445
442
  currentCount: 1
446
443
  })
@@ -504,15 +501,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
504
501
  });
505
502
  });
506
503
  if (timeSlots) {
507
- const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
508
- const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, durationType).format("HH:mm");
509
504
  let targetResource = null;
510
505
  for (const n of resources) {
511
506
  const recordCount = countMap[n.id] || 0;
512
507
  const canUseTime = n.times.find(
513
508
  (item) => (0, import_resources.getIsUsableByTimeItem)({
514
- timeSlice: item,
515
- time: { start_time, end_time },
509
+ timeSlice: timeSlots,
510
+ time: item,
516
511
  resource: n,
517
512
  currentCount: recordCount + 1
518
513
  })
@@ -558,15 +553,32 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
558
553
  this.store.accountList.getAccounts().forEach((account) => {
559
554
  const cartItems = this.store.cart.getCartByAccount(account.getId());
560
555
  const allCartItems = this.store.cart.getItems();
561
- cartItems.forEach((item) => {
562
- var _a;
556
+ let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
557
+ cartItems.forEach((item, index) => {
558
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
563
559
  if (timeSlots) {
560
+ if (index !== 0 && recordTimeSlots) {
561
+ let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes");
562
+ let end_at = start_at.add(((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0, ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes");
563
+ recordTimeSlots = {
564
+ start_time: start_at.format("HH:mm"),
565
+ end_time: end_at.format("HH:mm"),
566
+ start_at,
567
+ end_at
568
+ };
569
+ }
564
570
  const res = this.autoSelectAccountResources({
565
571
  holder_id: item.holder_id,
566
572
  resources_code,
567
- timeSlots,
573
+ timeSlots: recordTimeSlots,
568
574
  countMap: selectResourcesMap
569
575
  });
576
+ if ((_i = item._origin.resources) == null ? void 0 : _i.some((n) => {
577
+ var _a2;
578
+ return n.form_id === ((_a2 = res == null ? void 0 : res.selectedResource) == null ? void 0 : _a2.form_id);
579
+ })) {
580
+ return;
581
+ }
570
582
  if (res == null ? void 0 : res.selectedResource) {
571
583
  if (!selectResourcesMap[res.selectedResource.id]) {
572
584
  selectResourcesMap[res.selectedResource.id] = 1;
@@ -591,8 +603,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
591
603
  }
592
604
  } else {
593
605
  const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
594
- const targetRenderList = (_a = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _a.renderList;
606
+ const targetRenderList = (_j = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _j.renderList;
595
607
  if (targetRenderList && targetRenderList.length > 0) {
608
+ if ((_k = item._origin.resources) == null ? void 0 : _k.some((n) => n.form_id === targetRenderList[0].form_id)) {
609
+ return;
610
+ }
596
611
  const targetResource = targetRenderList[0];
597
612
  targetResource.capacity = 1;
598
613
  this.store.cart.updateItem({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.29",
4
+ "version": "0.0.31",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",