@pisell/pisellos 2.0.23 → 2.0.25

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.
@@ -65,18 +65,13 @@ var DateModule = class extends import_BaseModule.BaseModule {
65
65
  getDateList() {
66
66
  return this.store.dateList;
67
67
  }
68
- async getResourceAvailableTimeList(params) {
69
- var _a;
70
- const { url, query, rules, type } = params;
68
+ setDateList(dateList) {
69
+ this.store.dateList = dateList;
70
+ }
71
+ async fetchResourceDates(params) {
72
+ const { url, query } = params;
71
73
  const fetchUrl = url || "/schedule/resource/list";
72
74
  const { start_date, end_date, resource_ids } = query || {};
73
- if (!start_date || !end_date) {
74
- return [];
75
- }
76
- let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
77
- if (!(resource_ids == null ? void 0 : resource_ids.length)) {
78
- return (0, import_utils.disableAllDates)(dates);
79
- }
80
75
  try {
81
76
  const res = await this.request.get(fetchUrl, {
82
77
  start_date,
@@ -86,6 +81,24 @@ var DateModule = class extends import_BaseModule.BaseModule {
86
81
  }, {
87
82
  useCache: true
88
83
  });
84
+ return res;
85
+ } catch (error) {
86
+ console.error(error);
87
+ }
88
+ }
89
+ async getResourceAvailableTimeList(params) {
90
+ var _a;
91
+ const { query, rules, type } = params;
92
+ const { start_date, end_date, resource_ids } = query || {};
93
+ if (!start_date || !end_date) {
94
+ return [];
95
+ }
96
+ let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
97
+ if (!(resource_ids == null ? void 0 : resource_ids.length)) {
98
+ return (0, import_utils.disableAllDates)(dates);
99
+ }
100
+ try {
101
+ const res = await this.fetchResourceDates(params);
89
102
  if (!((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.length)) {
90
103
  return (0, import_utils.disableAllDates)(dates);
91
104
  }
@@ -58,10 +58,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
58
58
  productList
59
59
  };
60
60
  }
61
- const mergedDiscountList = (0, import_utils.uniqueById)([
61
+ const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
62
62
  ...oldDiscountList,
63
63
  ...newDiscountList
64
- ]);
64
+ ]), "product_id");
65
65
  const result = this.calcDiscount({
66
66
  discountList: mergedDiscountList,
67
67
  productList: [...productList]
@@ -6,6 +6,7 @@ export interface ScheduleState {
6
6
  export type ScheduleAvailabilityDateItem = {
7
7
  date: string;
8
8
  schedule_id: number[];
9
+ product_ids: number[];
9
10
  };
10
11
  export interface ScheduleModuleAPI {
11
12
  }
@@ -5,7 +5,7 @@ import { BookingByStepState } from './types';
5
5
  import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem, ECartItemInfoType, ECartItemCheckType } from '../../modules';
6
6
  import { Account } from '../../modules/Account/types';
7
7
  import { IStep } from '../../modules/Step/tyeps';
8
- import { TimeSliceItem } from './utils/resources';
8
+ import { TimeSliceItem, ResourceItem } from './utils/resources';
9
9
  import { ITime } from '../../modules/Date/types';
10
10
  import dayjs from 'dayjs';
11
11
  import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
@@ -153,7 +153,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
153
153
  id: number | undefined;
154
154
  _id: string;
155
155
  product: ProductData | undefined;
156
- resources: import("./utils/resources").ResourceItem[];
156
+ resources: ResourceItem[];
157
157
  holder_id: string | number | undefined;
158
158
  holder_name: string | undefined;
159
159
  } | undefined;
@@ -189,7 +189,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
189
189
  private getScheduleDataByIds;
190
190
  openProductDetail(productId: number): Promise<void>;
191
191
  closeProductDetail(): void;
192
- getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
192
+ getTimeslotBySchedule({ date, scheduleIds, resources, product, }: {
193
193
  date: string;
194
194
  scheduleIds?: number[];
195
195
  resources?: ProductResourceItem[];
@@ -221,9 +221,30 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
221
221
  * @memberof BookingByStepImpl
222
222
  */
223
223
  getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
224
+ /**
225
+ * 根据日期范围批量获取时间槽
226
+ * @param params 参数对象
227
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
228
+ */
229
+ getTimeslotsScheduleByDateRange({ startDate, endDate, scheduleIds, resources, }: {
230
+ startDate: string;
231
+ endDate: string;
232
+ scheduleIds?: number[];
233
+ resources?: ProductResourceItem[];
234
+ }): Promise<Record<string, TimeSliceItem[]>>;
224
235
  getAvailableDateForSession(params?: {
225
236
  startDate?: string;
226
237
  endDate?: string;
227
238
  type?: 'month';
228
- }): Promise<ITime[]>;
239
+ }): Promise<{
240
+ dateList: ITime[];
241
+ firstAvailableDate: ITime | undefined;
242
+ }>;
243
+ getAvailableDateForSessionOptimize(params?: {
244
+ startDate?: string;
245
+ endDate?: string;
246
+ }): Promise<{
247
+ dateList: any;
248
+ firstAvailableDate: any;
249
+ }>;
229
250
  }
@@ -37,10 +37,14 @@ var import_types = require("./types");
37
37
  var import_products = require("./utils/products");
38
38
  var import_resources = require("./utils/resources");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
+ var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
41
+ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
42
  var import_utils = require("../../modules/Resource/utils");
41
43
  var import_lodash_es = require("lodash-es");
42
44
  var import_utils2 = require("../../modules/Schedule/utils");
43
45
  var import_utils3 = require("../../modules/Date/utils");
46
+ import_dayjs.default.extend(import_isSameOrBefore.default);
47
+ import_dayjs.default.extend(import_isSameOrAfter.default);
44
48
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
45
49
  constructor() {
46
50
  super(...arguments);
@@ -211,12 +215,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
211
215
  product_ids,
212
216
  category_ids = []
213
217
  }) {
218
+ var _a;
214
219
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
215
220
  this.setDateRange([
216
221
  { date, status: "available", week: "", weekNum: 0 },
217
222
  { date, status: "available", week: "", weekNum: 0 }
218
223
  ]);
219
- const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
224
+ const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null && n !== void 0);
225
+ if (!(product_ids == null ? void 0 : product_ids.length)) {
226
+ const schedule = scheduleList.find((n) => n.date === date);
227
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
228
+ product_ids = schedule.product_ids;
229
+ }
230
+ }
220
231
  return await this.loadProducts({
221
232
  schedule_ids: scheduleIds,
222
233
  product_ids,
@@ -242,16 +253,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
242
253
  });
