@pisell/pisellos 0.0.30 → 0.0.32

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),
@@ -859,15 +861,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
859
861
  var _loop = function _loop() {
860
862
  var n = _step.value;
861
863
  var canUseTime = n.times.find(function (item) {
862
- return getIsUsableByTimeItem({
863
- timeSlice: item,
864
- time: {
865
- start_time: start_time,
866
- end_time: end_time
867
- },
864
+ var res = getIsUsableByTimeItem({
865
+ timeSlice: timeSlots,
866
+ time: item,
868
867
  resource: n,
869
868
  currentCount: 1
870
869
  });
870
+ return res.usable;
871
871
  });
872
872
  if (canUseTime) {
873
873
  targetResource = n;
@@ -887,7 +887,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
887
887
  };
888
888
  } else {
889
889
  // 如果没有传递 timeSlots,证明是第一个资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
890
- var _duration = resourceProductData.product.duration.value;
890
+ var duration = resourceProductData.product.duration.value;
891
891
  var resourcesMap = getResourcesMap(resources);
892
892
  var resourceIds = resources.map(function (n) {
893
893
  return n.id;
@@ -895,7 +895,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
895
895
  var _timeSlots = getTimeSlicesByResources({
896
896
  resourceIds: resourceIds,
897
897
  resourcesMap: resourcesMap,
898
- duration: _duration,
898
+ duration: duration,
899
899
  currentDate: dateRange[0].date,
900
900
  split: 10
901
901
  });
@@ -950,9 +950,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
950
950
  });
951
951
 
952
952
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
953
+ // 每个商品
953
954
  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");
955
+ // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
956
+ // const end_time = dayjs(`${dateRange[0].date} ${timeSlots.start_time}`)
957
+ // .add(duration, durationType as dayjs.ManipulateType)
958
+ // .format("HH:mm");
956
959
  // 根据 start_time 和 end_time 去匹配资源
957
960
  var targetResource = null;
958
961
  var _iterator2 = _createForOfIteratorHelper(resources),
@@ -962,15 +965,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
962
965
  var n = _step2.value;
963
966
  var recordCount = countMap[n.id] || 0;
964
967
  var canUseTime = n.times.find(function (item) {
965
- return getIsUsableByTimeItem({
966
- timeSlice: item,
967
- time: {
968
- start_time: start_time,
969
- end_time: end_time
970
- },
968
+ var res = getIsUsableByTimeItem({
969
+ timeSlice: timeSlots,
970
+ time: item,
971
971
  resource: n,
972
972
  currentCount: recordCount + 1
973
973
  });
974
+ return res.usable;
974
975
  });
975
976
  if (canUseTime) {
976
977
  targetResource = n;
@@ -1029,23 +1030,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1029
1030
  var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1030
1031
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1031
1032
  var allCartItems = _this7.store.cart.getItems();
1032
- cartItems.forEach(function (item) {
1033
+ var recordTimeSlots = cloneDeep(timeSlots);
1034
+ // timeSlots 传进来的只是用户选中的时间片,但是实际上需要根据多个商品时间进行累加
1035
+ // 假设 timeSlots.start_time 是15:40 duration 是 30min
1036
+ // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1037
+
1038
+ cartItems.forEach(function (item, index) {
1033
1039
  if (timeSlots) {
1034
- var _item$_origin$resourc2;
1040
+ if (index !== 0 && recordTimeSlots) {
1041
+ var _item$_productOrigin$, _item$_productOrigin2, _ref8, _item$_productOrigin3, _item$_productOrigin$2, _item$_productOrigin4, _ref9, _item$_productOrigin5;
1042
+ 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");
1043
+ 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");
1044
+ recordTimeSlots = {
1045
+ start_time: start_at.format("HH:mm"),
1046
+ end_time: end_at.format("HH:mm"),
1047
+ start_at: start_at,
1048
+ end_at: end_at
1049
+ };
1050
+ }
1035
1051
  // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1036
1052
  var res = _this7.autoSelectAccountResources({
1037
1053
  holder_id: item.holder_id,
1038
1054
  resources_code: resources_code,
1039
- timeSlots: timeSlots,
1055
+ timeSlots: recordTimeSlots,
1040
1056
  countMap: selectResourcesMap
1041
1057
  });
1042
- // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1043
- if ((_item$_origin$resourc2 = item._origin.resources) !== null && _item$_origin$resourc2 !== void 0 && _item$_origin$resourc2.some(function (n) {
1044
- var _res$selectedResource;
1045
- return n.form_id === (res === null || res === void 0 || (_res$selectedResource = res.selectedResource) === null || _res$selectedResource === void 0 ? void 0 : _res$selectedResource.form_id);
1046
- })) {
1047
- return;
1048
- }
1058
+ // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1059
+ // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
1060
+ // return
1061
+ // }
1049
1062
  if (res !== null && res !== void 0 && res.selectedResource) {
1050
1063
  if (!selectResourcesMap[res.selectedResource.id]) {
1051
1064
  selectResourcesMap[res.selectedResource.id] = 1;
@@ -1075,9 +1088,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1075
1088
  return n.code === resources_code;
1076
1089
  })) === null || _productResources$fin === void 0 ? void 0 : _productResources$fin.renderList;
1077
1090
  if (targetRenderList && targetRenderList.length > 0) {
1078
- var _item$_origin$resourc3;
1091
+ var _item$_origin$resourc2;
1079
1092
  // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1080
- if ((_item$_origin$resourc3 = item._origin.resources) !== null && _item$_origin$resourc3 !== void 0 && _item$_origin$resourc3.some(function (n) {
1093
+ if ((_item$_origin$resourc2 = item._origin.resources) !== null && _item$_origin$resourc2 !== void 0 && _item$_origin$resourc2.some(function (n) {
1081
1094
  return n.form_id === targetRenderList[0].form_id;
1082
1095
  })) {
1083
1096
  return;
@@ -1112,8 +1125,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1112
1125
  var cartItems = this.store.cart.getItems();
1113
1126
  var resourceIds = [];
1114
1127
  cartItems.forEach(function (item) {
1115
- var _item$_productOrigin2;
1116
- (_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) {
1128
+ var _item$_productOrigin6;
1129
+ (_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) {
1117
1130
  if (n.code === resources_code) {
1118
1131
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1119
1132
  }
@@ -1132,8 +1145,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1132
1145
  var accountDuration = 0;
1133
1146
  var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1134
1147
  cartItems.forEach(function (item) {
1135
- var _item$_productOrigin$, _item$_productOrigin3;
1136
- 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;
1148
+ var _item$_productOrigin$3, _item$_productOrigin7;
1149
+ 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;
1137
1150
  });
1138
1151
  if (accountDuration > duration) {
1139
1152
  duration = accountDuration;
@@ -1173,9 +1186,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1173
1186
  accountItems.forEach(function (item, index) {
1174
1187
  var newResources = cloneDeep(item._origin.resources);
1175
1188
  newResources.forEach(function (resource) {
1176
- var _item$_productOrigin$2, _item$_productOrigin4, _ref8, _item$_productOrigin5;
1189
+ var _item$_productOrigin$4, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1177
1190
  resource.startTime = currentStartTime;
1178
- 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");
1191
+ 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");
1179
1192
  delete resource.times;
1180
1193
  });
1181
1194
  _this9.store.cart.updateItem({
@@ -432,19 +432,17 @@ 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
- const canUseTime = n.times.find(
441
- (item) => (0, import_resources.getIsUsableByTimeItem)({
442
- timeSlice: item,
443
- time: { start_time, end_time },
437
+ const canUseTime = n.times.find((item) => {
438
+ const res = (0, import_resources.getIsUsableByTimeItem)({
439
+ timeSlice: timeSlots,
440
+ time: item,
444
441
  resource: n,
445
442
  currentCount: 1
446
- })
447
- );
443
+ });
444
+ return res.usable;
445
+ });
448
446
  if (canUseTime) {
449
447
  targetResource = n;
450
448
  break;
@@ -504,19 +502,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
504
502
  });
505
503
  });
506
504
  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
505
  let targetResource = null;
510
506
  for (const n of resources) {
511
507
  const recordCount = countMap[n.id] || 0;
512
- const canUseTime = n.times.find(
513
- (item) => (0, import_resources.getIsUsableByTimeItem)({
514
- timeSlice: item,
515
- time: { start_time, end_time },
508
+ const canUseTime = n.times.find((item) => {
509
+ const res = (0, import_resources.getIsUsableByTimeItem)({
510
+ timeSlice: timeSlots,
511
+ time: item,
516
512
  resource: n,
517
513
  currentCount: recordCount + 1
518
- })
519
- );
514
+ });
515
+ return res.usable;
516
+ });
520
517
  if (canUseTime) {
521
518
  targetResource = n;
522
519
  break;
@@ -558,21 +555,26 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
558
555
  this.store.accountList.getAccounts().forEach((account) => {
559
556
  const cartItems = this.store.cart.getCartByAccount(account.getId());
560
557
  const allCartItems = this.store.cart.getItems();
561
- cartItems.forEach((item) => {
562
- var _a, _b, _c;
558
+ let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
559
+ cartItems.forEach((item, index) => {
560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
563
561
  if (timeSlots) {
562
+ if (index !== 0 && recordTimeSlots) {
563
+ 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");
564
+ 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");
565
+ recordTimeSlots = {
566
+ start_time: start_at.format("HH:mm"),
567
+ end_time: end_at.format("HH:mm"),
568
+ start_at,
569
+ end_at
570
+ };
571
+ }
564
572
  const res = this.autoSelectAccountResources({
565
573
  holder_id: item.holder_id,
566
574
  resources_code,
567
- timeSlots,
575
+ timeSlots: recordTimeSlots,
568
576
  countMap: selectResourcesMap
569
577
  });
570
- if ((_a = item._origin.resources) == null ? void 0 : _a.some((n) => {
571
- var _a2;
572
- return n.form_id === ((_a2 = res == null ? void 0 : res.selectedResource) == null ? void 0 : _a2.form_id);
573
- })) {
574
- return;
575
- }
576
578
  if (res == null ? void 0 : res.selectedResource) {
577
579
  if (!selectResourcesMap[res.selectedResource.id]) {
578
580
  selectResourcesMap[res.selectedResource.id] = 1;
@@ -597,9 +599,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
597
599
  }
598
600
  } else {
599
601
  const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
600
- const targetRenderList = (_b = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _b.renderList;
602
+ const targetRenderList = (_i = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _i.renderList;
601
603
  if (targetRenderList && targetRenderList.length > 0) {
602
- if ((_c = item._origin.resources) == null ? void 0 : _c.some((n) => n.form_id === targetRenderList[0].form_id)) {
604
+ if ((_j = item._origin.resources) == null ? void 0 : _j.some((n) => n.form_id === targetRenderList[0].form_id)) {
603
605
  return;
604
606
  }
605
607
  const targetResource = targetRenderList[0];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.30",
4
+ "version": "0.0.32",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",