@pisell/pisellos 0.0.43 → 0.0.45

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.
Files changed (127) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +19 -0
  5. package/dist/modules/AccountList/index.js +224 -70
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +5 -5
  13. package/dist/modules/Cart/index.js +32 -19
  14. package/dist/modules/Cart/types.d.ts +18 -4
  15. package/dist/modules/Cart/utils.d.ts +29 -5
  16. package/dist/modules/Cart/utils.js +72 -26
  17. package/dist/modules/Date/index.d.ts +6 -6
  18. package/dist/modules/Date/index.js +41 -55
  19. package/dist/modules/Date/types.d.ts +22 -6
  20. package/dist/modules/Date/utils.d.ts +4 -3
  21. package/dist/modules/Date/utils.js +74 -23
  22. package/dist/modules/Discount/index.d.ts +4 -4
  23. package/dist/modules/Discount/index.js +11 -11
  24. package/dist/modules/Order/index.d.ts +11 -5
  25. package/dist/modules/Order/index.js +39 -18
  26. package/dist/modules/Order/types.d.ts +10 -3
  27. package/dist/modules/Product/index.d.ts +4 -1
  28. package/dist/modules/Product/index.js +22 -0
  29. package/dist/modules/Product/types.d.ts +7 -3
  30. package/dist/modules/ProductList/index.js +11 -5
  31. package/dist/modules/Resource/utils.js +1 -1
  32. package/dist/modules/Rules/index.d.ts +4 -4
  33. package/dist/modules/Rules/index.js +11 -11
  34. package/dist/modules/Rules/types.d.ts +1 -1
  35. package/dist/modules/Schedule/index.d.ts +8 -3
  36. package/dist/modules/Schedule/index.js +45 -5
  37. package/dist/modules/Schedule/type.d.ts +7 -7
  38. package/dist/modules/Schedule/types.d.ts +8 -8
  39. package/dist/modules/Schedule/utils.d.ts +9 -3
  40. package/dist/modules/Schedule/utils.js +77 -48
  41. package/dist/modules/Step/index.d.ts +14 -3
  42. package/dist/modules/Step/index.js +54 -2
  43. package/dist/modules/Summary/index.d.ts +5 -5
  44. package/dist/modules/Summary/index.js +7 -7
  45. package/dist/modules/Summary/types.d.ts +2 -2
  46. package/dist/modules/Summary/utils.d.ts +4 -4
  47. package/dist/modules/Summary/utils.js +3 -3
  48. package/dist/plugins/index.d.ts +3 -3
  49. package/dist/plugins/request.d.ts +3 -3
  50. package/dist/plugins/request.js +30 -30
  51. package/dist/plugins/shopStore.d.ts +1 -1
  52. package/dist/solution/BookingByStep/index.d.ts +65 -16
  53. package/dist/solution/BookingByStep/index.js +553 -216
  54. package/dist/solution/BookingByStep/types.d.ts +2 -2
  55. package/dist/solution/BookingByStep/types.js +9 -9
  56. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  57. package/dist/solution/BookingByStep/utils/products.js +3 -0
  58. package/dist/solution/BookingByStep/utils/resources.d.ts +5 -5
  59. package/dist/solution/BookingByStep/utils/resources.js +11 -11
  60. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  61. package/dist/solution/ShopDiscount/index.js +16 -16
  62. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  63. package/dist/solution/ShopDiscount/utils.js +1 -1
  64. package/lib/core/index.js +7 -2
  65. package/lib/modules/Account/index.d.ts +2 -6
  66. package/lib/modules/Account/index.js +15 -30
  67. package/lib/modules/Account/types.d.ts +12 -1
  68. package/lib/modules/AccountList/index.d.ts +19 -0
  69. package/lib/modules/AccountList/index.js +109 -12
  70. package/lib/modules/AccountList/types.d.ts +33 -1
  71. package/lib/modules/AccountList/utils.d.ts +9 -0
  72. package/lib/modules/AccountList/utils.js +39 -0
  73. package/lib/modules/BaseModule.d.ts +2 -2
  74. package/lib/modules/BaseModule.js +14 -3
  75. package/lib/modules/Cart/index.d.ts +5 -5
  76. package/lib/modules/Cart/index.js +27 -6
  77. package/lib/modules/Cart/types.d.ts +18 -4
  78. package/lib/modules/Cart/utils.d.ts +29 -5
  79. package/lib/modules/Cart/utils.js +47 -3
  80. package/lib/modules/Date/index.d.ts +6 -6
  81. package/lib/modules/Date/index.js +6 -6
  82. package/lib/modules/Date/types.d.ts +22 -6
  83. package/lib/modules/Date/utils.d.ts +4 -3
  84. package/lib/modules/Date/utils.js +37 -6
  85. package/lib/modules/Discount/index.d.ts +4 -4
  86. package/lib/modules/Discount/index.js +9 -2
  87. package/lib/modules/Guests/index.js +4 -1
  88. package/lib/modules/Order/index.d.ts +11 -5
  89. package/lib/modules/Order/index.js +18 -3
  90. package/lib/modules/Order/types.d.ts +10 -3
  91. package/lib/modules/Payment/index.js +1 -6
  92. package/lib/modules/Product/index.d.ts +4 -1
  93. package/lib/modules/Product/index.js +16 -0
  94. package/lib/modules/Product/types.d.ts +7 -3
  95. package/lib/modules/ProductList/index.js +21 -7
  96. package/lib/modules/Resource/index.js +4 -1
  97. package/lib/modules/Resource/utils.js +7 -4
  98. package/lib/modules/Rules/index.d.ts +4 -4
  99. package/lib/modules/Rules/types.d.ts +1 -1
  100. package/lib/modules/Schedule/index.d.ts +8 -3
  101. package/lib/modules/Schedule/index.js +33 -2
  102. package/lib/modules/Schedule/type.d.ts +7 -7
  103. package/lib/modules/Schedule/types.d.ts +8 -8
  104. package/lib/modules/Schedule/utils.d.ts +9 -3
  105. package/lib/modules/Schedule/utils.js +32 -4
  106. package/lib/modules/Step/index.d.ts +14 -3
  107. package/lib/modules/Step/index.js +38 -1
  108. package/lib/modules/Summary/index.d.ts +5 -5
  109. package/lib/modules/Summary/types.d.ts +2 -2
  110. package/lib/modules/Summary/utils.d.ts +4 -4
  111. package/lib/plugins/index.d.ts +3 -3
  112. package/lib/plugins/request.d.ts +3 -3
  113. package/lib/plugins/request.js +48 -11
  114. package/lib/plugins/shopStore.d.ts +1 -1
  115. package/lib/solution/BookingByStep/index.d.ts +65 -16
  116. package/lib/solution/BookingByStep/index.js +351 -39
  117. package/lib/solution/BookingByStep/types.d.ts +2 -2
  118. package/lib/solution/BookingByStep/types.js +36 -9
  119. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  120. package/lib/solution/BookingByStep/utils/products.js +3 -0
  121. package/lib/solution/BookingByStep/utils/resources.d.ts +5 -5
  122. package/lib/solution/BookingByStep/utils/resources.js +103 -52
  123. package/lib/solution/BuyTickets/index.js +34 -20
  124. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  125. package/lib/solution/ShopDiscount/index.js +10 -2
  126. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  127. package/package.json +4 -2