243
254
  for (const item of cartItems) {
244
255
  const targetProduct = res.find((n) => n.id === item.id);
245
- const cartProduct = await this.store.products.getProduct(item.id);
256
+ const cartProduct = await this.store.products.getProduct(
257
+ item.id
258
+ );
246
259
  const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
247
260
  let bundle = item._bundleOrigin;
248
261
  productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
249
262
  productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
250
263
  bundle = bundle == null ? void 0 : bundle.map((n) => {
251
264
  var _a2;
252
- const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find((m) => m.id === n.group_id);
265
+ const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
266
+ (m) => m.id === n.group_id
267
+ );
253
268
  if (targetBundle) {
254
- const targetBundleItem = targetBundle.bundle_item.find((m) => m.id === n.id);
269
+ const targetBundleItem = targetBundle.bundle_item.find(
270
+ (m) => m.id === n.id
271
+ );
255
272
  if (targetBundleItem) {
256
273
  return {
257
274
  ...n,
@@ -268,13 +285,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
268
285
  bundle
269
286
  });
270
287
  }
271
- ;
272
288
  }
273
289
  }
274
290
  // 加载当前店铺下所有 schedule
275
291
  async loadAllSchedule() {
276
292
  var _a;
277
- const scheduleList = await this.request.get(`/schedule`, { num: 999 }, { useCache: true });
293
+ const scheduleList = await this.request.get(
294
+ `/schedule`,
295
+ { num: 999 },
296
+ { useCache: true }
297
+ );
278
298
  this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
279
299
  }
280
300
  // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
@@ -627,8 +647,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
627
647
  capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
628
648
  product_bundle: item._origin.product.product_bundle
629
649
  });
630
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
631
- const originResource = allOriginResources.find((n) => n.id === targetRes.id);
650
+ const currentCapacity = (0, import_resources.getSumCapacity)({
651
+ capacity: formatCapacity
652
+ });
653
+ const originResource = allOriginResources.find(
654
+ (n) => n.id === targetRes.id
655
+ );
632
656
  if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
633
657
  return true;
634
658
  }
@@ -651,7 +675,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
651
675
  }
652
676
  )))
653
677
  return true;
654
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
678
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
679
+ targetRes.id
680
+ ))
655
681
  return true;
656
682
  }
657
683
  return false;
@@ -666,8 +692,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
666
692
  _id: item._id,
667
693
  resources,
668
694
  date: {
669
- startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
670
- endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
695
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
696
+ "YYYY-MM-DD HH:mm"
697
+ ),
698
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format(
699
+ "YYYY-MM-DD HH:mm"
700
+ )
671
701
  }
