@pisell/pisellos 2.0.3 → 2.0.5

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 (146) 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 +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  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 +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +111 -12
  17. package/dist/modules/Cart/utils.js +286 -73
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +2 -2
  37. package/dist/modules/Rules/index.js +97 -29
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +90 -24
  61. package/dist/solution/BookingByStep/index.js +989 -317
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +111 -12
  88. package/lib/modules/Cart/utils.js +186 -43
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +2 -2
  111. package/lib/modules/Rules/index.js +100 -25
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +90 -24
  135. package/lib/solution/BookingByStep/index.js +667 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. 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", "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);
@@ -115,6 +130,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
115
130
  getStepList() {
116
131
  return this.store.step.getStepList();
117
132
  }
133
+ /**
134
+ * 添加step
135
+ */
136
+ addStep(step, key) {
137
+ this.store.step.addStep(step, key);
138
+ }
139
+ /**
140
+ * 删除step
141
+ */
142
+ removeStep(key) {
143
+ this.store.step.removeStep(key);
144
+ }
118
145
  // 获取购物车里 temp.xxx的方法
119
146
  // async getStoreCart(key?: string) {
120
147
  // return this.store.cart.getTemp(key);
@@ -123,47 +150,145 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
123
150
  async loadProducts({
124
151
  category_ids = [],
125
152
  product_ids = [],
126
- collection = []
153
+ collection = [],
154
+ schedule_ids = []
127
155
  }) {
156
+ if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
157
+ const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
158
+ if (schedule_ids_data.length) {
159
+ schedule_ids = schedule_ids_data;
160
+ }
161
+ }
128
162
  const productsData = await this.request.post(
129
163
  `/product/query`,
130
164
  {
131
165
  open_quotation: 1,
132
166
  open_bundle: 1,
133
- extension_type: ["product_appointment", "appointment_ticket"],
134
- with: ["category", "collection"],
167
+ extension_type: [
168
+ "product_appointment",
169
+ "appointment_ticket",
170
+ "session_product",
171
+ "session_ticket"
172
+ ],
173
+ with: ["category", "collection", "resourceRelation"],
135
174
  status: "published",
136
175
  num: 500,
137
176
  skip: 1,
138
177
  category_ids,
139
178
  ids: product_ids,
140
179
  collection,
141
- front_end_cache_id: this.cacheId
180
+ front_end_cache_id: this.cacheId,
181
+ client_schedule_ids: schedule_ids
142
182
  },
143
183
  { useCache: true }
144
184
  );
145
185
  this.store.products.addProduct(productsData.data.list);
146
186
  return productsData.data.list;
147
187
  }
188
+ async loadProductByScheduleDate({
189
+ date,
190
+ product_ids
191
+ }) {
192
+ const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
193
+ this.setDateRange([
194
+ { date, status: "available", week: "", weekNum: 0 },
195
+ { date, status: "available", week: "", weekNum: 0 }
196
+ ]);
197
+ const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
198
+ return await this.loadProducts({ schedule_ids: scheduleIds, product_ids });
199
+ }
200
+ // 加载当前店铺下所有 schedule
201
+ async loadAllSchedule() {
202
+ var _a;
203
+ const scheduleList = await this.request.get(`/schedule`);
204
+ this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
205
+ }
206
+ // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
207
+ async loadScheduleAvailableDate({
208
+ startDate,
209
+ endDate,
210
+ custom_page_id
211
+ }) {
212
+ var _a;
213
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
214
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
215
+ }
216
+ let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
217
+ dates = (0, import_utils3.disableAllDates)(dates);
218
+ if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
219
+ return dates;
220
+ }
221
+ const res = await this.request.get(
222
+ `/schedule/product/availability`,
223
+ {
224
+ start_date: startDate,
225
+ end_date: endDate,
226
+ custom_page_id
227
+ }
228
+ );
229
+ this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
230
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
231
+ return dates;
232
+ }
233
+ res.data.date_list.forEach((n) => {
234
+ if (n.schedule_id && n.schedule_id.length) {
235
+ const index = dates.findIndex((m) => m.date === n.date);
236
+ if (index !== -1) {
237
+ dates[index].status = "available";
238
+ }
239
+ }
240
+ });
241
+ dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
242
+ return dates;
243
+ }
148
244
  async storeProduct(productData) {
149
245
  const activeAccount = this.getActiveAccount();
150
- if (!activeAccount) {
151
- throw new Error("没有找到当前账户");
152
- }
153
246
  const { bundle, options, origin, product_variant_id } = productData || {};
154
247
  const product = { ...origin, product_variant_id };
155
- this.store.cart.addItem({
156
- account: activeAccount,
248
+ const addCartItem = {
157
249
  product,
158
250
  bundle,
159
251
  options
160
- });
252
+ };
253
+ if (activeAccount) {
254
+ addCartItem.account = activeAccount;
255
+ }
256
+ this.store.cart.addItem(addCartItem);
257
+ }
258
+ // 添加单个账户或者 guest
259
+ async addAccount(account, extra) {
260
+ if ((extra == null ? void 0 : extra.type) === "holder") {
261
+ const accountModules = await this.store.accountList.addHolderAccounts(
262
+ [account],
263
+ extra.customerId
264
+ );
265
+ return accountModules[0].getAccount();
266
+ }
267
+ const newAccount = await this.store.accountList.addAccount(
268
+ account
269
+ );
270
+ return newAccount.getAccount();
161
271
  }
