@pisell/pisellos 3.0.42 → 3.0.43
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.
- package/dist/modules/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +28 -8
- package/dist/modules/Date/index.js +70 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +218 -80
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +753 -1076
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/dist/solution/BookingByStep/utils/resources.js +39 -95
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -8
- package/lib/modules/Date/index.js +59 -2
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +154 -63
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +391 -589
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/lib/solution/BookingByStep/utils/resources.js +21 -58
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- package/package.json +1 -1
|
@@ -45,6 +45,8 @@ var import_utils2 = require("../../modules/Schedule/utils");
|
|
|
45
45
|
var import_utils3 = require("../../modules/Date/utils");
|
|
46
46
|
var import_utils4 = require("../../modules/Product/utils");
|
|
47
47
|
var import_timeslots = require("./utils/timeslots");
|
|
48
|
+
var import_changePrice = require("../../modules/Cart/utils/changePrice");
|
|
49
|
+
var import_capacity = require("./utils/capacity");
|
|
48
50
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
49
51
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
50
52
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -111,7 +113,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
111
113
|
throw new Error(`模块 ${step} 不存在`);
|
|
112
114
|
}
|
|
113
115
|
});
|
|
114
|
-
this.loadAllSchedule();
|
|
116
|
+
this.store.schedule.loadAllSchedule();
|
|
115
117
|
this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
|
|
116
118
|
}
|
|
117
119
|
// 初始化step
|
|
@@ -158,56 +160,52 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
158
160
|
updateStep(key, step) {
|
|
159
161
|
this.store.step.updateStep(key, step);
|
|
160
162
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* 加载商品,然后导到商品列表里去
|
|
166
|
+
* @param {({
|
|
167
|
+
* category_ids?: number[];
|
|
168
|
+
* product_ids?: number[];
|
|
169
|
+
* collection?: number | string[];
|
|
170
|
+
* schedule_date?: string;
|
|
171
|
+
* })} {
|
|
172
|
+
* category_ids = [],
|
|
173
|
+
* product_ids = [],
|
|
174
|
+
* collection = [],
|
|
175
|
+
* schedule_date,
|
|
176
|
+
* }
|
|
177
|
+
* @return {*}
|
|
178
|
+
* @memberof BookingByStepImpl
|
|
179
|
+
*/
|
|
166
180
|
async loadProducts({
|
|
167
181
|
category_ids = [],
|
|
168
182
|
product_ids = [],
|
|
169
183
|
collection = [],
|
|
170
|
-
// schedule_ids = [],
|
|
171
184
|
schedule_date
|
|
172
185
|
}) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
const productsData = await this.request.post(
|
|
182
|
-
`/product/query`,
|
|
183
|
-
{
|
|
184
|
-
open_quotation: 1,
|
|
185
|
-
open_bundle: 0,
|
|
186
|
-
exclude_extension_type: [
|
|
187
|
-
"product_party",
|
|
188
|
-
"product_event",
|
|
189
|
-
"product_series_event",
|
|
190
|
-
"product_package_ticket",
|
|
191
|
-
"ticket",
|
|
192
|
-
"event_item"
|
|
193
|
-
],
|
|
194
|
-
with: ["category", "collection", "resourceRelation"],
|
|
195
|
-
status: "published",
|
|
196
|
-
num: 500,
|
|
197
|
-
skip: 1,
|
|
198
|
-
customer_id,
|
|
199
|
-
category_ids,
|
|
200
|
-
ids: product_ids,
|
|
201
|
-
collection,
|
|
202
|
-
front_end_cache_id: this.cacheId,
|
|
203
|
-
// client_schedule_ids: schedule_ids,
|
|
204
|
-
schedule_date
|
|
205
|
-
},
|
|
206
|
-
{ useCache: true }
|
|
207
|
-
);
|
|
208
|
-
this.store.products.addProduct(productsData.data.list);
|
|
209
|
-
return productsData.data.list;
|
|
186
|
+
return this.store.products.loadProducts({
|
|
187
|
+
category_ids,
|
|
188
|
+
product_ids,
|
|
189
|
+
collection,
|
|
190
|
+
schedule_date,
|
|
191
|
+
cacheId: this.cacheId
|
|
192
|
+
});
|
|
210
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* 通过 schedule 来读取商品,适用于 session 类商品
|
|
196
|
+
*
|
|
197
|
+
* @param {{
|
|
198
|
+
* date: string;
|
|
199
|
+
* product_ids?: number[];
|
|
200
|
+
* category_ids?: number[];
|
|
201
|
+
* }} {
|
|
202
|
+
* date,
|
|
203
|
+
* product_ids = [],
|
|
204
|
+
* category_ids = [],
|
|
205
|
+
* }
|
|
206
|
+
* @return {*}
|
|
207
|
+
* @memberof BookingByStepImpl
|
|
208
|
+
*/
|
|
211
209
|
async loadProductByScheduleDate({
|
|
212
210
|
date,
|
|
213
211
|
product_ids = [],
|
|
@@ -229,12 +227,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
229
227
|
(n, index, self) => self.indexOf(n) === index
|
|
230
228
|
);
|
|
231
229
|
return await this.loadProducts({
|
|
232
|
-
// schedule_ids: scheduleIds,
|
|
233
230
|
product_ids: allProductIds,
|
|
234
231
|
category_ids,
|
|
235
232
|
schedule_date: date
|
|
236
233
|
});
|
|
237
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
|
|
237
|
+
*
|
|
238
|
+
* @param {string} date
|
|
239
|
+
* @memberof BookingByStepImpl
|
|
240
|
+
*/
|
|
238
241
|
async updateQuotationPriceAndCart(date) {
|
|
239
242
|
var _a;
|
|
240
243
|
const cartItems = this.store.cart.getItems();
|
|
@@ -251,129 +254,43 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
251
254
|
schedule_date: date,
|
|
252
255
|
customer_id
|
|
253
256
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
var _a2;
|
|
265
|
-
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
266
|
-
(m) => m.id === n.group_id
|
|
267
|
-
);
|
|
268
|
-
if (targetBundle) {
|
|
269
|
-
const targetBundleItem = targetBundle.bundle_item.find(
|
|
270
|
-
(m) => m.id === n.id
|
|
271
|
-
);
|
|
272
|
-
if (targetBundleItem) {
|
|
273
|
-
return {
|
|
274
|
-
...n,
|
|
275
|
-
price: targetBundleItem.price,
|
|
276
|
-
base_price: targetBundleItem.base_price
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return n;
|
|
281
|
-
});
|
|
282
|
-
this.store.cart.updateItem({
|
|
283
|
-
_id: item._id,
|
|
284
|
-
product: productInfo,
|
|
285
|
-
bundle
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
|
|
257
|
+
await (0, import_changePrice.updateAllCartItemPrice)(
|
|
258
|
+
cartItems,
|
|
259
|
+
res,
|
|
260
|
+
(id) => this.store.products.getProduct(id),
|
|
261
|
+
(params) => this.store.cart.updateItem(params)
|
|
262
|
+
);
|
|
263
|
+
this.core.effects.emit(
|
|
264
|
+
`${this.store.cart.name}:onUpdateQuotationPrice`,
|
|
265
|
+
{}
|
|
266
|
+
);
|
|
289
267
|
}
|
|
290
268
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
269
|
+
/**
|
|
270
|
+
* ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
|
|
271
|
+
* 适用于先选日期的流程,确定日期是否可用
|
|
272
|
+
* 已知问题:如果挂接的商品的资源不可用,后端是不会计算的
|
|
273
|
+
*
|
|
274
|
+
* @param {LoadScheduleAvailableDateParams} {
|
|
275
|
+
* startDate,
|
|
276
|
+
* endDate,
|
|
277
|
+
* custom_page_id,
|
|
278
|
+
* channel,
|
|
279
|
+
* }
|
|
280
|
+
* @memberof BookingByStepImpl
|
|
281
|
+
*/
|
|
302
282
|
async loadScheduleAvailableDate({
|
|
303
283
|
startDate,
|
|
304
284
|
endDate,
|
|
305
285
|
custom_page_id,
|
|
306
286
|
channel
|
|
307
287
|
}) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
315
|
-
return dates;
|
|
316
|
-
}
|
|
317
|
-
const res = await this.request.get(
|
|
318
|
-
`/schedule/product/availability/v2`,
|
|
319
|
-
{
|
|
320
|
-
start_date: startDate,
|
|
321
|
-
end_date: endDate,
|
|
322
|
-
custom_page_id,
|
|
323
|
-
channel
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
|
|
327
|
-
this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
|
|
328
|
-
if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
329
|
-
return dates;
|
|
330
|
-
}
|
|
331
|
-
if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
|
|
332
|
-
dates.forEach((n) => {
|
|
333
|
-
n.status = "available";
|
|
334
|
-
});
|
|
335
|
-
} else {
|
|
336
|
-
res.data.date_list.forEach((n) => {
|
|
337
|
-
const index = dates.findIndex((m) => m.date === n.date);
|
|
338
|
-
if (index !== -1) {
|
|
339
|
-
dates[index].status = "available";
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
|
|
344
|
-
return dates;
|
|
345
|
-
}
|
|
346
|
-
async storeProduct(productData) {
|
|
347
|
-
const activeAccount = this.getActiveAccount();
|
|
348
|
-
const { bundle, options, origin, product_variant_id, quantity = 1, rowKey } = productData || {};
|
|
349
|
-
const cartItems = this.store.cart.getItems();
|
|
350
|
-
if (rowKey) {
|
|
351
|
-
const targetCartItem = cartItems.find((n) => {
|
|
352
|
-
var _a;
|
|
353
|
-
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
354
|
-
});
|
|
355
|
-
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
356
|
-
this.store.cart.updateItem({
|
|
357
|
-
_id: targetCartItem._id,
|
|
358
|
-
product: {
|
|
359
|
-
...targetCartItem._productOrigin
|
|
360
|
-
},
|
|
361
|
-
quantity: (targetCartItem.num || 1) + quantity
|
|
362
|
-
});
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
const product = { ...origin, product_variant_id, rowKey };
|
|
367
|
-
const addCartItem = {
|
|
368
|
-
product,
|
|
369
|
-
bundle,
|
|
370
|
-
options,
|
|
371
|
-
quantity
|
|
372
|
-
};
|
|
373
|
-
if (activeAccount) {
|
|
374
|
-
addCartItem.account = activeAccount;
|
|
375
|
-
}
|
|
376
|
-
this.store.cart.addItem(addCartItem);
|
|
288
|
+
return await this.store.schedule.loadScheduleAvailableDate({
|
|
289
|
+
startDate,
|
|
290
|
+
endDate,
|
|
291
|
+
custom_page_id,
|
|
292
|
+
channel
|
|
293
|
+
});
|
|
377
294
|
}
|
|
378
295
|
// 添加单个账户或者 guest
|
|
379
296
|
async addAccount(account, extra) {
|
|
@@ -426,7 +343,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
426
343
|
}
|
|
427
344
|
getActiveAccount() {
|
|
428
345
|
const activeAccount = this.store.accountList.getActiveAccount();
|
|
429
|
-
|
|
346
|
+
const account = activeAccount == null ? void 0 : activeAccount.getAccount();
|
|
347
|
+
return account === null ? void 0 : account;
|
|
430
348
|
}
|
|
431
349
|
removeAccount(id) {
|
|
432
350
|
this.store.accountList.removeAccount(id);
|
|
@@ -442,7 +360,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
442
360
|
if (cartItems.length) {
|
|
443
361
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
444
362
|
if (!date) {
|
|
445
|
-
const normalProductCartItem = cartItems.find(
|
|
363
|
+
const normalProductCartItem = cartItems.find(
|
|
364
|
+
(n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
|
|
365
|
+
);
|
|
446
366
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
447
367
|
}
|
|
448
368
|
this.updateQuotationPriceAndCart(date);
|
|
@@ -550,7 +470,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
550
470
|
if (cartItems.length) {
|
|
551
471
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
552
472
|
if (!date) {
|
|
553
|
-
const normalProductCartItem = cartItems.find(
|
|
473
|
+
const normalProductCartItem = cartItems.find(
|
|
474
|
+
(n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
|
|
475
|
+
);
|
|
554
476
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
555
477
|
}
|
|
556
478
|
this.updateQuotationPriceAndCart(date);
|
|
@@ -583,7 +505,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
583
505
|
const cartItems = this.store.cart.getItems();
|
|
584
506
|
const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
|
|
585
507
|
newCartItems.forEach((item) => {
|
|
586
|
-
var _a
|
|
508
|
+
var _a;
|
|
587
509
|
if (item._origin.resources && item._origin.resources.length) {
|
|
588
510
|
item._origin.resources = item._origin.resources.map((n) => {
|
|
589
511
|
const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
|
|
@@ -592,12 +514,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
592
514
|
delete newResourcesItem.resourceType;
|
|
593
515
|
return { ...newResourcesItem };
|
|
594
516
|
});
|
|
595
|
-
const formatCapacity = (0,
|
|
596
|
-
|
|
597
|
-
product_bundle: item._origin.product.product_bundle
|
|
598
|
-
});
|
|
599
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
600
|
-
if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
|
|
517
|
+
const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
|
|
518
|
+
if (!((_a = item._origin) == null ? void 0 : _a.metadata)) {
|
|
601
519
|
item._origin.metadata = {};
|
|
602
520
|
}
|
|
603
521
|
item._origin.metadata.capacity = formatCapacity;
|
|
@@ -605,10 +523,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
605
523
|
}
|
|
606
524
|
});
|
|
607
525
|
let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
608
|
-
if ((0, import_utils4.areAllNormalProducts)(
|
|
526
|
+
if ((0, import_utils4.areAllNormalProducts)(
|
|
527
|
+
newCartItems.map((n) => n._productOrigin)
|
|
528
|
+
)) {
|
|
609
529
|
type = "virtual";
|
|
610
530
|
}
|
|
611
|
-
return this.store.order.submitOrder({
|
|
531
|
+
return this.store.order.submitOrder({
|
|
532
|
+
query: { cartItems: newCartItems, type }
|
|
533
|
+
});
|
|
612
534
|
}
|
|
613
535
|
// 拉起支付模块
|
|
614
536
|
async pay() {
|
|
@@ -626,31 +548,136 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
626
548
|
async getOtherParams() {
|
|
627
549
|
return this.otherParams;
|
|
628
550
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
551
|
+
/**
|
|
552
|
+
* 往购物车加商品数据(duration 类、普通商品)
|
|
553
|
+
* 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
|
|
554
|
+
*
|
|
555
|
+
* @param {ProductData} productData
|
|
556
|
+
* @memberof BookingByStepImpl
|
|
557
|
+
*/
|
|
558
|
+
async storeProduct(productData) {
|
|
559
|
+
const activeAccount = this.getActiveAccount();
|
|
560
|
+
this.addProductToCart({
|
|
561
|
+
product: productData,
|
|
562
|
+
account: activeAccount
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* 往购物车加商品数据
|
|
567
|
+
*
|
|
568
|
+
* @param {({
|
|
569
|
+
* product: ProductData;
|
|
570
|
+
* date?: { startTime: string; endTime: string } | null;
|
|
571
|
+
* account?: Account | null;
|
|
572
|
+
* })} {
|
|
573
|
+
* product,
|
|
574
|
+
* date,
|
|
575
|
+
* account,
|
|
576
|
+
* }
|
|
577
|
+
* @return {*}
|
|
578
|
+
* @memberof BookingByStepImpl
|
|
579
|
+
*/
|
|
580
|
+
addProductToCart({
|
|
581
|
+
product,
|
|
582
|
+
date,
|
|
583
|
+
account
|
|
584
|
+
}) {
|
|
585
|
+
const {
|
|
586
|
+
bundle,
|
|
587
|
+
options,
|
|
588
|
+
origin,
|
|
589
|
+
product_variant_id,
|
|
590
|
+
rowKey,
|
|
591
|
+
quantity = 1
|
|
592
|
+
} = product || {};
|
|
593
|
+
const productData = { ...origin, product_variant_id };
|
|
594
|
+
if (!account) {
|
|
595
|
+
const activeAccount = this.getActiveAccount();
|
|
596
|
+
if (activeAccount) {
|
|
597
|
+
account = activeAccount;
|
|
598
|
+
}
|
|
635
599
|
}
|
|
636
|
-
|
|
600
|
+
const flag = this.store.cart.mergeCartItemByRowKey({
|
|
601
|
+
rowKey,
|
|
602
|
+
quantity,
|
|
603
|
+
account: account || void 0
|
|
604
|
+
});
|
|
605
|
+
if (flag) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const addItemParams = {
|
|
609
|
+
product: productData,
|
|
610
|
+
bundle,
|
|
611
|
+
options,
|
|
612
|
+
quantity
|
|
613
|
+
};
|
|
614
|
+
if (date) {
|
|
615
|
+
addItemParams.date = date;
|
|
616
|
+
}
|
|
617
|
+
if (account) {
|
|
618
|
+
addItemParams.account = account;
|
|
619
|
+
}
|
|
620
|
+
this.addProductCheck({ date });
|
|
621
|
+
this.store.cart.addItem(addItemParams);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* 添加完购物车以后做的一些检测,比如日期是否在同一天
|
|
625
|
+
*
|
|
626
|
+
* @param {({ date?: { startTime: string; endTime: string } | null })} { date }
|
|
627
|
+
* @memberof BookingByStepImpl
|
|
628
|
+
*/
|
|
629
|
+
addProductCheck({
|
|
630
|
+
date
|
|
631
|
+
}) {
|
|
632
|
+
if (date) {
|
|
633
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
634
|
+
const cartItemsByDate = cartItems.filter(
|
|
635
|
+
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
636
|
+
);
|
|
637
|
+
if (cartItemsByDate.length) {
|
|
638
|
+
cartItemsByDate.forEach((n) => {
|
|
639
|
+
this.store.cart.removeItem(n._id);
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
beforeUpdateCart(params, targetCartItem) {
|
|
637
645
|
if (params.resources) {
|
|
638
|
-
const
|
|
639
|
-
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
640
|
-
product_bundle: targetCartItem._origin.product.product_bundle
|
|
641
|
-
});
|
|
642
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
646
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
|
|
643
647
|
params.resources = params.resources.map((n) => {
|
|
644
648
|
n.capacity = currentCapacity || 1;
|
|
645
|
-
|
|
646
|
-
(0, import_resources.checkSubResourcesCapacity)(n);
|
|
649
|
+
(0, import_capacity.checkSubResourcesCapacity)(n);
|
|
647
650
|
return n;
|
|
648
651
|
});
|
|
649
652
|
}
|
|
653
|
+
}
|
|
654
|
+
// 更新购物车
|
|
655
|
+
updateCart(params) {
|
|
656
|
+
const targetCartItem = this.store.cart.getItem(params._id);
|
|
657
|
+
if (!targetCartItem) {
|
|
658
|
+
throw new Error(`没有找到${params._id}购物车商品`);
|
|
659
|
+
}
|
|
660
|
+
this.beforeUpdateCart(params, targetCartItem);
|
|
650
661
|
this.store.cart.updateItem(params);
|
|
662
|
+
this.updateCartCheck(params, targetCartItem);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
|
|
666
|
+
*
|
|
667
|
+
* @param {IUpdateItemParams} params
|
|
668
|
+
* @param {CartItem} targetCartItem
|
|
669
|
+
* @return {*}
|
|
670
|
+
* @memberof BookingByStepImpl
|
|
671
|
+
*/
|
|
672
|
+
updateCartCheck(params, targetCartItem) {
|
|
673
|
+
var _a;
|
|
651
674
|
if (this.otherParams.isRetailTemplate) {
|
|
652
675
|
return;
|
|
653
676
|
}
|
|
677
|
+
let currentResourcesCapacityMap = {};
|
|
678
|
+
(_a = params.resources) == null ? void 0 : _a.forEach((n) => {
|
|
679
|
+
currentResourcesCapacityMap[n.id] = n.capacity;
|
|
680
|
+
});
|
|
654
681
|
const allOriginResources = [];
|
|
655
682
|
const dateRange = this.store.date.getDateRange();
|
|
656
683
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -671,50 +698,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
671
698
|
cartItems.forEach((item) => {
|
|
672
699
|
var _a2;
|
|
673
700
|
if (item._id !== targetCartItem._id) {
|
|
701
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
|
|
674
702
|
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
675
|
-
const sameFormIdResources =
|
|
703
|
+
const sameFormIdResources = (0, import_resources.filterResourcesByFormItem)(
|
|
704
|
+
targetCartItem._origin.resources,
|
|
705
|
+
m.form_id
|
|
706
|
+
);
|
|
676
707
|
if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
|
|
677
708
|
return true;
|
|
678
709
|
}
|
|
679
710
|
return !sameFormIdResources.some((targetRes) => {
|
|
680
|
-
var _a3, _b, _c;
|
|
681
711
|
if (targetRes.resourceType !== "single") {
|
|
682
|
-
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
683
|
-
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
684
|
-
product_bundle: item._origin.product.product_bundle
|
|
685
|
-
});
|
|
686
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
687
|
-
capacity: formatCapacity
|
|
688
|
-
});
|
|
689
712
|
const originResource = allOriginResources.find(
|
|
690
713
|
(n) => n.id === targetRes.id
|
|
691
714
|
);
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
715
|
+
const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
|
|
716
|
+
currentResourcesCapacityMap[m.id] || 0,
|
|
717
|
+
currentCapacity,
|
|
718
|
+
originResource == null ? void 0 : originResource.capacity
|
|
719
|
+
);
|
|
720
|
+
if (canUse)
|
|
721
|
+
currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
722
|
+
return !canUse;
|
|
697
723
|
}
|
|
698
724
|
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
699
|
-
|
|
700
|
-
return true;
|
|
701
|
-
if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
702
|
-
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
703
|
-
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
704
|
-
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
705
|
-
m.id
|
|
706
|
-
) || targetRes.metadata.combined_resource.resource_ids.some(
|
|
707
|
-
(n) => {
|
|
708
|
-
return m.metadata.combined_resource.resource_ids.includes(
|
|
709
|
-
n
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
)))
|
|
713
|
-
return true;
|
|
714
|
-
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
715
|
-
targetRes.id
|
|
716
|
-
))
|
|
717
|
-
return true;
|
|
725
|
+
return (0, import_resources.checkTwoResourcesIntersection)(targetRes, m);
|
|
718
726
|
}
|
|
719
727
|
return false;
|
|
720
728
|
});
|
|
@@ -815,25 +823,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
815
823
|
resources.push(...n.resource);
|
|
816
824
|
});
|
|
817
825
|
}
|
|
826
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
818
827
|
if (!resources.length) {
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}
|
|
828
|
+
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
829
|
+
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
830
|
+
const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
|
|
831
|
+
resources.push(...dateResources || []);
|
|
832
|
+
} else {
|
|
833
|
+
const dateList = this.store.date.getDateList();
|
|
834
|
+
dateList.forEach((n) => {
|
|
835
|
+
if (n.resource)
|
|
836
|
+
resources.push(...n.resource);
|
|
837
|
+
});
|
|
838
|
+
}
|
|
824
839
|
}
|
|
825
840
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
826
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
827
841
|
const arr = [];
|
|
828
842
|
cartItems.forEach((cartItem) => {
|
|
829
|
-
var _a, _b, _c, _d, _e, _f
|
|
843
|
+
var _a, _b, _c, _d, _e, _f;
|
|
830
844
|
let selectedResources = [];
|
|
831
|
-
const formatCapacity = (0,
|
|
832
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
833
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
834
|
-
});
|
|
845
|
+
const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
835
846
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
836
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
837
847
|
if (cartItem.holder_id) {
|
|
838
848
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
839
849
|
cartItems,
|
|
@@ -849,7 +859,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
849
859
|
}
|
|
850
860
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
851
861
|
resourcesMap,
|
|
852
|
-
((
|
|
862
|
+
((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
853
863
|
selectedResources,
|
|
854
864
|
currentCapacity
|
|
855
865
|
);
|
|
@@ -862,20 +872,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
862
872
|
);
|
|
863
873
|
const resourcesUseableMap = {};
|
|
864
874
|
productResources.forEach((n) => {
|
|
865
|
-
n.renderList =
|
|
866
|
-
var _a2, _b2, _c2, _d2;
|
|
867
|
-
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
868
|
-
const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
|
|
869
|
-
if (aIsCombined && !bIsCombined)
|
|
870
|
-
return 1;
|
|
871
|
-
if (!aIsCombined && bIsCombined)
|
|
872
|
-
return -1;
|
|
873
|
-
return 0;
|
|
874
|
-
});
|
|
875
|
+
n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
|
|
875
876
|
n.renderList = n.renderList.filter((m) => {
|
|
876
|
-
const mTimes =
|
|
877
|
-
|
|
878
|
-
|
|
877
|
+
const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
|
|
878
|
+
m.times,
|
|
879
|
+
startTime,
|
|
880
|
+
endTime
|
|
881
|
+
);
|
|
879
882
|
if (mTimes.length === 0) {
|
|
880
883
|
return false;
|
|
881
884
|
}
|
|
@@ -905,8 +908,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
905
908
|
});
|
|
906
909
|
});
|
|
907
910
|
} else {
|
|
908
|
-
const hasFlexibleDuration = ((
|
|
909
|
-
const operating_day_boundary = (
|
|
911
|
+
const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
|
|
912
|
+
const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
|
|
910
913
|
productResources.forEach((item) => {
|
|
911
914
|
item.renderList = item.renderList.filter((n) => {
|
|
912
915
|
var _a2, _b2, _c2;
|
|
@@ -939,138 +942,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
939
942
|
});
|
|
940
943
|
return arr;
|
|
941
944
|
}
|
|
942
|
-
|
|
945
|
+
/**
|
|
946
|
+
* 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
947
|
+
*
|
|
948
|
+
* @return {*}
|
|
949
|
+
* @memberof BookingByStepImpl
|
|
950
|
+
*/
|
|
943
951
|
checkResourceListForDate() {
|
|
944
|
-
const
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
dateRange.forEach((n) => {
|
|
948
|
-
if (n.resource)
|
|
949
|
-
resources.push(...n.resource);
|
|
950
|
-
});
|
|
951
|
-
}
|
|
952
|
-
if (!resources.length) {
|
|
953
|
-
const dateList = this.store.date.getDateList();
|
|
954
|
-
dateList.forEach((n) => {
|
|
955
|
-
if (n.resource)
|
|
956
|
-
resources.push(...n.resource);
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
960
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
961
|
-
const arr = [];
|
|
962
|
-
cartItems.forEach((cartItem) => {
|
|
963
|
-
var _a, _b, _c;
|
|
964
|
-
let selectedResources = [];
|
|
965
|
-
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
966
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
967
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
968
|
-
});
|
|
969
|
-
cartItem._origin.metadata.capacity = formatCapacity;
|
|
970
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
971
|
-
if (cartItem.holder_id) {
|
|
972
|
-
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
973
|
-
cartItems,
|
|
974
|
-
cartItem.holder_id,
|
|
975
|
-
resourcesMap
|
|
976
|
-
);
|
|
977
|
-
} else {
|
|
978
|
-
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
979
|
-
cartItems,
|
|
980
|
-
cartItem._id,
|
|
981
|
-
resourcesMap
|
|
982
|
-
);
|
|
983
|
-
}
|
|
984
|
-
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
985
|
-
resourcesMap,
|
|
986
|
-
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
987
|
-
selectedResources,
|
|
988
|
-
currentCapacity
|
|
989
|
-
);
|
|
990
|
-
if (cartItem._origin.start_time) {
|
|
991
|
-
const startTime = (0, import_dayjs.default)(
|
|
992
|
-
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
993
|
-
);
|
|
994
|
-
const endTime = (0, import_dayjs.default)(
|
|
995
|
-
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
996
|
-
);
|
|
997
|
-
const resourcesUseableMap = {};
|
|
998
|
-
productResources.forEach((n) => {
|
|
999
|
-
n.renderList = n.renderList.sort((a, b) => {
|
|
1000
|
-
var _a2, _b2, _c2, _d;
|
|
1001
|
-
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1002
|
-
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1003
|
-
if (aIsCombined && !bIsCombined)
|
|
1004
|
-
return 1;
|
|
1005
|
-
if (!aIsCombined && bIsCombined)
|
|
1006
|
-
return -1;
|
|
1007
|
-
return 0;
|
|
1008
|
-
});
|
|
1009
|
-
n.renderList = n.renderList.filter((m) => {
|
|
1010
|
-
const mTimes = m.times.filter((n2) => {
|
|
1011
|
-
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(endTime));
|
|
1012
|
-
});
|
|
1013
|
-
if (mTimes.length === 0) {
|
|
1014
|
-
return false;
|
|
1015
|
-
}
|
|
1016
|
-
const canUseArr = mTimes.map((item) => {
|
|
1017
|
-
var _a2;
|
|
1018
|
-
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1019
|
-
timeSlice: {
|
|
1020
|
-
start_time: startTime.format("HH:mm"),
|
|
1021
|
-
end_time: endTime.format("HH:mm"),
|
|
1022
|
-
start_at: startTime,
|
|
1023
|
-
end_at: endTime
|
|
1024
|
-
},
|
|
1025
|
-
time: item,
|
|
1026
|
-
resource: m,
|
|
1027
|
-
currentCount: currentCapacity || 0,
|
|
1028
|
-
resourcesUseableMap,
|
|
1029
|
-
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1030
|
-
});
|
|
1031
|
-
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1032
|
-
resourcesUseableMap[m.id] = res.usable;
|
|
1033
|
-
}
|
|
1034
|
-
return res.usable;
|
|
1035
|
-
});
|
|
1036
|
-
if (m.onlyComputed)
|
|
1037
|
-
return false;
|
|
1038
|
-
return !canUseArr.some((n2) => n2 === false);
|
|
1039
|
-
});
|
|
1040
|
-
});
|
|
1041
|
-
} else {
|
|
1042
|
-
productResources.forEach((item) => {
|
|
1043
|
-
item.renderList = item.renderList.filter((n) => {
|
|
1044
|
-
var _a2, _b2;
|
|
1045
|
-
const recordCount = n.capacity || 0;
|
|
1046
|
-
if (n.onlyComputed)
|
|
1047
|
-
return false;
|
|
1048
|
-
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1049
|
-
resource: n,
|
|
1050
|
-
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
|
|
1051
|
-
split: 10,
|
|
1052
|
-
currentDate: dateRange[0].date
|
|
1053
|
-
});
|
|
1054
|
-
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
1055
|
-
});
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
arr.push({
|
|
1059
|
-
id: cartItem.id,
|
|
1060
|
-
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1061
|
-
_id: cartItem._id,
|
|
1062
|
-
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1063
|
-
productResources
|
|
1064
|
-
});
|
|
1065
|
-
});
|
|
1066
|
-
const hasResource = arr.every(
|
|
1067
|
-
(n) => n.productResources.every((m) => m.renderList.length > 0)
|
|
952
|
+
const resourcesList = this.getResourcesList();
|
|
953
|
+
const hasResource = resourcesList.every(
|
|
954
|
+
(item) => item.resources.every((resource) => resource.renderList.length > 0)
|
|
1068
955
|
);
|
|
1069
956
|
return hasResource;
|
|
1070
957
|
}
|
|
1071
|
-
|
|
958
|
+
/**
|
|
959
|
+
* 给单个购物车里的商品获取资源列表,给 UI 用的
|
|
960
|
+
*
|
|
961
|
+
* @param {(string | number)} id
|
|
962
|
+
* @return {*}
|
|
963
|
+
* @memberof BookingByStepImpl
|
|
964
|
+
*/
|
|
1072
965
|
getResourcesListByCartItem(id) {
|
|
1073
|
-
var _a, _b
|
|
966
|
+
var _a, _b;
|
|
1074
967
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1075
968
|
const dateRange = this.store.date.getDateRange();
|
|
1076
969
|
const resources = [];
|
|
@@ -1084,11 +977,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1084
977
|
throw new Error(`没有找到${id}购物车商品`);
|
|
1085
978
|
}
|
|
1086
979
|
let selectedResources = [];
|
|
1087
|
-
const
|
|
1088
|
-
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1089
|
-
product_bundle: targetCartItem._origin.product.product_bundle
|
|
1090
|
-
});
|
|
1091
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
980
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
|
|
1092
981
|
if (targetCartItem.holder_id) {
|
|
1093
982
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1094
983
|
cartItems,
|
|
@@ -1104,7 +993,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1104
993
|
}
|
|
1105
994
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1106
995
|
resourcesMap,
|
|
1107
|
-
((
|
|
996
|
+
((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
1108
997
|
selectedResources,
|
|
1109
998
|
currentCapacity
|
|
1110
999
|
);
|
|
@@ -1129,21 +1018,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1129
1018
|
};
|
|
1130
1019
|
}
|
|
1131
1020
|
}
|
|
1132
|
-
// 通过资源列表和指定的资源 id,获取指定资源的时间切片
|
|
1133
|
-
getResourceTimeSlot({
|
|
1134
|
-
product,
|
|
1135
|
-
resources,
|
|
1136
|
-
currentResourceId
|
|
1137
|
-
}) {
|
|
1138
|
-
const dateRange = this.store.date.getDateRange();
|
|
1139
|
-
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1140
|
-
resource: resources.find((n) => n.id === currentResourceId),
|
|
1141
|
-
duration: product.duration.value,
|
|
1142
|
-
split: 10,
|
|
1143
|
-
currentDate: dateRange[0].date
|
|
1144
|
-
});
|
|
1145
|
-
return timeSlots;
|
|
1146
|
-
}
|
|
1147
1021
|
// 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
|
|
1148
1022
|
autoSelectAccountResources({
|
|
1149
1023
|
cartItem,
|
|
@@ -1175,11 +1049,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1175
1049
|
});
|
|
1176
1050
|
}
|
|
1177
1051
|
if (!AllResources.length) {
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1052
|
+
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
1053
|
+
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
1054
|
+
const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
|
|
1055
|
+
AllResources.push(...dateResources || []);
|
|
1056
|
+
} else {
|
|
1057
|
+
const dateList = this.store.date.getDateList();
|
|
1058
|
+
dateList.forEach((n) => {
|
|
1059
|
+
if (n.resource)
|
|
1060
|
+
AllResources.push(...n.resource);
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1183
1063
|
}
|
|
1184
1064
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1185
1065
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
@@ -1299,17 +1179,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1299
1179
|
const accountList = this.store.accountList.getAccounts();
|
|
1300
1180
|
const selectForCartResources = (cartItems2) => {
|
|
1301
1181
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
1302
|
-
const hasFlexibleProduct = cartItems2.some(
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1182
|
+
const hasFlexibleProduct = cartItems2.some(
|
|
1183
|
+
(item) => {
|
|
1184
|
+
var _a2, _b;
|
|
1185
|
+
return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
|
|
1186
|
+
}
|
|
1187
|
+
);
|
|
1306
1188
|
cartItems2.forEach((item, index) => {
|
|
1307
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1308
|
-
const
|
|
1309
|
-
capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
|
|
1310
|
-
product_bundle: item._origin.product.product_bundle
|
|
1311
|
-
});
|
|
1312
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1189
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1190
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
|
|
1313
1191
|
if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
|
|
1314
1192
|
recordTimeSlots = {
|
|
1315
1193
|
start_time: item._origin.start_time,
|
|
@@ -1319,16 +1197,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1319
1197
|
};
|
|
1320
1198
|
}
|
|
1321
1199
|
if (recordTimeSlots) {
|
|
1322
|
-
const currentResourceConfig = (
|
|
1200
|
+
const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
|
|
1323
1201
|
(n) => n.code === resources_code
|
|
1324
1202
|
);
|
|
1325
|
-
if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((
|
|
1203
|
+
if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct) {
|
|
1326
1204
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
1327
|
-
((
|
|
1205
|
+
((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
|
|
1328
1206
|
"minutes"
|
|
1329
1207
|
);
|
|
1330
1208
|
let end_at = start_at.add(
|
|
1331
|
-
((
|
|
1209
|
+
((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
|
|
1332
1210
|
"minutes"
|
|
1333
1211
|
);
|
|
1334
1212
|
recordTimeSlots = {
|
|
@@ -1361,7 +1239,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1361
1239
|
});
|
|
1362
1240
|
}
|
|
1363
1241
|
res.selectedResource.capacity = currentCapacity;
|
|
1364
|
-
(0,
|
|
1242
|
+
(0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
|
|
1365
1243
|
this.store.cart.updateItem({
|
|
1366
1244
|
_id: item._id,
|
|
1367
1245
|
// 这里要做去重,避免出现同样类型的资源被塞进同一个商品
|
|
@@ -1382,7 +1260,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1382
1260
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1383
1261
|
let selectedResources = [];
|
|
1384
1262
|
const resources2 = (0, import_lodash_es.cloneDeep)(
|
|
1385
|
-
((
|
|
1263
|
+
((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
|
|
1386
1264
|
);
|
|
1387
1265
|
const currentResourcesRenderList = [];
|
|
1388
1266
|
resources2.forEach((n) => {
|
|
@@ -1430,11 +1308,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1430
1308
|
return recordCount >= currentCapacity;
|
|
1431
1309
|
});
|
|
1432
1310
|
});
|
|
1433
|
-
const targetRenderList = (
|
|
1311
|
+
const targetRenderList = (_k = productResources.find(
|
|
1434
1312
|
(n) => n.code === resources_code
|
|
1435
|
-
)) == null ? void 0 :
|
|
1313
|
+
)) == null ? void 0 : _k.renderList;
|
|
1436
1314
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
1437
|
-
if ((
|
|
1315
|
+
if ((_l = item._origin.resources) == null ? void 0 : _l.some(
|
|
1438
1316
|
(n) => n.form_id === targetRenderList[0].form_id
|
|
1439
1317
|
)) {
|
|
1440
1318
|
return;
|
|
@@ -1446,7 +1324,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1446
1324
|
});
|
|
1447
1325
|
const targetResource = fastestResource || targetRenderList[0];
|
|
1448
1326
|
targetResource.capacity = currentCapacity;
|
|
1449
|
-
(0,
|
|
1327
|
+
(0, import_capacity.checkSubResourcesCapacity)(targetResource);
|
|
1450
1328
|
if (!selectResourcesMap[targetResource.id]) {
|
|
1451
1329
|
selectResourcesMap[targetResource.id] = currentCapacity;
|
|
1452
1330
|
} else {
|
|
@@ -1568,10 +1446,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1568
1446
|
];
|
|
1569
1447
|
}
|
|
1570
1448
|
const resourcesUseableMap = {};
|
|
1571
|
-
const hasFlexibleDuration = cartItems.some(
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1449
|
+
const hasFlexibleDuration = cartItems.some(
|
|
1450
|
+
(item) => {
|
|
1451
|
+
var _a2, _b2;
|
|
1452
|
+
return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
|
|
1453
|
+
}
|
|
1454
|
+
);
|
|
1575
1455
|
const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
|
|
1576
1456
|
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1577
1457
|
resourceIds,
|
|
@@ -1590,7 +1470,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1590
1470
|
submitTimeSlot(timeSlots) {
|
|
1591
1471
|
var _a, _b;
|
|
1592
1472
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1593
|
-
const allResources = this.store.date.getResourcesListByDate(
|
|
1473
|
+
const allResources = this.store.date.getResourcesListByDate(
|
|
1474
|
+
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1475
|
+
);
|
|
1594
1476
|
const itemsByAccount = cartItems.reduce(
|
|
1595
1477
|
(acc, item) => {
|
|
1596
1478
|
const holderId = item.holder_id;
|
|
@@ -1616,13 +1498,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1616
1498
|
value: 10
|
|
1617
1499
|
};
|
|
1618
1500
|
resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1619
|
-
const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1501
|
+
const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
|
|
1502
|
+
(n) => n.id === resource.id
|
|
1503
|
+
)) == null ? void 0 : _c.times;
|
|
1504
|
+
const resourcesEndTime = targetResourceTimes.reduce(
|
|
1505
|
+
(acc, curr) => {
|
|
1506
|
+
return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
|
|
1507
|
+
},
|
|
1508
|
+
targetResourceTimes[0]
|
|
1509
|
+
);
|
|
1510
|
+
const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
|
|
1511
|
+
"YYYY-MM-DD"
|
|
1512
|
+
);
|
|
1624
1513
|
const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
|
|
1625
|
-
const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
|
|
1514
|
+
const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
|
|
1515
|
+
(0, import_dayjs.default)(operatingBoundaryDateTime)
|
|
1516
|
+
) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
|
|
1626
1517
|
let formattedEndTime;
|
|
1627
1518
|
if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
|
|
1628
1519
|
const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
|
|
@@ -1633,10 +1524,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1633
1524
|
resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
|
|
1634
1525
|
} else {
|
|
1635
1526
|
resource.startTime = currentStartTime;
|
|
1636
|
-
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1637
|
-
((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10,
|
|
1638
|
-
"minutes"
|
|
1639
|
-
).format("YYYY-MM-DD HH:mm");
|
|
1527
|
+
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10, "minutes").format("YYYY-MM-DD HH:mm");
|
|
1640
1528
|
}
|
|
1641
1529
|
});
|
|
1642
1530
|
this.store.cart.updateItem({
|
|
@@ -1682,10 +1570,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1682
1570
|
if (targetProduct) {
|
|
1683
1571
|
const targetProductData = targetProduct.getData();
|
|
1684
1572
|
this.store.currentProduct = targetProduct;
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1573
|
+
if (targetProductData["schedule.ids"]) {
|
|
1574
|
+
const newScheduleArr = this.getScheduleDataByIds(
|
|
1575
|
+
targetProductData["schedule.ids"]
|
|
1576
|
+
);
|
|
1577
|
+
targetProduct.setOtherParams("schedule", newScheduleArr);
|
|
1578
|
+
} else if (targetProductData.duration) {
|
|
1579
|
+
const dateRange = this.store.date.getDateRange();
|
|
1580
|
+
if (!(dateRange == null ? void 0 : dateRange.length))
|
|
1581
|
+
return;
|
|
1582
|
+
this.getAvailableDate({
|
|
1583
|
+
startDate: dateRange[0].date,
|
|
1584
|
+
endDate: dateRange[dateRange.length - 1].date,
|
|
1585
|
+
products: [targetProductData]
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1689
1588
|
}
|
|
1690
1589
|
}
|
|
1691
1590
|
closeProductDetail() {
|
|
@@ -1742,7 +1641,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1742
1641
|
return -1;
|
|
1743
1642
|
return 0;
|
|
1744
1643
|
});
|
|
1745
|
-
const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
|
|
1644
|
+
const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
|
|
1645
|
+
(n) => n.status === 1
|
|
1646
|
+
)) == null ? void 0 : _f.id;
|
|
1746
1647
|
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1747
1648
|
const resourcesUseableMap = {};
|
|
1748
1649
|
let count = 0;
|
|
@@ -1778,7 +1679,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1778
1679
|
}
|
|
1779
1680
|
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1780
1681
|
});
|
|
1781
|
-
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1682
|
+
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1683
|
+
(n) => n === false
|
|
1684
|
+
) && // 只统计第一种资源的容量和 left
|
|
1685
|
+
m.form_id === firstEnabledResourceId) {
|
|
1782
1686
|
if (currentResourcesCount >= count) {
|
|
1783
1687
|
count = currentResourcesCount;
|
|
1784
1688
|
}
|
|
@@ -1800,63 +1704,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1800
1704
|
});
|
|
1801
1705
|
return formatScheduleTimeSlots;
|
|
1802
1706
|
}
|
|
1803
|
-
addProductToCart({
|
|
1804
|
-
product,
|
|
1805
|
-
date,
|
|
1806
|
-
account
|
|
1807
|
-
}) {
|
|
1808
|
-
const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
|
|
1809
|
-
const productData = { ...origin, product_variant_id };
|
|
1810
|
-
if (!account) {
|
|
1811
|
-
const activeAccount = this.getActiveAccount();
|
|
1812
|
-
if (activeAccount) {
|
|
1813
|
-
account = activeAccount;
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
if (rowKey) {
|
|
1817
|
-
const cartItems = this.store.cart.getItems();
|
|
1818
|
-
const targetCartItem = cartItems.find((n) => {
|
|
1819
|
-
var _a;
|
|
1820
|
-
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
1821
|
-
});
|
|
1822
|
-
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
1823
|
-
this.store.cart.updateItem({
|
|
1824
|
-
_id: targetCartItem._id,
|
|
1825
|
-
product: {
|
|
1826
|
-
...targetCartItem._productOrigin,
|
|
1827
|
-
quantity: (targetCartItem.num || 1) + quantity
|
|
1828
|
-
}
|
|
1829
|
-
});
|
|
1830
|
-
return;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
this.store.cart.addItem({
|
|
1834
|
-
product: productData,
|
|
1835
|
-
date,
|
|
1836
|
-
account,
|
|
1837
|
-
bundle,
|
|
1838
|
-
options,
|
|
1839
|
-
quantity
|
|
1840
|
-
});
|
|
1841
|
-
if (date) {
|
|
1842
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1843
|
-
const cartItemsByDate = cartItems.filter(
|
|
1844
|
-
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
1845
|
-
);
|
|
1846
|
-
if (cartItemsByDate.length) {
|
|
1847
|
-
cartItemsByDate.forEach((n) => {
|
|
1848
|
-
this.store.cart.removeItem(n._id);
|
|
1849
|
-
});
|
|
1850
|
-
}
|
|
1851
|
-
const dateRange = this.store.date.getDateRange();
|
|
1852
|
-
if ((dateRange == null ? void 0 : dateRange[0]) && !(0, import_dayjs.default)(dateRange[0].date).isSame((0, import_dayjs.default)(date.startTime), "day")) {
|
|
1853
|
-
this.setDateRange([
|
|
1854
|
-
{ date: (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 },
|
|
1855
|
-
{ date: (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 }
|
|
1856
|
-
]);
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
1707
|
setOtherData(key, value) {
|
|
1861
1708
|
this.otherData[key] = value;
|
|
1862
1709
|
this.checkSaveCache({
|
|
@@ -1885,7 +1732,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1885
1732
|
* @memberof BookingByStepImpl
|
|
1886
1733
|
*/
|
|
1887
1734
|
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
1888
|
-
var _a, _b
|
|
1735
|
+
var _a, _b;
|
|
1889
1736
|
const dateRange = this.store.date.getDateRange();
|
|
1890
1737
|
const resources = [];
|
|
1891
1738
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -1907,12 +1754,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1907
1754
|
if (!cartItem)
|
|
1908
1755
|
return [];
|
|
1909
1756
|
let selectedResources = [];
|
|
1910
|
-
const formatCapacity = (0,
|
|
1911
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1912
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
1913
|
-
});
|
|
1757
|
+
const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
1914
1758
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
1915
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1916
1759
|
if (cartItem.holder_id) {
|
|
1917
1760
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1918
1761
|
cartItems,
|
|
@@ -1928,7 +1771,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1928
1771
|
}
|
|
1929
1772
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1930
1773
|
resourcesMap,
|
|
1931
|
-
((
|
|
1774
|
+
((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
1932
1775
|
selectedResources,
|
|
1933
1776
|
currentCapacity
|
|
1934
1777
|
);
|
|
@@ -1947,9 +1790,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1947
1790
|
const resourcesUseableMap = {};
|
|
1948
1791
|
targetResource.renderList = targetResource.renderList.sort(
|
|
1949
1792
|
(a, b) => {
|
|
1950
|
-
var _a2, _b2,
|
|
1793
|
+
var _a2, _b2, _c, _d;
|
|
1951
1794
|
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1952
|
-
const bIsCombined = ((_d = (
|
|
1795
|
+
const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1953
1796
|
if (aIsCombined && !bIsCombined)
|
|
1954
1797
|
return 1;
|
|
1955
1798
|
if (!aIsCombined && bIsCombined)
|
|
@@ -2036,56 +1879,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2036
1879
|
}
|
|
2037
1880
|
return results;
|
|
2038
1881
|
}
|
|
2039
|
-
async getAvailableDateForSession(params = {}) {
|
|
2040
|
-
let { startDate, endDate, type } = params;
|
|
2041
|
-
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"))) {
|
|
2042
|
-
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
2043
|
-
}
|
|
2044
|
-
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
2045
|
-
let tempProducts = [];
|
|
2046
|
-
if (this.store.currentProduct) {
|
|
2047
|
-
tempProducts = [
|
|
2048
|
-
{
|
|
2049
|
-
...this.store.currentProduct.getData(),
|
|
2050
|
-
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
2051
|
-
}
|
|
2052
|
-
];
|
|
2053
|
-
}
|
|
2054
|
-
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
2055
|
-
this.otherParams.currentResourcesMap = resourcesMap;
|
|
2056
|
-
const res = await this.store.date.getResourceDates({
|
|
2057
|
-
query: {
|
|
2058
|
-
start_date: startDate || "",
|
|
2059
|
-
end_date: endDate || "",
|
|
2060
|
-
resource_ids: resourceIds
|
|
2061
|
-
},
|
|
2062
|
-
rules,
|
|
2063
|
-
type
|
|
2064
|
-
});
|
|
2065
|
-
if (this.store.currentProduct) {
|
|
2066
|
-
const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
|
|
2067
|
-
startDate: startDate || "",
|
|
2068
|
-
endDate: endDate || ""
|
|
2069
|
-
});
|
|
2070
|
-
res.forEach((n) => {
|
|
2071
|
-
if (!dateListWithTimeSlots[n.date]) {
|
|
2072
|
-
n.status = "unavailable";
|
|
2073
|
-
} else {
|
|
2074
|
-
const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
|
|
2075
|
-
(d) => d.count
|
|
2076
|
-
);
|
|
2077
|
-
if (!allTimeSlotsCanUse) {
|
|
2078
|
-
n.status = "unavailable";
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
const firstAvailableDate = res.find((n) => n.status === "available");
|
|
2084
|
-
return {
|
|
2085
|
-
dateList: res,
|
|
2086
|
-
firstAvailableDate
|
|
2087
|
-
};
|
|
2088
|
-
}
|
|
2089
1882
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
2090
1883
|
var _a, _b, _c, _d, _e, _f;
|
|
2091
1884
|
let { startDate, endDate } = params;
|
|
@@ -2093,14 +1886,29 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2093
1886
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
2094
1887
|
}
|
|
2095
1888
|
const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1889
|
+
let tempEndDate = endDateAfterMonth;
|
|
2096
1890
|
if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
|
|
2097
|
-
|
|
1891
|
+
tempEndDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
|
|
2098
1892
|
} else {
|
|
2099
|
-
|
|
1893
|
+
tempEndDate = endDateAfterMonth;
|
|
1894
|
+
}
|
|
1895
|
+
if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
|
|
1896
|
+
tempEndDate = endDate || "";
|
|
1897
|
+
}
|
|
1898
|
+
endDate = tempEndDate;
|
|
1899
|
+
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
1900
|
+
if (cache) {
|
|
1901
|
+
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")) {
|
|
1902
|
+
this.store.date.setDateList(cache.dateList);
|
|
1903
|
+
return {
|
|
1904
|
+
dateList: cache.dateList,
|
|
1905
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
2100
1908
|
}
|
|
2101
1909
|
let tempProducts;
|
|
2102
|
-
tempProducts = (
|
|
2103
|
-
const schedule = (
|
|
1910
|
+
tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
|
|
1911
|
+
const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
|
|
2104
1912
|
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
2105
1913
|
schedule,
|
|
2106
1914
|
startDate || "",
|
|
@@ -2114,16 +1922,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2114
1922
|
resource_ids: tempResourceIds
|
|
2115
1923
|
}
|
|
2116
1924
|
});
|
|
2117
|
-
const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
|
|
2118
|
-
if (cache) {
|
|
2119
|
-
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")) {
|
|
2120
|
-
this.store.date.setDateList(cache.dateList);
|
|
2121
|
-
return {
|
|
2122
|
-
dateList: cache.dateList,
|
|
2123
|
-
firstAvailableDate: cache.firstAvailableDate
|
|
2124
|
-
};
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
1925
|
let dates = [];
|
|
2128
1926
|
let currentDate = (0, import_dayjs.default)(startDate);
|
|
2129
1927
|
let firstAvailableDate = "";
|
|
@@ -2183,25 +1981,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2183
1981
|
if (mTimes.length === 0) {
|
|
2184
1982
|
return;
|
|
2185
1983
|
}
|
|
2186
|
-
const targetCanUseTimes = mTimes.some(
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
resourcesUseableMap[m.id]
|
|
1984
|
+
const targetCanUseTimes = mTimes.some(
|
|
1985
|
+
(childTiem) => {
|
|
1986
|
+
const res2 = (0, import_resources.getIsUsableByTimeItem)({
|
|
1987
|
+
timeSlice: {
|
|
1988
|
+
start_time: item.start,
|
|
1989
|
+
end_time: item.end,
|
|
1990
|
+
start_at: (0, import_dayjs.default)(item.start),
|
|
1991
|
+
end_at: (0, import_dayjs.default)(item.end)
|
|
1992
|
+
},
|
|
1993
|
+
time: childTiem,
|
|
1994
|
+
resource: m,
|
|
1995
|
+
currentCount: 1,
|
|
1996
|
+
resourcesUseableMap,
|
|
1997
|
+
cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
|
|
1998
|
+
});
|
|
1999
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
|
|
2000
|
+
resourcesUseableMap[m.id] = res2.usable;
|
|
2001
|
+
}
|
|
2002
|
+
return res2.usable && !m.onlyComputed;
|
|
2202
2003
|
}
|
|
2203
|
-
|
|
2204
|
-
});
|
|
2004
|
+
);
|
|
2205
2005
|
return targetCanUseTimes;
|
|
2206
2006
|
});
|
|
2207
2007
|
});
|
|
@@ -2249,6 +2049,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2249
2049
|
});
|
|
2250
2050
|
}
|
|
2251
2051
|
isTargetNormalProduct(product) {
|
|
2052
|
+
if (!product)
|
|
2053
|
+
return false;
|
|
2252
2054
|
return (0, import_utils4.isNormalProduct)(product);
|
|
2253
2055
|
}
|
|
2254
2056
|
isTargetCartIdNormalProduct(id) {
|