672
702
  });
673
703
  } else {
@@ -1147,10 +1177,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1147
1177
  if (mTimes.length === 0) {
1148
1178
  continue;
1149
1179
  }
1150
- const totalCapacity = (countMap[n.id] || []).reduce((sum, item) => {
1151
- const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
1152
- return hasOverlap ? sum + item.pax : sum;
1153
- }, 0);
1180
+ const totalCapacity = (countMap[n.id] || []).reduce(
1181
+ (sum, item) => {
1182
+ const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
1183
+ return hasOverlap ? sum + item.pax : sum;
1184
+ },
1185
+ 0
1186
+ );
1154
1187
  const canUseTime = mTimes.find((item) => {
1155
1188
  var _a2;
1156
1189
  const res = (0, import_resources.getIsUsableByTimeItem)({
@@ -1228,7 +1261,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1228
1261
  };
1229
1262
  }
1230
1263
  if (recordTimeSlots) {
1231
- const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
1264
+ const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1265
+ (n) => n.code === resources_code
1266
+ );
1232
1267
  const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
1233
1268
  if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1234
1269
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
@@ -1407,7 +1442,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1407
1442
  (n) => n.code === resources_code
1408
1443
  )) == null ? void 0 : _g.id;
1409
1444
  if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1410
- const currentCutOffTime = (0, import_dayjs.default)().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
1445
+ const currentCutOffTime = (0, import_dayjs.default)().add(
1446
+ item._productOrigin.cut_off_time.unit,
1447
+ item._productOrigin.cut_off_time.unit_type
1448
+ );
1411
1449
  if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
1412
1450
  maxCutOffTimeValue = currentCutOffTime;
1413
1451
  maxCutOffTime = item._productOrigin.cut_off_time;
@@ -1599,7 +1637,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1599
1637
  date
1600
1638
  );
1601
1639
  const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1602
- console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
1603
1640
  let allProductResources = productResources.flatMap((n) => n.renderList);
1604
1641
  allProductResources.sort((a, b) => {
1605
1642
  var _a2, _b2, _c2, _d;
@@ -1645,7 +1682,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1645
1682
  }
1646
1683
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1647
1684
  });
1648
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && currentResourcesCount >= count) {
1685
+ if (!currentResourcesTimeSlotCanUsedArr.some(
1686
+ (n) => n === false
1687
+ ) && currentResourcesCount >= count) {
1649
1688
  count = currentResourcesCount;
1650
1689
  }
1651
1690
  });
@@ -1717,7 +1756,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1717
1756
  *
1718
1757
  * @param {string} cartItemId
1719
1758
  * @param {string} resourceCode
1720
- * @return {*}
1759
+ * @return {*}
1721
1760
  * @memberof BookingByStepImpl
1722
1761
  */
1723
1762
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
@@ -1768,7 +1807,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1768
1807
  selectedResources,
1769
1808
  currentCapacity
1770
1809
  );
1771
- const targetResource = productResources.find((resource) => resource.code === resourceCode);
1810
+ const targetResource = productResources.find(
1811
+ (resource) => resource.code === resourceCode
1812
+ );
1772
1813
  if (!targetResource)
1773
1814
  return [];
1774
1815
  if (cartItem._origin.start_time) {
@@ -1779,16 +1820,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1779
1820
  `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
1780
1821
  );
1781
1822
  const resourcesUseableMap = {};
1782
- targetResource.renderList = targetResource.renderList.sort((a, b) => {
1783
- var _a2, _b2, _c2, _d;
1784
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1785
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1786
- if (aIsCombined && !bIsCombined)
1787
- return 1;
1788
- if (!aIsCombined && bIsCombined)
1789
- return -1;
1790
- return 0;
1791
- });
1823
+ targetResource.renderList = targetResource.renderList.sort(
1824
+ (a, b) => {
1825
+ var _a2, _b2, _c2, _d;
1826
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1827
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1828
+ if (aIsCombined && !bIsCombined)
1829
+ return 1;
1830
+ if (!aIsCombined && bIsCombined)
1831
+ return -1;
1832
+ return 0;
1833
+ }
1834
+ );
1792
1835
  targetResource.renderList = targetResource.renderList.filter((m) => {
1793
1836
  const mTimes = m.times.filter((n) => {
1794
1837
  return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
@@ -1836,6 +1879,38 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1836
1879
  }
1837
1880
  return targetResource.renderList;
1838
1881
  }
1882
+ /**
1883
+ * 根据日期范围批量获取时间槽
1884
+ * @param params 参数对象
1885
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
1886
+ */
1887
+ async getTimeslotsScheduleByDateRange({
1888
+ startDate,
1889
+ endDate,
1890
+ scheduleIds,
1891
+ resources
1892
+ }) {
1893
+ console.log(
1894
+ "appoimentBooking-session-date-getTimeslotsScheduleByDateRange",
1895
+ { startDate, endDate, scheduleIds, resources }
1896
+ );
1897
+ const dates = [];
1898
+ let currentDate = (0, import_dayjs.default)(startDate);
1899
+ const end = (0, import_dayjs.default)(endDate);
1900
+ while (currentDate.isSameOrBefore(end)) {
1901
+ dates.push(currentDate.format("YYYY-MM-DD"));
1902
+ currentDate = currentDate.add(1, "day");
1903
+ }
1904
+ const results = {};
1905
+ for (const date of dates) {
1906
+ results[date] = this.getTimeslotBySchedule({
1907
+ date,
1908
+ scheduleIds,
1909
+ resources
1910
+ });
1911
+ }
1912
+ return results;
1913
+ }
1839
1914
  async getAvailableDateForSession(params = {}) {
1840
1915
  let { startDate, endDate, type } = params;
1841
1916
  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"))) {
@@ -1862,7 +1937,165 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1862
1937
  rules,
1863
1938
  type
1864
1939
  });
1865
- return res;
1940
+ if (this.store.currentProduct) {
1941
+ const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
1942
+ startDate: startDate || "",
1943
+ endDate: endDate || ""
1944
+ });
1945
+ res.forEach((n) => {
1946
+ if (!dateListWithTimeSlots[n.date]) {
1947
+ n.status = "unavailable";
1948
+ } else {
1949
+ const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
1950
+ (d) => d.count
1951
+ );
1952
+ if (!allTimeSlotsCanUse) {
1953
+ n.status = "unavailable";
1954
+ }
1955
+ }
1956
+ });
1957
+ }
1958
+ const firstAvailableDate = res.find((n) => n.status === "available");
1959
+ return {
1960
+ dateList: res,
1961
+ firstAvailableDate
1962
+ };
1963
+ }
1964
+ async getAvailableDateForSessionOptimize(params = {}) {
1965
+ var _a, _b, _c, _d, _e, _f;
1966
+ const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1967
+ if (cache) {
1968
+ 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")) {
1969
+ return {
1970
+ dateList: cache.dateList,
1971
+ firstAvailableDate: cache.firstAvailableDate
1972
+ };
1973
+ }
1974
+ }
1975
+ let { startDate, endDate } = params;
1976
+ 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"))) {
1977
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1978
+ }
1979
+ endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
1980
+ let tempProducts;
1981
+ tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1982
+ const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
1983
+ const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
1984
+ schedule,
1985
+ startDate || "",
1986
+ endDate || ""
1987
+ );
1988
+ const tempResourceIds = (0, import_resources.getResourcesIdsByProduct)(tempProducts);
1989
+ const res = await this.store.date.fetchResourceDates({
1990
+ query: {
1991
+ start_date: startDate || "",
1992
+ end_date: endDate || "",
1993
+ resource_ids: tempResourceIds
1994
+ }
1995
+ });
1996
+ let dates = [];
1997
+ let currentDate = (0, import_dayjs.default)(startDate);
1998
+ let firstAvailableDate = "";
1999
+ const openResources = ((_e = (_d = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.filter(
2000
+ (m) => m.status === 1
2001
+ )) || [];
2002
+ const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
2003
+ const targetSchedules = this.store.schedule.getScheduleListByIds(
2004
+ tempProducts["schedule.ids"]
2005
+ );
2006
+ while ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(endDate), "day") || (0, import_dayjs.default)(currentDate).isSame((0, import_dayjs.default)(endDate), "day")) {
2007
+ const currentDateStr = currentDate.format("YYYY-MM-DD");
2008
+ let status = "available";
2009
+ const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
2010
+ if (latestStartDate || earliestEndDate) {
2011
+ if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
2012
+ status = "unavailable";
2013
+ }
2014
+ if (earliestEndDate && (0, import_dayjs.default)(currentDate).isAfter(earliestEndDate, "day")) {
2015
+ status = "unavailable";
2016
+ }
2017
+ }
2018
+ if (status === "available") {
2019
+ const scheduleByDate = filteredSchedule.find(
2020
+ (n) => n.date === currentDateStr
2021
+ );
2022
+ if (!scheduleByDate || (scheduleByDate == null ? void 0 : scheduleByDate.isExcluded)) {
2023
+ status = "unavailable";
2024
+ }
2025
+ }
2026
+ if (status === "available") {
2027
+ const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
2028
+ targetSchedules,
2029
+ {},
2030
+ currentDateStr
2031
+ );
2032
+ const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
2033
+ const timesSlotCanUse = scheduleTimeSlots.some((item) => {
2034
+ const resourcesUseableMap = {};
2035
+ return openResources.every((resource) => {
2036
+ const currentResourcesList = allProductResources.filter(
2037
+ (n) => n.form_id === resource.resource_type_id
2038
+ );
2039
+ return currentResourcesList == null ? void 0 : currentResourcesList.some((m) => {
2040
+ const mTimes = m.times.filter((n) => {
2041
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
2042
+ });
2043
+ if (mTimes.length === 0) {
2044
+ return;
2045
+ }
2046
+ const targetCanUseTimes = mTimes.some((childTiem) => {
2047
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
2048
+ timeSlice: {
2049
+ start_time: item.start,
2050
+ end_time: item.end,
2051
+ start_at: (0, import_dayjs.default)(item.start),
2052
+ end_at: (0, import_dayjs.default)(item.end)
2053
+ },
2054
+ time: childTiem,
2055
+ resource: m,
2056
+ currentCount: 1,
2057
+ resourcesUseableMap,
2058
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2059
+ });
2060
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2061
+ resourcesUseableMap[m.id] = res2.usable;
2062
+ }
2063
+ return res2.usable && !m.onlyComputed;
2064
+ });
2065
+ return targetCanUseTimes;
2066
+ });
2067
+ });
2068
+ });
2069
+ if (!timesSlotCanUse) {
2070
+ status = "unavailable";
2071
+ }
2072
+ if (status === "available" && !firstAvailableDate) {
2073
+ firstAvailableDate = currentDateStr;
2074
+ }
2075
+ }
2076
+ dates.push({
2077
+ date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
2078
+ week: (0, import_dayjs.default)(currentDate).format("ddd"),
2079
+ weekNum: (0, import_dayjs.default)(currentDate).day(),
2080
+ status
2081
+ });
2082
+ if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
2083
+ break;
2084
+ }
2085
+ currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
2086
+ }
2087
+ dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
2088
+ this.store.date.setDateList(dates);
2089
+ (_f = this.store.currentProduct) == null ? void 0 : _f.setOtherParams("timeSlotBySchedule", {
2090
+ dateList: dates,
2091
+ firstAvailableDate,
2092
+ startDate,
2093
+ endDate
2094
+ });
2095
+ return {
2096
+ dateList: dates,
2097
+ firstAvailableDate
2098
+ };
1866
2099
  }
1867
2100
  };
1868
2101
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,5 +1,5 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import { CartItem } from '../../../modules';
2
+ import { CartItem, ProductData } from '../../../modules';
3
3
  /**
4
4
  * 1. 获取资源列表
5
5
  * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -133,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
133
133
  * @return {*}
134
134
  * @Author: zhiwei.Wang
135
135
  */
136
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, }: {
137
137
  resourceIds: number[];
138
138
  resourcesMap: any;
139
139
  duration: number;
@@ -201,4 +201,41 @@ export declare const getSumCapacity: ({ capacity }: {
201
201
  * @Author: jinglin.tan
202
202
  */
203
203
  export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
204
+ /**
205
+ * @title: 根据日期范围过滤日程
206
+ *
207
+ * @export
208
+ * @param {any[]} schedule
209
+ * @param {string} startDate
210
+ * @param {string} endDate
211
+ * @return {*}
212
+ */
213
+ export declare function filterScheduleByDateRange(schedule: any[], startDate: string, endDate: string): any[];
214
+ /**
215
+ * 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
216
+ *
217
+ * @export
218
+ * @param {ProductData} product
219
+ * @return {*}
220
+ */
221
+ export declare function checkSessionProductLeadTime(product: ProductData): {
222
+ latestStartDate: string;
223
+ earliestEndDate: string;
224
+ };
225
+ /**
226
+ * 基于商品的 resources 配置,返回可选择的资源的 id 列表
227
+ *
228
+ * @export
229
+ * @param {ProductData} product
230
+ * @return {*}
231
+ */
232
+ export declare function getResourcesIdsByProduct(product: ProductData): number[];
233
+ /**
234
+ * 资源排序,把单个资源靠前,组合资源排在后面
235
+ *
236
+ * @export
237
+ * @param {ResourceItem[]} resourcesList
238
+ * @return {*}
239
+ */
240
+ export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
204
241
  export {};