@@ -39,6 +39,8 @@ var import_resources = require("./utils/resources");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
40
  var import_utils = require("../../modules/Resource/utils");
41
41
  var import_lodash_es = require("lodash-es");
42
+ var import_utils2 = require("../../modules/Schedule/utils");
43
+ var import_utils3 = require("../../modules/Date/utils");
42
44
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
43
45
  constructor() {
44
46
  super(...arguments);
@@ -46,9 +48,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
46
48
  this.defaultVersion = "1.0.0";
47
49
  this.isSolution = true;
48
50
  this.otherParams = {};
51
+ this.otherData = {};
49
52
  }
53
+ // 提供给 UI 层的临时数据存储,会进缓存
50
54
  async initialize(core, options) {
51
- var _a, _b;
55
+ var _a, _b, _c, _d;
52
56
  this.core = core;
53
57
  this.store = options.store || {};
54
58
  this.otherParams = options.otherParams || {};
@@ -66,9 +70,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
66
70
  if (sessionData) {
67
71
  const data = JSON.parse(sessionData);
68
72
  targetCacheData = data[this.otherParams.cacheId];
73
+ this.otherData = ((_d = (_c = data[this.otherParams.cacheId]) == null ? void 0 : _c[this.name]) == null ? void 0 : _d["otherData"]) || {};
69
74
  }
70
75
  }
