@pisell/pisellos 3.0.41 → 3.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +28 -8
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +74 -10
- package/dist/modules/Date/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +218 -80
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/modules/Schedule/utils.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +121 -30
- package/dist/solution/BookingByStep/index.js +760 -1065
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/dist/solution/BookingByStep/utils/resources.js +39 -95
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -8
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -5
- package/lib/modules/Date/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +154 -63
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/modules/Schedule/utils.js +4 -1
- package/lib/solution/BookingByStep/index.d.ts +121 -30
- package/lib/solution/BookingByStep/index.js +395 -585
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
- package/lib/solution/BookingByStep/utils/resources.js +21 -58
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- package/package.json +1 -1
|
@@ -303,7 +303,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
303
303
|
key: "removeAccount",
|
|
304
304
|
value: function () {
|
|
305
305
|
var _removeAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
|
|
306
|
-
var index;
|
|
306
|
+
var _this$getActiveAccoun, index;
|
|
307
307
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
308
308
|
while (1) switch (_context6.prev = _context6.next) {
|
|
309
309
|
case 0:
|
|
@@ -324,26 +324,31 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
324
324
|
this.store.accountList = this.store.accountList.filter(function (account) {
|
|
325
325
|
return account.id !== id;
|
|
326
326
|
});
|
|
327
|
-
|
|
327
|
+
|
|
328
|
+
// 检测 如果被删除的是活跃账号,则默认把第一个账号设置为 activeAccount
|
|
329
|
+
if (!this.getActiveAccount() || ((_this$getActiveAccoun = this.getActiveAccount()) === null || _this$getActiveAccoun === void 0 ? void 0 : _this$getActiveAccoun.getId()) === id || this.store.accounts.length === 1) {
|
|
330
|
+
this.setActiveAccount(this.store.accounts[0].getId());
|
|
331
|
+
}
|
|
332
|
+
_context6.next = 12;
|
|
328
333
|
return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
|
|
329
|
-
case
|
|
330
|
-
_context6.next =
|
|
334
|
+
case 12:
|
|
335
|
+
_context6.next = 19;
|
|
331
336
|
break;
|
|
332
|
-
case
|
|
333
|
-
_context6.prev =
|
|
337
|
+
case 14:
|
|
338
|
+
_context6.prev = 14;
|
|
334
339
|
_context6.t0 = _context6["catch"](0);
|
|
335
340
|
this.store.error = _context6.t0 instanceof Error ? _context6.t0.message : 'Failed to remove account';
|
|
336
|
-
_context6.next =
|
|
341
|
+
_context6.next = 19;
|
|
337
342
|
return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
|
|
338
|
-
case
|
|
339
|
-
_context6.prev =
|
|
343
|
+
case 19:
|
|
344
|
+
_context6.prev = 19;
|
|
340
345
|
this.store.isLoading = false;
|
|
341
|
-
return _context6.finish(
|
|
342
|
-
case
|
|
346
|
+
return _context6.finish(19);
|
|
347
|
+
case 22:
|
|
343
348
|
case "end":
|
|
344
349
|
return _context6.stop();
|
|
345
350
|
}
|
|
346
|
-
}, _callee6, this, [[0,
|
|
351
|
+
}, _callee6, this, [[0, 14, 19, 22]]);
|
|
347
352
|
}));
|
|
348
353
|
function removeAccount(_x9) {
|
|
349
354
|
return _removeAccount.apply(this, arguments);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
3
|
import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
|
|
4
|
+
import { Account } from '../Account';
|
|
4
5
|
export * from './types';
|
|
5
6
|
/**
|
|
6
7
|
* 购物车模块实现
|
|
@@ -67,4 +68,17 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
67
68
|
clear(): void;
|
|
68
69
|
storeChange(): void;
|
|
69
70
|
checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
73
|
+
*
|
|
74
|
+
* @param {string} rowKey
|
|
75
|
+
* @param {number} quantity
|
|
76
|
+
* @return {*}
|
|
77
|
+
* @memberof CartModule
|
|
78
|
+
*/
|
|
79
|
+
mergeCartItemByRowKey(params: {
|
|
80
|
+
rowKey?: string;
|
|
81
|
+
quantity?: number;
|
|
82
|
+
account?: Account;
|
|
83
|
+
}): boolean;
|
|
70
84
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
4
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
5
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
6
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -25,6 +27,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
25
27
|
import { ECartItemCheckType, ECartItemInfoType } from "./types";
|
|
26
28
|
import { createCartItemOrigin, deleteHolderFromCartItem, deleteRelationFormsFromCartItem, deleteResourceFromCartItem, deleteTimeFromCartItem, formatAccountToCartItem, formatDateToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatRelationFormsToCartItem, formatResourceToCartItem, getUniqueId, handleVariantProduct } from "./utils";
|
|
27
29
|
import { cloneDeep } from 'lodash-es';
|
|
30
|
+
import { isNormalProduct } from "../Product/utils";
|
|
28
31
|
export * from "./types";
|
|
29
32
|
|
|
30
33
|
/**
|
|
@@ -253,7 +256,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
253
256
|
bundle: bundle,
|
|
254
257
|
options: options,
|
|
255
258
|
product_variant_id: newProduct.product_variant_id,
|
|
256
|
-
quantity: quantity
|
|
259
|
+
quantity: quantity,
|
|
260
|
+
discounts: discounts
|
|
257
261
|
});
|
|
258
262
|
}
|
|
259
263
|
if (discounts) {
|
|
@@ -482,6 +486,39 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
482
486
|
}
|
|
483
487
|
return result;
|
|
484
488
|
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
492
|
+
*
|
|
493
|
+
* @param {string} rowKey
|
|
494
|
+
* @param {number} quantity
|
|
495
|
+
* @return {*}
|
|
496
|
+
* @memberof CartModule
|
|
497
|
+
*/
|
|
498
|
+
}, {
|
|
499
|
+
key: "mergeCartItemByRowKey",
|
|
500
|
+
value: function mergeCartItemByRowKey(params) {
|
|
501
|
+
var rowKey = params.rowKey,
|
|
502
|
+
quantity = params.quantity,
|
|
503
|
+
account = params.account;
|
|
504
|
+
var flag = false;
|
|
505
|
+
var cartItems = this.getItems();
|
|
506
|
+
var targetCartItem = cartItems.find(function (n) {
|
|
507
|
+
var _n$_productOrigin;
|
|
508
|
+
return ((_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.rowKey) === rowKey;
|
|
509
|
+
});
|
|
510
|
+
var isSameAccount = (account === null || account === void 0 ? void 0 : account.id) === (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id);
|
|
511
|
+
if (rowKey && targetCartItem && isNormalProduct(targetCartItem._productOrigin) && isSameAccount) {
|
|
512
|
+
this.updateItem({
|
|
513
|
+
_id: targetCartItem._id,
|
|
514
|
+
product: _objectSpread(_objectSpread({}, targetCartItem._productOrigin), {}, {
|
|
515
|
+
quantity: (targetCartItem.num || 1) + (quantity || 1)
|
|
516
|
+
})
|
|
517
|
+
});
|
|
518
|
+
flag = true;
|
|
519
|
+
}
|
|
520
|
+
return flag;
|
|
521
|
+
}
|
|
485
522
|
}]);
|
|
486
523
|
return CartModule;
|
|
487
524
|
}(BaseModule);
|
|
@@ -20,6 +20,7 @@ export declare const formatProductToCartItem: (params: {
|
|
|
20
20
|
options?: any;
|
|
21
21
|
product_variant_id?: number;
|
|
22
22
|
quantity?: number;
|
|
23
|
+
discounts?: any[];
|
|
23
24
|
}) => CartItem;
|
|
24
25
|
export declare const formatProductToCartItemOrigin: (params: {
|
|
25
26
|
cartItem: CartItem;
|
|
@@ -40,6 +41,7 @@ export declare const getProductTotalPrice: (params: {
|
|
|
40
41
|
bundle?: any;
|
|
41
42
|
options?: any;
|
|
42
43
|
num?: number;
|
|
44
|
+
discounts?: any[];
|
|
43
45
|
}) => number;
|
|
44
46
|
/**
|
|
45
47
|
* 获取商品原始总价
|
|
@@ -52,6 +54,7 @@ export declare const getProductOriginTotalPrice: (params: {
|
|
|
52
54
|
bundle?: any;
|
|
53
55
|
options?: any;
|
|
54
56
|
num?: number;
|
|
57
|
+
discounts?: any[];
|
|
55
58
|
}) => number | undefined;
|
|
56
59
|
/**
|
|
57
60
|
* 格式化套餐规格信息
|
|
@@ -28,7 +28,10 @@ export var handleVariantProduct = function handleVariantProduct(product) {
|
|
|
28
28
|
});
|
|
29
29
|
if (targetVariant) {
|
|
30
30
|
product.price = targetVariant.price;
|
|
31
|
-
|
|
31
|
+
// 如果 original_price 为 0,就不改了
|
|
32
|
+
if (Number(targetVariant.original_price) > 0) {
|
|
33
|
+
product.original_price = targetVariant.original_price;
|
|
34
|
+
}
|
|
32
35
|
product.is_charge_tax = targetVariant.is_charge_tax;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -48,7 +51,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
48
51
|
options = params.options,
|
|
49
52
|
product_variant_id = params.product_variant_id,
|
|
50
53
|
_params$quantity = params.quantity,
|
|
51
|
-
quantity = _params$quantity === void 0 ? 1 : _params$quantity
|
|
54
|
+
quantity = _params$quantity === void 0 ? 1 : _params$quantity,
|
|
55
|
+
discounts = params.discounts;
|
|
52
56
|
var num = quantity; // 当前按照单个商品加入购物车
|
|
53
57
|
if (product) {
|
|
54
58
|
cartItem.id = product === null || product === void 0 ? void 0 : product.id;
|
|
@@ -59,14 +63,16 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
59
63
|
product: product,
|
|
60
64
|
bundle: bundle,
|
|
61
65
|
options: options,
|
|
62
|
-
num: num
|
|
66
|
+
num: num,
|
|
67
|
+
discounts: discounts
|
|
63
68
|
});
|
|
64
69
|
cartItem.summaryTotal = cartItem.total * (num || 1);
|
|
65
70
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
66
71
|
product: product,
|
|
67
72
|
bundle: bundle,
|
|
68
73
|
options: options,
|
|
69
|
-
num: num
|
|
74
|
+
num: num,
|
|
75
|
+
discounts: discounts
|
|
70
76
|
});
|
|
71
77
|
cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
|
|
72
78
|
cartItem.like_status = 'common';
|
|
@@ -161,7 +167,8 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
|
|
|
161
167
|
export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
162
168
|
var product = params.product,
|
|
163
169
|
bundle = params.bundle,
|
|
164
|
-
options = params.options
|
|
170
|
+
options = params.options,
|
|
171
|
+
discounts = params.discounts;
|
|
165
172
|
// const num = params.num || 1;
|
|
166
173
|
var price = Number(product.price);
|
|
167
174
|
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
@@ -176,6 +183,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
176
183
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
177
184
|
}, price);
|
|
178
185
|
}
|
|
186
|
+
|
|
187
|
+
// 如果商品有折扣,则计算折扣
|
|
188
|
+
if (discounts !== null && discounts !== void 0 && discounts.length) {
|
|
189
|
+
discounts.forEach(function (currentValue) {
|
|
190
|
+
// 不是商品券则代表折扣卡,计算打折后的价格
|
|
191
|
+
// 一个商品折扣卡只能存在于一张
|
|
192
|
+
if (currentValue.type !== 'good_pass') {
|
|
193
|
+
var discountPrice = new Decimal(100).minus(currentValue.discount.percent || 0).div(100).mul(new Decimal(price || 0)).toFixed(2);
|
|
194
|
+
price = Number(discountPrice);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
179
198
|
return price;
|
|
180
199
|
};
|
|
181
200
|
|
|
@@ -188,10 +207,11 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
188
207
|
export var getProductOriginTotalPrice = function getProductOriginTotalPrice(params) {
|
|
189
208
|
var product = params.product,
|
|
190
209
|
bundle = params.bundle,
|
|
191
|
-
options = params.options
|
|
210
|
+
options = params.options,
|
|
211
|
+
discounts = params.discounts;
|
|
192
212
|
var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
|
|
193
213
|
var price = Number(product.original_price);
|
|
194
|
-
if (isNaN(price) || price === 0) {
|
|
214
|
+
if ((isNaN(price) || price === 0) && !(discounts !== null && discounts !== void 0 && discounts.length)) {
|
|
195
215
|
return undefined;
|
|
196
216
|
}
|
|
197
217
|
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
@@ -206,7 +226,7 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
|
|
|
206
226
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
207
227
|
}, price);
|
|
208
228
|
}
|
|
209
|
-
return price
|
|
229
|
+
return price;
|
|
210
230
|
};
|
|
211
231
|
|
|
212
232
|
/**
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Product } from "../../Product";
|
|
2
|
+
import { CartItem, IUpdateItemParams } from "../types";
|
|
3
|
+
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
13
|
+
import Decimal from "decimal.js";
|
|
14
|
+
export function updateAllCartItemPrice(_x, _x2, _x3, _x4) {
|
|
15
|
+
return _updateAllCartItemPrice.apply(this, arguments);
|
|
16
|
+
}
|
|
17
|
+
function _updateAllCartItemPrice() {
|
|
18
|
+
_updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart) {
|
|
19
|
+
var _iterator, _step, _loop;
|
|
20
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
21
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_iterator = _createForOfIteratorHelper(cartItems);
|
|
24
|
+
_context2.prev = 1;
|
|
25
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
26
|
+
var _bundle;
|
|
27
|
+
var item, targetProduct, cartProduct, productInfo, bundle;
|
|
28
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
item = _step.value;
|
|
32
|
+
targetProduct = priceData.find(function (n) {
|
|
33
|
+
return n.id === item.id;
|
|
34
|
+
});
|
|
35
|
+
_context.next = 4;
|
|
36
|
+
return getProduct(item.id);
|
|
37
|
+
case 4:
|
|
38
|
+
cartProduct = _context.sent;
|
|
39
|
+
productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
|
|
40
|
+
bundle = item._bundleOrigin;
|
|
41
|
+
productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
|
|
42
|
+
productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
|
|
43
|
+
bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
|
|
44
|
+
var _targetProduct$bundle;
|
|
45
|
+
// 更新 bundle 的价格
|
|
46
|
+
var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
|
|
47
|
+
return m.id === n.group_id;
|
|
48
|
+
});
|
|
49
|
+
if (targetBundle) {
|
|
50
|
+
var targetBundleItem = targetBundle.bundle_item.find(function (m) {
|
|
51
|
+
return m.id === n.id;
|
|
52
|
+
});
|
|
53
|
+
if (targetBundleItem.price_type === 'markdown') {
|
|
54
|
+
targetBundleItem.price = new Decimal(targetBundleItem.price || 0).mul(-1).toNumber();
|
|
55
|
+
}
|
|
56
|
+
if (targetBundleItem) {
|
|
57
|
+
return _objectSpread(_objectSpread({}, n), {}, {
|
|
58
|
+
price: targetBundleItem.price,
|
|
59
|
+
base_price: targetBundleItem.base_price
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return n;
|
|
64
|
+
});
|
|
65
|
+
updateCart({
|
|
66
|
+
_id: item._id,
|
|
67
|
+
product: productInfo,
|
|
68
|
+
bundle: bundle
|
|
69
|
+
});
|
|
70
|
+
case 11:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _loop);
|
|
75
|
+
});
|
|
76
|
+
_iterator.s();
|
|
77
|
+
case 4:
|
|
78
|
+
if ((_step = _iterator.n()).done) {
|
|
79
|
+
_context2.next = 8;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
return _context2.delegateYield(_loop(), "t0", 6);
|
|
83
|
+
case 6:
|
|
84
|
+
_context2.next = 4;
|
|
85
|
+
break;
|
|
86
|
+
case 8:
|
|
87
|
+
_context2.next = 13;
|
|
88
|
+
break;
|
|
89
|
+
case 10:
|
|
90
|
+
_context2.prev = 10;
|
|
91
|
+
_context2.t1 = _context2["catch"](1);
|
|
92
|
+
_iterator.e(_context2.t1);
|
|
93
|
+
case 13:
|
|
94
|
+
_context2.prev = 13;
|
|
95
|
+
_iterator.f();
|
|
96
|
+
return _context2.finish(13);
|
|
97
|
+
case 16:
|
|
98
|
+
case "end":
|
|
99
|
+
return _context2.stop();
|
|
100
|
+
}
|
|
101
|
+
}, _callee, null, [[1, 10, 13, 16]]);
|
|
102
|
+
}));
|
|
103
|
+
return _updateAllCartItemPrice.apply(this, arguments);
|
|
104
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2
8
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
10
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -17,6 +23,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
17
23
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
24
|
import { BaseModule } from "../BaseModule";
|
|
19
25
|
import { disableAllDates, generateMonthDates, handleAvailableDateByResource, handleAvailableDatesByRules } from "./utils";
|
|
26
|
+
import cloneDeep from 'lodash-es/cloneDeep';
|
|
20
27
|
export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
21
28
|
_inherits(DateModule, _BaseModule);
|
|
22
29
|
var _super = _createSuper(DateModule);
|
|
@@ -86,17 +93,40 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
86
93
|
key: "getResourceDates",
|
|
87
94
|
value: function () {
|
|
88
95
|
var _getResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
89
|
-
var dates;
|
|
96
|
+
var _params$query, currentDateList, currentDateListMap, resourceIds, hasResource, dates;
|
|
90
97
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
91
98
|
while (1) switch (_context2.prev = _context2.next) {
|
|
92
99
|
case 0:
|
|
93
|
-
|
|
100
|
+
if (!params.useCache) {
|
|
101
|
+
_context2.next = 7;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
// 发请求之前,做一道检测,看 dateList 里是否有对应日期,且对应日期里是否都有对应 resource_ids 的资源
|
|
105
|
+
currentDateList = this.getDateList() || [];
|
|
106
|
+
currentDateListMap = new Map(currentDateList.map(function (item) {
|
|
107
|
+
return [item.date, item];
|
|
108
|
+
}));
|
|
109
|
+
resourceIds = ((_params$query = params.query) === null || _params$query === void 0 ? void 0 : _params$query.resource_ids) || [];
|
|
110
|
+
hasResource = resourceIds.every(function (id) {
|
|
111
|
+
var _currentItem$resource;
|
|
112
|
+
var currentItem = currentDateListMap.get(id.toString());
|
|
113
|
+
return currentItem === null || currentItem === void 0 || (_currentItem$resource = currentItem.resource) === null || _currentItem$resource === void 0 ? void 0 : _currentItem$resource.some(function (n) {
|
|
114
|
+
return n.id === id;
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
if (!hasResource) {
|
|
118
|
+
_context2.next = 7;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
return _context2.abrupt("return", currentDateList);
|
|
122
|
+
case 7:
|
|
123
|
+
_context2.next = 9;
|
|
94
124
|
return this.getResourceAvailableTimeList(params);
|
|
95
|
-
case
|
|
125
|
+
case 9:
|
|
96
126
|
dates = _context2.sent;
|
|
97
|
-
this.
|
|
127
|
+
this.setDateList(dates);
|
|
98
128
|
return _context2.abrupt("return", dates);
|
|
99
|
-
case
|
|
129
|
+
case 12:
|
|
100
130
|
case "end":
|
|
101
131
|
return _context2.stop();
|
|
102
132
|
}
|
|
@@ -115,17 +145,51 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
115
145
|
}, {
|
|
116
146
|
key: "setDateList",
|
|
117
147
|
value: function setDateList(dateList) {
|
|
118
|
-
this.store.dateList = dateList;
|
|
148
|
+
// this.store.dateList = dateList;
|
|
149
|
+
// 并不能直接简单的进行复制
|
|
150
|
+
// 我们需要把每一天的资源都进行一个合并
|
|
151
|
+
var currentDateList = cloneDeep(this.store.dateList) || [];
|
|
152
|
+
dateList.forEach(function (item) {
|
|
153
|
+
var currentItemIndex = currentDateList.findIndex(function (n) {
|
|
154
|
+
return n.date === item.date;
|
|
155
|
+
});
|
|
156
|
+
if (currentItemIndex !== -1) {
|
|
157
|
+
var _item$resource, _currentItem$resource3;
|
|
158
|
+
var currentItem = currentDateList[currentItemIndex];
|
|
159
|
+
// 看那一天的数据有没有相同的,把不同的资源合并进去即可
|
|
160
|
+
var newResource = (_item$resource = item.resource) === null || _item$resource === void 0 ? void 0 : _item$resource.filter(function (n) {
|
|
161
|
+
var _currentItem$resource2;
|
|
162
|
+
return !((_currentItem$resource2 = currentItem.resource) !== null && _currentItem$resource2 !== void 0 && _currentItem$resource2.some(function (m) {
|
|
163
|
+
return m.id === n.id;
|
|
164
|
+
}));
|
|
165
|
+
});
|
|
166
|
+
// 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
|
|
167
|
+
(_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
|
|
168
|
+
var _item$resource2;
|
|
169
|
+
var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.find(function (m) {
|
|
170
|
+
return m.id === n.id;
|
|
171
|
+
});
|
|
172
|
+
if (newResource) {
|
|
173
|
+
n.times = newResource.times;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
currentItem.resource = [].concat(_toConsumableArray(currentItem.resource || []), _toConsumableArray(newResource || []));
|
|
177
|
+
currentDateList[currentItemIndex] = currentItem;
|
|
178
|
+
} else {
|
|
179
|
+
currentDateList.push(item);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
this.store.dateList = currentDateList;
|
|
119
183
|
}
|
|
120
184
|
}, {
|
|
121
185
|
key: "fetchResourceDates",
|
|
122
186
|
value: function () {
|
|
123
187
|
var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
124
|
-
var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
|
|
188
|
+
var url, query, _params$useCache, useCache, fetchUrl, _ref, start_date, end_date, resource_ids, res;
|
|
125
189
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
126
190
|
while (1) switch (_context3.prev = _context3.next) {
|
|
127
191
|
case 0:
|
|
128
|
-
url = params.url, query = params.query;
|
|
192
|
+
url = params.url, query = params.query, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache;
|
|
129
193
|
fetchUrl = url || '/schedule/resource/list';
|
|
130
194
|
_ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
|
|
131
195
|
_context3.prev = 3;
|
|
@@ -134,9 +198,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
134
198
|
start_date: start_date,
|
|
135
199
|
end_date: end_date,
|
|
136
200
|
resource_ids: resource_ids,
|
|
137
|
-
front_end_cache_id: this.cacheId
|
|
201
|
+
front_end_cache_id: useCache && this.cacheId
|
|
138
202
|
}, {
|
|
139
|
-
useCache:
|
|
203
|
+
useCache: useCache
|
|
140
204
|
});
|
|
141
205
|
case 6:
|
|
142
206
|
res = _context3.sent;
|
|
@@ -17,6 +17,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
loadPrepareConfig(params: {
|
|
18
18
|
action?: 'create';
|
|
19
19
|
with_good_pass: 0 | 1;
|
|
20
|
+
with_discount_card: 0 | 1;
|
|
20
21
|
customer_id: number;
|
|
21
22
|
}): Promise<Discount[]>;
|
|
22
23
|
batchSearch(code: string): Promise<Discount[]>;
|