@pisell/pisellos 3.0.41 → 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/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +74 -10
- package/dist/modules/Date/types.d.ts +2 -0
- 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/modules/Schedule/utils.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +121 -30
- package/dist/solution/BookingByStep/index.js +760 -1065
- 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/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -5
- package/lib/modules/Date/types.d.ts +2 -0
- 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/modules/Schedule/utils.js +4 -1
- package/lib/solution/BookingByStep/index.d.ts +121 -30
- package/lib/solution/BookingByStep/index.js +395 -585
- 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);
|
|
@@ -469,7 +389,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
469
389
|
// 获取商品/服务的可用日期
|
|
470
390
|
async getAvailableDate(params = {}) {
|
|
471
391
|
var _a, _b, _c;
|
|
472
|
-
let { products, startDate, endDate, type } = params;
|
|
392
|
+
let { products, startDate, endDate, type, useCache = true } = params;
|
|
473
393
|
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"))) {
|
|
474
394
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
475
395
|
}
|
|
@@ -506,7 +426,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
506
426
|
resource_ids: resourceIds
|
|
507
427
|
},
|
|
508
428
|
rules,
|
|
509
|
-
type
|
|
429
|
+
type,
|
|
430
|
+
useCache
|
|
510
431
|
});
|
|
511
432
|
return res;
|
|
512
433
|
}
|
|
@@ -549,7 +470,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
549
470
|
if (cartItems.length) {
|
|
550
471
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
551
472
|
if (!date) {
|
|
552
|
-
const normalProductCartItem = cartItems.find(
|
|
473
|
+
const normalProductCartItem = cartItems.find(
|
|
474
|
+
(n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
|
|
475
|
+
);
|
|
553
476
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
554
477
|
}
|
|
555
478
|
this.updateQuotationPriceAndCart(date);
|
|
@@ -582,7 +505,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
582
505
|
const cartItems = this.store.cart.getItems();
|
|
583
506
|
const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
|
|
584
507
|
newCartItems.forEach((item) => {
|
|
585
|
-
var _a
|
|
508
|
+
var _a;
|
|
586
509
|
if (item._origin.resources && item._origin.resources.length) {
|
|
587
510
|
item._origin.resources = item._origin.resources.map((n) => {
|
|
588
511
|
const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
|
|
@@ -591,12 +514,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
591
514
|
delete newResourcesItem.resourceType;
|
|
592
515
|
return { ...newResourcesItem };
|
|
593
516
|
});
|
|
594
|
-
const formatCapacity = (0,
|
|
595
|
-
|
|
596
|
-
product_bundle: item._origin.product.product_bundle
|
|
597
|
-
});
|
|
598
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
599
|
-
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)) {
|
|
600
519
|
item._origin.metadata = {};
|
|
601
520
|
}
|
|
602
521
|
item._origin.metadata.capacity = formatCapacity;
|
|
@@ -604,10 +523,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
604
523
|
}
|
|
605
524
|
});
|
|
606
525
|
let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
607
|
-
if ((0, import_utils4.areAllNormalProducts)(
|
|
526
|
+
if ((0, import_utils4.areAllNormalProducts)(
|
|
527
|
+
newCartItems.map((n) => n._productOrigin)
|
|
528
|
+
)) {
|
|
608
529
|
type = "virtual";
|
|
609
530
|
}
|
|
610
|
-
return this.store.order.submitOrder({
|
|
531
|
+
return this.store.order.submitOrder({
|
|
532
|
+
query: { cartItems: newCartItems, type }
|
|
533
|
+
});
|
|
611
534
|
}
|
|
612
535
|
// 拉起支付模块
|
|
613
536
|
async pay() {
|
|
@@ -625,31 +548,136 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
625
548
|
async getOtherParams() {
|
|
626
549
|
return this.otherParams;
|
|
627
550
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
+
}
|
|
634
599
|
}
|
|
635
|
-
|
|
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) {
|
|
636
645
|
if (params.resources) {
|
|
637
|
-
const
|
|
638
|
-
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
639
|
-
product_bundle: targetCartItem._origin.product.product_bundle
|
|
640
|
-
});
|
|
641
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
646
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
|
|
642
647
|
params.resources = params.resources.map((n) => {
|
|
643
648
|
n.capacity = currentCapacity || 1;
|
|
644
|
-
|
|
645
|
-
(0, import_resources.checkSubResourcesCapacity)(n);
|
|
649
|
+
(0, import_capacity.checkSubResourcesCapacity)(n);
|
|
646
650
|
return n;
|
|
647
651
|
});
|
|
648
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);
|
|
649
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;
|
|
650
674
|
if (this.otherParams.isRetailTemplate) {
|
|
651
675
|
return;
|
|
652
676
|
}
|
|
677
|
+
let currentResourcesCapacityMap = {};
|
|
678
|
+
(_a = params.resources) == null ? void 0 : _a.forEach((n) => {
|
|
679
|
+
currentResourcesCapacityMap[n.id] = n.capacity;
|
|
680
|
+
});
|
|
653
681
|
const allOriginResources = [];
|
|
654
682
|
const dateRange = this.store.date.getDateRange();
|
|
655
683
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -670,50 +698,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
670
698
|
cartItems.forEach((item) => {
|
|
671
699
|
var _a2;
|
|
672
700
|
if (item._id !== targetCartItem._id) {
|
|
701
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
|
|
673
702
|
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
674
|
-
const sameFormIdResources =
|
|
703
|
+
const sameFormIdResources = (0, import_resources.filterResourcesByFormItem)(
|
|
704
|
+
targetCartItem._origin.resources,
|
|
705
|
+
m.form_id
|
|
706
|
+
);
|
|
675
707
|
if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
|
|
676
708
|
return true;
|
|
677
709
|
}
|
|
678
710
|
return !sameFormIdResources.some((targetRes) => {
|
|
679
|
-
var _a3, _b, _c;
|
|
680
711
|
if (targetRes.resourceType !== "single") {
|
|
681
|
-
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
682
|
-
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
683
|
-
product_bundle: item._origin.product.product_bundle
|
|
684
|
-
});
|
|
685
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
686
|
-
capacity: formatCapacity
|
|
687
|
-
});
|
|
688
712
|
const originResource = allOriginResources.find(
|
|
689
713
|
(n) => n.id === targetRes.id
|
|
690
714
|
);
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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;
|
|
696
723
|
}
|
|
697
724
|
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
698
|
-
|
|
699
|
-
return true;
|
|
700
|
-
if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
701
|
-
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
702
|
-
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
703
|
-
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
704
|
-
m.id
|
|
705
|
-
) || targetRes.metadata.combined_resource.resource_ids.some(
|
|
706
|
-
(n) => {
|
|
707
|
-
return m.metadata.combined_resource.resource_ids.includes(
|
|
708
|
-
n
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
)))
|
|
712
|
-
return true;
|
|
713
|
-
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
714
|
-
targetRes.id
|
|
715
|
-
))
|
|
716
|
-
return true;
|
|
725
|
+
return (0, import_resources.checkTwoResourcesIntersection)(targetRes, m);
|
|
717
726
|
}
|
|
718
727
|
return false;
|
|
719
728
|
});
|
|
@@ -814,25 +823,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
814
823
|
resources.push(...n.resource);
|
|
815
824
|
});
|
|
816
825
|
}
|
|
826
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
817
827
|
if (!resources.length) {
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
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
|
+
}
|
|
823
839
|
}
|
|
824
840
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
825
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
826
841
|
const arr = [];
|
|
827
842
|
cartItems.forEach((cartItem) => {
|
|
828
|
-
var _a, _b, _c, _d, _e, _f
|
|
843
|
+
var _a, _b, _c, _d, _e, _f;
|
|
829
844
|
let selectedResources = [];
|
|
830
|
-
const formatCapacity = (0,
|
|
831
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
832
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
833
|
-
});
|
|
845
|
+
const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
834
846
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
835
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
836
847
|
if (cartItem.holder_id) {
|
|
837
848
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
838
849
|
cartItems,
|
|
@@ -848,7 +859,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
848
859
|
}
|
|
849
860
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
850
861
|
resourcesMap,
|
|
851
|
-
((
|
|
862
|
+
((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
852
863
|
selectedResources,
|
|
853
864
|
currentCapacity
|
|
854
865
|
);
|
|
@@ -861,20 +872,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
861
872
|
);
|
|
862
873
|
const resourcesUseableMap = {};
|
|
863
874
|
productResources.forEach((n) => {
|
|
864
|
-
n.renderList =
|
|
865
|
-
var _a2, _b2, _c2, _d2;
|
|
866
|
-
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
867
|
-
const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
|
|
868
|
-
if (aIsCombined && !bIsCombined)
|
|
869
|
-
return 1;
|
|
870
|
-
if (!aIsCombined && bIsCombined)
|
|
871
|
-
return -1;
|
|
872
|
-
return 0;
|
|
873
|
-
});
|
|
875
|
+
n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
|
|
874
876
|
n.renderList = n.renderList.filter((m) => {
|
|
875
|
-
const mTimes =
|
|
876
|
-
|
|
877
|
-
|
|
877
|
+
const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
|
|
878
|
+
m.times,
|
|
879
|
+
startTime,
|
|
880
|
+
endTime
|
|
881
|
+
);
|
|
878
882
|
if (mTimes.length === 0) {
|
|
879
883
|
return false;
|
|
880
884
|
}
|
|
@@ -904,8 +908,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
904
908
|
});
|
|
905
909
|
});
|
|
906
910
|
} else {
|
|
907
|
-
const hasFlexibleDuration = ((
|
|
908
|
-
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;
|
|
909
913
|
productResources.forEach((item) => {
|
|
910
914
|
item.renderList = item.renderList.filter((n) => {
|
|
911
915
|
var _a2, _b2, _c2;
|
|
@@ -938,138 +942,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
938
942
|
});
|
|
939
943
|
return arr;
|
|
940
944
|
}
|
|
941
|
-
|
|
945
|
+
/**
|
|
946
|
+
* 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
947
|
+
*
|
|
948
|
+
* @return {*}
|
|
949
|
+
* @memberof BookingByStepImpl
|
|
950
|
+
*/
|
|
942
951
|
checkResourceListForDate() {
|
|
943
|
-
const
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
dateRange.forEach((n) => {
|
|
947
|
-
if (n.resource)
|
|
948
|
-
resources.push(...n.resource);
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
if (!resources.length) {
|
|
952
|
-
const dateList = this.store.date.getDateList();
|
|
953
|
-
dateList.forEach((n) => {
|
|
954
|
-
if (n.resource)
|
|
955
|
-
resources.push(...n.resource);
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
959
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
960
|
-
const arr = [];
|
|
961
|
-
cartItems.forEach((cartItem) => {
|
|
962
|
-
var _a, _b, _c;
|
|
963
|
-
let selectedResources = [];
|
|
964
|
-
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
965
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
966
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
967
|
-
});
|
|
968
|
-
cartItem._origin.metadata.capacity = formatCapacity;
|
|
969
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
970
|
-
if (cartItem.holder_id) {
|
|
971
|
-
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
972
|
-
cartItems,
|
|
973
|
-
cartItem.holder_id,
|
|
974
|
-
resourcesMap
|
|
975
|
-
);
|
|
976
|
-
} else {
|
|
977
|
-
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
978
|
-
cartItems,
|
|
979
|
-
cartItem._id,
|
|
980
|
-
resourcesMap
|
|
981
|
-
);
|
|
982
|
-
}
|
|
983
|
-
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
984
|
-
resourcesMap,
|
|
985
|
-
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
986
|
-
selectedResources,
|
|
987
|
-
currentCapacity
|
|
988
|
-
);
|
|
989
|
-
if (cartItem._origin.start_time) {
|
|
990
|
-
const startTime = (0, import_dayjs.default)(
|
|
991
|
-
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
992
|
-
);
|
|
993
|
-
const endTime = (0, import_dayjs.default)(
|
|
994
|
-
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
995
|
-
);
|
|
996
|
-
const resourcesUseableMap = {};
|
|
997
|
-
productResources.forEach((n) => {
|
|
998
|
-
n.renderList = n.renderList.sort((a, b) => {
|
|
999
|
-
var _a2, _b2, _c2, _d;
|
|
1000
|
-
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1001
|
-
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1002
|
-
if (aIsCombined && !bIsCombined)
|
|
1003
|
-
return 1;
|
|
1004
|
-
if (!aIsCombined && bIsCombined)
|
|
1005
|
-
return -1;
|
|
1006
|
-
return 0;
|
|
1007
|
-
});
|
|
1008
|
-
n.renderList = n.renderList.filter((m) => {
|
|
1009
|
-
const mTimes = m.times.filter((n2) => {
|
|
1010
|
-
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));
|
|
1011
|
-
});
|
|
1012
|
-
if (mTimes.length === 0) {
|
|
1013
|
-
return false;
|
|
1014
|
-
}
|
|
1015
|
-
const canUseArr = mTimes.map((item) => {
|
|
1016
|
-
var _a2;
|
|
1017
|
-
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1018
|
-
timeSlice: {
|
|
1019
|
-
start_time: startTime.format("HH:mm"),
|
|
1020
|
-
end_time: endTime.format("HH:mm"),
|
|
1021
|
-
start_at: startTime,
|
|
1022
|
-
end_at: endTime
|
|
1023
|
-
},
|
|
1024
|
-
time: item,
|
|
1025
|
-
resource: m,
|
|
1026
|
-
currentCount: currentCapacity || 0,
|
|
1027
|
-
resourcesUseableMap,
|
|
1028
|
-
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1029
|
-
});
|
|
1030
|
-
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1031
|
-
resourcesUseableMap[m.id] = res.usable;
|
|
1032
|
-
}
|
|
1033
|
-
return res.usable;
|
|
1034
|
-
});
|
|
1035
|
-
if (m.onlyComputed)
|
|
1036
|
-
return false;
|
|
1037
|
-
return !canUseArr.some((n2) => n2 === false);
|
|
1038
|
-
});
|
|
1039
|
-
});
|
|
1040
|
-
} else {
|
|
1041
|
-
productResources.forEach((item) => {
|
|
1042
|
-
item.renderList = item.renderList.filter((n) => {
|
|
1043
|
-
var _a2, _b2;
|
|
1044
|
-
const recordCount = n.capacity || 0;
|
|
1045
|
-
if (n.onlyComputed)
|
|
1046
|
-
return false;
|
|
1047
|
-
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1048
|
-
resource: n,
|
|
1049
|
-
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
|
|
1050
|
-
split: 10,
|
|
1051
|
-
currentDate: dateRange[0].date
|
|
1052
|
-
});
|
|
1053
|
-
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
1054
|
-
});
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
arr.push({
|
|
1058
|
-
id: cartItem.id,
|
|
1059
|
-
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1060
|
-
_id: cartItem._id,
|
|
1061
|
-
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1062
|
-
productResources
|
|
1063
|
-
});
|
|
1064
|
-
});
|
|
1065
|
-
const hasResource = arr.every(
|
|
1066
|
-
(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)
|
|
1067
955
|
);
|
|
1068
956
|
return hasResource;
|
|
1069
957
|
}
|
|
1070
|
-
|
|
958
|
+
/**
|
|
959
|
+
* 给单个购物车里的商品获取资源列表,给 UI 用的
|
|
960
|
+
*
|
|
961
|
+
* @param {(string | number)} id
|
|
962
|
+
* @return {*}
|
|
963
|
+
* @memberof BookingByStepImpl
|
|
964
|
+
*/
|
|
1071
965
|
getResourcesListByCartItem(id) {
|
|
1072
|
-
var _a, _b
|
|
966
|
+
var _a, _b;
|
|
1073
967
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1074
968
|
const dateRange = this.store.date.getDateRange();
|
|
1075
969
|
const resources = [];
|
|
@@ -1083,11 +977,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1083
977
|
throw new Error(`没有找到${id}购物车商品`);
|
|
1084
978
|
}
|
|
1085
979
|
let selectedResources = [];
|
|
1086
|
-
const
|
|
1087
|
-
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1088
|
-
product_bundle: targetCartItem._origin.product.product_bundle
|
|
1089
|
-
});
|
|
1090
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
980
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
|
|
1091
981
|
if (targetCartItem.holder_id) {
|
|
1092
982
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1093
983
|
cartItems,
|
|
@@ -1103,7 +993,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1103
993
|
}
|
|
1104
994
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1105
995
|
resourcesMap,
|
|
1106
|
-
((
|
|
996
|
+
((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
1107
997
|
selectedResources,
|
|
1108
998
|
currentCapacity
|
|
1109
999
|
);
|
|
@@ -1128,21 +1018,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1128
1018
|
};
|
|
1129
1019
|
}
|
|
1130
1020
|
}
|
|
1131
|
-
// 通过资源列表和指定的资源 id,获取指定资源的时间切片
|
|
1132
|
-
getResourceTimeSlot({
|
|
1133
|
-
product,
|
|
1134
|
-
resources,
|
|
1135
|
-
currentResourceId
|
|
1136
|
-
}) {
|
|
1137
|
-
const dateRange = this.store.date.getDateRange();
|
|
1138
|
-
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1139
|
-
resource: resources.find((n) => n.id === currentResourceId),
|
|
1140
|
-
duration: product.duration.value,
|
|
1141
|
-
split: 10,
|
|
1142
|
-
currentDate: dateRange[0].date
|
|
1143
|
-
});
|
|
1144
|
-
return timeSlots;
|
|
1145
|
-
}
|
|
1146
1021
|
// 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
|
|
1147
1022
|
autoSelectAccountResources({
|
|
1148
1023
|
cartItem,
|
|
@@ -1174,11 +1049,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1174
1049
|
});
|
|
1175
1050
|
}
|
|
1176
1051
|
if (!AllResources.length) {
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
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
|
+
}
|
|
1182
1063
|
}
|
|
1183
1064
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1184
1065
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
@@ -1298,17 +1179,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1298
1179
|
const accountList = this.store.accountList.getAccounts();
|
|
1299
1180
|
const selectForCartResources = (cartItems2) => {
|
|
1300
1181
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
1301
|
-
const hasFlexibleProduct = cartItems2.some(
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
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
|
+
);
|
|
1305
1188
|
cartItems2.forEach((item, index) => {
|
|
1306
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l
|
|
1307
|
-
const
|
|
1308
|
-
capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
|
|
1309
|
-
product_bundle: item._origin.product.product_bundle
|
|
1310
|
-
});
|
|
1311
|
-
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);
|
|
1312
1191
|
if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
|
|
1313
1192
|
recordTimeSlots = {
|
|
1314
1193
|
start_time: item._origin.start_time,
|
|
@@ -1318,16 +1197,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1318
1197
|
};
|
|
1319
1198
|
}
|
|
1320
1199
|
if (recordTimeSlots) {
|
|
1321
|
-
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(
|
|
1322
1201
|
(n) => n.code === resources_code
|
|
1323
1202
|
);
|
|
1324
|
-
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) {
|
|
1325
1204
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
1326
|
-
((
|
|
1205
|
+
((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
|
|
1327
1206
|
"minutes"
|
|
1328
1207
|
);
|
|
1329
1208
|
let end_at = start_at.add(
|
|
1330
|
-
((
|
|
1209
|
+
((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
|
|
1331
1210
|
"minutes"
|
|
1332
1211
|
);
|
|
1333
1212
|
recordTimeSlots = {
|
|
@@ -1360,7 +1239,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1360
1239
|
});
|
|
1361
1240
|
}
|
|
1362
1241
|
res.selectedResource.capacity = currentCapacity;
|
|
1363
|
-
(0,
|
|
1242
|
+
(0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
|
|
1364
1243
|
this.store.cart.updateItem({
|
|
1365
1244
|
_id: item._id,
|
|
1366
1245
|
// 这里要做去重,避免出现同样类型的资源被塞进同一个商品
|
|
@@ -1381,7 +1260,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1381
1260
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1382
1261
|
let selectedResources = [];
|
|
1383
1262
|
const resources2 = (0, import_lodash_es.cloneDeep)(
|
|
1384
|
-
((
|
|
1263
|
+
((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
|
|
1385
1264
|
);
|
|
1386
1265
|
const currentResourcesRenderList = [];
|
|
1387
1266
|
resources2.forEach((n) => {
|
|
@@ -1429,11 +1308,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1429
1308
|
return recordCount >= currentCapacity;
|
|
1430
1309
|
});
|
|
1431
1310
|
});
|
|
1432
|
-
const targetRenderList = (
|
|
1311
|
+
const targetRenderList = (_k = productResources.find(
|
|
1433
1312
|
(n) => n.code === resources_code
|
|
1434
|
-
)) == null ? void 0 :
|
|
1313
|
+
)) == null ? void 0 : _k.renderList;
|
|
1435
1314
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
1436
|
-
if ((
|
|
1315
|
+
if ((_l = item._origin.resources) == null ? void 0 : _l.some(
|
|
1437
1316
|
(n) => n.form_id === targetRenderList[0].form_id
|
|
1438
1317
|
)) {
|
|
1439
1318
|
return;
|
|
@@ -1445,7 +1324,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1445
1324
|
});
|
|
1446
1325
|
const targetResource = fastestResource || targetRenderList[0];
|
|
1447
1326
|
targetResource.capacity = currentCapacity;
|
|
1448
|
-
(0,
|
|
1327
|
+
(0, import_capacity.checkSubResourcesCapacity)(targetResource);
|
|
1449
1328
|
if (!selectResourcesMap[targetResource.id]) {
|
|
1450
1329
|
selectResourcesMap[targetResource.id] = currentCapacity;
|
|
1451
1330
|
} else {
|
|
@@ -1567,10 +1446,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1567
1446
|
];
|
|
1568
1447
|
}
|
|
1569
1448
|
const resourcesUseableMap = {};
|
|
1570
|
-
const hasFlexibleDuration = cartItems.some(
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
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
|
+
);
|
|
1574
1455
|
const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
|
|
1575
1456
|
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1576
1457
|
resourceIds,
|
|
@@ -1589,7 +1470,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1589
1470
|
submitTimeSlot(timeSlots) {
|
|
1590
1471
|
var _a, _b;
|
|
1591
1472
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1592
|
-
const allResources = this.store.date.getResourcesListByDate(
|
|
1473
|
+
const allResources = this.store.date.getResourcesListByDate(
|
|
1474
|
+
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1475
|
+
);
|
|
1593
1476
|
const itemsByAccount = cartItems.reduce(
|
|
1594
1477
|
(acc, item) => {
|
|
1595
1478
|
const holderId = item.holder_id;
|
|
@@ -1615,13 +1498,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1615
1498
|
value: 10
|
|
1616
1499
|
};
|
|
1617
1500
|
resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1618
|
-
const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
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
|
+
);
|
|
1623
1513
|
const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
|
|
1624
|
-
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;
|
|
1625
1517
|
let formattedEndTime;
|
|
1626
1518
|
if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
|
|
1627
1519
|
const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
|
|
@@ -1632,10 +1524,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1632
1524
|
resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
|
|
1633
1525
|
} else {
|
|
1634
1526
|
resource.startTime = currentStartTime;
|
|
1635
|
-
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1636
|
-
((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10,
|
|
1637
|
-
"minutes"
|
|
1638
|
-
).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");
|
|
1639
1528
|
}
|
|
1640
1529
|
});
|
|
1641
1530
|
this.store.cart.updateItem({
|
|
@@ -1681,10 +1570,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1681
1570
|
if (targetProduct) {
|
|
1682
1571
|
const targetProductData = targetProduct.getData();
|
|
1683
1572
|
this.store.currentProduct = targetProduct;
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
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
|
+
}
|
|
1688
1588
|
}
|
|
1689
1589
|
}
|
|
1690
1590
|
closeProductDetail() {
|
|
@@ -1741,7 +1641,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1741
1641
|
return -1;
|
|
1742
1642
|
return 0;
|
|
1743
1643
|
});
|
|
1744
|
-
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;
|
|
1745
1647
|
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1746
1648
|
const resourcesUseableMap = {};
|
|
1747
1649
|
let count = 0;
|
|
@@ -1777,7 +1679,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1777
1679
|
}
|
|
1778
1680
|
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1779
1681
|
});
|
|
1780
|
-
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1682
|
+
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1683
|
+
(n) => n === false
|
|
1684
|
+
) && // 只统计第一种资源的容量和 left
|
|
1685
|
+
m.form_id === firstEnabledResourceId) {
|
|
1781
1686
|
if (currentResourcesCount >= count) {
|
|
1782
1687
|
count = currentResourcesCount;
|
|
1783
1688
|
}
|
|
@@ -1799,56 +1704,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1799
1704
|
});
|
|
1800
1705
|
return formatScheduleTimeSlots;
|
|
1801
1706
|
}
|
|
1802
|
-
addProductToCart({
|
|
1803
|
-
product,
|
|
1804
|
-
date,
|
|
1805
|
-
account
|
|
1806
|
-
}) {
|
|
1807
|
-
const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
|
|
1808
|
-
const productData = { ...origin, product_variant_id };
|
|
1809
|
-
if (!account) {
|
|
1810
|
-
const activeAccount = this.getActiveAccount();
|
|
1811
|
-
if (activeAccount) {
|
|
1812
|
-
account = activeAccount;
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
if (rowKey) {
|
|
1816
|
-
const cartItems = this.store.cart.getItems();
|
|
1817
|
-
const targetCartItem = cartItems.find((n) => {
|
|
1818
|
-
var _a;
|
|
1819
|
-
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
1820
|
-
});
|
|
1821
|
-
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
1822
|
-
this.store.cart.updateItem({
|
|
1823
|
-
_id: targetCartItem._id,
|
|
1824
|
-
product: {
|
|
1825
|
-
...targetCartItem._productOrigin,
|
|
1826
|
-
quantity: (targetCartItem.num || 1) + quantity
|
|
1827
|
-
}
|
|
1828
|
-
});
|
|
1829
|
-
return;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
this.store.cart.addItem({
|
|
1833
|
-
product: productData,
|
|
1834
|
-
date,
|
|
1835
|
-
account,
|
|
1836
|
-
bundle,
|
|
1837
|
-
options,
|
|
1838
|
-
quantity
|
|
1839
|
-
});
|
|
1840
|
-
if (date) {
|
|
1841
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1842
|
-
const cartItemsByDate = cartItems.filter(
|
|
1843
|
-
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
1844
|
-
);
|
|
1845
|
-
if (cartItemsByDate.length) {
|
|
1846
|
-
cartItemsByDate.forEach((n) => {
|
|
1847
|
-
this.store.cart.removeItem(n._id);
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
1707
|
setOtherData(key, value) {
|
|
1853
1708
|
this.otherData[key] = value;
|
|
1854
1709
|
this.checkSaveCache({
|
|
@@ -1877,7 +1732,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1877
1732
|
* @memberof BookingByStepImpl
|
|
1878
1733
|
*/
|
|
1879
1734
|
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
1880
|
-
var _a, _b
|
|
1735
|
+
var _a, _b;
|
|
1881
1736
|
const dateRange = this.store.date.getDateRange();
|
|
1882
1737
|
const resources = [];
|
|
1883
1738
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -1899,12 +1754,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1899
1754
|
if (!cartItem)
|
|
1900
1755
|
return [];
|
|
1901
1756
|
let selectedResources = [];
|
|
1902
|
-
const formatCapacity = (0,
|
|
1903
|
-
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1904
|
-
product_bundle: cartItem._origin.product.product_bundle
|
|
1905
|
-
});
|
|
1757
|
+
const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
1906
1758
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
1907
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1908
1759
|
if (cartItem.holder_id) {
|
|
1909
1760
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1910
1761
|
cartItems,
|
|
@@ -1920,7 +1771,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1920
1771
|
}
|
|
1921
1772
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1922
1773
|
resourcesMap,
|
|
1923
|
-
((
|
|
1774
|
+
((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
1924
1775
|
selectedResources,
|
|
1925
1776
|
currentCapacity
|
|
1926
1777
|
);
|
|
@@ -1939,9 +1790,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1939
1790
|
const resourcesUseableMap = {};
|
|
1940
1791
|
targetResource.renderList = targetResource.renderList.sort(
|
|
1941
1792
|
(a, b) => {
|
|
1942
|
-
var _a2, _b2,
|
|
1793
|
+
var _a2, _b2, _c, _d;
|
|
1943
1794
|
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1944
|
-
const bIsCombined = ((_d = (
|
|
1795
|
+
const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1945
1796
|
if (aIsCombined && !bIsCombined)
|
|
1946
1797
|
return 1;
|
|
1947
1798
|
if (!aIsCombined && bIsCombined)
|
|
@@ -2028,56 +1879,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2028
1879
|
}
|
|
2029
1880
|
return results;
|
|
2030
1881
|
}
|
|
2031
|
-
async getAvailableDateForSession(params = {}) {
|
|
2032
|
-
let { startDate, endDate, type } = params;
|
|
2033
|
-
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"))) {
|
|
2034
|
-
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
2035
|
-
}
|
|
2036
|
-
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
2037
|
-
let tempProducts = [];
|
|
2038
|
-
if (this.store.currentProduct) {
|
|
2039
|
-
tempProducts = [
|
|
2040
|
-
{
|
|
2041
|
-
...this.store.currentProduct.getData(),
|
|
2042
|
-
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
2043
|
-
}
|
|
2044
|
-
];
|
|
2045
|
-
}
|
|
2046
|
-
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
2047
|
-
this.otherParams.currentResourcesMap = resourcesMap;
|
|
2048
|
-
const res = await this.store.date.getResourceDates({
|
|
2049
|
-
query: {
|
|
2050
|
-
start_date: startDate || "",
|
|
2051
|
-
end_date: endDate || "",
|
|
2052
|
-
resource_ids: resourceIds
|
|
2053
|
-
},
|
|
2054
|
-
rules,
|
|
2055
|
-
type
|
|
2056
|
-
});
|
|
2057
|
-
if (this.store.currentProduct) {
|
|
2058
|
-
const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
|
|
2059
|
-
startDate: startDate || "",
|
|
2060
|
-
endDate: endDate || ""
|
|
2061
|
-
});
|
|
2062
|
-
res.forEach((n) => {
|
|
2063
|
-
if (!dateListWithTimeSlots[n.date]) {
|
|
2064
|
-
n.status = "unavailable";
|
|
2065
|
-
} else {
|
|
2066
|
-
const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
|
|
2067
|
-
(d) => d.count
|
|
2068
|
-
);
|
|
2069
|
-
if (!allTimeSlotsCanUse) {
|
|
2070
|
-
n.status = "unavailable";
|
|
2071
|
-
}
|
|
2072
|
-
}
|
|
2073
|
-
});
|
|
2074
|
-
}
|
|
2075
|
-
const firstAvailableDate = res.find((n) => n.status === "available");
|
|
2076
|
-
return {
|
|
2077
|
-
dateList: res,
|
|
2078
|
-
firstAvailableDate
|
|
2079
|
-
};
|
|
2080
|
-
}
|
|
2081
1882
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
2082
1883
|
var _a, _b, _c, _d, _e, _f;
|
|
2083
1884
|
let { startDate, endDate } = params;
|
|
@@ -2085,14 +1886,29 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2085
1886
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
2086
1887
|
}
|
|
2087
1888
|
const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1889
|
+
let tempEndDate = endDateAfterMonth;
|
|
2088
1890
|
if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
|
|
2089
|
-
|
|
1891
|
+
tempEndDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
|
|
2090
1892
|
} else {
|
|
2091
|
-
|
|
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
|
+
}
|
|
2092
1908
|
}
|
|
2093
1909
|
let tempProducts;
|
|
2094
|
-
tempProducts = (
|
|
2095
|
-
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"];
|
|
2096
1912
|
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
2097
1913
|
schedule,
|
|
2098
1914
|
startDate || "",
|
|
@@ -2106,16 +1922,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2106
1922
|
resource_ids: tempResourceIds
|
|
2107
1923
|
}
|
|
2108
1924
|
});
|
|
2109
|
-
const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
|
|
2110
|
-
if (cache) {
|
|
2111
|
-
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")) {
|
|
2112
|
-
this.store.date.setDateList(cache.dateList);
|
|
2113
|
-
return {
|
|
2114
|
-
dateList: cache.dateList,
|
|
2115
|
-
firstAvailableDate: cache.firstAvailableDate
|
|
2116
|
-
};
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
1925
|
let dates = [];
|
|
2120
1926
|
let currentDate = (0, import_dayjs.default)(startDate);
|
|
2121
1927
|
let firstAvailableDate = "";
|
|
@@ -2175,25 +1981,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2175
1981
|
if (mTimes.length === 0) {
|
|
2176
1982
|
return;
|
|
2177
1983
|
}
|
|
2178
|
-
const targetCanUseTimes = mTimes.some(
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
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;
|
|
2194
2003
|
}
|
|
2195
|
-
|
|
2196
|
-
});
|
|
2004
|
+
);
|
|
2197
2005
|
return targetCanUseTimes;
|
|
2198
2006
|
});
|
|
2199
2007
|
});
|
|
@@ -2211,7 +2019,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2211
2019
|
weekNum: (0, import_dayjs.default)(currentDate).day(),
|
|
2212
2020
|
status
|
|
2213
2021
|
});
|
|
2214
|
-
if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") >
|
|
2022
|
+
if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 31) {
|
|
2215
2023
|
break;
|
|
2216
2024
|
}
|
|
2217
2025
|
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
@@ -2241,6 +2049,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2241
2049
|
});
|
|
2242
2050
|
}
|
|
2243
2051
|
isTargetNormalProduct(product) {
|
|
2052
|
+
if (!product)
|
|
2053
|
+
return false;
|
|
2244
2054
|
return (0, import_utils4.isNormalProduct)(product);
|
|
2245
2055
|
}
|
|
2246
2056
|
isTargetCartIdNormalProduct(id) {
|