71
- const moduleArr = ["accountList", "cart", "schedule", "summary", "step", "products", "date", "order", "payment"];
76
+ const moduleArr = [
77
+ "accountList",
78
+ "cart",
79
+ "schedule",
80
+ "summary",
81
+ "step",
82
+ "products",
83
+ "date",
84
+ "order",
85
+ "payment"
86
+ ];
72
87
  moduleArr.forEach((step) => {
73
88
  var _a2, _b2;
74
89
  const targetModule = (0, import_types.createModule)(step, this.name);
@@ -116,6 +131,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
116
131
  getStepList() {
117
132
  return this.store.step.getStepList();
118
133
  }
134
+ /**
135
+ * 添加step
136
+ */
137
+ addStep(step, key) {
138
+ this.store.step.addStep(step, key);
139
+ }
140
+ /**
141
+ * 删除step
142
+ */
143
+ removeStep(key) {
144
+ this.store.step.removeStep(key);
145
+ }
119
146
  // 获取购物车里 temp.xxx的方法
120
147
  // async getStoreCart(key?: string) {
121
148
  // return this.store.cart.getTemp(key);
@@ -132,8 +159,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
132
159
  {
133
160
  open_quotation: 1,
134
161
  open_bundle: 1,
135
- extension_type: ["product_appointment", "appointment_ticket", "session_product"],
136
- with: ["category", "collection"],
162
+ extension_type: [
163
+ "product_appointment",
164
+ "appointment_ticket",
165
+ "session_product",
166
+ "session_ticket"
167
+ ],
168
+ with: ["category", "collection", "resourceRelation"],
137
169
  status: "published",
138
170
  num: 500,
139
171
  skip: 1,
@@ -148,24 +180,55 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
148
180
  this.store.products.addProduct(productsData.data.list);
149
181
  return productsData.data.list;
150
182
  }
151
- loadProductByScheduleDate(date) {
152
- const scheduleList = this.store.schedule.getAvailabilityDateList();
183
+ async loadProductByScheduleDate(date) {
184
+ const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
153
185
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
154
- this.loadProducts({ schedule_ids: scheduleIds });
186
+ this.store.cart.clear();
187
+ return await this.loadProducts({ schedule_ids: scheduleIds });
155
188
  }
156
189
  // 加载当前店铺下所有 schedule
157
190
  async loadAllSchedule() {
191
+ var _a;
158
192
  const scheduleList = await this.request.get(`/schedule`);
159
- this.store.schedule.setScheduleList(scheduleList.data);
193
+ this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
160
194
  }
161
195
  // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
162
- async loadAvailableDate({ startDate, endDate, custom_page_id }) {
163
- const res = await this.request.get(`/schedule/product/availability`, {
164
- start_date: startDate,
165
- end_date: endDate,
166
- custom_page_id
196
+ async loadScheduleAvailableDate({
197
+ startDate,
198
+ endDate,
199
+ custom_page_id
200
+ }) {
201
+ var _a;
202
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)())) {
203
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
204
+ }
205
+ let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
206
+ dates = (0, import_utils3.disableAllDates)(dates);
207
+ if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)())) {
208
+ return dates;
209
+ }
210
+ const res = await this.request.get(
211
+ `/schedule/product/availability`,
212
+ {
213
+ start_date: startDate,
214
+ end_date: endDate,
215
+ custom_page_id
216
+ }
217
+ );
218
+ this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
219
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)())) {
220
+ return dates;
221
+ }
222
+ res.data.date_list.forEach((n) => {
223
+ if (n.schedule_id && n.schedule_id.length) {
224
+ const index = dates.findIndex((m) => m.date === n.date);
225
+ if (index !== -1) {
226
+ dates[index].status = "available";
227
+ }
228
+ }
167
229
  });
168
- this.store.schedule.setAvailabilityDateList(res.data.date_list);
230
+ dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
231
+ return dates;
169
232
  }
