@pisell/pisellos 0.0.27 → 0.0.28

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.
@@ -213,6 +213,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
213
213
  return account;
214
214
  });
215
215
  this.core.effects.emit("".concat(this.name, ":changed"), {
216
+ path: 'accounts',
216
217
  value: this.store.accountList
217
218
  });
218
219
  case 2:
@@ -106,10 +106,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
106
106
  timeSlots: any[];
107
107
  selectedResource: any;
108
108
  } | undefined;
109
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, }: {
109
+ autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
110
110
  holder_id: string;
111
111
  resources_code: string | number;
112
112
  timeSlots?: TimeSliceItem;
113
+ countMap: Record<number, number>;
113
114
  }): {
114
115
  selectedResource: any;
115
116
  timeSlots?: undefined;
@@ -479,16 +479,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
479
479
  value: function () {
480
480
  var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(accountId, accountInfo) {
481
481
  var _this4 = this;
482
- var account, cartItems;
482
+ var account, stateAccountId, cartItems;
483
483
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
484
484
  while (1) switch (_context11.prev = _context11.next) {
485
485
  case 0:
486
486
  account = this.store.accountList.getAccount(accountId);
487
487
  if (!account) {
488
- _context11.next = 8;
488
+ _context11.next = 9;
489
489
  break;
490
490
  }
491
- this.store.accountList.updateAccountListById(account.getId(), accountInfo);
491
+ stateAccountId = account.getId();
492
492
  account.setAccountInfo(accountInfo);
493
493
  // 然后去购物车,把原先关联了 holder_id 为 accountId 的商品,替换为 holder_id = accountInfo.id
494
494
  cartItems = this.store.cart.getItems();
@@ -500,11 +500,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
500
500
  });
501
501
  }
502
502
  });
503
- _context11.next = 9;
503
+ this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
504
+ _context11.next = 10;
504
505
  break;
505
- case 8:
506
- throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
507
506
  case 9:
507
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
508
+ case 10:
508
509
  case "end":
509
510
  return _context11.stop();
510
511
  }
@@ -916,7 +917,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
916
917
  var _accountCartItems$0$_, _accountCartItems$;
917
918
  var holder_id = _ref7.holder_id,
918
919
  resources_code = _ref7.resources_code,
919
- timeSlots = _ref7.timeSlots;
920
+ timeSlots = _ref7.timeSlots,
921
+ countMap = _ref7.countMap;
920
922
  var dateRange = this.store.date.getDateRange();
921
923
  var cartItems = this.store.cart.getItems();