162
272
  // 添加账户或者 guest
163
- async addAccount(accounts) {
164
- accounts.forEach((account) => {
165
- this.store.accountList.addAccount(account);
166
- });
273
+ async addAccounts(accounts, extra) {
274
+ if ((extra == null ? void 0 : extra.type) === "holder") {
275
+ this.store.accountList.addHolderAccounts(
276
+ accounts,
277
+ extra.customerId
278
+ );
279
+ return;
280
+ }
281
+ const res = [];
282
+ for (const account of accounts) {
283
+ const accountModule = await this.store.accountList.addAccount(
284
+ account
285
+ );
286
+ const accountData = accountModule.getAccount();
287
+ if (accountData) {
288
+ res.push(accountData);
289
+ }
290
+ }
291
+ return res;
167
292
  }
168
293
  // 获取所有账户
169
294
  async getAccounts() {
@@ -185,6 +310,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
185
310
  this.store.accountList.removeAccount(id);
186
311
  this.clearCartByAccount(id);
187
312
  }
313
+ /**
314
+ * 获取holder类型账户列表
315
+ * @param params
316
+ */
317
+ async fetchHolderAccountsAsync(params) {
318
+ return this.store.accountList.fetchHolderAccounts(params);
319
+ }
188
320
  // 设置日期范围,注入到日期模块中
189
321
  async setDateRange(dateRange) {
190
322
  this.store.date.setDateRange(dateRange);
@@ -201,24 +333,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
201
333
  }
202
334
  // 获取商品/服务的可用日期
203
335
  async getAvailableDate(params = {}) {
204
- var _a, _b, _c, _d;
205
- const { products, startDate, endDate } = params;
206
- const tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
207
- const tempStartDate = startDate || ((_b = (_a = this.otherParams) == null ? void 0 : _a.dateRange) == null ? void 0 : _b[0]);
208
- const tempEndDate = endDate || ((_d = (_c = this.otherParams) == null ? void 0 : _c.dateRange) == null ? void 0 : _d[1]);
336
+ let { products, startDate, endDate, type } = params;
337
+ 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"))) {
338
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
339
+ }
340
+ let tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
341
+ if (tempProducts.length) {
342
+ tempProducts.forEach((p) => {
343
+ if (p == null ? void 0 : p["schedule.ids"]) {
344
+ const scheduleData = this.getScheduleDataByIds(p["schedule.ids"]);
345
+ p["_schedule"] = scheduleData;
346
+ }
347
+ });
348
+ }
349
+ if (this.store.currentProduct) {
350
+ tempProducts = [
351
+ {
352
+ ...this.store.currentProduct.getData(),
353
+ _schedule: this.store.currentProduct.getOtherParams()["schedule"]
354
+ }
355
+ ];
356
+ }
357
+ let dateRange = this.store.date.getDateRange();
358
+ const tempStartDate = startDate || (dateRange == null ? void 0 : dateRange[0].date);
359
+ const tempEndDate = endDate || (dateRange == null ? void 0 : dateRange[1].date);
209
360
  if (!tempProducts.length) {
210
361
  return [];
211
362
  }
212
363
  const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
213
- console.log("resourceIds", tempProducts);
214
364
  this.otherParams.currentResourcesMap = resourcesMap;
215
- const res = await this.store.date.getMonthDates({
365
+ const res = await this.store.date.getResourceDates({
366
+ url: params.url,
216
367
  query: {
217
368
  start_date: tempStartDate,
218
369
  end_date: tempEndDate,
219
370
  resource_ids: resourceIds
220
371
  },
221
- rules
372
+ rules,
373
+ type
222
374
  });
223
375
  return res;
224
376
  }
@@ -230,6 +382,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
230
382
  const summary = await this.store.summary.getSummary(cartItems);
231
383
  return summary;
232
384
  }
385
+ /**
386
+ * 获取协议
387
+ */
388
+ async getProtocol(protocolId) {
389
+ return this.store.summary.getProtocol(protocolId);
390
+ }
233
391
  // 获取可选择的商品、服务列表
234
392
  async getProducts() {
235
393
  return this.store.products.getProducts();
@@ -262,11 +420,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
262
420
  const res = await this.request.post(`/pay/order/free-pay/${id}`);
263
421
  return res;
264
422
  }
423
+ /**
424
+ * 检查购物车提交订单前是否符合条件
425
+ * @param type 类型 "holder" | "account"
426
+ * @returns boolean
427
+ */
428
+ checkBeforeSubmitOrder(type) {
429
+ return this.store.order.checkBeforeSubmitOrder({
430
+ type,
431
+ cartItems: this.store.cart.getItems()
432
+ });
433
+ }
265
434
  // 购物车提交订单
266
435
  async submitOrder() {
267
436
  const cartItems = this.store.cart.getItems();
268
437
  const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
269
438
  newCartItems.forEach((item) => {
439
+ var _a, _b;
270
440
  item._origin.resources = item._origin.resources.map((n) => {
271
441
  const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
272
442
  delete newResourcesItem.id;
@@ -274,8 +444,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
274
444
  delete newResourcesItem.resourceType;
275
445
  return { ...newResourcesItem };
276
446
  });
447
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
448
+ capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
449
+ product_bundle: item._origin.product.product_bundle
450
+ });
451
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
452
+ if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
453
+ item._origin.metadata = {};
454
+ }
455
+ item._origin.metadata.capacity = formatCapacity;
456
+ item._origin.number = currentCapacity;
277
457
  });