170
233
  async storeProduct(productData) {
171
234
  const activeAccount = this.getActiveAccount();
@@ -182,7 +245,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
182
245
  });
183
246
  }
184
247
  // 添加账户或者 guest
185
- async addAccount(accounts) {
248
+ async addAccount(accounts, extra) {
249
+ if ((extra == null ? void 0 : extra.type) === "holder") {
250
+ this.store.accountList.addHolderAccounts(
251
+ accounts,
252
+ extra.customerId
253
+ );
254
+ return;
255
+ }
186
256
  accounts.forEach((account) => {
187
257
  this.store.accountList.addAccount(account);
188
258
  });
@@ -207,6 +277,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
207
277
  this.store.accountList.removeAccount(id);
208
278
  this.clearCartByAccount(id);
209
279
  }
280
+ /**
281
+ * 获取holder类型账户列表
282
+ * @param params
283
+ */
284
+ async fetchHolderAccountsAsync(params) {
285
+ return this.store.accountList.fetchHolderAccounts(params);
286
+ }
210
287
  // 设置日期范围,注入到日期模块中
211
288
  async setDateRange(dateRange) {
212
289
  this.store.date.setDateRange(dateRange);
@@ -224,23 +301,42 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
224
301
  // 获取商品/服务的可用日期
225
302
  async getAvailableDate(params = {}) {
226
303
  var _a, _b, _c, _d;
227
- const { products, startDate, endDate } = params;
228
- const tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
304
+ let { products, startDate, endDate, type } = params;
305
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)()) && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)()) || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)()))) {
306
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
307
+ }
308
+ let tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
309
+ if (tempProducts.length) {
310
+ tempProducts.forEach((p) => {
311
+ if (p == null ? void 0 : p["schedule.ids"]) {
312
+ const scheduleData = this.getScheduleDataByIds(p["schedule.ids"]);
313
+ p["_schedule"] = scheduleData;
314
+ }
315
+ });
316
+ }
317
+ if (this.store.currentProduct) {
318
+ tempProducts = [
319
+ {
320
+ ...this.store.currentProduct.getData(),
321
+ _schedule: this.store.currentProduct.getOtherParams()["schedule"]
322
+ }
323
+ ];
324
+ }
229
325
  const tempStartDate = startDate || ((_b = (_a = this.otherParams) == null ? void 0 : _a.dateRange) == null ? void 0 : _b[0]);
230
326
  const tempEndDate = endDate || ((_d = (_c = this.otherParams) == null ? void 0 : _c.dateRange) == null ? void 0 : _d[1]);
231
327
  if (!tempProducts.length) {
232
328
  return [];
233
329
  }
234
330
  const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
235
- console.log("resourceIds", tempProducts);
236
331
  this.otherParams.currentResourcesMap = resourcesMap;
237
- const res = await this.store.date.getMonthDates({
332
+ const res = await this.store.date.getResourceDates({
238
333
  query: {
239
334
  start_date: tempStartDate,
240
335
  end_date: tempEndDate,
241
336
  resource_ids: resourceIds
242
337
  },
243
- rules
338
+ rules,
339
+ type
244
340
  });
245
341
  return res;
246
342
  }
@@ -290,6 +386,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
290
386
  const res = await this.request.post(`/pay/order/free-pay/${id}`);
291
387
  return res;
292
388
  }
389
+ /**
390
+ * 检查购物车提交订单前是否符合条件
391
+ * @param type 类型 "holder" | "account"
392
+ * @returns boolean
393
+ */
394
+ checkBeforeSubmitOrder(type) {
395
+ return this.store.order.checkBeforeSubmitOrder({
396
+ type,
397
+ cartItems: this.store.cart.getItems()
398
+ });
399
+ }
293
400
  // 购物车提交订单
294
401
  async submitOrder() {
295
402
  const cartItems = this.store.cart.getItems();
@@ -303,7 +410,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
303
410
  return { ...newResourcesItem };
304
411
  });
305
412
  });
306
- return this.store.order.commitOrder({ query: { cartItems: newCartItems } });
413
+ return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
307
414
  }
308
415
  // 拉起支付模块