922
924
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
@@ -958,6 +960,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
958
960
  try {
959
961
  var _loop2 = function _loop2() {
960
962
  var n = _step2.value;
963
+ var recordCount = countMap[n.id] || 0;
961
964
  var canUseTime = n.times.find(function (item) {
962
965
  return getIsUsableByTimeItem({
963
966
  timeSlice: item,
@@ -966,7 +969,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
966
969
  end_time: end_time
967
970
  },
968
971
  resource: n,
969
- currentCount: 1
972
+ currentCount: recordCount + 1
970
973
  });
971
974
  });
972
975
  if (canUseTime) {
@@ -1021,6 +1024,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1021
1024
  var resourcesMap = getResourcesMap(resources);
1022
1025
  // 一个账号一个账号处理
1023
1026
  var errorList = [];
1027
+ var selectResourcesMap = {};
1024
1028
  this.store.accountList.getAccounts().forEach(function (account) {
1025
1029
  var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1026
1030
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
@@ -1031,9 +1035,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1031
1035
  var res = _this7.autoSelectAccountResources({
1032
1036
  holder_id: item.holder_id,
1033
1037
  resources_code: resources_code,
1034
- timeSlots: timeSlots
1038
+ timeSlots: timeSlots,
1039
+ countMap: selectResourcesMap
1035
1040
  });
1036
1041
  if (res !== null && res !== void 0 && res.selectedResource) {
1042
+ if (!selectResourcesMap[res.selectedResource.id]) {
1043
+ selectResourcesMap[res.selectedResource.id] = 1;
1044
+ } else {
1045
+ selectResourcesMap[res.selectedResource.id]++;
1046
+ }
1037
1047
  console.log(_this7.store.cart.getItems());
1038
1048
  _this7.store.cart.updateItem({
1039
1049
  _id: item._id,
@@ -1122,47 +1132,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1122
1132
  }
1123
1133
 
1124
1134
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
1125
- // submitTimeSlot({
1126
- // resourceProductData,
1127
- // selectedResources,
1128
- // timeSlots,
1129
- // }: {
1130
- // resourceProductData: any;
1131
- // selectedResources: any[];
1132
- // timeSlots: TimeSliceItem;
1133
- // }) {
1134
- // const newResources = cloneDeep(selectedResources);
1135
- // newResources.forEach((n) => {
1136
- // n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1137
- // n.endTime = dayjs(n.startTime)
1138
- // .add(
1139
- // resourceProductData.product.duration.value,
1140
- // resourceProductData.product.duration.type
1141
- // )
1142
- // .format("YYYY-MM-DD HH:mm");
1143
- // delete n.times;
1144
- // });
1145
- // this.store.cart.updateItem({
1146
- // _id: resourceProductData._id,
1147
- // resources: newResources,
1148
- // });
1149
- // }
1150
1135
  }, {
1151
1136
  key: "submitTimeSlot",
1152
1137
  value: function submitTimeSlot(timeSlots) {
1153
1138
  var _this9 = this;
1139
+ // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
1154
1140
  var cartItems = this.store.cart.getItems();
1155
- cartItems.forEach(function (item) {
1156
- var newResources = cloneDeep(item._origin.resources);
1157
- newResources.forEach(function (n) {
1158
- var _item$_productOrigin$2, _item$_productOrigin4, _ref8, _item$_productOrigin5;
1159
- n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1160
- n.endTime = dayjs(n.startTime).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");
1161
- delete n.times;
1162
- });
1163
- _this9.store.cart.updateItem({
1164
- _id: item._id,
1165
- resources: newResources
1141
+
1142
+ // 按账号分组
1143
+ var itemsByAccount = cartItems.reduce(function (acc, item) {
1144
+ var holderId = item.holder_id;
1145
+ if (!acc[holderId]) {
1146
+ acc[holderId] = [];
1147
+ }
1148
+ acc[holderId].push(item);
1149
+ return acc;
1150
+ }, {});
1151
+
1152
+ // 处理每个账号的商品
1153
+ Object.values(itemsByAccount).forEach(function (accountItems) {
1154
+ var currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1155
+ accountItems.forEach(function (item, index) {
1156
+ var newResources = cloneDeep(item._origin.resources);
1157
+ newResources.forEach(function (resource) {
1158
+ var _item$_productOrigin$2, _item$_productOrigin4, _ref8, _item$_productOrigin5;
1159
+ resource.startTime = currentStartTime;
1160
+ 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");
1161
+ delete resource.times;
1162
+ });
1163
+ _this9.store.cart.updateItem({
1164
+ _id: item._id,
1165
+ resources: newResources
1166
+ });
1167
+
1168
+ // 更新下一个商品的开始时间为当前商品的结束时间
1169
+ if (index < accountItems.length - 1) {
1170
+ currentStartTime = newResources[0].endTime;
1171
+ }
1166
1172
  });
1167
1173
  });
1168
1174
  }
@@ -110,6 +110,9 @@ var checkCapacity = function checkCapacity(_ref) {
110
110
  resource = _ref.resource,
111
111
  _ref$currentCount = _ref.currentCount,
112
112
  currentCount = _ref$currentCount === void 0 ? 1 : _ref$currentCount;
113
+ if (currentCount > resource.capacity) {
114
+ return false;
115
+ }
113
116
  var conflict = (event_list || []).filter(function (d) {
114
117
  return isConflict({
115
118
  start_at: d.start_at,
@@ -116,7 +116,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
116
116
  }
117
117
  return account;
118
118
  });
119
- this.core.effects.emit(`${this.name}:changed`, { value: this.store.accountList });
119
+ this.core.effects.emit(`${this.name}:changed`, { path: "accounts", value: this.store.accountList });
120
120
  }
121
121
  async removeAccount(id) {
122
122
  try {
@@ -106,10 +106,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
106
106
  timeSlots: any[];
107
107
  selectedResource: any;
108
108
  } | undefined;
109
- autoSelectAccountResources({ holder_id, resources_code, timeSlots, }: {
109
+ autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
110
110
  holder_id: string;
111
111
  resources_code: string | number;
112
112
  timeSlots?: TimeSliceItem;
113
+ countMap: Record<number, number>;
113
114
  }): {
114
115
  selectedResource: any;
115
116
  timeSlots?: undefined;
@@ -238,7 +238,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
238
238
  async setLoginAccount(accountId, accountInfo) {
239
239
  const account = this.store.accountList.getAccount(accountId);
240
240
  if (account) {
241
- this.store.accountList.updateAccountListById(account.getId(), accountInfo);
241
+ let stateAccountId = account.getId();
242
242
  account.setAccountInfo(accountInfo);
243
243
  const cartItems = this.store.cart.getItems();
244
244
  cartItems.forEach((item) => {
@@ -249,6 +249,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
249
249
  });
250
250
  }
251
251
  });
252
+ this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
252
253
  } else {
253
254
  throw new Error(`没有找到${accountId}账户`);
254
255
  }
@@ -476,7 +477,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
476
477
  autoSelectAccountResources({
477
478
  holder_id,
478
479
  resources_code,
479
- timeSlots
480
+ timeSlots,
481
+ countMap
480
482
  }) {
481
483
  var _a, _b, _c;
482
484
  const dateRange = this.store.date.getDateRange();
@@ -506,12 +508,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
506
508
  const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, durationType).format("HH:mm");
507
509
  let targetResource = null;
508
510
  for (const n of resources) {
511
+ const recordCount = countMap[n.id] || 0;
509
512
  const canUseTime = n.times.find(
510
513
  (item) => (0, import_resources.getIsUsableByTimeItem)({
511
514
  timeSlice: item,
512
515
  time: { start_time, end_time },
513
516
  resource: n,
514
- currentCount: 1
517
+ currentCount: recordCount + 1
515
518
  })
516
519
  );
517
520
  if (canUseTime) {
@@ -551,6 +554,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
551
554
  });
552
555
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
553
556
  const errorList = [];
557
+ const selectResourcesMap = {};
554
558
  this.store.accountList.getAccounts().forEach((account) => {
555
559
  const cartItems = this.store.cart.getCartByAccount(account.getId());
556
560
  const allCartItems = this.store.cart.getItems();
@@ -560,9 +564,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
560
564
  const res = this.autoSelectAccountResources({
561
565
  holder_id: item.holder_id,
562
566
  resources_code,
563
- timeSlots
567
+ timeSlots,
568
+ countMap: selectResourcesMap
564
569
  });
565
570
  if (res == null ? void 0 : res.selectedResource) {
571
+ if (!selectResourcesMap[res.selectedResource.id]) {
572
+ selectResourcesMap[res.selectedResource.id] = 1;
573
+ } else {
574
+ selectResourcesMap[res.selectedResource.id]++;
575
+ }
566
576
  console.log(this.store.cart.getItems());
567
577
  this.store.cart.updateItem({
568
578
  _id: item._id,
@@ -639,47 +649,33 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
639
649
  return timeSlots;
640
650
  }
641
651
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
642
- // submitTimeSlot({
643
- // resourceProductData,
644
- // selectedResources,
645
- // timeSlots,
646
- // }: {
647
- // resourceProductData: any;
648
- // selectedResources: any[];
649
- // timeSlots: TimeSliceItem;
650
- // }) {
651
- // const newResources = cloneDeep(selectedResources);
652
- // newResources.forEach((n) => {
653
- // n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
654
- // n.endTime = dayjs(n.startTime)
655
- // .add(
656
- // resourceProductData.product.duration.value,
657
- // resourceProductData.product.duration.type
658
- // )
659
- // .format("YYYY-MM-DD HH:mm");
660
- // delete n.times;
661
- // });
662
- // this.store.cart.updateItem({
663
- // _id: resourceProductData._id,
664
- // resources: newResources,
665
- // });
666
- // }
667
652
  submitTimeSlot(timeSlots) {
668
653
  const cartItems = this.store.cart.getItems();
669
- cartItems.forEach((item) => {
670
- const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
671
- newResources.forEach((n) => {
672
- var _a, _b, _c, _d;
673
- n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
674
- n.endTime = (0, import_dayjs.default)(n.startTime).add(
675
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
676
- ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
677
- ).format("YYYY-MM-DD HH:mm");
678
- delete n.times;
679
- });
680
- this.store.cart.updateItem({
681
- _id: item._id,
682
- resources: newResources
654
+ const itemsByAccount = cartItems.reduce((acc, item) => {
655
+ const holderId = item.holder_id;
656
+ if (!acc[holderId]) {
657
+ acc[holderId] = [];
658
+ }
659
+ acc[holderId].push(item);
660
+ return acc;
661
+ }, {});
662
+ Object.values(itemsByAccount).forEach((accountItems) => {
663
+ let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
664
+ accountItems.forEach((item, index) => {
665
+ const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
666
+ newResources.forEach((resource) => {
667
+ var _a, _b, _c, _d;
668
+ resource.startTime = currentStartTime;
669
+ resource.endTime = (0, import_dayjs.default)(currentStartTime).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").format("YYYY-MM-DD HH:mm");
670
+ delete resource.times;
671
+ });
672
+ this.store.cart.updateItem({
673
+ _id: item._id,
674
+ resources: newResources
675
+ });
676
+ if (index < accountItems.length - 1) {
677
+ currentStartTime = newResources[0].endTime;
678
+ }
683
679
  });
684
680
  });
685
681
  }
@@ -72,6 +72,9 @@ var formatResource = (resourceItem, booking) => {
72
72
  return _resourceItem;
73
73
  };
74
74
  var checkCapacity = ({ event_list, timeSlice, resource, currentCount = 1 }) => {
75
+ if (currentCount > resource.capacity) {
76
+ return false;
77
+ }
75
78
  let conflict = (event_list || []).filter((d) => {
76
79
  return isConflict({ start_at: d.start_at, end_at: d.end_at }, { start_at: timeSlice.start_at, end_at: timeSlice.end_at });
77
80
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.27",
4
+ "version": "0.0.28",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",