278
- return this.store.order.commitOrder({ query: { cartItems: newCartItems } });
458
+ return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
279
459
  }
280
460
  // 拉起支付模块
281
461
  async pay() {
@@ -295,24 +475,40 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
295
475
  }
296
476
  // 更新购物车
297
477
  updateCart(params) {
478
+ var _a;
479
+ const targetCartItem = this.store.cart.getItem(params._id);
480
+ if (!targetCartItem) {
481
+ throw new Error(`没有找到${params._id}购物车商品`);
482
+ }
298
483
  if (params.resources) {
484
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
485
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
486
+ product_bundle: targetCartItem._origin.product.product_bundle
487
+ });
488
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
299
489
  params.resources = params.resources.map((n) => {
300
- n.capacity = 1;
490
+ n.capacity = currentCapacity || 1;
491
+ (0, import_resources.checkSubResourcesCapacity)(n);
301
492
  return n;
302
493
  });
303
494
  }
304
495
  this.store.cart.updateItem(params);
305
- const targetCartItem = this.store.cart.getItem(params._id);
306
- if (!targetCartItem) {
307
- throw new Error(`没有找到${params._id}购物车商品`);
308
- }
309
496
  const cartItems = this.store.cart.getItems();
310
497
  cartItems.forEach((item) => {
311
- var _a;
498
+ var _a2;
312
499
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
313
- const resources = (_a = item._origin.resources) == null ? void 0 : _a.filter(
314
- (m) => !targetCartItem._origin.resources.some((targetRes) => targetRes.id === m.id)
315
- );
500
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
501
+ return !targetCartItem._origin.resources.some((targetRes) => {
502
+ var _a3, _b;
503
+ if (targetRes.id === m.id)
504
+ return true;
505
+ if (((_a3 = targetRes.metadata.combined_resource) == null ? void 0 : _a3.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id))
506
+ return true;
507
+ if (((_b = m.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
508
+ return true;
509
+ return false;
510
+ });
511
+ });
316
512
  this.store.cart.updateItem({
317
513
  _id: item._id,
318
514
  resources
@@ -346,8 +542,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
346
542
  /**
347
543
  * 从购物车中按类别删除信息
348
544
  */
349
- deleteCartItemInfo(types) {
350
- this.store.cart.deleteCartItemInfo(types);
545
+ deleteCartItemInfo(type, _id) {
546
+ this.store.cart.deleteCartItemInfo(type, _id);
547
+ }
548
+ checkCartItemByType(cartItem, type) {
549
+ return this.store.cart.checkCartItemByType(cartItem, type);
351
550
  }
352
551
  destroy() {
353
552
  var _a, _b, _c, _d, _e, _f;
@@ -364,15 +563,94 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
364
563
  getResourcesList() {
365
564
  const dateRange = this.store.date.getDateRange();
366
565
  const resources = [];
367
- dateRange.forEach((n) => {
368
- if (n.resource)
369
- resources.push(...n.resource);
370
- });
371
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
566
+ if (dateRange == null ? void 0 : dateRange.length) {
567
+ dateRange.forEach((n) => {
568
+ if (n.resource)
569
+ resources.push(...n.resource);
570
+ });
571
+ }
572
+ if (!resources.length) {
573
+ const dateList = this.store.date.getDateList();
574
+ dateList.forEach((n) => {
575
+ if (n.resource)
576
+ resources.push(...n.resource);
577
+ });
578
+ }
579
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
372
580
  const cartItems = this.store.cart.getItems();
373
581
  const arr = [];
582
+ const capacityMap = {};
374
583
  cartItems.forEach((cartItem) => {
375
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, cartItem, cartItems);
584
+ var _a, _b, _c;
585
+ let selectedResources = [];
586
+ if (cartItem.holder_id) {
587
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
588
+ cartItems,
589
+ cartItem.holder_id,
590
+ resourcesMap
591
+ );
592
+ } else {
593
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
594
+ cartItems,
595
+ cartItem._id,
596
+ resourcesMap
597
+ );
598
+ }
599
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
600
+ capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
601
+ product_bundle: cartItem._origin.product.product_bundle
602
+ });
603
+ cartItem._origin.metadata.capacity = formatCapacity;
604
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
605
+ const productResources = (0, import_resources.getResourcesByProduct)(
606
+ resourcesMap,
607
+ ((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
608
+ selectedResources,
609
+ currentCapacity
610
+ );
611
+ if (cartItem._origin.start_time) {
612
+ const startTime = (0, import_dayjs.default)(
613
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
614
+ );
615
+ const endTime = (0, import_dayjs.default)(
616
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
617
+ );
618
+ productResources.sort((a, b) => {
619
+ var _a2, _b2, _c2, _d;
620
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
621
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
622
+ if (aIsCombined && !bIsCombined)
623
+ return 1;
624
+ if (!aIsCombined && bIsCombined)
625
+ return -1;
626
+ return 0;
627
+ });
628
+ const resourcesUseableMap = {};
629
+ productResources.forEach((n) => {
630
+ n.renderList = n.renderList.filter((m) => {
631
+ const recordCount = capacityMap[m.id] || 0;
632
+ const canUseTime = m.times.find((item) => {
633
+ const res = (0, import_resources.getIsUsableByTimeItem)({
634
+ timeSlice: {
635
+ start_time: startTime.format("HH:mm"),
636
+ end_time: endTime.format("HH:mm"),
637
+ start_at: startTime,
638
+ end_at: endTime
639
+ },
640
+ time: item,
641
+ resource: m,
642
+ currentCount: recordCount + (currentCapacity || 0),
643
+ resourcesUseableMap
644
+ });
645
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
646
+ resourcesUseableMap[m.id] = res.usable;
647
+ }
648
+ return res.usable;
649
+ });
650
+ return canUseTime;
651
+ });
652
+ });
653
+ }
376
654
  arr.push({
377
655
  id: cartItem.id,
378
656
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -388,20 +666,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
388
666
  }
389
667
  // 给单个购物车里的商品获取资源列表
390
668
  getResourcesListByCartItem(id) {
391
- const cartItems = this.store.cart.getItems();
669
+ var _a, _b, _c;
670
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
392
671
  const dateRange = this.store.date.getDateRange();
393
672
  const resources = [];
394
673
  dateRange.forEach((n) => {
395
674
  if (n.resource)
396
675
  resources.push(...n.resource);
397
676
  });
398
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
399
- const arr = [];
677
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
400
678
  const targetCartItem = cartItems.find((n) => n._id === id);
401
679
  if (!targetCartItem) {
402
680
  throw new Error(`没有找到${id}购物车商品`);
403
681
  }
404
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, targetCartItem, cartItems);
682
+ let selectedResources = [];
683
+ if (targetCartItem.holder_id) {
684
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
685
+ cartItems,
686
+ targetCartItem.holder_id,
687
+ resourcesMap
688
+ );
689
+ } else {
690
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
691
+ cartItems,
692
+ targetCartItem._id,
693
+ resourcesMap
694
+ );
695
+ }
696
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
697
+ capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
698
+ product_bundle: targetCartItem._origin.product.product_bundle
699
+ });
700
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
701
+ const productResources = (0, import_resources.getResourcesByProduct)(
702
+ resourcesMap,
703
+ ((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
704
+ selectedResources,
705
+ currentCapacity
706
+ );
405
707
  if (productResources) {
406
708
  return {
407
709
  id: targetCartItem.id,
@@ -430,83 +732,44 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
430
732
  });
431
733
  return timeSlots;
432
734
  }
433
- // 自动分派可用的资源-单种资源类型
434
- autoSelectResource({
435
- resourceProductData,
436
- resources,
437
- timeSlots
438
- }) {
439
- const dateRange = this.store.date.getDateRange();
440
- if (timeSlots) {
441
- let targetResource = null;
442
- for (const n of resources) {
443
- const canUseTime = n.times.find((item) => {
444
- const res = (0, import_resources.getIsUsableByTimeItem)({
445
- timeSlice: timeSlots,
446
- time: item,
447
- resource: n,
448
- currentCount: 1
449
- });
450
- return res.usable;
451
- });
452
- if (canUseTime) {
453
- targetResource = n;
454
- break;
455
- }
456
- }
457
- return {
458
- selectedResource: targetResource
459
- };
460
- } else {
461
- const duration = resourceProductData.product.duration.value;
462
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
463
- const resourceIds = resources.map((n) => n.id);
464
- const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
465
- resourceIds,
466
- resourcesMap,
467
- duration,
468
- currentDate: dateRange[0].date,
469
- split: 10
470
- });
471
- if (!timeSlots2) {
472
- return;
473
- }
474
- return {
475
- timeSlots: timeSlots2,
476
- selectedResource: resources[0]
477
- };
478
- }
479
- }
480
735
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
481
736
  autoSelectAccountResources({
482
737
  holder_id,
483
738
  resources_code,
484
739
  timeSlots,
485
- countMap
740
+ countMap,
741
+ capacity
486
742
  }) {
487
- var _a, _b, _c;
488
743
  const dateRange = this.store.date.getDateRange();
489
- const cartItems = this.store.cart.getItems();
490
- const accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
744
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
745
+ let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
491
746
  if (!accountCartItems.length) {
492
- return {
493
- selectedResource: null
494
- };
747
+ accountCartItems = cartItems;
495
748
  }
496
749
  let duration = accountCartItems.reduce((acc, n) => {
497
- var _a2, _b2;
498
- return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0);
750
+ var _a, _b;
751
+ return acc + (((_b = (_a = n._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0);
499
752
  }, 0);
500
- let durationType = ((_c = (_b = (_a = accountCartItems[0]) == null ? void 0 : _a._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.type) ?? "minutes";
501
- const resources = [];
753
+ let resources = [];
502
754
  accountCartItems.forEach((item) => {
503
- var _a2, _b2, _c2;
504
- (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
755
+ var _a, _b, _c;
756
+ (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
505
757
  if (n.code === resources_code) {
506
758
  resources.push(...n.renderList || []);
507
759
  }
508
760
  });
509
761
  });
762
+ resources.sort((a, b) => {
763
+ var _a, _b, _c, _d;
764
+ const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
765
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
766
+ if (aIsCombined && !bIsCombined)
767
+ return 1;
768
+ if (!aIsCombined && bIsCombined)
769
+ return -1;
770
+ return 0;
771
+ });
772
+ const resourcesUseableMap = {};
510
773
  if (timeSlots) {
511
774
  let targetResource = null;
512
775
  for (const n of resources) {
@@ -516,8 +779,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
516
779
  timeSlice: timeSlots,
517
780
  time: item,
518
781
  resource: n,
519
- currentCount: recordCount + 1
782
+ currentCount: recordCount + (capacity || 0),
783
+ resourcesUseableMap
520
784
  });
785
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false) {
786
+ resourcesUseableMap[n.id] = res.usable;
787
+ }
521
788
  return res.usable;
522
789
  });
523
790
  if (canUseTime) {
@@ -536,7 +803,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
536
803
  resourcesMap,
537
804
  duration,
538
805
  currentDate: dateRange[0].date,
539
- split: 10
806
+ split: 10,
807
+ capacity,
808
+ resourcesUseableMap
540
809
  });
541
810
  if (!timeSlots2) {
542
811
  return;
@@ -549,30 +818,45 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
549
818
  }
550
819
  // 给所有购物车里的商品先分配一个资源
551
820
  autoSelectAllProductResources(resources_code, timeSlots) {
821
+ var _a;
552
822
  const dateRange = this.store.date.getDateRange();
553
823
  const resources = [];
554
- dateRange.forEach((n) => {
555
- if (n.resource)
556
- resources.push(...n.resource);
557
- });
558
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
824
+ if ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date) {
825
+ dateRange.forEach((n) => {
826
+ if (n.resource)
827
+ resources.push(...n.resource);
828
+ });
829
+ }
830
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
559
831
  const errorList = [];
560
832
  const selectResourcesMap = {};
561
- this.store.accountList.getAccounts().forEach((account) => {
562
- const cartItems = this.store.cart.getCartByAccount(account.getId());
563
- const allCartItems = this.store.cart.getItems();
833
+ const accountList = this.store.accountList.getAccounts();
834
+ const selectForCartResources = (cartItems2) => {
564
835
  let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
565
- cartItems.forEach((item, index) => {
566
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
567
- if (timeSlots) {
836
+ cartItems2.forEach((item, index) => {
837
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
838
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
839
+ capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
840
+ product_bundle: item._origin.product.product_bundle
841
+ });
842
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
843
+ if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
844
+ recordTimeSlots = {
845
+ start_time: item._origin.start_time,
846
+ end_time: item._origin.end_time,
847
+ start_at: (0, import_dayjs.default)(`${item.start_date} ${item._origin.start_time}`),
848
+ end_at: (0, import_dayjs.default)(`${item.end_date} ${item._origin.end_time}`)
849
+ };
850
+ }
851
+ if (recordTimeSlots) {
568
852
  if (index !== 0 && recordTimeSlots) {
569
853
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
570
- ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0,
571
- ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes"
854
+ ((_c = (_b = item._productOrigin) == null ? void 0 : _b.duration) == null ? void 0 : _c.value) ?? 0,
855
+ ((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) ?? "minutes"
572
856
  );
573
857
  let end_at = start_at.add(
574
- ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) ?? 0,
575
- ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.type) ?? "minutes"
858
+ ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
859
+ ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
576
860
  );
577
861
  recordTimeSlots = {
578
862
  start_time: start_at.format("HH:mm"),
@@ -585,16 +869,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
585
869
  holder_id: item.holder_id,
586
870
  resources_code,
587
871
  timeSlots: recordTimeSlots,
588
- countMap: selectResourcesMap
872
+ countMap: selectResourcesMap,
873
+ capacity: currentCapacity
589
874
  });
590
875
  if (res == null ? void 0 : res.selectedResource) {
591
876
  if (!selectResourcesMap[res.selectedResource.id]) {
592
- selectResourcesMap[res.selectedResource.id] = 1;
877
+ selectResourcesMap[res.selectedResource.id] = currentCapacity;
593
878
  } else {
594
- selectResourcesMap[res.selectedResource.id]++;
879
+ selectResourcesMap[res.selectedResource.id] += currentCapacity;
595
880
  }
596
- console.log(this.store.cart.getItems());
597
- res.selectedResource.capacity = 1;
881
+ res.selectedResource.capacity = currentCapacity;
882
+ (0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
598
883
  this.store.cart.updateItem({
599
884
  _id: item._id,
600
885
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -605,19 +890,43 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
605
890
  res.selectedResource
606
891
  ]
607
892
  });
608
- console.log(this.store.cart.getItems());
609
893
  } else {
610
894
  errorList.push(item._id);
611
895
  }
612
896
  } else {
613
- const productResources = (0, import_resources.getResourcesByProduct)(resourcesMap, item, allCartItems);
614
- const targetRenderList = (_i = productResources.find((n) => n.code === resources_code)) == null ? void 0 : _i.renderList;
897
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
898
+ let selectedResources = [];
899
+ if (item.holder_id) {
900
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
901
+ allCartItems,
902
+ item.holder_id,
903
+ resourcesMap
904
+ );
905
+ } else {
906
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
907
+ allCartItems,
908
+ item._id,
909
+ resourcesMap
910
+ );
911
+ }
912
+ const productResources = (0, import_resources.getResourcesByProduct)(
913
+ resourcesMap,
914
+ ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
915
+ selectedResources,
916
+ currentCapacity
917
+ );
918
+ const targetRenderList = (_l = productResources.find(
919
+ (n) => n.code === resources_code
920
+ )) == null ? void 0 : _l.renderList;
615
921
  if (targetRenderList && targetRenderList.length > 0) {
616
- if ((_j = item._origin.resources) == null ? void 0 : _j.some((n) => n.form_id === targetRenderList[0].form_id)) {
922
+ if ((_m = item._origin.resources) == null ? void 0 : _m.some(
923
+ (n) => n.form_id === targetRenderList[0].form_id
924
+ )) {
617
925
  return;
618
926
  }
619
927
  const targetResource = targetRenderList[0];
620
- targetResource.capacity = 1;
928
+ targetResource.capacity = currentCapacity;
929
+ (0, import_resources.checkSubResourcesCapacity)(targetResource);
621
930
  this.store.cart.updateItem({
622
931
  _id: item._id,
623
932
  resources: [
@@ -632,18 +941,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
632
941
  }
633
942
  }
634
943
  });
635
- });
944
+ };
945
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
946
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
947
+ accountList.forEach((account) => {
948
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
949
+ selectForCartResources(cartItems2);
950
+ });
951
+ } else {
952
+ selectForCartResources(cartItems);
953
+ }
636
954
  return { errorList };
637
955
  }
638
956
  // 从购物车中获取已经分配好第一步资源的所有时间片
639
957
  getTimeSlotByAllResources(resources_code) {
640
- const dateRange = this.store.date.getDateRange();
958
+ var _a, _b, _c, _d;
959
+ let dateRange = this.store.date.getDateRange();
641
960
  const resources = [];
642
- const cartItems = this.store.cart.getItems();
961
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
643
962
  const resourceIds = [];
644
963
  cartItems.forEach((item) => {
645
- var _a, _b, _c;
646
- (_c = (_b = (_a = item._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.forEach((n) => {
964
+ var _a2, _b2, _c2;
965
+ (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
647
966
  if (n.code === resources_code) {
648
967
  resources.push(...n.renderList || []);
649
968
  }
@@ -654,29 +973,58 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
654
973
  });
655
974
  const resourcesMap = (0, import_utils.getResourcesMap)(resources);
656
975
  let duration = 0;
657
- this.store.accountList.getAccounts().forEach((account) => {
976
+ const accountList = this.store.accountList.getAccounts();
977
+ const checkDuration = (cartItems2) => {
658
978
  let accountDuration = 0;
659
- const cartItems2 = this.store.cart.getCartByAccount(account.getId());
660
979
  cartItems2.forEach((item) => {
661
- var _a, _b;
662
- accountDuration += ((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0;
980
+ var _a2, _b2;
981
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) ?? 0;
663
982
  });
664
983
  if (accountDuration > duration) {
665
984
  duration = accountDuration;
666
985
  }
667
- });
986
+ };
987
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
988
+ accountList.forEach((account) => {
989
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
990
+ checkDuration(cartItems2);
991
+ });
992
+ } else {
993
+ checkDuration(cartItems);
994
+ }
995
+ if (!((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.start_date) && !((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
996
+ return [];
997
+ }
998
+ if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
999
+ dateRange = [
1000
+ {
1001
+ date: cartItems == null ? void 0 : cartItems[0].start_date,
1002
+ status: "available",
1003
+ week: "",
1004
+ weekNum: 0
1005
+ },
1006
+ {
1007
+ date: ((_c = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _c.end_date) || ((_d = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _d.start_date) || "",
1008
+ status: "available",
1009
+ week: "",
1010
+ weekNum: 0
1011
+ }
1012
+ ];
1013
+ }
1014
+ const resourcesUseableMap = {};
668
1015
  const timeSlots = (0, import_resources.getTimeSlicesByResources)({
669
1016
  resourceIds,
670
1017
  resourcesMap,
671
1018
  duration,
672
1019
  currentDate: dateRange[0].date,
673
- split: 10
1020
+ split: 10,
1021
+ resourcesUseableMap
674
1022
  });
675
1023
  return timeSlots;
676
1024
  }
677
1025
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车
678
1026
  submitTimeSlot(timeSlots) {
679
- const cartItems = this.store.cart.getItems();
1027
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
680
1028
  const itemsByAccount = cartItems.reduce((acc, item) => {
681
1029
  const holderId = item.holder_id;
682
1030
  if (!acc[holderId]) {
@@ -712,6 +1060,180 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
712
1060
  }
713
1061
  clearCacheByModule(module2) {
714
1062
  }
1063
+ getScheduleDataByIds(scheduleIds) {
1064
+ const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1065
+ const targetSchedulesData = targetSchedules.map((item) => {
1066
+ return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
1067
+ });
1068
+ const newSchedule = {};
1069
+ targetSchedulesData.forEach((item) => {
1070
+ item.forEach((n) => {
1071
+ if (!newSchedule[n.date]) {
1072
+ newSchedule[n.date] = n;
1073
+ } else {
1074
+ if (!n.isExcluded) {
1075
+ newSchedule[n.date].isExcluded = false;
1076
+ }
1077
+ }
1078
+ });
1079
+ });
1080
+ const newScheduleArr = Object.values(newSchedule);
1081
+ return newScheduleArr;
1082
+ }
1083
+ // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
1084
+ async openProductDetail(productId) {
1085
+ const targetProduct = await this.store.products.getProduct(productId);
1086
+ if (targetProduct) {
1087
+ const targetProductData = targetProduct.getData();
1088
+ this.store.currentProduct = targetProduct;
1089
+ const newScheduleArr = this.getScheduleDataByIds(
1090
+ targetProductData["schedule.ids"]
1091
+ );
1092
+ targetProduct.setOtherParams("schedule", newScheduleArr);
1093
+ }
1094
+ }
1095
+ closeProductDetail() {
1096
+ var _a;
1097
+ (_a = this.store.currentProduct) == null ? void 0 : _a.setOtherParams("schedule", []);
1098
+ this.store.currentProduct = void 0;
1099
+ }
1100
+ getTimeslotBySchedule({
1101
+ date,
1102
+ scheduleIds,
1103
+ resources
1104
+ }) {
1105
+ var _a, _b, _c;
1106
+ const targetProduct = this.store.currentProduct;
1107
+ const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
1108
+ let targetSchedules = [];
1109
+ if (scheduleIds == null ? void 0 : scheduleIds.length) {
1110
+ targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1111
+ } else {
1112
+ targetSchedules = this.store.schedule.getScheduleListByIds(
1113
+ targetProductData["schedule.ids"]
1114
+ );
1115
+ }
1116
+ const resourcesDates = this.store.date.getDateList();
1117
+ const targetResourceDate = resourcesDates.find((n) => n.date === date);
1118
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1119
+ const resourcesMap = (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1120
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
1121
+ cartItems,
1122
+ "",
1123
+ resourcesMap
1124
+ );
1125
+ const productResources = (0, import_resources.getResourcesByProduct)(
1126
+ resourcesMap,
1127
+ resources || ((_c = (_b = (_a = this.store.currentProduct) == null ? void 0 : _a.getData()) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
1128
+ selectedResources,
1129
+ 1
1130
+ );
1131
+ const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
1132
+ targetSchedules,
1133
+ {},
1134
+ date
1135
+ );
1136
+ const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1137
+ console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
1138
+ let allProductResources = productResources.flatMap((n) => n.renderList);
1139
+ allProductResources.sort((a, b) => {
1140
+ var _a2, _b2, _c2, _d;
1141
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1142
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1143
+ if (aIsCombined && !bIsCombined)
1144
+ return 1;
1145
+ if (!aIsCombined && bIsCombined)
1146
+ return -1;
1147
+ return 0;
1148
+ });
1149
+ const resourcesUseableMap = {};
1150
+ const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1151
+ let count = 0;
1152
+ allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1153
+ m.times.forEach((childTiem) => {
1154
+ const res = (0, import_resources.getIsUsableByTimeItem)({
1155
+ timeSlice: {
1156
+ start_time: item.start,
1157
+ end_time: item.end,
1158
+ start_at: (0, import_dayjs.default)(item.start),
1159
+ end_at: (0, import_dayjs.default)(item.end)
1160
+ },
1161
+ time: childTiem,
1162
+ resource: m,
1163
+ currentCount: 1,
1164
+ resourcesUseableMap
1165
+ });
1166
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false) {
1167
+ resourcesUseableMap[m.id] = res.usable;
1168
+ }
1169
+ if (res.usable && res.remainingCapacity >= count) {
1170
+ count = res.remainingCapacity;
1171
+ }
1172
+ });
1173
+ });
1174
+ const startDayJs = (0, import_dayjs.default)(item.start);
1175
+ const endDayJs = (0, import_dayjs.default)(item.end);
1176
+ return {
1177
+ start_time: startDayJs.format("HH:mm"),
1178
+ end_time: endDayJs.format("HH:mm"),
1179
+ start_at: startDayJs,
1180
+ end_at: endDayJs,
1181
+ count
1182
+ };
1183
+ });
1184
+ return formatScheduleTimeSlots;
1185
+ }
1186
+ addProductToCart({
1187
+ product,
1188
+ date,
1189
+ account
1190
+ }) {
1191
+ const { bundle, options, origin, product_variant_id } = product || {};
1192
+ const productData = { ...origin, product_variant_id };
1193
+ if (!account) {
1194
+ const activeAccount = this.getActiveAccount();
1195
+ if (activeAccount) {
1196
+ account = activeAccount;
1197
+ }
1198
+ }
1199
+ this.store.cart.addItem({
1200
+ product: productData,
1201
+ date,
1202
+ account,
1203
+ bundle,
1204
+ options
1205
+ });
1206
+ if (date) {
1207
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1208
+ const cartItemsByDate = cartItems.filter(
1209
+ (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
1210
+ );
1211
+ if (cartItemsByDate.length) {
1212
+ cartItemsByDate.forEach((n) => {
1213
+ this.store.cart.removeItem(n._id);
1214
+ });
1215
+ }
1216
+ }
1217
+ }
1218
+ setOtherData(key, value) {
1219
+ this.otherData[key] = value;
1220
+ this.checkSaveCache({
1221
+ cacheId: this.cacheId,
1222
+ fatherModule: this.name,
1223
+ store: { otherData: this.otherData },
1224
+ cacheKey: ["otherData"]
1225
+ });
1226
+ }
1227
+ getOtherData(key) {
1228
+ return this.otherData[key];
1229
+ }
1230
+ async getProductTypeById(id) {
1231
+ const product = await this.store.products.getProduct(id);
1232
+ if (product) {
1233
+ return product.getProductType();
1234
+ }
1235
+ return "normal";
1236
+ }
715
1237
  };
716
1238
  // Annotate the CommonJS export names for ESM import in node:
717
1239
  0 && (module.exports = {