309
416
  async pay() {
@@ -323,11 +430,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
323
430
  }
324
431
  // 更新购物车
325
432
  updateCart(params) {
326
- this.store.cart.updateItem(params);
327
433
  const targetCartItem = this.store.cart.getItem(params._id);
328
434
  if (!targetCartItem) {
329
435
  throw new Error(`没有找到${params._id}购物车商品`);
330
436
  }
437
+ if (params.resources) {
438
+ params.resources = params.resources.map((n) => {
439
+ n.capacity = targetCartItem.num || 1;
440
+ (0, import_resources.checkSubResourcesCapacity)(n);
441
+ return n;
442
+ });
443
+ }
444
+ this.store.cart.updateItem(params);
331
445
  const cartItems = this.store.cart.getItems();
332
446
  cartItems.forEach((item) => {
333
447
  var _a;
@@ -395,21 +509,71 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
395
509
  getResourcesList() {
396
510
  const dateRange = this.store.date.getDateRange();
397
511
  const resources = [];
398
- dateRange.forEach((n) => {
399
- if (n.resource)
400
- resources.push(...n.resource);
401
- });
512
+ if (dateRange == null ? void 0 : dateRange.length) {
513
+ dateRange.forEach((n) => {
514
+ if (n.resource)
515
+ resources.push(...n.resource);
516
+ });
517
+ } else {
518
+ const dateList = this.store.date.getDateList();
519
+ dateList.forEach((n) => {
520
+ if (n.resource)
521
+ resources.push(...n.resource);
522
+ });
523
+ }
402
524
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
403
525
  const cartItems = this.store.cart.getItems();
404
526
  const arr = [];
527
+ const capacityMap = {};
405
528
  cartItems.forEach((cartItem) => {
406
529
  var _a, _b, _c;
407
- if (!cartItem.holder_id)
408
- return;
409
- const selectedResources = (0, import_resources.getOthersSelectedResources)(cartItems, cartItem.holder_id, resourcesMap);
410
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity, product_bundle: cartItem._origin.product.product_bundle });
530
+ let selectedResources = [];
531
+ if (cartItem.holder_id) {
532
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
533
+ cartItems,
534
+ cartItem.holder_id,
535
+ resourcesMap
536
+ );
537
+ }
538
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
539
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
540
+ product_bundle: cartItem._origin.product.product_bundle
541
+ });
411
542
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
412
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [], selectedResources, currentCapacity);
543
+ const productResources = (0, import_resources.getResourcesByProduct)(
544
+ resourcesMap,
545
+ ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
546
+ selectedResources,
547
+ currentCapacity
548
+ );
549
+ if (cartItem._origin.start_time) {
550
+ const startTime = (0, import_dayjs.default)(
551
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
552
+ );
553
+ const endTime = (0, import_dayjs.default)(
554
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
555
+ );
556
+ productResources.forEach((n) => {
557
+ n.renderList = n.renderList.filter((m) => {
558
+ const recordCount = capacityMap[m.id] || 0;
559
+ const canUseTime = m.times.find((item) => {
560
+ const res = (0, import_resources.getIsUsableByTimeItem)({
561
+ timeSlice: {
562
+ start_time: startTime.format("HH:mm"),
563
+ end_time: endTime.format("HH:mm"),
564
+ start_at: startTime,
565
+ end_at: endTime
566
+ },
567
+ time: item,
568
+ resource: m,
569
+ currentCount: recordCount + (currentCapacity || 0)
570
+ });
571
+ return res.usable;
572
+ });
573
+ return canUseTime;
574
+ });
575
+ });
576
+ }
413
577
  arr.push({
414
578
  id: cartItem.id,
415
579
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -440,10 +604,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
440
604
  }
441
605
  if (!targetCartItem.holder_id)
442
606
  return;
443
- const selectedResources = (0, import_resources.getOthersSelectedResources)(cartItems, targetCartItem.holder_id, resourcesMap);
444
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity, product_bundle: targetCartItem._origin.product.product_bundle });
607
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
608
+ cartItems,
609
+ targetCartItem.holder_id,
610
+ resourcesMap
611
+ );
612
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
613
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
614
+ product_bundle: targetCartItem._origin.product.product_bundle
615
+ });
445
616
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
446
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [], selectedResources, currentCapacity);
617
+ const productResources = (0, import_resources.getResourcesByProduct)(
618
+ resourcesMap,
619
+ ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
620
+ selectedResources,
621
+ currentCapacity
622
+ );
447
623
  if (productResources) {
448
624
  return {
449
625
  id: targetCartItem.id,
@@ -605,7 +781,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
605
781
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
606
782
  cartItems.forEach((item, index) => {
607
783
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
608
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity, product_bundle: item._origin.product.product_bundle });
784
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
785
+ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
786
+ product_bundle: item._origin.product.product_bundle
787
+ });
609
788
  const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
