@pisell/pisellos 0.0.116 → 0.0.117
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.js +16 -35
- package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
- package/dist/modules/Cart/utils/cartAccount.js +52 -0
- package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
- package/dist/modules/Cart/utils/cartDate.js +55 -0
- package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
- package/dist/modules/Cart/utils/cartDiscount.js +35 -0
- package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
- package/dist/modules/Cart/utils/cartNote.js +29 -0
- package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
- package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
- package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
- package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
- package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
- package/dist/modules/Cart/utils/cartResource.js +102 -0
- package/dist/modules/Cart/utils/index.d.ts +34 -0
- package/dist/modules/Cart/utils/index.js +63 -0
- package/dist/modules/Order/index.js +3 -2
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +4 -0
- package/dist/modules/Product/utils.d.ts +17 -0
- package/dist/modules/Product/utils.js +41 -0
- package/dist/solution/BookingByStep/index.d.ts +25 -0
- package/dist/solution/BookingByStep/index.js +305 -56
- package/lib/modules/Cart/index.js +14 -25
- package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
- package/lib/modules/Cart/utils/cartAccount.js +65 -0
- package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
- package/lib/modules/Cart/utils/cartDate.js +75 -0
- package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
- package/lib/modules/Cart/utils/cartDiscount.js +52 -0
- package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
- package/lib/modules/Cart/utils/cartNote.js +46 -0
- package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
- package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
- package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
- package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
- package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
- package/lib/modules/Cart/utils/cartResource.js +124 -0
- package/lib/modules/Cart/utils/index.d.ts +34 -0
- package/lib/modules/Cart/utils/index.js +91 -0
- package/lib/modules/Order/index.js +2 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +4 -0
- package/lib/modules/Product/utils.d.ts +17 -0
- package/lib/modules/Product/utils.js +46 -0
- package/lib/solution/BookingByStep/index.d.ts +25 -0
- package/lib/solution/BookingByStep/index.js +166 -21
- package/package.json +1 -1
- package/dist/modules/Cart/utils.d.ts +0 -257
- package/lib/modules/Cart/utils.d.ts +0 -257
|
@@ -37,6 +37,7 @@ import { getResourcesMap } from "../../modules/Resource/utils";
|
|
|
37
37
|
import { cloneDeep } from 'lodash-es';
|
|
38
38
|
import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
|
|
39
39
|
import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
|
|
40
|
+
import { areAllNormalProducts, isNormalProduct } from "../../modules/Product/utils";
|
|
40
41
|
import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
|
|
41
42
|
export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
42
43
|
_inherits(BookingByStepImpl, _BaseModule);
|
|
@@ -545,26 +546,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
545
546
|
key: "storeProduct",
|
|
546
547
|
value: function () {
|
|
547
548
|
var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productData) {
|
|
548
|
-
var activeAccount, _ref4, bundle, options, origin, product_variant_id, product, addCartItem;
|
|
549
|
+
var activeAccount, _ref4, bundle, options, origin, product_variant_id, _ref4$quantity, quantity, rowKey, cartItems, targetCartItem, product, addCartItem;
|
|
549
550
|
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
550
551
|
while (1) switch (_context8.prev = _context8.next) {
|
|
551
552
|
case 0:
|
|
552
553
|
// 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
|
|
553
554
|
activeAccount = this.getActiveAccount();
|
|
554
|
-
_ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id;
|
|
555
|
+
_ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id, _ref4$quantity = _ref4.quantity, quantity = _ref4$quantity === void 0 ? 1 : _ref4$quantity, rowKey = _ref4.rowKey; // 检查购物车里是否已经存在 rowKey相同的数据,如果是则更新数量
|
|
556
|
+
cartItems = this.store.cart.getItems();
|
|
557
|
+
if (!rowKey) {
|
|
558
|
+
_context8.next = 8;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
targetCartItem = cartItems.find(function (n) {
|
|
562
|
+
var _n$_productOrigin;
|
|
563
|
+
return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
|
|
564
|
+
});
|
|
565
|
+
if (!(targetCartItem && isNormalProduct(targetCartItem._productOrigin))) {
|
|
566
|
+
_context8.next = 8;
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
this.store.cart.updateItem({
|
|
570
|
+
_id: targetCartItem._id,
|
|
571
|
+
product: _objectSpread({}, targetCartItem._productOrigin),
|
|
572
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
573
|
+
});
|
|
574
|
+
return _context8.abrupt("return");
|
|
575
|
+
case 8:
|
|
555
576
|
product = _objectSpread(_objectSpread({}, origin), {}, {
|
|
556
|
-
product_variant_id: product_variant_id
|
|
577
|
+
product_variant_id: product_variant_id,
|
|
578
|
+
rowKey: rowKey
|
|
557
579
|
});
|
|
558
580
|
addCartItem = {
|
|
559
581
|
product: product,
|
|
560
582
|
bundle: bundle,
|
|
561
|
-
options: options
|
|
583
|
+
options: options,
|
|
584
|
+
quantity: quantity
|
|
562
585
|
};
|
|
563
586
|
if (activeAccount) {
|
|
564
587
|
addCartItem.account = activeAccount;
|
|
565
588
|
}
|
|
566
589
|
this.store.cart.addItem(addCartItem);
|
|
567
|
-
case
|
|
590
|
+
case 12:
|
|
568
591
|
case "end":
|
|
569
592
|
return _context8.stop();
|
|
570
593
|
}
|
|
@@ -735,7 +758,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
735
758
|
key: "fetchHolderAccountsAsync",
|
|
736
759
|
value: (function () {
|
|
737
760
|
var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
738
|
-
var cartItems, _this$store$date$getD, date,
|
|
761
|
+
var cartItems, _this$store$date$getD, date, normalProductCartItem;
|
|
739
762
|
return _regeneratorRuntime().wrap(function _callee11$(_context12) {
|
|
740
763
|
while (1) switch (_context12.prev = _context12.next) {
|
|
741
764
|
case 0:
|
|
@@ -744,7 +767,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
744
767
|
date = (_this$store$date$getD = this.store.date.getDateRange()) === null || _this$store$date$getD === void 0 || (_this$store$date$getD = _this$store$date$getD[0]) === null || _this$store$date$getD === void 0 ? void 0 : _this$store$date$getD.date;
|
|
745
768
|
if (!date) {
|
|
746
769
|
// 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
|
|
747
|
-
|
|
770
|
+
// 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
|
|
771
|
+
normalProductCartItem = cartItems.find(function (n) {
|
|
772
|
+
return !isNormalProduct(n._productOrigin);
|
|
773
|
+
});
|
|
774
|
+
date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
|
|
748
775
|
}
|
|
749
776
|
this.updateQuotationPriceAndCart(date);
|
|
750
777
|
}
|
|
@@ -979,7 +1006,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
979
1006
|
value: function () {
|
|
980
1007
|
var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(accountId, accountInfo) {
|
|
981
1008
|
var _this5 = this;
|
|
982
|
-
var account, stateAccountId, cartItems, _this$store$date$getD2, date,
|
|
1009
|
+
var account, stateAccountId, cartItems, _this$store$date$getD2, date, normalProductCartItem;
|
|
983
1010
|
return _regeneratorRuntime().wrap(function _callee18$(_context19) {
|
|
984
1011
|
while (1) switch (_context19.prev = _context19.next) {
|
|
985
1012
|
case 0:
|
|
@@ -1006,7 +1033,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1006
1033
|
date = (_this$store$date$getD2 = this.store.date.getDateRange()) === null || _this$store$date$getD2 === void 0 || (_this$store$date$getD2 = _this$store$date$getD2[0]) === null || _this$store$date$getD2 === void 0 ? void 0 : _this$store$date$getD2.date;
|
|
1007
1034
|
if (!date) {
|
|
1008
1035
|
// 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
|
|
1009
|
-
|
|
1036
|
+
// 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
|
|
1037
|
+
normalProductCartItem = cartItems.find(function (n) {
|
|
1038
|
+
return !isNormalProduct(n._productOrigin);
|
|
1039
|
+
});
|
|
1040
|
+
date = (normalProductCartItem === null || normalProductCartItem === void 0 ? void 0 : normalProductCartItem.start_date) || '';
|
|
1010
1041
|
}
|
|
1011
1042
|
this.updateQuotationPriceAndCart(date);
|
|
1012
1043
|
}
|
|
@@ -1115,14 +1146,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1115
1146
|
item._origin.number = currentCapacity;
|
|
1116
1147
|
}
|
|
1117
1148
|
});
|
|
1118
|
-
type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
|
|
1149
|
+
type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking'; // 如果购物车里全都是普通商品,type 也应该为 virtual
|
|
1150
|
+
if (areAllNormalProducts(newCartItems.map(function (n) {
|
|
1151
|
+
return n._productOrigin;
|
|
1152
|
+
}))) {
|
|
1153
|
+
type = 'virtual';
|
|
1154
|
+
}
|
|
1119
1155
|
return _context22.abrupt("return", this.store.order.submitOrder({
|
|
1120
1156
|
query: {
|
|
1121
1157
|
cartItems: newCartItems,
|
|
1122
1158
|
type: type
|
|
1123
1159
|
}
|
|
1124
1160
|
}));
|
|
1125
|
-
case
|
|
1161
|
+
case 6:
|
|
1126
1162
|
case "end":
|
|
1127
1163
|
return _context22.stop();
|
|
1128
1164
|
}
|
|
@@ -1266,7 +1302,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1266
1302
|
var _item$_origin$resourc;
|
|
1267
1303
|
var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
|
|
1268
1304
|
// 检查当前资源是否与目标资源的任何资源匹配
|
|
1269
|
-
|
|
1305
|
+
// 目标资源,应该只取跟当前 m.form_id 相同的资源
|
|
1306
|
+
var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
|
|
1307
|
+
return n.form_id === m.form_id;
|
|
1308
|
+
});
|
|
1309
|
+
if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
|
|
1310
|
+
return true;
|
|
1311
|
+
}
|
|
1312
|
+
return !sameFormIdResources.some(function (targetRes) {
|
|
1270
1313
|
// 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
|
|
1271
1314
|
if (targetRes.resourceType !== 'single') {
|
|
1272
1315
|
var _item$_productOrigin2;
|
|
@@ -1280,10 +1323,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1280
1323
|
var originResource = allOriginResources.find(function (n) {
|
|
1281
1324
|
return n.id === targetRes.id;
|
|
1282
1325
|
});
|
|
1283
|
-
if (currentResourcesCapacityMap[
|
|
1326
|
+
if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
|
|
1284
1327
|
return true;
|
|
1285
1328
|
}
|
|
1286
|
-
currentResourcesCapacityMap[
|
|
1329
|
+
currentResourcesCapacityMap[m.id] += _currentCapacity;
|
|
1287
1330
|
return false;
|
|
1288
1331
|
}
|
|
1289
1332
|
if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
|
|
@@ -1430,7 +1473,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1430
1473
|
});
|
|
1431
1474
|
}
|
|
1432
1475
|
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
1433
|
-
var cartItems = this.store.cart.getItems()
|
|
1476
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
1477
|
+
return !isNormalProduct(n._productOrigin);
|
|
1478
|
+
});
|
|
1434
1479
|
var arr = [];
|
|
1435
1480
|
cartItems.forEach(function (cartItem) {
|
|
1436
1481
|
var _cartItem$_productOri, _cartItem$_productOri2;
|
|
@@ -1555,7 +1600,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1555
1600
|
});
|
|
1556
1601
|
}
|
|
1557
1602
|
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
1558
|
-
var cartItems = this.store.cart.getItems()
|
|
1603
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
1604
|
+
return !isNormalProduct(n._productOrigin);
|
|
1605
|
+
});
|
|
1559
1606
|
var arr = [];
|
|
1560
1607
|
cartItems.forEach(function (cartItem) {
|
|
1561
1608
|
var _cartItem$_productOri5, _cartItem$_productOri6;
|
|
@@ -1669,7 +1716,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1669
1716
|
key: "getResourcesListByCartItem",
|
|
1670
1717
|
value: function getResourcesListByCartItem(id) {
|
|
1671
1718
|
var _targetCartItem$_prod2, _targetCartItem$_prod3;
|
|
1672
|
-
var cartItems =
|
|
1719
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
1720
|
+
return !isNormalProduct(n._productOrigin);
|
|
1721
|
+
});
|
|
1673
1722
|
var dateRange = this.store.date.getDateRange();
|
|
1674
1723
|
var resources = [];
|
|
1675
1724
|
dateRange.forEach(function (n) {
|
|
@@ -1748,6 +1797,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1748
1797
|
timeSlots = _ref8.timeSlots,
|
|
1749
1798
|
countMap = _ref8.countMap,
|
|
1750
1799
|
capacity = _ref8.capacity;
|
|
1800
|
+
if (isNormalProduct(cartItem._productOrigin)) {
|
|
1801
|
+
return {};
|
|
1802
|
+
}
|
|
1751
1803
|
var dateRange = this.store.date.getDateRange();
|
|
1752
1804
|
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
1753
1805
|
// 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
|
|
@@ -1760,8 +1812,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1760
1812
|
}
|
|
1761
1813
|
// duration=所有商品时间的集合
|
|
1762
1814
|
var duration = accountCartItems.reduce(function (acc, n) {
|
|
1763
|
-
var _n$_productOrigin$dur, _n$
|
|
1764
|
-
return acc + ((_n$_productOrigin$dur = (_n$
|
|
1815
|
+
var _n$_productOrigin$dur, _n$_productOrigin2;
|
|
1816
|
+
return acc + ((_n$_productOrigin$dur = (_n$_productOrigin2 = n._productOrigin) === null || _n$_productOrigin2 === void 0 || (_n$_productOrigin2 = _n$_productOrigin2.duration) === null || _n$_productOrigin2 === void 0 ? void 0 : _n$_productOrigin2.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
|
|
1765
1817
|
}, 0);
|
|
1766
1818
|
// 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
|
|
1767
1819
|
// let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
|
|
@@ -2093,7 +2145,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2093
2145
|
}
|
|
2094
2146
|
});
|
|
2095
2147
|
};
|
|
2096
|
-
var cartItems =
|
|
2148
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
2149
|
+
return !isNormalProduct(n._productOrigin);
|
|
2150
|
+
});
|
|
2097
2151
|
|
|
2098
2152
|
// 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
|
|
2099
2153
|
if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
|
|
@@ -2114,12 +2168,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2114
2168
|
value: function getTimeSlotByAllResources(resources_code) {
|
|
2115
2169
|
var _dateRange,
|
|
2116
2170
|
_this10 = this,
|
|
2117
|
-
_cartItems
|
|
2118
|
-
_cartItems$
|
|
2171
|
+
_cartItems$,
|
|
2172
|
+
_cartItems$2;
|
|
2119
2173
|
var dateRange = this.store.date.getDateRange();
|
|
2120
2174
|
// 取出购物车中所有一已选择的第一步资源
|
|
2121
2175
|
var resources = [];
|
|
2122
|
-
var cartItems =
|
|
2176
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
2177
|
+
return !isNormalProduct(n._productOrigin);
|
|
2178
|
+
});
|
|
2123
2179
|
// if (cartItems?.[0].start_date) return [];
|
|
2124
2180
|
var resourceIds = [];
|
|
2125
2181
|
var resourcesTypeId = undefined;
|
|
@@ -2198,18 +2254,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2198
2254
|
}
|
|
2199
2255
|
// 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
|
|
2200
2256
|
// 同时 session 类商品的流程也不应该调用这个方法
|
|
2201
|
-
if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$
|
|
2257
|
+
if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$ = cartItems[0]) !== null && _cartItems$ !== void 0 && _cartItems$.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$2 = cartItems[0]) !== null && _cartItems$2 !== void 0 && _cartItems$2.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
|
|
2202
2258
|
return [];
|
|
2203
2259
|
}
|
|
2204
2260
|
if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
|
|
2205
|
-
var _cartItems$
|
|
2261
|
+
var _cartItems$3, _cartItems$4;
|
|
2206
2262
|
dateRange = [{
|
|
2207
2263
|
date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
|
|
2208
2264
|
status: 'available',
|
|
2209
2265
|
week: '',
|
|
2210
2266
|
weekNum: 0
|
|
2211
2267
|
}, {
|
|
2212
|
-
date: (cartItems === null || cartItems === void 0 || (_cartItems$
|
|
2268
|
+
date: (cartItems === null || cartItems === void 0 || (_cartItems$3 = cartItems[0]) === null || _cartItems$3 === void 0 ? void 0 : _cartItems$3.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$4 = cartItems[0]) === null || _cartItems$4 === void 0 ? void 0 : _cartItems$4.start_date) || '',
|
|
2213
2269
|
status: 'available',
|
|
2214
2270
|
week: '',
|
|
2215
2271
|
weekNum: 0
|
|
@@ -2234,7 +2290,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2234
2290
|
value: function submitTimeSlot(timeSlots) {
|
|
2235
2291
|
var _this11 = this;
|
|
2236
2292
|
// 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
|
|
2237
|
-
var cartItems =
|
|
2293
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
2294
|
+
return !isNormalProduct(n._productOrigin);
|
|
2295
|
+
});
|
|
2238
2296
|
|
|
2239
2297
|
// 按账号分组
|
|
2240
2298
|
var itemsByAccount = cartItems.reduce(function (acc, item) {
|
|
@@ -2459,7 +2517,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2459
2517
|
bundle = _ref14.bundle,
|
|
2460
2518
|
options = _ref14.options,
|
|
2461
2519
|
origin = _ref14.origin,
|
|
2462
|
-
product_variant_id = _ref14.product_variant_id
|
|
2520
|
+
product_variant_id = _ref14.product_variant_id,
|
|
2521
|
+
rowKey = _ref14.rowKey,
|
|
2522
|
+
_ref14$quantity = _ref14.quantity,
|
|
2523
|
+
quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
|
|
2463
2524
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
2464
2525
|
product_variant_id: product_variant_id
|
|
2465
2526
|
});
|
|
@@ -2469,17 +2530,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2469
2530
|
account = activeAccount;
|
|
2470
2531
|
}
|
|
2471
2532
|
}
|
|
2533
|
+
if (rowKey) {
|
|
2534
|
+
var cartItems = this.store.cart.getItems();
|
|
2535
|
+
var targetCartItem = cartItems.find(function (n) {
|
|
2536
|
+
var _n$_productOrigin3;
|
|
2537
|
+
return ((_n$_productOrigin3 = n._productOrigin) === null || _n$_productOrigin3 === void 0 ? void 0 : _n$_productOrigin3.rowKey) === rowKey;
|
|
2538
|
+
});
|
|
2539
|
+
if (targetCartItem && isNormalProduct(targetCartItem._productOrigin)) {
|
|
2540
|
+
this.store.cart.updateItem({
|
|
2541
|
+
_id: targetCartItem._id,
|
|
2542
|
+
product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
|
|
2543
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
2544
|
+
})
|
|
2545
|
+
});
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2472
2549
|
this.store.cart.addItem({
|
|
2473
2550
|
product: productData,
|
|
2474
2551
|
date: date,
|
|
2475
2552
|
account: account,
|
|
2476
2553
|
bundle: bundle,
|
|
2477
|
-
options: options
|
|
2554
|
+
options: options,
|
|
2555
|
+
quantity: quantity
|
|
2478
2556
|
});
|
|
2479
2557
|
// 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
|
|
2480
2558
|
if (date) {
|
|
2481
|
-
var
|
|
2482
|
-
|
|
2559
|
+
var _cartItems = this.store.cart.getItems().filter(function (n) {
|
|
2560
|
+
return !isNormalProduct(n._productOrigin);
|
|
2561
|
+
});
|
|
2562
|
+
var cartItemsByDate = _cartItems.filter(function (n) {
|
|
2483
2563
|
return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
|
|
2484
2564
|
});
|
|
2485
2565
|
if (cartItemsByDate.length) {
|
|
@@ -2563,7 +2643,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2563
2643
|
});
|
|
2564
2644
|
}
|
|
2565
2645
|
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
2566
|
-
var cartItems = this.store.cart.getItems()
|
|
2646
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
2647
|
+
return !isNormalProduct(n._productOrigin);
|
|
2648
|
+
});
|
|
2567
2649
|
var cartItem = cartItems.find(function (item) {
|
|
2568
2650
|
return item._id === cartItemId;
|
|
2569
2651
|
});
|
|
@@ -2645,10 +2727,153 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2645
2727
|
}
|
|
2646
2728
|
return targetResource.renderList;
|
|
2647
2729
|
}
|
|
2730
|
+
|
|
2731
|
+
/**
|
|
2732
|
+
* 根据日期范围批量获取时间槽
|
|
2733
|
+
* @param params 参数对象
|
|
2734
|
+
* @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
|
|
2735
|
+
*/
|
|
2736
|
+
}, {
|
|
2737
|
+
key: "getTimeslotsScheduleByDateRange",
|
|
2738
|
+
value: (function () {
|
|
2739
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(_ref15) {
|
|
2740
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i, _dates, date;
|
|
2741
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context29) {
|
|
2742
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2743
|
+
case 0:
|
|
2744
|
+
startDate = _ref15.startDate, endDate = _ref15.endDate, scheduleIds = _ref15.scheduleIds, resources = _ref15.resources;
|
|
2745
|
+
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
2746
|
+
startDate: startDate,
|
|
2747
|
+
endDate: endDate,
|
|
2748
|
+
scheduleIds: scheduleIds,
|
|
2749
|
+
resources: resources
|
|
2750
|
+
});
|
|
2751
|
+
// 生成日期范围内的所有日期
|
|
2752
|
+
dates = [];
|
|
2753
|
+
currentDate = dayjs(startDate);
|
|
2754
|
+
end = dayjs(endDate);
|
|
2755
|
+
while (currentDate.isSameOrBefore(end)) {
|
|
2756
|
+
dates.push(currentDate.format('YYYY-MM-DD'));
|
|
2757
|
+
currentDate = currentDate.add(1, 'day');
|
|
2758
|
+
}
|
|
2759
|
+
// 如果不支持 Web Worker,使用同步方式处理
|
|
2760
|
+
results = {};
|
|
2761
|
+
for (_i = 0, _dates = dates; _i < _dates.length; _i++) {
|
|
2762
|
+
date = _dates[_i];
|
|
2763
|
+
results[date] = this.getTimeslotBySchedule({
|
|
2764
|
+
date: date,
|
|
2765
|
+
scheduleIds: scheduleIds,
|
|
2766
|
+
resources: resources
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
return _context29.abrupt("return", results);
|
|
2770
|
+
case 9:
|
|
2771
|
+
case "end":
|
|
2772
|
+
return _context29.stop();
|
|
2773
|
+
}
|
|
2774
|
+
}, _callee28, this);
|
|
2775
|
+
}));
|
|
2776
|
+
function getTimeslotsScheduleByDateRange(_x21) {
|
|
2777
|
+
return _getTimeslotsScheduleByDateRange.apply(this, arguments);
|
|
2778
|
+
}
|
|
2779
|
+
return getTimeslotsScheduleByDateRange;
|
|
2780
|
+
}())
|
|
2781
|
+
}, {
|
|
2782
|
+
key: "getAvailableDateForSession",
|
|
2783
|
+
value: function () {
|
|
2784
|
+
var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2785
|
+
var params,
|
|
2786
|
+
startDate,
|
|
2787
|
+
endDate,
|
|
2788
|
+
type,
|
|
2789
|
+
tempProducts,
|
|
2790
|
+
_ref16,
|
|
2791
|
+
resourceIds,
|
|
2792
|
+
rules,
|
|
2793
|
+
resourcesMap,
|
|
2794
|
+
res,
|
|
2795
|
+
dateListWithTimeSlots,
|
|
2796
|
+
firstAvailableDate,
|
|
2797
|
+
_args30 = arguments;
|
|
2798
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context30) {
|
|
2799
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
2800
|
+
case 0:
|
|
2801
|
+
params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
|
|
2802
|
+
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2803
|
+
startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2804
|
+
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
2805
|
+
startDate = dayjs().format('YYYY-MM-DD');
|
|
2806
|
+
}
|
|
2807
|
+
// 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
|
|
2808
|
+
endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
|
|
2809
|
+
tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
|
|
2810
|
+
if (this.store.currentProduct) {
|
|
2811
|
+
tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
|
|
2812
|
+
_schedule: this.store.currentProduct.getOtherParams()['schedule']
|
|
2813
|
+
})];
|
|
2814
|
+
}
|
|
2815
|
+
// 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
|
|
2816
|
+
_ref16 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref16.resourceIds, rules = _ref16.rules, resourcesMap = _ref16.resourcesMap;
|
|
2817
|
+
this.otherParams.currentResourcesMap = resourcesMap;
|
|
2818
|
+
_context30.next = 10;
|
|
2819
|
+
return this.store.date.getResourceDates({
|
|
2820
|
+
query: {
|
|
2821
|
+
start_date: startDate || '',
|
|
2822
|
+
end_date: endDate || '',
|
|
2823
|
+
resource_ids: resourceIds
|
|
2824
|
+
},
|
|
2825
|
+
rules: rules,
|
|
2826
|
+
type: type
|
|
2827
|
+
});
|
|
2828
|
+
case 10:
|
|
2829
|
+
res = _context30.sent;
|
|
2830
|
+
if (!this.store.currentProduct) {
|
|
2831
|
+
_context30.next = 16;
|
|
2832
|
+
break;
|
|
2833
|
+
}
|
|
2834
|
+
_context30.next = 14;
|
|
2835
|
+
return this.getTimeslotsScheduleByDateRange({
|
|
2836
|
+
startDate: startDate || '',
|
|
2837
|
+
endDate: endDate || ''
|
|
2838
|
+
});
|
|
2839
|
+
case 14:
|
|
2840
|
+
dateListWithTimeSlots = _context30.sent;
|
|
2841
|
+
res.forEach(function (n) {
|
|
2842
|
+
if (!dateListWithTimeSlots[n.date]) {
|
|
2843
|
+
n.status = 'unavailable';
|
|
2844
|
+
} else {
|
|
2845
|
+
var allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(function (d) {
|
|
2846
|
+
return d.count;
|
|
2847
|
+
});
|
|
2848
|
+
if (!allTimeSlotsCanUse) {
|
|
2849
|
+
n.status = 'unavailable';
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
case 16:
|
|
2854
|
+
// 找到第一个可用的日期返回给 UI
|
|
2855
|
+
firstAvailableDate = res.find(function (n) {
|
|
2856
|
+
return n.status === 'available';
|
|
2857
|
+
});
|
|
2858
|
+
return _context30.abrupt("return", {
|
|
2859
|
+
dateList: res,
|
|
2860
|
+
firstAvailableDate: firstAvailableDate
|
|
2861
|
+
});
|
|
2862
|
+
case 18:
|
|
2863
|
+
case "end":
|
|
2864
|
+
return _context30.stop();
|
|
2865
|
+
}
|
|
2866
|
+
}, _callee29, this);
|
|
2867
|
+
}));
|
|
2868
|
+
function getAvailableDateForSession() {
|
|
2869
|
+
return _getAvailableDateForSession.apply(this, arguments);
|
|
2870
|
+
}
|
|
2871
|
+
return getAvailableDateForSession;
|
|
2872
|
+
}()
|
|
2648
2873
|
}, {
|
|
2649
2874
|
key: "getAvailableDateForSessionOptimize",
|
|
2650
2875
|
value: function () {
|
|
2651
|
-
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2876
|
+
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
2652
2877
|
var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
|
|
2653
2878
|
var params,
|
|
2654
2879
|
cache,
|
|
@@ -2666,22 +2891,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2666
2891
|
allProductResources,
|
|
2667
2892
|
targetSchedules,
|
|
2668
2893
|
_loop3,
|
|
2669
|
-
|
|
2670
|
-
return _regeneratorRuntime().wrap(function
|
|
2671
|
-
while (1) switch (
|
|
2894
|
+
_args32 = arguments;
|
|
2895
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context32) {
|
|
2896
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
2672
2897
|
case 0:
|
|
2673
|
-
params =
|
|
2898
|
+
params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
|
|
2674
2899
|
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2675
2900
|
cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
|
|
2676
2901
|
if (!cache) {
|
|
2677
|
-
|
|
2902
|
+
_context32.next = 5;
|
|
2678
2903
|
break;
|
|
2679
2904
|
}
|
|
2680
2905
|
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2681
|
-
|
|
2906
|
+
_context32.next = 5;
|
|
2682
2907
|
break;
|
|
2683
2908
|
}
|
|
2684
|
-
return
|
|
2909
|
+
return _context32.abrupt("return", {
|
|
2685
2910
|
dateList: cache.dateList,
|
|
2686
2911
|
firstAvailableDate: cache.firstAvailableDate
|
|
2687
2912
|
});
|
|
@@ -2698,7 +2923,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2698
2923
|
schedule = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['schedule'];
|
|
2699
2924
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2700
2925
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2701
|
-
|
|
2926
|
+
_context32.next = 14;
|
|
2702
2927
|
return this.store.date.fetchResourceDates({
|
|
2703
2928
|
query: {
|
|
2704
2929
|
start_date: startDate || '',
|
|
@@ -2707,7 +2932,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2707
2932
|
}
|
|
2708
2933
|
});
|
|
2709
2934
|
case 14:
|
|
2710
|
-
res =
|
|
2935
|
+
res = _context32.sent;
|
|
2711
2936
|
// 2. 商品 schedule 数据,确定日程在每一天的时间片
|
|
2712
2937
|
// 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
|
|
2713
2938
|
dates = [];
|
|
@@ -2720,8 +2945,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2720
2945
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
2721
2946
|
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
2722
2947
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
2723
|
-
return _regeneratorRuntime().wrap(function _loop3$(
|
|
2724
|
-
while (1) switch (
|
|
2948
|
+
return _regeneratorRuntime().wrap(function _loop3$(_context31) {
|
|
2949
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
2725
2950
|
case 0:
|
|
2726
2951
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
2727
2952
|
status = 'available'; // 1. 检查商品的提前量等情况是否满足
|
|
@@ -2813,32 +3038,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2813
3038
|
|
|
2814
3039
|
// 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
|
|
2815
3040
|
if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
|
|
2816
|
-
|
|
3041
|
+
_context31.next = 9;
|
|
2817
3042
|
break;
|
|
2818
3043
|
}
|
|
2819
|
-
return
|
|
3044
|
+
return _context31.abrupt("return", 1);
|
|
2820
3045
|
case 9:
|
|
2821
3046
|
currentDate = dayjs(currentDate).add(1, 'day');
|
|
2822
3047
|
case 10:
|
|
2823
3048
|
case "end":
|
|
2824
|
-
return
|
|
3049
|
+
return _context31.stop();
|
|
2825
3050
|
}
|
|
2826
3051
|
}, _loop3);
|
|
2827
3052
|
});
|
|
2828
3053
|
case 22:
|
|
2829
3054
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
2830
|
-
|
|
3055
|
+
_context32.next = 28;
|
|
2831
3056
|
break;
|
|
2832
3057
|
}
|
|
2833
|
-
return
|
|
3058
|
+
return _context32.delegateYield(_loop3(), "t0", 24);
|
|
2834
3059
|
case 24:
|
|
2835
|
-
if (!
|
|
2836
|
-
|
|
3060
|
+
if (!_context32.t0) {
|
|
3061
|
+
_context32.next = 26;
|
|
2837
3062
|
break;
|
|
2838
3063
|
}
|
|
2839
|
-
return
|
|
3064
|
+
return _context32.abrupt("break", 28);
|
|
2840
3065
|
case 26:
|
|
2841
|
-
|
|
3066
|
+
_context32.next = 22;
|
|
2842
3067
|
break;
|
|
2843
3068
|
case 28:
|
|
2844
3069
|
// 最终把资源数据也加到日期内
|
|
@@ -2852,21 +3077,45 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2852
3077
|
startDate: startDate,
|
|
2853
3078
|
endDate: endDate
|
|
2854
3079
|
});
|
|
2855
|
-
return
|
|
3080
|
+
return _context32.abrupt("return", {
|
|
2856
3081
|
dateList: dates,
|
|
2857
3082
|
firstAvailableDate: firstAvailableDate
|
|
2858
3083
|
});
|
|
2859
3084
|
case 32:
|
|
2860
3085
|
case "end":
|
|
2861
|
-
return
|
|
3086
|
+
return _context32.stop();
|
|
2862
3087
|
}
|
|
2863
|
-
},
|
|
3088
|
+
}, _callee30, this);
|
|
2864
3089
|
}));
|
|
2865
3090
|
function getAvailableDateForSessionOptimize() {
|
|
2866
3091
|
return _getAvailableDateForSessionOptimize.apply(this, arguments);
|
|
2867
3092
|
}
|
|
2868
3093
|
return getAvailableDateForSessionOptimize;
|
|
2869
3094
|
}()
|
|
3095
|
+
}, {
|
|
3096
|
+
key: "isCartAllNormalProducts",
|
|
3097
|
+
value: function isCartAllNormalProducts() {
|
|
3098
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
3099
|
+
return !isNormalProduct(n._productOrigin);
|
|
3100
|
+
});
|
|
3101
|
+
return !cartItems.length;
|
|
3102
|
+
}
|
|
3103
|
+
}, {
|
|
3104
|
+
key: "isCartHasDurationProduct",
|
|
3105
|
+
value: function isCartHasDurationProduct() {
|
|
3106
|
+
var cartItems = this.store.cart.getItems().filter(function (n) {
|
|
3107
|
+
return !isNormalProduct(n._productOrigin);
|
|
3108
|
+
});
|
|
3109
|
+
return cartItems.some(function (n) {
|
|
3110
|
+
var _n$_productOrigin4;
|
|
3111
|
+
return (_n$_productOrigin4 = n._productOrigin) === null || _n$_productOrigin4 === void 0 ? void 0 : _n$_productOrigin4.duration;
|
|
3112
|
+
});
|
|
3113
|
+
}
|
|
3114
|
+
}, {
|
|
3115
|
+
key: "isTargetNormalProduct",
|
|
3116
|
+
value: function isTargetNormalProduct(product) {
|
|
3117
|
+
return isNormalProduct(product);
|
|
3118
|
+
}
|
|
2870
3119
|
}]);
|
|
2871
3120
|
return BookingByStepImpl;
|
|
2872
3121
|
}(BaseModule);
|