@pisell/pisellos 1.0.0 → 1.0.1
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/Cart/index.d.ts +0 -14
- package/dist/modules/Cart/index.js +0 -36
- package/dist/modules/Cart/utils/cartProduct.js +1 -10
- package/dist/modules/Date/index.js +6 -57
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +7 -15
- package/dist/modules/Discount/types.d.ts +0 -10
- package/dist/modules/ProductList/index.d.ts +0 -7
- package/dist/modules/ProductList/index.js +39 -102
- package/dist/modules/Rules/index.js +71 -196
- package/dist/modules/Rules/types.d.ts +0 -6
- package/dist/modules/Schedule/index.d.ts +1 -9
- package/dist/modules/Schedule/index.js +2 -122
- package/dist/modules/Schedule/types.d.ts +0 -13
- package/dist/solution/BookingByStep/index.d.ts +30 -120
- package/dist/solution/BookingByStep/index.js +1065 -750
- package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/dist/solution/BookingByStep/utils/resources.js +94 -39
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +32 -93
- package/lib/modules/Cart/index.d.ts +0 -14
- package/lib/modules/Cart/index.js +0 -32
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Date/index.js +10 -62
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +6 -18
- package/lib/modules/Discount/types.d.ts +0 -10
- package/lib/modules/ProductList/index.d.ts +0 -7
- package/lib/modules/ProductList/index.js +0 -45
- package/lib/modules/Rules/index.js +56 -147
- package/lib/modules/Rules/types.d.ts +0 -6
- package/lib/modules/Schedule/index.d.ts +1 -9
- package/lib/modules/Schedule/index.js +1 -79
- package/lib/modules/Schedule/types.d.ts +0 -13
- package/lib/solution/BookingByStep/index.d.ts +30 -120
- package/lib/solution/BookingByStep/index.js +581 -392
- package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/lib/solution/BookingByStep/utils/resources.js +59 -23
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +18 -85
- package/package.json +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
- package/dist/modules/Cart/utils/changePrice.js +0 -104
- package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/dist/solution/BookingByStep/utils/capacity.js +0 -132
- package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
- package/lib/modules/Cart/utils/changePrice.js +0 -78
- package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/lib/solution/BookingByStep/utils/capacity.js +0 -106
|
@@ -45,8 +45,6 @@ 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");
|
|
50
48
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
51
49
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
52
50
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -113,7 +111,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
113
111
|
throw new Error(`模块 ${step} 不存在`);
|
|
114
112
|
}
|
|
115
113
|
});
|
|
116
|
-
this.
|
|
114
|
+
this.loadAllSchedule();
|
|
117
115
|
this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
|
|
118
116
|
}
|
|
119
117
|
// 初始化step
|
|
@@ -160,52 +158,56 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
160
158
|
updateStep(key, step) {
|
|
161
159
|
this.store.step.updateStep(key, step);
|
|
162
160
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
*/
|
|
161
|
+
// 获取购物车里 temp.xxx的方法
|
|
162
|
+
// async getStoreCart(key?: string) {
|
|
163
|
+
// return this.store.cart.getTemp(key);
|
|
164
|
+
// }
|
|
165
|
+
// 加载商品,然后导到商品列表里去
|
|
180
166
|
async loadProducts({
|
|
181
167
|
category_ids = [],
|
|
182
168
|
product_ids = [],
|
|
183
169
|
collection = [],
|
|
170
|
+
// schedule_ids = [],
|
|
184
171
|
schedule_date
|
|
185
172
|
}) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
173
|
+
var _a;
|
|
174
|
+
let userPlugin = this.core.getPlugin("user");
|
|
175
|
+
let customer_id = void 0;
|
|
176
|
+
try {
|
|
177
|
+
customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error(error);
|
|
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;
|
|
193
210
|
}
|
|
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
|
-
*/
|
|
209
211
|
async loadProductByScheduleDate({
|
|
210
212
|
date,
|
|
211
213
|
product_ids = [],
|
|
@@ -226,17 +228,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
226
228
|
(n, index, self) => self.indexOf(n) === index
|
|
227
229
|
);
|
|
228
230
|
return await this.loadProducts({
|
|
231
|
+
// schedule_ids: scheduleIds,
|
|
229
232
|
product_ids: allProductIds,
|
|
230
233
|
category_ids,
|
|
231
234
|
schedule_date: date
|
|
232
235
|
});
|
|
233
236
|
}
|
|
234
|
-
/**
|
|
235
|
-
* 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
|
|
236
|
-
*
|
|
237
|
-
* @param {string} date
|
|
238
|
-
* @memberof BookingByStepImpl
|
|
239
|
-
*/
|
|
240
237
|
async updateQuotationPriceAndCart(date) {
|
|
241
238
|
var _a;
|
|
242
239
|
const cartItems = this.store.cart.getItems();
|
|
@@ -253,43 +250,129 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
253
250
|
schedule_date: date,
|
|
254
251
|
customer_id
|
|
255
252
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
253
|
+
for (const item of cartItems) {
|
|
254
|
+
const targetProduct = res.find((n) => n.id === item.id);
|
|
255
|
+
const cartProduct = await this.store.products.getProduct(
|
|
256
|
+
item.id
|
|
257
|
+
);
|
|
258
|
+
const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
|
|
259
|
+
let bundle = item._bundleOrigin;
|
|
260
|
+
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
261
|
+
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
262
|
+
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
263
|
+
var _a2;
|
|
264
|
+
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
265
|
+
(m) => m.id === n.group_id
|
|
266
|
+
);
|
|
267
|
+
if (targetBundle) {
|
|
268
|
+
const targetBundleItem = targetBundle.bundle_item.find(
|
|
269
|
+
(m) => m.id === n.id
|
|
270
|
+
);
|
|
271
|
+
if (targetBundleItem) {
|
|
272
|
+
return {
|
|
273
|
+
...n,
|
|
274
|
+
price: targetBundleItem.price,
|
|
275
|
+
base_price: targetBundleItem.base_price
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return n;
|
|
280
|
+
});
|
|
281
|
+
this.store.cart.updateItem({
|
|
282
|
+
_id: item._id,
|
|
283
|
+
product: productInfo,
|
|
284
|
+
bundle
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
|
|
266
288
|
}
|
|
267
289
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
* @memberof BookingByStepImpl
|
|
280
|
-
*/
|
|
290
|
+
// 加载当前店铺下所有 schedule
|
|
291
|
+
async loadAllSchedule() {
|
|
292
|
+
var _a;
|
|
293
|
+
const scheduleList = await this.request.get(
|
|
294
|
+
`/schedule`,
|
|
295
|
+
{ num: 999 },
|
|
296
|
+
{ useCache: true }
|
|
297
|
+
);
|
|
298
|
+
this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
|
|
299
|
+
}
|
|
300
|
+
// ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
|
|
281
301
|
async loadScheduleAvailableDate({
|
|
282
302
|
startDate,
|
|
283
303
|
endDate,
|
|
284
304
|
custom_page_id,
|
|
285
305
|
channel
|
|
286
306
|
}) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
307
|
+
var _a, _b, _c;
|
|
308
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
309
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
310
|
+
}
|
|
311
|
+
let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
|
|
312
|
+
dates = (0, import_utils3.disableAllDates)(dates);
|
|
313
|
+
if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
|
|
314
|
+
return dates;
|
|
315
|
+
}
|
|
316
|
+
const res = await this.request.get(
|
|
317
|
+
`/schedule/product/availability/v2`,
|
|
318
|
+
{
|
|
319
|
+
start_date: startDate,
|
|
320
|
+
end_date: endDate,
|
|
321
|
+
custom_page_id,
|
|
322
|
+
channel
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
|
|
326
|
+
this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
|
|
327
|
+
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")) {
|
|
328
|
+
return dates;
|
|
329
|
+
}
|
|
330
|
+
if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
|
|
331
|
+
dates.forEach((n) => {
|
|
332
|
+
n.status = "available";
|
|
333
|
+
});
|
|
334
|
+
} else {
|
|
335
|
+
res.data.date_list.forEach((n) => {
|
|
336
|
+
const index = dates.findIndex((m) => m.date === n.date);
|
|
337
|
+
if (index !== -1) {
|
|
338
|
+
dates[index].status = "available";
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
|
|
343
|
+
return dates;
|
|
344
|
+
}
|
|
345
|
+
async storeProduct(productData) {
|
|
346
|
+
const activeAccount = this.getActiveAccount();
|
|
347
|
+
const { bundle, options, origin, product_variant_id, quantity = 1, rowKey } = productData || {};
|
|
348
|
+
const cartItems = this.store.cart.getItems();
|
|
349
|
+
if (rowKey) {
|
|
350
|
+
const targetCartItem = cartItems.find((n) => {
|
|
351
|
+
var _a;
|
|
352
|
+
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
353
|
+
});
|
|
354
|
+
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
355
|
+
this.store.cart.updateItem({
|
|
356
|
+
_id: targetCartItem._id,
|
|
357
|
+
product: {
|
|
358
|
+
...targetCartItem._productOrigin
|
|
359
|
+
},
|
|
360
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
361
|
+
});
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const product = { ...origin, product_variant_id, rowKey };
|
|
366
|
+
const addCartItem = {
|
|
367
|
+
product,
|
|
368
|
+
bundle,
|
|
369
|
+
options,
|
|
370
|
+
quantity
|
|
371
|
+
};
|
|
372
|
+
if (activeAccount) {
|
|
373
|
+
addCartItem.account = activeAccount;
|
|
374
|
+
}
|
|
375
|
+
this.store.cart.addItem(addCartItem);
|
|
293
376
|
}
|
|
294
377
|
// 添加单个账户或者 guest
|
|
295
378
|
async addAccount(account, extra) {
|
|
@@ -342,8 +425,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
342
425
|
}
|
|
343
426
|
getActiveAccount() {
|
|
344
427
|
const activeAccount = this.store.accountList.getActiveAccount();
|
|
345
|
-
|
|
346
|
-
return account === null ? void 0 : account;
|
|
428
|
+
return activeAccount ? activeAccount.getAccount() : null;
|
|
347
429
|
}
|
|
348
430
|
removeAccount(id) {
|
|
349
431
|
this.store.accountList.removeAccount(id);
|
|
@@ -359,9 +441,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
359
441
|
if (cartItems.length) {
|
|
360
442
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
361
443
|
if (!date) {
|
|
362
|
-
const normalProductCartItem = cartItems.find(
|
|
363
|
-
(n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
|
|
364
|
-
);
|
|
444
|
+
const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
365
445
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
366
446
|
}
|
|
367
447
|
this.updateQuotationPriceAndCart(date);
|
|
@@ -468,9 +548,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
468
548
|
if (cartItems.length) {
|
|
469
549
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
470
550
|
if (!date) {
|
|
471
|
-
const normalProductCartItem = cartItems.find(
|
|
472
|
-
(n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
|
|
473
|
-
);
|
|
551
|
+
const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
474
552
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
475
553
|
}
|
|
476
554
|
this.updateQuotationPriceAndCart(date);
|
|
@@ -503,7 +581,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
503
581
|
const cartItems = this.store.cart.getItems();
|
|
504
582
|
const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
|
|
505
583
|
newCartItems.forEach((item) => {
|
|
506
|
-
var _a;
|
|
584
|
+
var _a, _b;
|
|
507
585
|
if (item._origin.resources && item._origin.resources.length) {
|
|
508
586
|
item._origin.resources = item._origin.resources.map((n) => {
|
|
509
587
|
const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
|
|
@@ -512,8 +590,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
512
590
|
delete newResourcesItem.resourceType;
|
|
513
591
|
return { ...newResourcesItem };
|
|
514
592
|
});
|
|
515
|
-
const
|
|
516
|
-
|
|
593
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
594
|
+
capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
|
|
595
|
+
product_bundle: item._origin.product.product_bundle
|
|
596
|
+
});
|
|
597
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
598
|
+
if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
|
|
517
599
|
item._origin.metadata = {};
|
|
518
600
|
}
|
|
519
601
|
item._origin.metadata.capacity = formatCapacity;
|
|
@@ -521,14 +603,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
521
603
|
}
|
|
522
604
|
});
|
|
523
605
|
let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
524
|
-
if ((0, import_utils4.areAllNormalProducts)(
|
|
525
|
-
newCartItems.map((n) => n._productOrigin)
|
|
526
|
-
)) {
|
|
606
|
+
if ((0, import_utils4.areAllNormalProducts)(newCartItems.map((n) => n._productOrigin))) {
|
|
527
607
|
type = "virtual";
|
|
528
608
|
}
|
|
529
|
-
return this.store.order.submitOrder({
|
|
530
|
-
query: { cartItems: newCartItems, type }
|
|
531
|
-
});
|
|
609
|
+
return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
|
|
532
610
|
}
|
|
533
611
|
// 拉起支付模块
|
|
534
612
|
async pay() {
|
|
@@ -546,136 +624,31 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
546
624
|
async getOtherParams() {
|
|
547
625
|
return this.otherParams;
|
|
548
626
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
*/
|
|
556
|
-
async storeProduct(productData) {
|
|
557
|
-
const activeAccount = this.getActiveAccount();
|
|
558
|
-
this.addProductToCart({
|
|
559
|
-
product: productData,
|
|
560
|
-
account: activeAccount
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* 往购物车加商品数据
|
|
565
|
-
*
|
|
566
|
-
* @param {({
|
|
567
|
-
* product: ProductData;
|
|
568
|
-
* date?: { startTime: string; endTime: string } | null;
|
|
569
|
-
* account?: Account | null;
|
|
570
|
-
* })} {
|
|
571
|
-
* product,
|
|
572
|
-
* date,
|
|
573
|
-
* account,
|
|
574
|
-
* }
|
|
575
|
-
* @return {*}
|
|
576
|
-
* @memberof BookingByStepImpl
|
|
577
|
-
*/
|
|
578
|
-
addProductToCart({
|
|
579
|
-
product,
|
|
580
|
-
date,
|
|
581
|
-
account
|
|
582
|
-
}) {
|
|
583
|
-
const {
|
|
584
|
-
bundle,
|
|
585
|
-
options,
|
|
586
|
-
origin,
|
|
587
|
-
product_variant_id,
|
|
588
|
-
rowKey,
|
|
589
|
-
quantity = 1
|
|
590
|
-
} = product || {};
|
|
591
|
-
const productData = { ...origin, product_variant_id };
|
|
592
|
-
if (!account) {
|
|
593
|
-
const activeAccount = this.getActiveAccount();
|
|
594
|
-
if (activeAccount) {
|
|
595
|
-
account = activeAccount;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
const flag = this.store.cart.mergeCartItemByRowKey({
|
|
599
|
-
rowKey,
|
|
600
|
-
quantity,
|
|
601
|
-
account: account || void 0
|
|
602
|
-
});
|
|
603
|
-
if (flag) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
const addItemParams = {
|
|
607
|
-
product: productData,
|
|
608
|
-
bundle,
|
|
609
|
-
options,
|
|
610
|
-
quantity
|
|
611
|
-
};
|
|
612
|
-
if (date) {
|
|
613
|
-
addItemParams.date = date;
|
|
614
|
-
}
|
|
615
|
-
if (account) {
|
|
616
|
-
addItemParams.account = account;
|
|
617
|
-
}
|
|
618
|
-
this.addProductCheck({ date });
|
|
619
|
-
this.store.cart.addItem(addItemParams);
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* 添加完购物车以后做的一些检测,比如日期是否在同一天
|
|
623
|
-
*
|
|
624
|
-
* @param {({ date?: { startTime: string; endTime: string } | null })} { date }
|
|
625
|
-
* @memberof BookingByStepImpl
|
|
626
|
-
*/
|
|
627
|
-
addProductCheck({
|
|
628
|
-
date
|
|
629
|
-
}) {
|
|
630
|
-
if (date) {
|
|
631
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
632
|
-
const cartItemsByDate = cartItems.filter(
|
|
633
|
-
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
634
|
-
);
|
|
635
|
-
if (cartItemsByDate.length) {
|
|
636
|
-
cartItemsByDate.forEach((n) => {
|
|
637
|
-
this.store.cart.removeItem(n._id);
|
|
638
|
-
});
|
|
639
|
-
}
|
|
627
|
+
// 更新购物车
|
|
628
|
+
updateCart(params) {
|
|
629
|
+
var _a;
|
|
630
|
+
const targetCartItem = this.store.cart.getItem(params._id);
|
|
631
|
+
if (!targetCartItem) {
|
|
632
|
+
throw new Error(`没有找到${params._id}购物车商品`);
|
|
640
633
|
}
|
|
641
|
-
|
|
642
|
-
beforeUpdateCart(params, targetCartItem) {
|
|
634
|
+
let currentResourcesCapacityMap = {};
|
|
643
635
|
if (params.resources) {
|
|
644
|
-
const
|
|
636
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
637
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
638
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
639
|
+
});
|
|
640
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
645
641
|
params.resources = params.resources.map((n) => {
|
|
646
642
|
n.capacity = currentCapacity || 1;
|
|
647
|
-
|
|
643
|
+
currentResourcesCapacityMap[n.id] = currentCapacity;
|
|
644
|
+
(0, import_resources.checkSubResourcesCapacity)(n);
|
|
648
645
|
return n;
|
|
649
646
|
});
|
|
650
647
|
}
|
|
651
|
-
}
|
|
652
|
-
// 更新购物车
|
|
653
|
-
updateCart(params) {
|
|
654
|
-
const targetCartItem = this.store.cart.getItem(params._id);
|
|
655
|
-
if (!targetCartItem) {
|
|
656
|
-
throw new Error(`没有找到${params._id}购物车商品`);
|
|
657
|
-
}
|
|
658
|
-
this.beforeUpdateCart(params, targetCartItem);
|
|
659
648
|
this.store.cart.updateItem(params);
|
|
660
|
-
this.updateCartCheck(params, targetCartItem);
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
|
|
664
|
-
*
|
|
665
|
-
* @param {IUpdateItemParams} params
|
|
666
|
-
* @param {CartItem} targetCartItem
|
|
667
|
-
* @return {*}
|
|
668
|
-
* @memberof BookingByStepImpl
|
|
669
|
-
*/
|
|
670
|
-
updateCartCheck(params, targetCartItem) {
|
|
671
|
-
var _a;
|
|
672
649
|
if (this.otherParams.isRetailTemplate) {
|
|
673
650
|
return;
|
|
674
651
|
}
|
|
675
|
-
let currentResourcesCapacityMap = {};
|
|
676
|
-
(_a = params.resources) == null ? void 0 : _a.forEach((n) => {
|
|
677
|
-
currentResourcesCapacityMap[n.id] = n.capacity;
|
|
678
|
-
});
|
|
679
652
|
const allOriginResources = [];
|
|
680
653
|
const dateRange = this.store.date.getDateRange();
|
|
681
654
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -696,31 +669,50 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
696
669
|
cartItems.forEach((item) => {
|
|
697
670
|
var _a2;
|
|
698
671
|
if (item._id !== targetCartItem._id) {
|
|
699
|
-
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
|
|
700
672
|
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
701
|
-
const sameFormIdResources = (
|
|
702
|
-
targetCartItem._origin.resources,
|
|
703
|
-
m.form_id
|
|
704
|
-
);
|
|
673
|
+
const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
|
|
705
674
|
if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
|
|
706
675
|
return true;
|
|
707
676
|
}
|
|
708
677
|
return !sameFormIdResources.some((targetRes) => {
|
|
678
|
+
var _a3, _b, _c;
|
|
709
679
|
if (targetRes.resourceType !== "single") {
|
|
680
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
681
|
+
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
682
|
+
product_bundle: item._origin.product.product_bundle
|
|
683
|
+
});
|
|
684
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
685
|
+
capacity: formatCapacity
|
|
686
|
+
});
|
|
710
687
|
const originResource = allOriginResources.find(
|
|
711
688
|
(n) => n.id === targetRes.id
|
|
712
689
|
);
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (canUse)
|
|
719
|
-
currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
720
|
-
return !canUse;
|
|
690
|
+
if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
694
|
+
return false;
|
|
721
695
|
}
|
|
722
696
|
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
723
|
-
|
|
697
|
+
if (targetRes.id === m.id)
|
|
698
|
+
return true;
|
|
699
|
+
if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
700
|
+
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
701
|
+
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
702
|
+
(targetRes.metadata.combined_resource.resource_ids.includes(
|
|
703
|
+
m.id
|
|
704
|
+
) || targetRes.metadata.combined_resource.resource_ids.some(
|
|
705
|
+
(n) => {
|
|
706
|
+
return m.metadata.combined_resource.resource_ids.includes(
|
|
707
|
+
n
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
)))
|
|
711
|
+
return true;
|
|
712
|
+
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
713
|
+
targetRes.id
|
|
714
|
+
))
|
|
715
|
+
return true;
|
|
724
716
|
}
|
|
725
717
|
return false;
|
|
726
718
|
});
|
|
@@ -817,30 +809,29 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
817
809
|
const resources = [];
|
|
818
810
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
819
811
|
dateRange.forEach((n) => {
|
|
820
|
-
|
|
812
|
+
if (n.resource)
|
|
813
|
+
resources.push(...n.resource);
|
|
821
814
|
});
|
|
822
815
|
}
|
|
823
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
824
816
|
if (!resources.length) {
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
}
|
|
830
|
-
const dateList = this.store.date.getDateList();
|
|
831
|
-
dateList.forEach((n) => {
|
|
832
|
-
if (n.resource)
|
|
833
|
-
resources.push(...n.resource);
|
|
834
|
-
});
|
|
835
|
-
}
|
|
817
|
+
const dateList = this.store.date.getDateList();
|
|
818
|
+
dateList.forEach((n) => {
|
|
819
|
+
if (n.resource)
|
|
820
|
+
resources.push(...n.resource);
|
|
821
|
+
});
|
|
836
822
|
}
|
|
837
823
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
824
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
838
825
|
const arr = [];
|
|
839
826
|
cartItems.forEach((cartItem) => {
|
|
840
|
-
var _a, _b, _c, _d, _e, _f;
|
|
827
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
841
828
|
let selectedResources = [];
|
|
842
|
-
const
|
|
829
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
830
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
831
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
832
|
+
});
|
|
843
833
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
834
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
844
835
|
if (cartItem.holder_id) {
|
|
845
836
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
846
837
|
cartItems,
|
|
@@ -856,7 +847,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
856
847
|
}
|
|
857
848
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
858
849
|
resourcesMap,
|
|
859
|
-
((
|
|
850
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
860
851
|
selectedResources,
|
|
861
852
|
currentCapacity
|
|
862
853
|
);
|
|
@@ -869,13 +860,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
869
860
|
);
|
|
870
861
|
const resourcesUseableMap = {};
|
|
871
862
|
productResources.forEach((n) => {
|
|
872
|
-
n.renderList = (
|
|
863
|
+
n.renderList = n.renderList.sort((a, b) => {
|
|
864
|
+
var _a2, _b2, _c2, _d2;
|
|
865
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
866
|
+
const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
|
|
867
|
+
if (aIsCombined && !bIsCombined)
|
|
868
|
+
return 1;
|
|
869
|
+
if (!aIsCombined && bIsCombined)
|
|
870
|
+
return -1;
|
|
871
|
+
return 0;
|
|
872
|
+
});
|
|
873
873
|
n.renderList = n.renderList.filter((m) => {
|
|
874
|
-
const mTimes = (
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
endTime
|
|
878
|
-
);
|
|
874
|
+
const mTimes = m.times.filter((n2) => {
|
|
875
|
+
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));
|
|
876
|
+
});
|
|
879
877
|
if (mTimes.length === 0) {
|
|
880
878
|
return false;
|
|
881
879
|
}
|
|
@@ -905,8 +903,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
905
903
|
});
|
|
906
904
|
});
|
|
907
905
|
} else {
|
|
908
|
-
const hasFlexibleDuration = ((
|
|
909
|
-
const operating_day_boundary = (
|
|
906
|
+
const hasFlexibleDuration = ((_e = (_d = cartItem._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.type) === "flexible";
|
|
907
|
+
const operating_day_boundary = (_h = (_g = (_f = this.shopStore.get("core")) == null ? void 0 : _f.core) == null ? void 0 : _g.operating_day_boundary) == null ? void 0 : _h.time;
|
|
910
908
|
productResources.forEach((item) => {
|
|
911
909
|
item.renderList = item.renderList.filter((n) => {
|
|
912
910
|
var _a2, _b2, _c2;
|
|
@@ -939,28 +937,138 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
939
937
|
});
|
|
940
938
|
return arr;
|
|
941
939
|
}
|
|
942
|
-
|
|
943
|
-
* 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
944
|
-
*
|
|
945
|
-
* @return {*}
|
|
946
|
-
* @memberof BookingByStepImpl
|
|
947
|
-
*/
|
|
940
|
+
// 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
|
|
948
941
|
checkResourceListForDate() {
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
|
|
942
|
+
const dateRange = this.store.date.getDateRange();
|
|
943
|
+
const resources = [];
|
|
944
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
945
|
+
dateRange.forEach((n) => {
|
|
946
|
+
if (n.resource)
|
|
947
|
+
resources.push(...n.resource);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if (!resources.length) {
|
|
951
|
+
const dateList = this.store.date.getDateList();
|
|
952
|
+
dateList.forEach((n) => {
|
|
953
|
+
if (n.resource)
|
|
954
|
+
resources.push(...n.resource);
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
958
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
959
|
+
const arr = [];
|
|
960
|
+
cartItems.forEach((cartItem) => {
|
|
961
|
+
var _a, _b, _c;
|
|
962
|
+
let selectedResources = [];
|
|
963
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
964
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
965
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
966
|
+
});
|
|
967
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
968
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
969
|
+
if (cartItem.holder_id) {
|
|
970
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
971
|
+
cartItems,
|
|
972
|
+
cartItem.holder_id,
|
|
973
|
+
resourcesMap
|
|
974
|
+
);
|
|
975
|
+
} else {
|
|
976
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
977
|
+
cartItems,
|
|
978
|
+
cartItem._id,
|
|
979
|
+
resourcesMap
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
983
|
+
resourcesMap,
|
|
984
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
985
|
+
selectedResources,
|
|
986
|
+
currentCapacity
|
|
987
|
+
);
|
|
988
|
+
if (cartItem._origin.start_time) {
|
|
989
|
+
const startTime = (0, import_dayjs.default)(
|
|
990
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
991
|
+
);
|
|
992
|
+
const endTime = (0, import_dayjs.default)(
|
|
993
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
994
|
+
);
|
|
995
|
+
const resourcesUseableMap = {};
|
|
996
|
+
productResources.forEach((n) => {
|
|
997
|
+
n.renderList = n.renderList.sort((a, b) => {
|
|
998
|
+
var _a2, _b2, _c2, _d;
|
|
999
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1000
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1001
|
+
if (aIsCombined && !bIsCombined)
|
|
1002
|
+
return 1;
|
|
1003
|
+
if (!aIsCombined && bIsCombined)
|
|
1004
|
+
return -1;
|
|
1005
|
+
return 0;
|
|
1006
|
+
});
|
|
1007
|
+
n.renderList = n.renderList.filter((m) => {
|
|
1008
|
+
const mTimes = m.times.filter((n2) => {
|
|
1009
|
+
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));
|
|
1010
|
+
});
|
|
1011
|
+
if (mTimes.length === 0) {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
const canUseArr = mTimes.map((item) => {
|
|
1015
|
+
var _a2;
|
|
1016
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1017
|
+
timeSlice: {
|
|
1018
|
+
start_time: startTime.format("HH:mm"),
|
|
1019
|
+
end_time: endTime.format("HH:mm"),
|
|
1020
|
+
start_at: startTime,
|
|
1021
|
+
end_at: endTime
|
|
1022
|
+
},
|
|
1023
|
+
time: item,
|
|
1024
|
+
resource: m,
|
|
1025
|
+
currentCount: currentCapacity || 0,
|
|
1026
|
+
resourcesUseableMap,
|
|
1027
|
+
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1028
|
+
});
|
|
1029
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1030
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
1031
|
+
}
|
|
1032
|
+
return res.usable;
|
|
1033
|
+
});
|
|
1034
|
+
if (m.onlyComputed)
|
|
1035
|
+
return false;
|
|
1036
|
+
return !canUseArr.some((n2) => n2 === false);
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
} else {
|
|
1040
|
+
productResources.forEach((item) => {
|
|
1041
|
+
item.renderList = item.renderList.filter((n) => {
|
|
1042
|
+
var _a2, _b2;
|
|
1043
|
+
const recordCount = n.capacity || 0;
|
|
1044
|
+
if (n.onlyComputed)
|
|
1045
|
+
return false;
|
|
1046
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1047
|
+
resource: n,
|
|
1048
|
+
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
|
|
1049
|
+
split: 10,
|
|
1050
|
+
currentDate: dateRange[0].date
|
|
1051
|
+
});
|
|
1052
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
1053
|
+
});
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
arr.push({
|
|
1057
|
+
id: cartItem.id,
|
|
1058
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1059
|
+
_id: cartItem._id,
|
|
1060
|
+
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
1061
|
+
productResources
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
const hasResource = arr.every(
|
|
1065
|
+
(n) => n.productResources.every((m) => m.renderList.length > 0)
|
|
952
1066
|
);
|
|
953
1067
|
return hasResource;
|
|
954
1068
|
}
|
|
955
|
-
|
|
956
|
-
* 给单个购物车里的商品获取资源列表,给 UI 用的
|
|
957
|
-
*
|
|
958
|
-
* @param {(string | number)} id
|
|
959
|
-
* @return {*}
|
|
960
|
-
* @memberof BookingByStepImpl
|
|
961
|
-
*/
|
|
1069
|
+
// 给单个购物车里的商品获取资源列表
|
|
962
1070
|
getResourcesListByCartItem(id) {
|
|
963
|
-
var _a, _b;
|
|
1071
|
+
var _a, _b, _c;
|
|
964
1072
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
965
1073
|
const dateRange = this.store.date.getDateRange();
|
|
966
1074
|
const resources = [];
|
|
@@ -974,7 +1082,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
974
1082
|
throw new Error(`没有找到${id}购物车商品`);
|
|
975
1083
|
}
|
|
976
1084
|
let selectedResources = [];
|
|
977
|
-
const
|
|
1085
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
1086
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1087
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
1088
|
+
});
|
|
1089
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
978
1090
|
if (targetCartItem.holder_id) {
|
|
979
1091
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
980
1092
|
cartItems,
|
|
@@ -990,7 +1102,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
990
1102
|
}
|
|
991
1103
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
992
1104
|
resourcesMap,
|
|
993
|
-
((
|
|
1105
|
+
((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
994
1106
|
selectedResources,
|
|
995
1107
|
currentCapacity
|
|
996
1108
|
);
|
|
@@ -1015,6 +1127,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1015
1127
|
};
|
|
1016
1128
|
}
|
|
1017
1129
|
}
|
|
1130
|
+
// 通过资源列表和指定的资源 id,获取指定资源的时间切片
|
|
1131
|
+
getResourceTimeSlot({
|
|
1132
|
+
product,
|
|
1133
|
+
resources,
|
|
1134
|
+
currentResourceId
|
|
1135
|
+
}) {
|
|
1136
|
+
const dateRange = this.store.date.getDateRange();
|
|
1137
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1138
|
+
resource: resources.find((n) => n.id === currentResourceId),
|
|
1139
|
+
duration: product.duration.value,
|
|
1140
|
+
split: 10,
|
|
1141
|
+
currentDate: dateRange[0].date
|
|
1142
|
+
});
|
|
1143
|
+
return timeSlots;
|
|
1144
|
+
}
|
|
1018
1145
|
// 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
|
|
1019
1146
|
autoSelectAccountResources({
|
|
1020
1147
|
cartItem,
|
|
@@ -1100,9 +1227,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1100
1227
|
},
|
|
1101
1228
|
0
|
|
1102
1229
|
);
|
|
1103
|
-
if (n.resourceType === "single" && totalCapacity > 0) {
|
|
1104
|
-
continue;
|
|
1105
|
-
}
|
|
1106
1230
|
const canUseTime = mTimes.find((item) => {
|
|
1107
1231
|
var _a2;
|
|
1108
1232
|
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
@@ -1170,15 +1294,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1170
1294
|
const accountList = this.store.accountList.getAccounts();
|
|
1171
1295
|
const selectForCartResources = (cartItems2) => {
|
|
1172
1296
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
1173
|
-
const hasFlexibleProduct = cartItems2.some(
|
|
1174
|
-
(item) => {
|
|
1175
|
-
var _a2, _b;
|
|
1176
|
-
return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
|
|
1177
|
-
}
|
|
1178
|
-
);
|
|
1179
1297
|
cartItems2.forEach((item, index) => {
|
|
1180
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1181
|
-
const
|
|
1298
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1299
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
1300
|
+
capacity: (_a2 = item._productOrigin) == null ? void 0 : _a2.capacity,
|
|
1301
|
+
product_bundle: item._origin.product.product_bundle
|
|
1302
|
+
});
|
|
1303
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1182
1304
|
if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
|
|
1183
1305
|
recordTimeSlots = {
|
|
1184
1306
|
start_time: item._origin.start_time,
|
|
@@ -1188,16 +1310,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1188
1310
|
};
|
|
1189
1311
|
}
|
|
1190
1312
|
if (recordTimeSlots) {
|
|
1191
|
-
const currentResourceConfig = (
|
|
1313
|
+
const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
|
|
1192
1314
|
(n) => n.code === resources_code
|
|
1193
1315
|
);
|
|
1194
|
-
if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((
|
|
1316
|
+
if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
|
|
1195
1317
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
1196
|
-
((
|
|
1318
|
+
((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) || 10,
|
|
1197
1319
|
"minutes"
|
|
1198
1320
|
);
|
|
1199
1321
|
let end_at = start_at.add(
|
|
1200
|
-
((
|
|
1322
|
+
((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.value) || 10,
|
|
1201
1323
|
"minutes"
|
|
1202
1324
|
);
|
|
1203
1325
|
recordTimeSlots = {
|
|
@@ -1230,7 +1352,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1230
1352
|
});
|
|
1231
1353
|
}
|
|
1232
1354
|
res.selectedResource.capacity = currentCapacity;
|
|
1233
|
-
(0,
|
|
1355
|
+
(0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
|
|
1234
1356
|
this.store.cart.updateItem({
|
|
1235
1357
|
_id: item._id,
|
|
1236
1358
|
// 这里要做去重,避免出现同样类型的资源被塞进同一个商品
|
|
@@ -1251,7 +1373,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1251
1373
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1252
1374
|
let selectedResources = [];
|
|
1253
1375
|
const resources2 = (0, import_lodash_es.cloneDeep)(
|
|
1254
|
-
((
|
|
1376
|
+
((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || []
|
|
1255
1377
|
);
|
|
1256
1378
|
const currentResourcesRenderList = [];
|
|
1257
1379
|
resources2.forEach((n) => {
|
|
@@ -1299,11 +1421,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1299
1421
|
return recordCount >= currentCapacity;
|
|
1300
1422
|
});
|
|
1301
1423
|
});
|
|
1302
|
-
const targetRenderList = (
|
|
1424
|
+
const targetRenderList = (_l = productResources.find(
|
|
1303
1425
|
(n) => n.code === resources_code
|
|
1304
|
-
)) == null ? void 0 :
|
|
1426
|
+
)) == null ? void 0 : _l.renderList;
|
|
1305
1427
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
1306
|
-
if ((
|
|
1428
|
+
if ((_m = item._origin.resources) == null ? void 0 : _m.some(
|
|
1307
1429
|
(n) => n.form_id === targetRenderList[0].form_id
|
|
1308
1430
|
)) {
|
|
1309
1431
|
return;
|
|
@@ -1315,7 +1437,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1315
1437
|
});
|
|
1316
1438
|
const targetResource = fastestResource || targetRenderList[0];
|
|
1317
1439
|
targetResource.capacity = currentCapacity;
|
|
1318
|
-
(0,
|
|
1440
|
+
(0, import_resources.checkSubResourcesCapacity)(targetResource);
|
|
1319
1441
|
if (!selectResourcesMap[targetResource.id]) {
|
|
1320
1442
|
selectResourcesMap[targetResource.id] = currentCapacity;
|
|
1321
1443
|
} else {
|
|
@@ -1349,7 +1471,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1349
1471
|
}
|
|
1350
1472
|
// 从购物车中获取已经分配好第一步资源的所有时间片
|
|
1351
1473
|
getTimeSlotByAllResources(resources_code) {
|
|
1352
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1474
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1353
1475
|
let dateRange = this.store.date.getDateRange();
|
|
1354
1476
|
const resources = [];
|
|
1355
1477
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
@@ -1359,7 +1481,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1359
1481
|
let maxCutOffTime = void 0;
|
|
1360
1482
|
let maxCutOffTimeValue = (0, import_dayjs.default)();
|
|
1361
1483
|
cartItems.forEach((item) => {
|
|
1362
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2,
|
|
1484
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
|
|
1363
1485
|
(_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
|
|
1364
1486
|
if (n.code === resources_code) {
|
|
1365
1487
|
resources.push(...n.renderList || []);
|
|
@@ -1372,7 +1494,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1372
1494
|
resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
|
|
1373
1495
|
(n) => n.code === resources_code
|
|
1374
1496
|
)) == null ? void 0 : _g2.id;
|
|
1375
|
-
if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((
|
|
1497
|
+
if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i2 = item._productOrigin) == null ? void 0 : _i2.cut_off_time.type) === "advance") {
|
|
1376
1498
|
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1377
1499
|
item._productOrigin.cut_off_time.unit,
|
|
1378
1500
|
item._productOrigin.cut_off_time.unit_type
|
|
@@ -1437,13 +1559,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1437
1559
|
];
|
|
1438
1560
|
}
|
|
1439
1561
|
const resourcesUseableMap = {};
|
|
1440
|
-
const hasFlexibleDuration = cartItems.some(
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
);
|
|
1446
|
-
const operating_day_boundary = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary;
|
|
1562
|
+
const hasFlexibleDuration = cartItems.some((item) => {
|
|
1563
|
+
var _a2, _b2;
|
|
1564
|
+
return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
|
|
1565
|
+
});
|
|
1566
|
+
const operating_day_boundary = (_i = (_h = (_g = this.shopStore.get("core")) == null ? void 0 : _g.core) == null ? void 0 : _h.operating_day_boundary) == null ? void 0 : _i.time;
|
|
1447
1567
|
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1448
1568
|
resourceIds,
|
|
1449
1569
|
resourcesMap,
|
|
@@ -1459,11 +1579,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1459
1579
|
}
|
|
1460
1580
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
|
|
1461
1581
|
submitTimeSlot(timeSlots) {
|
|
1462
|
-
var _a, _b;
|
|
1582
|
+
var _a, _b, _c;
|
|
1463
1583
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1464
|
-
const allResources = this.store.date.getResourcesListByDate(
|
|
1465
|
-
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1466
|
-
);
|
|
1584
|
+
const allResources = this.store.date.getResourcesListByDate(timeSlots.start_at.format("YYYY-MM-DD"));
|
|
1467
1585
|
const itemsByAccount = cartItems.reduce(
|
|
1468
1586
|
(acc, item) => {
|
|
1469
1587
|
const holderId = item.holder_id;
|
|
@@ -1475,36 +1593,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1475
1593
|
},
|
|
1476
1594
|
{}
|
|
1477
1595
|
);
|
|
1478
|
-
const operating_day_boundary = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary;
|
|
1596
|
+
const operating_day_boundary = (_c = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary) == null ? void 0 : _c.time;
|
|
1479
1597
|
Object.values(itemsByAccount).forEach((accountItems) => {
|
|
1480
1598
|
let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1481
1599
|
accountItems.forEach((item, index) => {
|
|
1482
1600
|
var _a2;
|
|
1483
1601
|
const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
|
|
1484
1602
|
newResources.forEach((resource) => {
|
|
1485
|
-
var _a3, _b2,
|
|
1603
|
+
var _a3, _b2, _c2, _d, _e;
|
|
1486
1604
|
if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
|
|
1487
1605
|
item.duration = {
|
|
1488
1606
|
type: "minutes",
|
|
1489
1607
|
value: 10
|
|
1490
1608
|
};
|
|
1491
1609
|
resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1492
|
-
const targetResourceTimes = (
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
|
|
1498
|
-
},
|
|
1499
|
-
targetResourceTimes[0]
|
|
1500
|
-
);
|
|
1501
|
-
const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
|
|
1502
|
-
"YYYY-MM-DD"
|
|
1503
|
-
);
|
|
1504
|
-
const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
|
|
1505
|
-
const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore(
|
|
1506
|
-
(0, import_dayjs.default)(operatingBoundaryDateTime)
|
|
1507
|
-
) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
|
|
1610
|
+
const targetResourceTimes = (_c2 = allResources == null ? void 0 : allResources.find((n) => n.id === resource.id)) == null ? void 0 : _c2.times;
|
|
1611
|
+
const resourcesEndTime = targetResourceTimes.reduce((acc, curr) => {
|
|
1612
|
+
return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
|
|
1613
|
+
}, targetResourceTimes[0]);
|
|
1614
|
+
const endTime = (0, import_dayjs.default)(resourcesEndTime.end_at).isBefore((0, import_dayjs.default)(operating_day_boundary)) ? resourcesEndTime.end_at : operating_day_boundary;
|
|
1508
1615
|
let formattedEndTime;
|
|
1509
1616
|
if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
|
|
1510
1617
|
const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
|
|
@@ -1515,7 +1622,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1515
1622
|
resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
|
|
1516
1623
|
} else {
|
|
1517
1624
|
resource.startTime = currentStartTime;
|
|
1518
|
-
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1625
|
+
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(
|
|
1626
|
+
((_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.value) || 10,
|
|
1627
|
+
"minutes"
|
|
1628
|
+
).format("YYYY-MM-DD HH:mm");
|
|
1519
1629
|
}
|
|
1520
1630
|
});
|
|
1521
1631
|
this.store.cart.updateItem({
|
|
@@ -1561,21 +1671,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1561
1671
|
if (targetProduct) {
|
|
1562
1672
|
const targetProductData = targetProduct.getData();
|
|
1563
1673
|
this.store.currentProduct = targetProduct;
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
targetProduct.setOtherParams("schedule", newScheduleArr);
|
|
1569
|
-
} else if (targetProductData.duration) {
|
|
1570
|
-
const dateRange = this.store.date.getDateRange();
|
|
1571
|
-
if (!(dateRange == null ? void 0 : dateRange.length))
|
|
1572
|
-
return;
|
|
1573
|
-
this.getAvailableDate({
|
|
1574
|
-
startDate: dateRange[0].date,
|
|
1575
|
-
endDate: dateRange[dateRange.length - 1].date,
|
|
1576
|
-
products: [targetProductData]
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1674
|
+
const newScheduleArr = this.getScheduleDataByIds(
|
|
1675
|
+
targetProductData["schedule.ids"]
|
|
1676
|
+
);
|
|
1677
|
+
targetProduct.setOtherParams("schedule", newScheduleArr);
|
|
1579
1678
|
}
|
|
1580
1679
|
}
|
|
1581
1680
|
closeProductDetail() {
|
|
@@ -1632,9 +1731,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1632
1731
|
return -1;
|
|
1633
1732
|
return 0;
|
|
1634
1733
|
});
|
|
1635
|
-
const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find(
|
|
1636
|
-
(n) => n.status === 1
|
|
1637
|
-
)) == null ? void 0 : _f.id;
|
|
1734
|
+
const firstEnabledResourceId = (_f = (_e = (_d = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.find((n) => n.status === 1)) == null ? void 0 : _f.id;
|
|
1638
1735
|
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1639
1736
|
const resourcesUseableMap = {};
|
|
1640
1737
|
let count = 0;
|
|
@@ -1670,10 +1767,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1670
1767
|
}
|
|
1671
1768
|
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1672
1769
|
});
|
|
1673
|
-
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1674
|
-
(n) => n === false
|
|
1675
|
-
) && // 只统计第一种资源的容量和 left
|
|
1676
|
-
m.form_id === firstEnabledResourceId) {
|
|
1770
|
+
if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && m.form_id === firstEnabledResourceId) {
|
|
1677
1771
|
if (currentResourcesCount >= count) {
|
|
1678
1772
|
count = currentResourcesCount;
|
|
1679
1773
|
}
|
|
@@ -1695,6 +1789,56 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1695
1789
|
});
|
|
1696
1790
|
return formatScheduleTimeSlots;
|
|
1697
1791
|
}
|
|
1792
|
+
addProductToCart({
|
|
1793
|
+
product,
|
|
1794
|
+
date,
|
|
1795
|
+
account
|
|
1796
|
+
}) {
|
|
1797
|
+
const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
|
|
1798
|
+
const productData = { ...origin, product_variant_id };
|
|
1799
|
+
if (!account) {
|
|
1800
|
+
const activeAccount = this.getActiveAccount();
|
|
1801
|
+
if (activeAccount) {
|
|
1802
|
+
account = activeAccount;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (rowKey) {
|
|
1806
|
+
const cartItems = this.store.cart.getItems();
|
|
1807
|
+
const targetCartItem = cartItems.find((n) => {
|
|
1808
|
+
var _a;
|
|
1809
|
+
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
1810
|
+
});
|
|
1811
|
+
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
1812
|
+
this.store.cart.updateItem({
|
|
1813
|
+
_id: targetCartItem._id,
|
|
1814
|
+
product: {
|
|
1815
|
+
...targetCartItem._productOrigin,
|
|
1816
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
this.store.cart.addItem({
|
|
1823
|
+
product: productData,
|
|
1824
|
+
date,
|
|
1825
|
+
account,
|
|
1826
|
+
bundle,
|
|
1827
|
+
options,
|
|
1828
|
+
quantity
|
|
1829
|
+
});
|
|
1830
|
+
if (date) {
|
|
1831
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1832
|
+
const cartItemsByDate = cartItems.filter(
|
|
1833
|
+
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
1834
|
+
);
|
|
1835
|
+
if (cartItemsByDate.length) {
|
|
1836
|
+
cartItemsByDate.forEach((n) => {
|
|
1837
|
+
this.store.cart.removeItem(n._id);
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1698
1842
|
setOtherData(key, value) {
|
|
1699
1843
|
this.otherData[key] = value;
|
|
1700
1844
|
this.checkSaveCache({
|
|
@@ -1723,7 +1867,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1723
1867
|
* @memberof BookingByStepImpl
|
|
1724
1868
|
*/
|
|
1725
1869
|
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
1726
|
-
var _a, _b;
|
|
1870
|
+
var _a, _b, _c;
|
|
1727
1871
|
const dateRange = this.store.date.getDateRange();
|
|
1728
1872
|
const resources = [];
|
|
1729
1873
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -1745,8 +1889,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1745
1889
|
if (!cartItem)
|
|
1746
1890
|
return [];
|
|
1747
1891
|
let selectedResources = [];
|
|
1748
|
-
const
|
|
1892
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
1893
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1894
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
1895
|
+
});
|
|
1749
1896
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
1897
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1750
1898
|
if (cartItem.holder_id) {
|
|
1751
1899
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1752
1900
|
cartItems,
|
|
@@ -1762,7 +1910,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1762
1910
|
}
|
|
1763
1911
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1764
1912
|
resourcesMap,
|
|
1765
|
-
((
|
|
1913
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
1766
1914
|
selectedResources,
|
|
1767
1915
|
currentCapacity
|
|
1768
1916
|
);
|
|
@@ -1781,9 +1929,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1781
1929
|
const resourcesUseableMap = {};
|
|
1782
1930
|
targetResource.renderList = targetResource.renderList.sort(
|
|
1783
1931
|
(a, b) => {
|
|
1784
|
-
var _a2, _b2,
|
|
1932
|
+
var _a2, _b2, _c2, _d;
|
|
1785
1933
|
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1786
|
-
const bIsCombined = ((_d = (
|
|
1934
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1787
1935
|
if (aIsCombined && !bIsCombined)
|
|
1788
1936
|
return 1;
|
|
1789
1937
|
if (!aIsCombined && bIsCombined)
|
|
@@ -1870,6 +2018,56 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1870
2018
|
}
|
|
1871
2019
|
return results;
|
|
1872
2020
|
}
|
|
2021
|
+
async getAvailableDateForSession(params = {}) {
|
|
2022
|
+
let { startDate, endDate, type } = params;
|
|
2023
|
+
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"))) {
|
|
2024
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
2025
|
+
}
|
|
2026
|
+
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
2027
|
+
let tempProducts = [];
|
|
2028
|
+
if (this.store.currentProduct) {
|
|
2029
|
+
tempProducts = [
|
|
2030
|
+
{
|
|
2031
|
+
...this.store.currentProduct.getData(),
|
|
2032
|
+
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
2033
|
+
}
|
|
2034
|
+
];
|
|
2035
|
+
}
|
|
2036
|
+
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
2037
|
+
this.otherParams.currentResourcesMap = resourcesMap;
|
|
2038
|
+
const res = await this.store.date.getResourceDates({
|
|
2039
|
+
query: {
|
|
2040
|
+
start_date: startDate || "",
|
|
2041
|
+
end_date: endDate || "",
|
|
2042
|
+
resource_ids: resourceIds
|
|
2043
|
+
},
|
|
2044
|
+
rules,
|
|
2045
|
+
type
|
|
2046
|
+
});
|
|
2047
|
+
if (this.store.currentProduct) {
|
|
2048
|
+
const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
|
|
2049
|
+
startDate: startDate || "",
|
|
2050
|
+
endDate: endDate || ""
|
|
2051
|
+
});
|
|
2052
|
+
res.forEach((n) => {
|
|
2053
|
+
if (!dateListWithTimeSlots[n.date]) {
|
|
2054
|
+
n.status = "unavailable";
|
|
2055
|
+
} else {
|
|
2056
|
+
const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
|
|
2057
|
+
(d) => d.count
|
|
2058
|
+
);
|
|
2059
|
+
if (!allTimeSlotsCanUse) {
|
|
2060
|
+
n.status = "unavailable";
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
const firstAvailableDate = res.find((n) => n.status === "available");
|
|
2066
|
+
return {
|
|
2067
|
+
dateList: res,
|
|
2068
|
+
firstAvailableDate
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
1873
2071
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1874
2072
|
var _a, _b, _c, _d, _e, _f;
|
|
1875
2073
|
let { startDate, endDate } = params;
|
|
@@ -1877,29 +2075,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1877
2075
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1878
2076
|
}
|
|
1879
2077
|
const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1880
|
-
let tempEndDate = endDateAfterMonth;
|
|
1881
2078
|
if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
|
|
1882
|
-
|
|
2079
|
+
endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
|
|
1883
2080
|
} else {
|
|
1884
|
-
|
|
1885
|
-
}
|
|
1886
|
-
if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
|
|
1887
|
-
tempEndDate = endDate || "";
|
|
1888
|
-
}
|
|
1889
|
-
endDate = tempEndDate;
|
|
1890
|
-
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
1891
|
-
if (cache) {
|
|
1892
|
-
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")) {
|
|
1893
|
-
this.store.date.setDateList(cache.dateList);
|
|
1894
|
-
return {
|
|
1895
|
-
dateList: cache.dateList,
|
|
1896
|
-
firstAvailableDate: cache.firstAvailableDate
|
|
1897
|
-
};
|
|
1898
|
-
}
|
|
2081
|
+
endDate = endDateAfterMonth;
|
|
1899
2082
|
}
|
|
1900
2083
|
let tempProducts;
|
|
1901
|
-
tempProducts = (
|
|
1902
|
-
const schedule = (
|
|
2084
|
+
tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
|
|
2085
|
+
const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
|
|
1903
2086
|
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
1904
2087
|
schedule,
|
|
1905
2088
|
startDate || "",
|
|
@@ -1913,6 +2096,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1913
2096
|
resource_ids: tempResourceIds
|
|
1914
2097
|
}
|
|
1915
2098
|
});
|
|
2099
|
+
const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
|
|
2100
|
+
if (cache) {
|
|
2101
|
+
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")) {
|
|
2102
|
+
this.store.date.setDateList(cache.dateList);
|
|
2103
|
+
return {
|
|
2104
|
+
dateList: cache.dateList,
|
|
2105
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
1916
2109
|
let dates = [];
|
|
1917
2110
|
let currentDate = (0, import_dayjs.default)(startDate);
|
|
1918
2111
|
let firstAvailableDate = "";
|
|
@@ -1972,27 +2165,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1972
2165
|
if (mTimes.length === 0) {
|
|
1973
2166
|
return;
|
|
1974
2167
|
}
|
|
1975
|
-
const targetCanUseTimes = mTimes.some(
|
|
1976
|
-
(
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
resourcesUseableMap[m.id] = res2.usable;
|
|
1992
|
-
}
|
|
1993
|
-
return res2.usable && !m.onlyComputed;
|
|
2168
|
+
const targetCanUseTimes = mTimes.some((childTiem) => {
|
|
2169
|
+
const res2 = (0, import_resources.getIsUsableByTimeItem)({
|
|
2170
|
+
timeSlice: {
|
|
2171
|
+
start_time: item.start,
|
|
2172
|
+
end_time: item.end,
|
|
2173
|
+
start_at: (0, import_dayjs.default)(item.start),
|
|
2174
|
+
end_at: (0, import_dayjs.default)(item.end)
|
|
2175
|
+
},
|
|
2176
|
+
time: childTiem,
|
|
2177
|
+
resource: m,
|
|
2178
|
+
currentCount: 1,
|
|
2179
|
+
resourcesUseableMap,
|
|
2180
|
+
cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
|
|
2181
|
+
});
|
|
2182
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
|
|
2183
|
+
resourcesUseableMap[m.id] = res2.usable;
|
|
1994
2184
|
}
|
|
1995
|
-
|
|
2185
|
+
return res2.usable && !m.onlyComputed;
|
|
2186
|
+
});
|
|
1996
2187
|
return targetCanUseTimes;
|
|
1997
2188
|
});
|
|
1998
2189
|
});
|
|
@@ -2040,8 +2231,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2040
2231
|
});
|
|
2041
2232
|
}
|
|
2042
2233
|
isTargetNormalProduct(product) {
|
|
2043
|
-
if (!product)
|
|
2044
|
-
return false;
|
|
2045
2234
|
return (0, import_utils4.isNormalProduct)(product);
|
|
2046
2235
|
}
|
|
2047
2236
|
isTargetCartIdNormalProduct(id) {
|