610
789
  if (timeSlots) {
611
790
  if (index !== 0 && recordTimeSlots) {
@@ -656,11 +835,24 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
656
835
  const allCartItems = this.store.cart.getItems();
657
836
  if (!item.holder_id)
658
837
  return;
659
- const selectedResources = (0, import_resources.getOthersSelectedResources)(allCartItems, item.holder_id, resourcesMap);
660
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [], selectedResources, currentCapacity);
661
- const targetRenderList = (_l = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _l.renderList;
838
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
839
+ allCartItems,
840
+ item.holder_id,
841
+ resourcesMap
842
+ );
843
+ const productResources = (0, import_resources.getResourcesByProduct)(
844
+ resourcesMap,
845
+ ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
846
+ selectedResources,
847
+ currentCapacity
848
+ );
849
+ const targetRenderList = (_l = productResources.find(
850
+ (n) => n.code === resources_code
851
+ )) == null ? void 0 : _l.renderList;
662
852
  if (targetRenderList && targetRenderList.length > 0) {
663
- if ((_m = item._origin.resources) == null ? void 0 : _m.some((n) => n.form_id === targetRenderList[0].form_id)) {
853
+ if ((_m = item._origin.resources) == null ? void 0 : _m.some(
854
+ (n) => n.form_id === targetRenderList[0].form_id
855
+ )) {
664
856
  return;
665
857
  }
666
858
  const targetResource = targetRenderList[0];
@@ -761,11 +953,131 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
761
953
  }
762
954
  clearCacheByModule(module2) {
763
955
  }
956
+ getScheduleDataByIds(scheduleIds) {
957
+ const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
958
+ const targetSchedulesData = targetSchedules.map((item) => {
959
+ return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
960
+ });
961
+ const newSchedule = {};
962
+ targetSchedulesData.forEach((item) => {
963
+ item.forEach((n) => {
964
+ if (!newSchedule[n.date]) {
965
+ newSchedule[n.date] = n;
966
+ } else {
967
+ if (!n.isExcluded) {
968
+ newSchedule[n.date].isExcluded = false;
969
+ }
970
+ }
971
+ });
972
+ });
973
+ const newScheduleArr = Object.values(newSchedule);
974
+ return newScheduleArr;
975
+ }
976
+ // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
764
977
  async openProductDetail(productId) {
765
978
  const targetProduct = await this.store.products.getProduct(productId);
766
979
  if (targetProduct) {
980
+ const targetProductData = targetProduct.getData();
767
981
  this.store.currentProduct = targetProduct;
982
+ const newScheduleArr = this.getScheduleDataByIds(
983
+ targetProductData["schedule.ids"]
984
+ );
985
+ targetProduct.setOtherParams("schedule", newScheduleArr);
986
+ }
987
+ }
988
+ closeProductDetail() {
989
+ var _a;
990
+ (_a = this.store.currentProduct) == null ? void 0 : _a.setOtherParams("schedule", []);
991
+ this.store.currentProduct = void 0;
992
+ }
993
+ getTimeslotBySchedule({
994
+ date,
995
+ scheduleIds
996
+ }) {
997
+ const targetProduct = this.store.currentProduct;
998
+ const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
999
+ let targetSchedules = [];
1000
+ if (scheduleIds == null ? void 0 : scheduleIds.length) {
1001
+ targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1002
+ } else {
1003
+ targetSchedules = this.store.schedule.getScheduleListByIds(
1004
+ targetProductData["schedule.ids"]
1005
+ );
1006
+ }
1007
+ const resourcesDates = this.store.date.getDateList();
1008
+ const targetResourceDate = resourcesDates.find((n) => n.date === date);
1009
+ const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
1010
+ targetSchedules,
1011
+ {},
1012
+ date
1013
+ );
1014
+ const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1015
+ console.log("scheduleTimeSlots:", scheduleTimeSlots, targetResourceDate);
1016
+ const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1017
+ var _a;
1018
+ console.log(item);
1019
+ let count = 0;
1020
+ (_a = targetResourceDate == null ? void 0 : targetResourceDate.resource) == null ? void 0 : _a.forEach((n) => {
1021
+ const res = (0, import_resources.getIsUsableByTimeItem)({
1022
+ timeSlice: {
1023
+ start_time: item.start,
1024
+ end_time: item.end,
1025
+ start_at: (0, import_dayjs.default)(item.start),
1026
+ end_at: (0, import_dayjs.default)(item.end)
1027
+ },
1028
+ time: item,
1029
+ resource: n,
1030
+ currentCount: 1
1031
+ });
1032
+ if (res.usable) {
1033
+ count += 1;
1034
+ }
1035
+ });
1036
+ const startDayJs = (0, import_dayjs.default)(item.start);
1037
+ const endDayJs = (0, import_dayjs.default)(item.end);
1038
+ return {
1039
+ start_time: startDayJs.format("HH:mm"),
1040
+ end_time: endDayJs.format("HH:mm"),
1041
+ start_at: startDayJs,
1042
+ end_at: endDayJs,
1043
+ count
1044
+ };
1045
+ });
1046
+ return formatScheduleTimeSlots;
1047
+ }
1048
+ addProductToCart({
1049
+ product,
1050
+ date,
1051
+ account
1052
+ }) {
1053
+ const { bundle, options, origin, product_variant_id } = product || {};
1054
+ const productData = { ...origin, product_variant_id };
1055
+ this.store.cart.addItem({
1056
+ product: productData,
1057
+ date,
1058
+ account,
1059
+ bundle,
1060
+ options
1061
+ });
1062
+ }
1063
+ setOtherData(key, value) {
1064
+ this.otherData[key] = value;
1065
+ this.checkSaveCache({
1066
+ cacheId: this.cacheId,
1067
+ fatherModule: this.name,
1068
+ store: { otherData: this.otherData },
1069
+ cacheKey: ["otherData"]
1070
+ });
1071
+ }
1072
+ getOtherData(key) {
1073
+ return this.otherData[key];
1074
+ }
1075
+ async getProductTypeById(id) {
1076
+ const product = await this.store.products.getProduct(id);
1077
+ if (product) {
1078
+ return product.getProductType();
768
1079
  }
1080
+ return "normal";
769
1081
  }
