@pisell/pisellos 0.0.121 → 0.0.122

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.
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -213,7 +213,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
213
213
  }): void;
214
214
  setOtherData(key: string, value: any): void;
215
215
  getOtherData(key: string): any;
216
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
216
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
217
217
  /**
218
218
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
219
219
  *
@@ -238,7 +238,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
238
238
  return this.request.post("/product/query", {
239
239
  open_quotation: 1,
240
240
  open_bundle: 0,
241
- extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket', 'normal'],
241
+ exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
242
242
  with: ['category', 'collection', 'resourceRelation'],
243
243
  status: 'published',
244
244
  num: 500,
@@ -2403,7 +2403,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2403
2403
  }, {
2404
2404
  key: "getTimeslotBySchedule",
2405
2405
  value: function getTimeslotBySchedule(_ref12) {
2406
- var _this$store$currentPr2;
2406
+ var _this$store$currentPr2, _targetProductData$pr;
2407
2407
  var date = _ref12.date,
2408
2408
  scheduleIds = _ref12.scheduleIds,
2409
2409
  resources = _ref12.resources,
@@ -2442,6 +2442,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2442
2442
  return 0;
2443
2443
  });
2444
2444
 
2445
+ // 找到当前商品下第一个启用的资源id
2446
+ var firstEnabledResourceId = targetProductData === null || targetProductData === void 0 || (_targetProductData$pr = targetProductData.product_resource) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.resources) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.find(function (n) {
2447
+ return n.status === 1;
2448
+ })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2449
+
2445
2450
  // 计算每个日程切片下日程可用的资源的容量总和
2446
2451
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2447
2452
  // 用来计算资源的可使用情况,针对单个schedule 时间片
@@ -2489,7 +2494,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2489
2494
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2490
2495
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2491
2496
  return n === false;
2492
- })) {
2497
+ })
2498
+ // 只统计第一种资源的容量和 left
2499
+ && m.form_id === firstEnabledResourceId) {
2493
2500
  if (currentResourcesCount >= count) {
2494
2501
  count = currentResourcesCount;
2495
2502
  }
@@ -2881,7 +2888,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2881
2888
  var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2882
2889
  var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
2883
2890
  var params,
2884
- cache,
2885
2891
  startDate,
2886
2892
  endDate,
2887
2893
  tempProducts,
@@ -2889,6 +2895,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2889
2895
  filteredSchedule,
2890
2896
  tempResourceIds,
2891
2897
  res,
2898
+ cache,
2892
2899
  dates,
2893
2900
  currentDate,
2894
2901
  firstAvailableDate,
@@ -2901,21 +2908,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2901
2908
  while (1) switch (_context32.prev = _context32.next) {
2902
2909
  case 0:
2903
2910
  params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
2904
- // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2905
- cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
2906
- if (!cache) {
2907
- _context32.next = 5;
2908
- break;
2909
- }
2910
- if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2911
- _context32.next = 5;
2912
- break;
2913
- }
2914
- return _context32.abrupt("return", {
2915
- dateList: cache.dateList,
2916
- firstAvailableDate: cache.firstAvailableDate
2917
- });
2918
- case 5:
2919
2911
  // 开始日期如果小于今天,直接以今天当做开始日期
2920
2912
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
2921
2913
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -2924,11 +2916,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2924
2916
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2925
2917
  endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2926
2918
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2927
- tempProducts = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getData();
2928
- schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
2919
+ tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2920
+ schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2929
2921
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2930
2922
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2931
- _context32.next = 14;
2923
+ _context32.next = 10;
2932
2924
  return this.store.date.fetchResourceDates({
2933
2925
  query: {
2934
2926
  start_date: startDate || '',
@@ -2936,8 +2928,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2936
2928
  resource_ids: tempResourceIds
2937
2929
  }
2938
2930
  });
2939
- case 14:
2931
+ case 10:
2940
2932
  res = _context32.sent;
2933
+ // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2934
+ // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2935
+ cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2936
+ if (!cache) {
2937
+ _context32.next = 16;
2938
+ break;
2939
+ }
2940
+ if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2941
+ _context32.next = 16;
2942
+ break;
2943
+ }
2944
+ this.store.date.setDateList(cache.dateList);
2945
+ return _context32.abrupt("return", {
2946
+ dateList: cache.dateList,
2947
+ firstAvailableDate: cache.firstAvailableDate
2948
+ });
2949
+ case 16:
2941
2950
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2942
2951
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2943
2952
  dates = [];
@@ -2946,7 +2955,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2946
2955
  openResources = ((_tempProducts = tempProducts) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.product_resource) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.resources) === null || _tempProducts === void 0 ? void 0 : _tempProducts.filter(function (m) {
2947
2956
  return m.status === 1;
2948
2957
  })) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
2949
- allProductResources = sortCombinedResources(res.data);
2958
+ allProductResources = sortCombinedResources(res.data); // allProductResources 需要根据商品里的资源的单个预约多个预约补充resourceType
2959
+ allProductResources.forEach(function (m) {
2960
+ var _tempProducts2;
2961
+ var resource = (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.product_resource) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.resources) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.find(function (n) {
2962
+ return n.id === m.form_id;
2963
+ });
2964
+ if (resource) {
2965
+ m.resourceType = resource.type;
2966
+ }
2967
+ });
2950
2968
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
2951
2969
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
2952
2970
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
@@ -3003,7 +3021,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3003
3021
  return;
3004
3022
  }
3005
3023
  var targetCanUseTimes = mTimes.some(function (childTiem) {
3006
- var _tempProducts2;
3024
+ var _tempProducts3;
3007
3025
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
3008
3026
  var res = getIsUsableByTimeItem({
3009
3027
  timeSlice: {
@@ -3016,7 +3034,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3016
3034
  resource: m,
3017
3035
  currentCount: 1,
3018
3036
  resourcesUseableMap: resourcesUseableMap,
3019
- cut_off_time: (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.cut_off_time
3037
+ cut_off_time: (_tempProducts3 = tempProducts) === null || _tempProducts3 === void 0 ? void 0 : _tempProducts3.cut_off_time
3020
3038
  });
3021
3039
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3022
3040
  resourcesUseableMap[m.id] = res.usable;
@@ -3055,22 +3073,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3055
3073
  }
3056
3074
  }, _loop3);
3057
3075
  });
3058
- case 22:
3076
+ case 24:
3059
3077
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3060
- _context32.next = 28;
3078
+ _context32.next = 30;
3061
3079
  break;
3062
3080
  }
3063
- return _context32.delegateYield(_loop3(), "t0", 24);
3064
- case 24:
3081
+ return _context32.delegateYield(_loop3(), "t0", 26);
3082
+ case 26:
3065
3083
  if (!_context32.t0) {
3066
- _context32.next = 26;
3084
+ _context32.next = 28;
3067
3085
  break;
3068
3086
  }
3069
- return _context32.abrupt("break", 28);
3070
- case 26:
3071
- _context32.next = 22;
3072
- break;
3087
+ return _context32.abrupt("break", 30);
3073
3088
  case 28:
3089
+ _context32.next = 24;
3090
+ break;
3091
+ case 30:
3074
3092
  // 最终把资源数据也加到日期内
3075
3093
  dates = handleAvailableDateByResource(res.data, dates);
3076
3094
  this.store.date.setDateList(dates);
@@ -3086,7 +3104,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3086
3104
  dateList: dates,
3087
3105
  firstAvailableDate: firstAvailableDate
3088
3106
  });
3089
- case 32:
3107
+ case 34:
3090
3108
  case "end":
3091
3109
  return _context32.stop();
3092
3110
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -213,7 +213,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
213
213
  }): void;
214
214
  setOtherData(key: string, value: any): void;
215
215
  getOtherData(key: string): any;
216
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
216
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
217
217
  /**
218
218
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
219
219
  *
@@ -180,12 +180,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
180
180
  {
181
181
  open_quotation: 1,
182
182
  open_bundle: 0,
183
- extension_type: [
184
- "product_appointment",
185
- "appointment_ticket",
186
- "session_product",
187
- "session_ticket",
188
- "normal"
183
+ exclude_extension_type: [
184
+ "product_party",
185
+ "product_event",
186
+ "product_series_event",
187
+ "product_package_ticket",
188
+ "ticket",
189
+ "event_item"
189
190
  ],
190
191
  with: ["category", "collection", "resourceRelation"],
191
192
  status: "published",
@@ -1651,7 +1652,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1651
1652
  resources,
1652
1653
  product
1653
1654
  }) {
1654
- var _a, _b, _c;
1655
+ var _a, _b, _c, _d, _e, _f;
1655
1656
  const targetProduct = this.store.currentProduct;
1656
1657
  const targetProductData = product || (targetProduct == null ? void 0 : targetProduct.getData());
1657
1658
  let targetSchedules = [];
@@ -1685,15 +1686,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1685
1686
  const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1686
1687
  let allProductResources = productResources.flatMap((n) => n.renderList);
1687
1688
  allProductResources.sort((a, b) => {
1688
- var _a2, _b2, _c2, _d;
1689
+ var _a2, _b2, _c2, _d2;
1689
1690
  const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1690
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1691
+ const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
1691
1692
  if (aIsCombined && !bIsCombined)
1692
1693
  return 1;
1693
1694
  if (!aIsCombined && bIsCombined)
1694
1695
  return -1;
1695
1696
  return 0;
1696
1697
  });
1698
+ const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find((n) => n.status === 1)) == null ? void 0 : _f.id;
1697
1699
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1698
1700
  const resourcesUseableMap = {};
1699
1701
  let count = 0;
@@ -1729,7 +1731,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1729
1731
  }
1730
1732
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1731
1733
  });
1732
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false)) {
1734
+ if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
1733
1735
  if (currentResourcesCount >= count) {
1734
1736
  count = currentResourcesCount;
1735
1737
  }
@@ -2032,23 +2034,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2032
2034
  }
2033
2035
  async getAvailableDateForSessionOptimize(params = {}) {
2034
2036
  var _a, _b, _c, _d, _e, _f;
2035
- const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
2036
- if (cache) {
2037
- if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
2038
- return {
2039
- dateList: cache.dateList,
2040
- firstAvailableDate: cache.firstAvailableDate
2041
- };
2042
- }
2043
- }
2044
2037
  let { startDate, endDate } = params;
2045
2038
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2046
2039
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2047
2040
  }
2048
2041
  endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2049
2042
  let tempProducts;
2050
- tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
2051
- const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2043
+ tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2044
+ const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
2052
2045
  const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2053
2046
  schedule,
2054
2047
  startDate || "",
@@ -2062,6 +2055,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2062
2055
  resource_ids: tempResourceIds
2063
2056
  }
2064
2057
  });
2058
+ const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
2059
+ if (cache) {
2060
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
2061
+ this.store.date.setDateList(cache.dateList);
2062
+ return {
2063
+ dateList: cache.dateList,
2064
+ firstAvailableDate: cache.firstAvailableDate
2065
+ };
2066
+ }
2067
+ }
2065
2068
  let dates = [];
2066
2069
  let currentDate = (0, import_dayjs.default)(startDate);
2067
2070
  let firstAvailableDate = "";
@@ -2069,6 +2072,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2069
2072
  (m) => m.status === 1
2070
2073
  )) || [];
2071
2074
  const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
2075
+ allProductResources.forEach((m) => {
2076
+ var _a2, _b2;
2077
+ const resource = (_b2 = (_a2 = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b2.find(
2078
+ (n) => n.id === m.form_id
2079
+ );
2080
+ if (resource) {
2081
+ m.resourceType = resource.type;
2082
+ }
2083
+ });
2072
2084
  const targetSchedules = this.store.schedule.getScheduleListByIds(
2073
2085
  tempProducts["schedule.ids"]
2074
2086
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.121",
4
+ "version": "0.0.122",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",