@pisell/pisellos 0.0.71 → 0.0.72

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.
@@ -38,11 +38,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  * 删除step
39
39
  */
40
40
  removeStep(key: string): void;
41
- loadProducts({ category_ids, product_ids, collection, schedule_ids, }: {
41
+ loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
42
42
  category_ids?: number[];
43
43
  product_ids?: number[];
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
+ schedule_date?: string;
46
47
  }): Promise<any>;
47
48
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
49
  date: string;
@@ -193,11 +193,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
193
193
  value: function () {
194
194
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
195
195
  var _schedule_ids;
196
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_ids_data, productsData;
196
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_date, schedule_ids_data, productsData;
197
197
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
198
198
  while (1) switch (_context2.prev = _context2.next) {
199
199
  case 0:
200
- _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids;
200
+ _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids, schedule_date = _ref.schedule_date;
201
201
  // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
202
202
  if (!((_schedule_ids = schedule_ids) !== null && _schedule_ids !== void 0 && _schedule_ids.length)) {
203
203
  schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map(function (n) {
@@ -220,7 +220,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
220
220
  ids: product_ids,
221
221
  collection: collection,
222
222
  front_end_cache_id: this.cacheId,
223
- client_schedule_ids: schedule_ids
223
+ client_schedule_ids: schedule_ids,
224
+ schedule_date: schedule_date
224
225
  }, {
225
226
  useCache: true
226
227
  });
@@ -269,7 +270,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
269
270
  return this.loadProducts({
270
271
  schedule_ids: scheduleIds,
271
272
  product_ids: product_ids,
272
- category_ids: category_ids
273
+ category_ids: category_ids,
274
+ schedule_date: date
273
275
  });
274
276
  case 6:
275
277
  return _context3.abrupt("return", _context3.sent);
@@ -1212,6 +1214,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1212
1214
  }
1213
1215
  return res.usable;
1214
1216
  });
1217
+ if (m.onlyComputed) return false;
1215
1218
  // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1216
1219
  return !canUseArr.some(function (n) {
1217
1220
  return n === false;
@@ -1223,6 +1226,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1223
1226
  // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1224
1227
  item.renderList = item.renderList.filter(function (n) {
1225
1228
  var recordCount = n.capacity || 0;
1229
+ if (n.onlyComputed) return false;
1226
1230
  return recordCount >= currentCapacity;
1227
1231
  });
1228
1232
  });
@@ -1275,6 +1279,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1275
1279
  capacity: formatCapacity
1276
1280
  });
1277
1281
  var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
1282
+ productResources.forEach(function (item) {
1283
+ item.renderList = item.renderList.filter(function (n) {
1284
+ var recordCount = n.capacity || 0;
1285
+ if (n.onlyComputed) return false;
1286
+ return recordCount >= currentCapacity;
1287
+ });
1288
+ });
1278
1289
  if (productResources) {
1279
1290
  return {
1280
1291
  id: targetCartItem.id,
@@ -1535,6 +1546,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1535
1546
  selectedResources = getOthersCartSelectedResources(allCartItems, item._id, _resourcesMap);
1536
1547
  }
1537
1548
  var productResources = getResourcesByProduct(_resourcesMap, cloneDeep(_resources), selectedResources, currentCapacity);
1549
+ productResources.forEach(function (item) {
1550
+ item.renderList = item.renderList.filter(function (n) {
1551
+ var recordCount = n.capacity || 0;
1552
+ if (n.onlyComputed) return false;
1553
+ return recordCount >= currentCapacity;
1554
+ });
1555
+ });
1538
1556
  // 自动选择 productResources 中对应 resources_code 的资源
1539
1557
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1540
1558
  return n.code === resources_code;
@@ -1615,7 +1633,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1615
1633
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
1616
1634
  // resources.push(...dateRange[0].resource);
1617
1635
  dateRange[0].resource.forEach(function (n) {
1618
- if (n.form_id === resourcesTypeId) {
1636
+ if (n.form_id === resourcesTypeId && !resources.find(function (m) {
1637
+ return m.id === n.id;
1638
+ })) {
1619
1639
  resources.push(n);
1620
1640
  }
1621
1641
  });
@@ -95,6 +95,15 @@ export declare const getTimesIntersection: (times: TimeSliceItem[], count: numbe
95
95
  * @Date: 2024-09-19 20:23
96
96
  */
97
97
  export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
98
+ /**
99
+ * @title: 合并子资源的时间切片至组合资源
100
+ * @description:
101
+ * @param {ResourceItem[]} resources
102
+ * @param {Record<string, ResourceItem>} resourcesMap
103
+ * @return {*}
104
+ * @Author: zhiwei.Wang
105
+ */
106
+ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], resourcesMap: Record<string, ResourceItem>) => void;
98
107
  /**
99
108
  * @title: 根据资源id列表获取时间切片
100
109
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -238,6 +238,16 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
238
238
  resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
239
239
  if (resourcesMap[id]) {
240
240
  combiningResources.push(resourcesMap[id]);
241
+ childAcc.push(Object.assign({}, resourcesMap[id], {
242
+ form_id: form_id,
243
+ resourceType: item.type,
244
+ children: combiningResources,
245
+ onlyComputed: true,
246
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
247
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
248
+ combined_resource: resourcesMap[id].combined_resource
249
+ })
250
+ }));
241
251
  }
242
252
  });
243
253
  }
@@ -260,6 +270,16 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
260
270
  resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
261
271
  if (resourcesMap[id]) {
262
272
  combiningResources.push(resourcesMap[id]);
273
+ childAcc.push(Object.assign({}, resourcesMap[id], {
274
+ form_id: form_id,
275
+ resourceType: item.type,
276
+ children: combiningResources,
277
+ onlyComputed: true,
278
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
279
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[id].metadata), {}, {
280
+ combined_resource: resourcesMap[id].combined_resource
281
+ })
282
+ }));
263
283
  }
264
284
  });
265
285
  }
@@ -458,6 +478,37 @@ export var getResourcesByIds = function getResourcesByIds(resourcesMap, ids) {
458
478
  });
459
479
  };
460
480
 
481
+ /**
482
+ * @title: 合并子资源的时间切片至组合资源
483
+ * @description:
484
+ * @param {ResourceItem[]} resources
485
+ * @param {Record<string, ResourceItem>} resourcesMap
486
+ * @return {*}
487
+ * @Author: zhiwei.Wang
488
+ */
489
+ export var mergeSubResourcesTimeSlices = function mergeSubResourcesTimeSlices(resources, resourcesMap) {
490
+ return resources.forEach(function (item) {
491
+ var _item$combined_resour;
492
+ if ((item === null || item === void 0 || (_item$combined_resour = item.combined_resource) === null || _item$combined_resour === void 0 ? void 0 : _item$combined_resour.status) === 1) {
493
+ var _item$combined_resour2;
494
+ item === null || item === void 0 || (_item$combined_resour2 = item.combined_resource) === null || _item$combined_resour2 === void 0 || _item$combined_resour2.resource_ids.forEach(function (id) {
495
+ var subResource = resourcesMap[id];
496
+ if (subResource) {
497
+ subResource.times.forEach(function (time) {
498
+ var fatherResourcesTime = item.times.find(function (n) {
499
+ return n.start_at === time.start_at && n.end_at === time.end_at;
500
+ });
501
+ if (fatherResourcesTime) {
502
+ var _fatherResourcesTime$;
503
+ (_fatherResourcesTime$ = fatherResourcesTime.event_list).push.apply(_fatherResourcesTime$, _toConsumableArray(time.event_list || []));
504
+ }
505
+ });
506
+ }
507
+ });
508
+ }
509
+ });
510
+ };
511
+
461
512
  /**
462
513
  * @title: 根据资源id列表获取时间切片
463
514
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -476,6 +527,7 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
476
527
  resourcesUseableMap = _ref5.resourcesUseableMap;
477
528
  // 获取资源列表
478
529
  var resources = getResourcesByIds(resourcesMap, resourceIds);
530
+ mergeSubResourcesTimeSlices(resources, resourcesMap);
479
531
  // 资源排下序,把单个资源靠前,组合资源排在后面
480
532
  resources.sort(function (a, b) {
481
533
  var _a$metadata, _b$metadata;
@@ -38,11 +38,12 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  * 删除step
39
39
  */
40
40
  removeStep(key: string): void;
41
- loadProducts({ category_ids, product_ids, collection, schedule_ids, }: {
41
+ loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
42
42
  category_ids?: number[];
43
43
  product_ids?: number[];
44
44
  collection?: number | string[];
45
45
  schedule_ids?: number[];
46
+ schedule_date?: string;
46
47
  }): Promise<any>;
47
48
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
48
49
  date: string;
@@ -151,7 +151,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
151
151
  category_ids = [],
152
152
  product_ids = [],
153
153
  collection = [],
154
- schedule_ids = []
154
+ schedule_ids = [],
155
+ schedule_date
155
156
  }) {
156
157
  if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
157
158
  const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
@@ -178,7 +179,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
178
179
  ids: product_ids,
179
180
  collection,
180
181
  front_end_cache_id: this.cacheId,
181
- client_schedule_ids: schedule_ids
182
+ client_schedule_ids: schedule_ids,
183
+ schedule_date
182
184
  },
183
185
  { useCache: true }
184
186
  );
@@ -196,7 +198,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
196
198
  { date, status: "available", week: "", weekNum: 0 }
197
199
  ]);
198
200
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
199
- return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids });
201
+ return await this.loadProducts({ schedule_ids: scheduleIds, product_ids, category_ids, schedule_date: date });
200
202
  }
201
203
  // 加载当前店铺下所有 schedule
202
204
  async loadAllSchedule() {
@@ -664,6 +666,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
664
666
  }
665
667
  return res.usable;
666
668
  });
669
+ if (m.onlyComputed)
670
+ return false;
667
671
  return !canUseArr.some((n2) => n2 === false);
668
672
  });
669
673
  });
@@ -671,6 +675,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
671
675
  productResources.forEach((item) => {
672
676
  item.renderList = item.renderList.filter((n) => {
673
677
  const recordCount = n.capacity || 0;
678
+ if (n.onlyComputed)
679
+ return false;
674
680
  return recordCount >= currentCapacity;
675
681
  });
676
682
  });
@@ -728,6 +734,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
728
734
  selectedResources,
729
735
  currentCapacity
730
736
  );
737
+ productResources.forEach((item) => {
738
+ item.renderList = item.renderList.filter((n) => {
739
+ const recordCount = n.capacity || 0;
740
+ if (n.onlyComputed)
741
+ return false;
742
+ return recordCount >= currentCapacity;
743
+ });
744
+ });
731
745
  if (productResources) {
732
746
  return {
733
747
  id: targetCartItem.id,
@@ -952,6 +966,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
952
966
  selectedResources,
953
967
  currentCapacity
954
968
  );
969
+ productResources.forEach((item2) => {
970
+ item2.renderList = item2.renderList.filter((n) => {
971
+ const recordCount = n.capacity || 0;
972
+ if (n.onlyComputed)
973
+ return false;
974
+ return recordCount >= currentCapacity;
975
+ });
976
+ });
955
977
  const targetRenderList = (_l = productResources.find(
956
978
  (n) => n.code === resources_code
957
979
  )) == null ? void 0 : _l.renderList;
@@ -1012,7 +1034,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1012
1034
  });
1013
1035
  if ((_b = (_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.resource) == null ? void 0 : _b.length) {
1014
1036
  dateRange[0].resource.forEach((n) => {
1015
- if (n.form_id === resourcesTypeId) {
1037
+ if (n.form_id === resourcesTypeId && !resources.find((m) => m.id === n.id)) {
1016
1038
  resources.push(n);
1017
1039
  }
1018
1040
  });
@@ -95,6 +95,15 @@ export declare const getTimesIntersection: (times: TimeSliceItem[], count: numbe
95
95
  * @Date: 2024-09-19 20:23
96
96
  */
97
97
  export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
98
+ /**
99
+ * @title: 合并子资源的时间切片至组合资源
100
+ * @description:
101
+ * @param {ResourceItem[]} resources
102
+ * @param {Record<string, ResourceItem>} resourcesMap
103
+ * @return {*}
104
+ * @Author: zhiwei.Wang
105
+ */
106
+ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], resourcesMap: Record<string, ResourceItem>) => void;
98
107
  /**
99
108
  * @title: 根据资源id列表获取时间切片
100
109
  * @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
@@ -40,7 +40,8 @@ __export(resources_exports, {
40
40
  getSumCapacity: () => getSumCapacity,
41
41
  getTimeSlicesByResource: () => getTimeSlicesByResource,
42
42
  getTimeSlicesByResources: () => getTimeSlicesByResources,
43
- getTimesIntersection: () => getTimesIntersection
43
+ getTimesIntersection: () => getTimesIntersection,
44
+ mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices
44
45
  });
45
46
  module.exports = __toCommonJS(resources_exports);
46
47
  var import_dayjs = __toESM(require("dayjs"));
@@ -178,6 +179,19 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
178
179
  (id) => {
179
180
  if (resourcesMap[id]) {
180
181
  combiningResources.push(resourcesMap[id]);
182
+ childAcc.push(
183
+ Object.assign({}, resourcesMap[id], {
184
+ form_id,
185
+ resourceType: item.type,
186
+ children: combiningResources,
187
+ onlyComputed: true,
188
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
189
+ metadata: {
190
+ ...resourcesMap[id].metadata,
191
+ combined_resource: resourcesMap[id].combined_resource
192
+ }
193
+ })
194
+ );
181
195
  }
182
196
  }
183
197
  );
@@ -207,6 +221,19 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
207
221
  (id) => {
208
222
  if (resourcesMap[id]) {
209
223
  combiningResources.push(resourcesMap[id]);
224
+ childAcc.push(
225
+ Object.assign({}, resourcesMap[id], {
226
+ form_id,
227
+ resourceType: item.type,
228
+ children: combiningResources,
229
+ onlyComputed: true,
230
+ // 是否是只用来计算用,组合资源里,假设商品只关联了组合资源没关联子资源,需要通过这个计算来在后面从 renderList 里删除这个资源
231
+ metadata: {
232
+ ...resourcesMap[id].metadata,
233
+ combined_resource: resourcesMap[id].combined_resource
234
+ }
235
+ })
236
+ );
210
237
  }
211
238
  }
212
239
  );
@@ -335,6 +362,24 @@ var getTimesIntersection = (times, count) => {
335
362
  var getResourcesByIds = (resourcesMap, ids) => {
336
363
  return (ids || []).map((id) => resourcesMap[id]);
337
364
  };
365
+ var mergeSubResourcesTimeSlices = (resources, resourcesMap) => {
366
+ return resources.forEach((item) => {
367
+ var _a, _b;
368
+ if (((_a = item == null ? void 0 : item.combined_resource) == null ? void 0 : _a.status) === 1) {
369
+ (_b = item == null ? void 0 : item.combined_resource) == null ? void 0 : _b.resource_ids.forEach((id) => {
370
+ const subResource = resourcesMap[id];
371
+ if (subResource) {
372
+ subResource.times.forEach((time) => {
373
+ const fatherResourcesTime = item.times.find((n) => n.start_at === time.start_at && n.end_at === time.end_at);
374
+ if (fatherResourcesTime) {
375
+ fatherResourcesTime.event_list.push(...time.event_list || []);
376
+ }
377
+ });
378
+ }
379
+ });
380
+ }
381
+ });
382
+ };
338
383
  var getTimeSlicesByResources = ({
339
384
  resourceIds,
340
385
  resourcesMap,
@@ -345,6 +390,7 @@ var getTimeSlicesByResources = ({
345
390
  resourcesUseableMap
346
391
  }) => {
347
392
  let resources = getResourcesByIds(resourcesMap, resourceIds);
393
+ mergeSubResourcesTimeSlices(resources, resourcesMap);
348
394
  resources.sort((a, b) => {
349
395
  var _a, _b, _c, _d;
350
396
  const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
@@ -506,5 +552,6 @@ var checkSubResourcesCapacity = (resource) => {
506
552
  getSumCapacity,
507
553
  getTimeSlicesByResource,
508
554
  getTimeSlicesByResources,
509
- getTimesIntersection
555
+ getTimesIntersection,
556
+ mergeSubResourcesTimeSlices
510
557
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.71",
4
+ "version": "0.0.72",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",