770
1082
  };
771
1083
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,4 +1,4 @@
1
- import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from "../../modules";
1
+ import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
2
2
  export interface BookingByStepState {
3
3
  cart: CartModule;
4
4
  summary: SummaryModule;
@@ -11,7 +11,7 @@ export interface BookingByStepState {
11
11
  accountList: AccountListModule;
12
12
  order: OrderModule;
13
13
  payment: PaymentModule;
14
- currentProduct: Product;
14
+ currentProduct?: Product;
15
15
  schedule: ScheduleModule;
16
16
  }
17
17
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
@@ -27,23 +27,50 @@ var import_modules = require("../../modules");
27
27
  function createModule(moduleName, solutionName, name, version) {
28
28
  switch (moduleName) {
29
29
  case "cart":
30
- return new import_modules.CartModule(`${solutionName}_${name || moduleName}`, version);
30
+ return new import_modules.CartModule(
31
+ `${solutionName}_${name || moduleName}`,
32
+ version
33
+ );
31
34
  case "summary":
32
- return new import_modules.SummaryModule(`${solutionName}_${name || moduleName}`, version);
35
+ return new import_modules.SummaryModule(
36
+ `${solutionName}_${name || moduleName}`,
37
+ version
38
+ );
33
39
  case "step":
34
- return new import_modules.StepModule(`${solutionName}_${name || moduleName}`, version);
40
+ return new import_modules.StepModule(
41
+ `${solutionName}_${name || moduleName}`,
42
+ version
43
+ );
35
44
  case "products":
36
- return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
45
+ return new import_modules.ProductList(
46
+ `${solutionName}_${name || moduleName}`,
47
+ version
48
+ );
37
49
  case "date":
38
- return new import_modules.DateModule(`${solutionName}_${name || moduleName}`, version);
50
+ return new import_modules.DateModule(
51
+ `${solutionName}_${name || moduleName}`,
52
+ version
53
+ );
39
54
  case "accountList":
40
- return new import_modules.AccountListModule(`${solutionName}_${name || moduleName}`, version);
55
+ return new import_modules.AccountListModule(
56
+ `${solutionName}_${name || moduleName}`,
57
+ version
58
+ );
41
59
  case "order":
42
- return new import_modules.OrderModule(`${solutionName}_${name || moduleName}`, version);
60
+ return new import_modules.OrderModule(
61
+ `${solutionName}_${name || moduleName}`,
62
+ version
63
+ );
43
64
  case "payment":
44
- return new import_modules.PaymentModule(`${solutionName}_${name || moduleName}`, version);
65
+ return new import_modules.PaymentModule(
66
+ `${solutionName}_${name || moduleName}`,
67
+ version
68
+ );
45
69
  case "schedule":
46
- return new import_modules.ScheduleModule(`${solutionName}_${name || moduleName}`, version);
70
+ return new import_modules.ScheduleModule(
71
+ `${solutionName}_${name || moduleName}`,
72
+ version
73
+ );
47
74
  default:
48
75
  throw new Error(`Unknown module type: ${moduleName}`);
49
76
  }
@@ -1,4 +1,4 @@
1
- import { ProductData, ProductResourceItem } from "../../../modules";
1
+ import { ProductData, ProductResourceItem } from '../../../modules';
2
2
  /**
3
3
  * 获取商品的可用资源
4
4
  * @param product 商品数据
@@ -50,6 +50,9 @@ var getAvailableProductResources = (products) => {
50
50
  if (tempResourceIds) {
51
51
  rule.resourceFormIds = [...new Set(tempResourceIds)];
52
52
  }
53
+ if (product == null ? void 0 : product._schedule) {
54
+ rule.schedule = product == null ? void 0 : product._schedule;
55
+ }
53
56
  rules.push(rule);
54
57
  });
55
58
  return { resourceIds: [...new Set(resourceIds)], rules, resourcesMap };
@@ -27,7 +27,7 @@ interface BookingItem {
27
27
  * @return {*}
28
28
  * @Author: zhiwei.Wang
29
29
  */
30
- export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount }: {
30
+ export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount, }: {
31
31
  timeSlice: TimeSliceItem;
32
32
  time: any;
33
33
  resource: ResourceItem;
@@ -53,7 +53,7 @@ export declare const getResourcesByProduct: (resourcesMap: Record<string, Resour
53
53
  * @Author: zhiwei.Wang
54
54
  * @Date: 2024-01-09 13:38
55
55
  */
56
- export declare const formatResources: ({ booking, resources }: {
56
+ export declare const formatResources: ({ booking, resources, }: {
57
57
  booking: BookingItem;
58
58
  resources: ResourceItem[];
59
59
  }) => {
@@ -66,7 +66,7 @@ export declare const formatResources: ({ booking, resources }: {
66
66
  * @return {*}
67
67
  * @Author: zhiwei.Wang
68
68
  */
69
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity }: {
69
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, }: {
70
70
  resource: ResourceItem;
71
71
  duration: number;
72
72
  split: number;
@@ -100,7 +100,7 @@ export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceIt
100
100
  * @return {*}
101
101
  * @Author: zhiwei.Wang
102
102
  */
103
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity }: {
103
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, }: {
104
104
  resourceIds: number[];
105
105
  resourcesMap: any;
106
106
  duration: number;
@@ -129,7 +129,7 @@ interface CapacityItem {
129
129
  * @return {*}
130
130
  * @Author: zhiwei.Wang
131
131
  */
132
- export declare const formatDefaultCapacitys: ({ capacity, product_bundle }: any) => CapacityItem[];
132
+ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
133
133
  /**
134
134
  * @title: 获取总容量
135
135
  * @description: