@pisell/private-materials 3.0.201 → 3.0.203
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/preview.js +142 -142
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +12 -27
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +18 -33
- package/es/components/booking/addons/model.d.ts +1 -1
- package/es/components/booking/components/footer/amount.js +5 -4
- package/es/components/booking/components/footer/utils.js +49 -29
- package/es/components/booking/forms/model.d.ts +1 -1
- package/es/components/booking/info/Provider.d.ts +0 -0
- package/es/components/booking/info/Provider.js +54 -0
- package/es/components/booking/info/clientVariant/vertical/index.js +93 -7
- package/es/components/booking/info/main.js +10 -9
- package/es/components/booking/info/pet/ChangePetModal/index.js +38 -23
- package/es/components/booking/info/service/addService/index.js +70 -99
- package/es/components/booking/info/service/addService/utils.d.ts +1 -0
- package/es/components/booking/info/service/addService/utils.js +55 -3
- package/es/components/booking/info/service/editService/BookingList/index.d.ts +5 -0
- package/es/components/booking/info/service/editService/BookingList/index.js +39 -0
- package/es/components/booking/info/service/editService/EditTabs/index.d.ts +3 -0
- package/es/components/booking/info/service/editService/EditTabs/index.js +35 -0
- package/es/components/booking/info/service/editService/index.js +234 -142
- package/es/components/booking/info/service/serve.d.ts +10 -0
- package/es/components/booking/info/service/serve.js +28 -0
- package/es/components/booking/info/service/serviceManager/distributeDiscount.d.ts +11 -0
- package/es/components/booking/info/service/serviceManager/distributeDiscount.js +55 -0
- package/es/components/booking/info/service/serviceManager/index.d.ts +20 -0
- package/es/components/booking/info/service/serviceManager/index.js +277 -0
- package/es/components/booking/info/service/serviceManager/utils.d.ts +0 -0
- package/es/components/booking/info/service/serviceManager/utils.js +0 -0
- package/es/components/booking/info/service2/Group/utils.d.ts +14 -0
- package/es/components/booking/info/service2/Group/utils.js +146 -0
- package/es/components/booking/info/service2/Lists.js +27 -33
- package/es/components/booking/info/service2/index.d.ts +4 -1
- package/es/components/booking/info/service2/index.js +5 -6
- package/es/components/booking/info/service2/status.js +1 -1
- package/es/components/booking/info/service2/utils.d.ts +95 -3
- package/es/components/booking/info/service2/utils.js +678 -52
- package/es/components/booking/info/utils.d.ts +11 -0
- package/es/components/booking/info/utils.js +24 -0
- package/es/components/booking/locales.d.ts +6 -0
- package/es/components/booking/locales.js +9 -3
- package/es/components/booking/model.d.ts +1 -0
- package/es/components/booking/notes/index.d.ts +1 -1
- package/es/components/booking/notes/model.d.ts +1 -1
- package/es/components/booking/payments/index.d.ts +1 -1
- package/es/components/booking/payments/model.d.ts +1 -1
- package/es/components/booking/utils.js +5 -4
- package/es/components/eftpos/hooks.d.ts +4 -4
- package/es/components/eftposPay/amount.d.ts +1 -1
- package/es/components/eftposPay/component/step/index.d.ts +6 -6
- package/es/components/eftposPay/component/step/step.d.ts +4 -4
- package/es/components/eftposPay/hooks.d.ts +1 -1
- package/es/components/eftposPay/store/index.d.ts +1 -1
- package/es/components/eftposPay/tyro/hooks.d.ts +2 -2
- package/es/components/eftposPay/windcave/helper.d.ts +1 -1
- package/es/components/schedules/index.d.ts +1 -1
- package/es/components/schedules/model.d.ts +1 -1
- package/es/components/shoppingCart/components/Cart/Product.js +11 -39
- package/es/components/shoppingCart/components/Render/index.js +8 -7
- package/es/components/shoppingCart/components/SelectHolderModal/index.js +12 -4
- package/es/components/shoppingCart/hooks/useClearCart.js +10 -5
- package/es/components/shoppingCart/type.d.ts +1 -1
- package/es/components/shoppingCart/utils.js +2 -5
- package/lib/components/booking/addons/model.d.ts +1 -1
- package/lib/components/booking/components/footer/amount.js +4 -3
- package/lib/components/booking/components/footer/utils.js +28 -28
- package/lib/components/booking/forms/model.d.ts +1 -1
- package/lib/components/booking/info/Provider.d.ts +0 -0
- package/lib/components/booking/info/Provider.js +0 -0
- package/lib/components/booking/info/clientVariant/vertical/index.js +51 -1
- package/lib/components/booking/info/main.js +6 -5
- package/lib/components/booking/info/pet/ChangePetModal/index.js +33 -23
- package/lib/components/booking/info/service/addService/index.js +50 -92
- package/lib/components/booking/info/service/addService/utils.d.ts +1 -0
- package/lib/components/booking/info/service/addService/utils.js +27 -0
- package/lib/components/booking/info/service/editService/BookingList/index.d.ts +5 -0
- package/lib/components/booking/info/service/editService/BookingList/index.js +55 -0
- package/lib/components/booking/info/service/editService/EditTabs/index.d.ts +3 -0
- package/lib/components/booking/info/service/editService/EditTabs/index.js +75 -0
- package/lib/components/booking/info/service/editService/index.js +309 -234
- package/lib/components/booking/info/service/serve.d.ts +10 -0
- package/lib/components/booking/info/service/serve.js +7 -2
- package/lib/components/booking/info/service/serviceManager/distributeDiscount.d.ts +11 -0
- package/lib/components/booking/info/service/serviceManager/distributeDiscount.js +70 -0
- package/lib/components/booking/info/service/serviceManager/index.d.ts +20 -0
- package/lib/components/booking/info/service/serviceManager/index.js +207 -0
- package/lib/components/booking/info/service/serviceManager/utils.d.ts +0 -0
- package/lib/components/booking/info/service/serviceManager/utils.js +0 -0
- package/lib/components/booking/info/service2/Group/utils.d.ts +14 -0
- package/lib/components/booking/info/service2/Group/utils.js +142 -0
- package/lib/components/booking/info/service2/Lists.js +14 -12
- package/lib/components/booking/info/service2/index.d.ts +4 -1
- package/lib/components/booking/info/service2/index.js +5 -5
- package/lib/components/booking/info/service2/status.js +1 -1
- package/lib/components/booking/info/service2/utils.d.ts +95 -3
- package/lib/components/booking/info/service2/utils.js +404 -48
- package/lib/components/booking/info/utils.d.ts +11 -0
- package/lib/components/booking/info/utils.js +35 -0
- package/lib/components/booking/locales.d.ts +6 -0
- package/lib/components/booking/locales.js +9 -3
- package/lib/components/booking/model.d.ts +1 -0
- package/lib/components/booking/notes/index.d.ts +1 -1
- package/lib/components/booking/notes/model.d.ts +1 -1
- package/lib/components/booking/payments/index.d.ts +1 -1
- package/lib/components/booking/payments/model.d.ts +1 -1
- package/lib/components/booking/utils.js +3 -4
- package/lib/components/eftpos/hooks.d.ts +4 -4
- package/lib/components/eftposPay/amount.d.ts +1 -1
- package/lib/components/eftposPay/component/step/index.d.ts +6 -6
- package/lib/components/eftposPay/component/step/step.d.ts +4 -4
- package/lib/components/eftposPay/hooks.d.ts +1 -1
- package/lib/components/eftposPay/store/index.d.ts +1 -1
- package/lib/components/eftposPay/tyro/hooks.d.ts +2 -2
- package/lib/components/eftposPay/windcave/helper.d.ts +1 -1
- package/lib/components/schedules/index.d.ts +1 -1
- package/lib/components/schedules/model.d.ts +1 -1
- package/lib/components/shoppingCart/components/Cart/Product.js +6 -22
- package/lib/components/shoppingCart/components/Render/index.js +6 -10
- package/lib/components/shoppingCart/components/SelectHolderModal/index.js +12 -4
- package/lib/components/shoppingCart/hooks/useClearCart.js +4 -9
- package/lib/components/shoppingCart/type.d.ts +1 -1
- package/lib/components/shoppingCart/utils.js +2 -8
- package/package.json +4 -4
|
@@ -18,4 +18,32 @@ export var getProductDetail = /*#__PURE__*/function () {
|
|
|
18
18
|
return function getProductDetail(_x, _x2) {
|
|
19
19
|
return _ref.apply(this, arguments);
|
|
20
20
|
};
|
|
21
|
+
}();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @title: 跨日预约获取预约商品报价单
|
|
25
|
+
* @description:
|
|
26
|
+
* @param {string} id
|
|
27
|
+
* @param {any} params
|
|
28
|
+
* @return {*}
|
|
29
|
+
* @Author: WangHan
|
|
30
|
+
* @Date: 2024-12-23 17:06
|
|
31
|
+
*/
|
|
32
|
+
export var postMultiDay = /*#__PURE__*/function () {
|
|
33
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id, params) {
|
|
34
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
35
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
return _context2.abrupt("return", request.getRequest().post("/shop/product/multi-day/detail/".concat(id), params, {
|
|
38
|
+
useCache: true
|
|
39
|
+
}));
|
|
40
|
+
case 1:
|
|
41
|
+
case "end":
|
|
42
|
+
return _context2.stop();
|
|
43
|
+
}
|
|
44
|
+
}, _callee2);
|
|
45
|
+
}));
|
|
46
|
+
return function postMultiDay(_x3, _x4) {
|
|
47
|
+
return _ref2.apply(this, arguments);
|
|
48
|
+
};
|
|
21
49
|
}();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Product {
|
|
2
|
+
_id: string;
|
|
3
|
+
_extend: {
|
|
4
|
+
origin_total: number;
|
|
5
|
+
total: number;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function distributeDiscountOrIncrease(products: Product[], // 商品列表
|
|
9
|
+
totalAdjustment: number, // 总折扣或加价金额,可能为负数(折扣)或正数(加价)
|
|
10
|
+
totalPrice: number): Product[];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import Decimal from 'decimal.js';
|
|
8
|
+
export function distributeDiscountOrIncrease(products,
|
|
9
|
+
// 商品列表
|
|
10
|
+
totalAdjustment,
|
|
11
|
+
// 总折扣或加价金额,可能为负数(折扣)或正数(加价)
|
|
12
|
+
totalPrice) {
|
|
13
|
+
// 总折扣
|
|
14
|
+
var totalAdjustmentDecimal = new Decimal(totalAdjustment);
|
|
15
|
+
var totalAdjustmentApplied = new Decimal(0);
|
|
16
|
+
|
|
17
|
+
// 存储调整后的商品
|
|
18
|
+
var adjustedProducts = [];
|
|
19
|
+
|
|
20
|
+
// 按比例分摊折扣/加价金额
|
|
21
|
+
products.forEach(function (product) {
|
|
22
|
+
// 原始价格
|
|
23
|
+
var productPrice = new Decimal(product._extend.origin_total);
|
|
24
|
+
// 按比例计算调整金额
|
|
25
|
+
var adjustmentAmount = productPrice.div(totalPrice).times(totalAdjustmentDecimal).toFixed(2, Decimal.ROUND_HALF_UP);
|
|
26
|
+
|
|
27
|
+
// 防止价格变负,调整均摊金额
|
|
28
|
+
var newPrice = productPrice.plus(adjustmentAmount).toFixed(2, Decimal.ROUND_HALF_UP);
|
|
29
|
+
var adjustedPrice = new Decimal(newPrice).lessThan(0) ? '0.00' : newPrice;
|
|
30
|
+
adjustedProducts.push(_objectSpread(_objectSpread({}, product), {}, {
|
|
31
|
+
_extend: _objectSpread(_objectSpread({}, product._extend), {}, {
|
|
32
|
+
total: parseFloat(adjustedPrice)
|
|
33
|
+
})
|
|
34
|
+
}));
|
|
35
|
+
totalAdjustmentApplied = totalAdjustmentApplied.plus(new Decimal(adjustmentAmount));
|
|
36
|
+
});
|
|
37
|
+
// 计算调整后的总金额
|
|
38
|
+
var finalTotalPrice = adjustedProducts.reduce(function (sum, product) {
|
|
39
|
+
return sum.plus(new Decimal(product._extend.total));
|
|
40
|
+
}, new Decimal(0));
|
|
41
|
+
|
|
42
|
+
// 如果总价与目标差异不为零,则调整最后一个商品价格 150 - (-10 + 140 ) = 0
|
|
43
|
+
var adjustmentDifference = new Decimal(totalPrice).minus(finalTotalPrice).plus(new Decimal(totalAdjustment));
|
|
44
|
+
if (!adjustmentDifference.isZero()) {
|
|
45
|
+
var lastProduct = adjustedProducts[adjustedProducts.length - 1];
|
|
46
|
+
var lastPrice = new Decimal(lastProduct._extend.total).plus(adjustmentDifference).toFixed(2, Decimal.ROUND_HALF_UP);
|
|
47
|
+
|
|
48
|
+
// 确保最后调整后的价格不为负数
|
|
49
|
+
lastPrice = new Decimal(lastPrice).lessThan(0) ? '0.00' : lastPrice;
|
|
50
|
+
lastProduct._extend.total = parseFloat(lastPrice);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 将结果格式化为以 _id 为键的对象
|
|
54
|
+
return adjustedProducts;
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const useService: ({ renderMode, onEdit, state, dispatch, }: {
|
|
2
|
+
renderMode?: any;
|
|
3
|
+
onEdit?: any;
|
|
4
|
+
state?: any;
|
|
5
|
+
dispatch?: any;
|
|
6
|
+
}) => {
|
|
7
|
+
createBookingData: ({ product }: any) => Promise<any>;
|
|
8
|
+
editBookingData: ({ changeValues }: {
|
|
9
|
+
changeValues: any;
|
|
10
|
+
}) => Promise<any>;
|
|
11
|
+
createBooking: ({ booking }: {
|
|
12
|
+
booking: any;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
editBooking: ({ booking }: {
|
|
15
|
+
booking: any;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
goEditPanel: ({ booking }: {
|
|
18
|
+
booking: any;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
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); } }
|
|
9
|
+
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); }); }; }
|
|
10
|
+
import { useMemo, useCallback } from 'react';
|
|
11
|
+
import { getUniqueId } from '@pisell/utils';
|
|
12
|
+
import { getProductExtend, getMultiDay } from "../addService/utils";
|
|
13
|
+
import { isDayBookingProduct, isDayBooking, isBookingProduct } from "../../service2/utils";
|
|
14
|
+
import { createBookingItemsByGroup, concatBookings } from "../../service2/Group/utils";
|
|
15
|
+
import { getServiceTimes, deleteCacheParams, getProductTotalPrice } from "../../../utils";
|
|
16
|
+
var lock = false;
|
|
17
|
+
export var useService = function useService(_ref) {
|
|
18
|
+
var _state$service2;
|
|
19
|
+
var renderMode = _ref.renderMode,
|
|
20
|
+
onEdit = _ref.onEdit,
|
|
21
|
+
state = _ref.state,
|
|
22
|
+
dispatch = _ref.dispatch;
|
|
23
|
+
var holderId = useMemo(function () {
|
|
24
|
+
var _state$activeCartId;
|
|
25
|
+
return Number((state === null || state === void 0 ? void 0 : (_state$activeCartId = state.activeCartId) === null || _state$activeCartId === void 0 ? void 0 : _state$activeCartId[0]) || 0);
|
|
26
|
+
}, [state === null || state === void 0 ? void 0 : state.activeCartId]);
|
|
27
|
+
var isDayBookingMode = useMemo(function () {
|
|
28
|
+
return isDayBooking(state);
|
|
29
|
+
}, [state === null || state === void 0 ? void 0 : state.renderType]);
|
|
30
|
+
var createBookingData = /*#__PURE__*/function () {
|
|
31
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
32
|
+
var product, _params, cacheItem, _total, _isEdit, _state$service$cacheI, _state$service;
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
product = _ref2.product;
|
|
37
|
+
if (!lock) {
|
|
38
|
+
_context.next = 3;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
return _context.abrupt("return");
|
|
42
|
+
case 3:
|
|
43
|
+
lock = true;
|
|
44
|
+
|
|
45
|
+
// 2秒后解除
|
|
46
|
+
setTimeout(function () {
|
|
47
|
+
lock = false;
|
|
48
|
+
}, 2000);
|
|
49
|
+
_params = product._params;
|
|
50
|
+
cacheItem = _objectSpread(_objectSpread({}, product), {}, {
|
|
51
|
+
product_id: product.id,
|
|
52
|
+
_id: getUniqueId(),
|
|
53
|
+
_key: _params.key,
|
|
54
|
+
_extend: {
|
|
55
|
+
start_date: state.date.value,
|
|
56
|
+
quantity: 1,
|
|
57
|
+
price: product.price,
|
|
58
|
+
product_name: product.title,
|
|
59
|
+
other: JSON.parse(JSON.stringify(_params))
|
|
60
|
+
},
|
|
61
|
+
new: 1
|
|
62
|
+
}); // 跨日预约
|
|
63
|
+
if (isDayBookingMode) {
|
|
64
|
+
cacheItem._extend.holder_id = holderId;
|
|
65
|
+
cacheItem._extend.end_date = state.date.end_date;
|
|
66
|
+
cacheItem._extend.sub_type = 'days';
|
|
67
|
+
}
|
|
68
|
+
_total = getProductTotalPrice(cacheItem); // 用于折扣 可修改
|
|
69
|
+
cacheItem._extend.total = _total;
|
|
70
|
+
// 用于储存原价
|
|
71
|
+
cacheItem._extend.origin_total = _total;
|
|
72
|
+
|
|
73
|
+
// 是否为编辑服务时重新选择商品
|
|
74
|
+
_isEdit = !!state.service.cacheItem;
|
|
75
|
+
if (_isEdit) {
|
|
76
|
+
// 重新选择则沿用之前的id, 并且不是新增状态
|
|
77
|
+
cacheItem._id = (_state$service$cacheI = state.service.cacheItem) === null || _state$service$cacheI === void 0 ? void 0 : _state$service$cacheI._id;
|
|
78
|
+
cacheItem.new = 0;
|
|
79
|
+
}
|
|
80
|
+
// 渲染到当前位置模式时,默认无资源 时间默认取顶部设置的时间
|
|
81
|
+
if (renderMode === 'current') {
|
|
82
|
+
// cacheItem._extend.resource = 0;
|
|
83
|
+
cacheItem.currentDefaultTime = state.date.value.format('HH:mm');
|
|
84
|
+
}
|
|
85
|
+
cacheItem._extend = getProductExtend({
|
|
86
|
+
cacheItem: cacheItem,
|
|
87
|
+
state: state
|
|
88
|
+
});
|
|
89
|
+
if (!isDayBookingMode) {
|
|
90
|
+
_context.next = 20;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
_context.next = 18;
|
|
94
|
+
return getMultiDay({
|
|
95
|
+
start_date: cacheItem._extend.startDate,
|
|
96
|
+
end_date: cacheItem._extend.endDate,
|
|
97
|
+
state: state,
|
|
98
|
+
cacheItem: cacheItem
|
|
99
|
+
});
|
|
100
|
+
case 18:
|
|
101
|
+
cacheItem = _context.sent;
|
|
102
|
+
if (isDayBookingProduct(cacheItem, state)) {
|
|
103
|
+
// 更换商品需要删除当前组下面的所有子预约 --待实现 在这里删除会导致如果直接返回还需要恢复
|
|
104
|
+
// const newList = filterItemByGroupId(cacheItem._id,state.service.value)
|
|
105
|
+
cacheItem = concatBookings(createBookingItemsByGroup(cacheItem));
|
|
106
|
+
}
|
|
107
|
+
case 20:
|
|
108
|
+
// 普通商品
|
|
109
|
+
if (isDayBookingMode && !isDayBookingProduct(cacheItem, state)) {
|
|
110
|
+
cacheItem.autoClose = true;
|
|
111
|
+
} else if (state.renderType === 'eventBooking') {
|
|
112
|
+
cacheItem.autoClose = false;
|
|
113
|
+
} else {
|
|
114
|
+
cacheItem.autoClose = !_isEdit && (cacheItem._extend.resource || cacheItem._extend.resource === 0 || (((_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.resourcesOrigin) || []).length === 1);
|
|
115
|
+
}
|
|
116
|
+
debugger;
|
|
117
|
+
return _context.abrupt("return", cacheItem);
|
|
118
|
+
case 23:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee);
|
|
123
|
+
}));
|
|
124
|
+
return function createBookingData(_x) {
|
|
125
|
+
return _ref3.apply(this, arguments);
|
|
126
|
+
};
|
|
127
|
+
}();
|
|
128
|
+
var currentResource = useCallback(function (useResource) {
|
|
129
|
+
var list = state.service.resources;
|
|
130
|
+
var item = list.find(function (d) {
|
|
131
|
+
return d.form_record_id == useResource;
|
|
132
|
+
}) || {};
|
|
133
|
+
return item;
|
|
134
|
+
}, [state === null || state === void 0 ? void 0 : (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.resources]);
|
|
135
|
+
var editBookingData = /*#__PURE__*/function () {
|
|
136
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
|
|
137
|
+
var _resourceItem$_extend;
|
|
138
|
+
var changeValues, _item, _extend, _getServiceTimes, startDate, endDate, resourceItem, _ref6, relation_type, item_id, schedule_id;
|
|
139
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
140
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
141
|
+
case 0:
|
|
142
|
+
changeValues = _ref4.changeValues;
|
|
143
|
+
_item = _objectSpread(_objectSpread({}, state.service.cacheItem), {}, {
|
|
144
|
+
autoClose: false
|
|
145
|
+
});
|
|
146
|
+
_extend = _objectSpread(_objectSpread({}, _item._extend), changeValues); // 跨日预约商品
|
|
147
|
+
if (isDayBookingProduct(state.service.cacheItem, state)) {
|
|
148
|
+
// 更新商品数量和更新日期
|
|
149
|
+
_extend.quantity = 1;
|
|
150
|
+
_extend.startDate = _extend === null || _extend === void 0 ? void 0 : _extend.start_date;
|
|
151
|
+
_extend.endDate = _extend === null || _extend === void 0 ? void 0 : _extend.end_date;
|
|
152
|
+
} else {
|
|
153
|
+
_getServiceTimes = getServiceTimes({
|
|
154
|
+
_extend: _extend
|
|
155
|
+
}), startDate = _getServiceTimes.startDate, endDate = _getServiceTimes.endDate;
|
|
156
|
+
_extend.startDate = startDate;
|
|
157
|
+
_extend.endDate = endDate;
|
|
158
|
+
}
|
|
159
|
+
resourceItem = currentResource(changeValues.resource);
|
|
160
|
+
_ref6 = (resourceItem === null || resourceItem === void 0 ? void 0 : (_resourceItem$_extend = resourceItem._extend) === null || _resourceItem$_extend === void 0 ? void 0 : _resourceItem$_extend.usableTime) || {}, relation_type = _ref6.relation_type, item_id = _ref6.item_id, schedule_id = _ref6.schedule_id;
|
|
161
|
+
_extend.relation_type = relation_type || 'form';
|
|
162
|
+
_extend.relation_id = item_id || (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.form_record_id) || 0;
|
|
163
|
+
_extend.schedule_id = schedule_id || 0;
|
|
164
|
+
if (_extend.bundle_edit !== undefined) {
|
|
165
|
+
_extend.bundle_edit = 1;
|
|
166
|
+
}
|
|
167
|
+
_item._extend = _extend;
|
|
168
|
+
_item._time = new Date().getTime();
|
|
169
|
+
return _context2.abrupt("return", _item);
|
|
170
|
+
case 13:
|
|
171
|
+
case "end":
|
|
172
|
+
return _context2.stop();
|
|
173
|
+
}
|
|
174
|
+
}, _callee2);
|
|
175
|
+
}));
|
|
176
|
+
return function editBookingData(_x2) {
|
|
177
|
+
return _ref5.apply(this, arguments);
|
|
178
|
+
};
|
|
179
|
+
}();
|
|
180
|
+
var createBooking = /*#__PURE__*/function () {
|
|
181
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
182
|
+
var booking;
|
|
183
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
184
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
185
|
+
case 0:
|
|
186
|
+
booking = _ref7.booking;
|
|
187
|
+
// 目前都是预生成数据, 所以需要从编辑面板处理一圈数据再返回列表
|
|
188
|
+
goEditPanel({
|
|
189
|
+
booking: booking
|
|
190
|
+
});
|
|
191
|
+
case 2:
|
|
192
|
+
case "end":
|
|
193
|
+
return _context3.stop();
|
|
194
|
+
}
|
|
195
|
+
}, _callee3);
|
|
196
|
+
}));
|
|
197
|
+
return function createBooking(_x3) {
|
|
198
|
+
return _ref8.apply(this, arguments);
|
|
199
|
+
};
|
|
200
|
+
}();
|
|
201
|
+
var editBooking = /*#__PURE__*/function () {
|
|
202
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref9) {
|
|
203
|
+
var _booking$_extend;
|
|
204
|
+
var booking, _list, _id, groupId;
|
|
205
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
206
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
207
|
+
case 0:
|
|
208
|
+
booking = _ref9.booking;
|
|
209
|
+
_list = state.service.value;
|
|
210
|
+
_id = booking === null || booking === void 0 ? void 0 : booking._id;
|
|
211
|
+
groupId = booking === null || booking === void 0 ? void 0 : (_booking$_extend = booking._extend) === null || _booking$_extend === void 0 ? void 0 : _booking$_extend.groupId;
|
|
212
|
+
if (groupId) {
|
|
213
|
+
_list = _list.filter(function (d) {
|
|
214
|
+
var _d$_extend;
|
|
215
|
+
return ((_d$_extend = d._extend) === null || _d$_extend === void 0 ? void 0 : _d$_extend.groupId) !== groupId;
|
|
216
|
+
});
|
|
217
|
+
_list = _list.concat(createBookingItemsByGroup(booking, true));
|
|
218
|
+
} else {
|
|
219
|
+
// 判断是新增还是编辑
|
|
220
|
+
if (!_list.some(function (d) {
|
|
221
|
+
return d._id === _id;
|
|
222
|
+
})) {
|
|
223
|
+
// 普通商品直接返回
|
|
224
|
+
if (!isBookingProduct(booking === null || booking === void 0 ? void 0 : booking.extension_type) || !isDayBookingMode) {
|
|
225
|
+
_list.push(booking);
|
|
226
|
+
} else {}
|
|
227
|
+
} else {
|
|
228
|
+
_list = _list.map(function (d) {
|
|
229
|
+
return d._id === _id ? _objectSpread(_objectSpread({}, booking), {}, {
|
|
230
|
+
new: 0
|
|
231
|
+
}) : d;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
deleteCacheParams();
|
|
236
|
+
dispatch({
|
|
237
|
+
type: 'setService',
|
|
238
|
+
payload: {
|
|
239
|
+
editModal: false,
|
|
240
|
+
addModal: false,
|
|
241
|
+
value: _list,
|
|
242
|
+
edit: true,
|
|
243
|
+
cacheItem: null,
|
|
244
|
+
changeService: false
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
case 7:
|
|
248
|
+
case "end":
|
|
249
|
+
return _context4.stop();
|
|
250
|
+
}
|
|
251
|
+
}, _callee4);
|
|
252
|
+
}));
|
|
253
|
+
return function editBooking(_x4) {
|
|
254
|
+
return _ref10.apply(this, arguments);
|
|
255
|
+
};
|
|
256
|
+
}();
|
|
257
|
+
var goEditPanel = function goEditPanel(_ref11) {
|
|
258
|
+
var booking = _ref11.booking;
|
|
259
|
+
dispatch({
|
|
260
|
+
type: 'setService',
|
|
261
|
+
payload: {
|
|
262
|
+
editModal: true,
|
|
263
|
+
cacheItem: booking,
|
|
264
|
+
addModal: !booking.autoClose,
|
|
265
|
+
changeService: false
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
onEdit(booking);
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
createBookingData: createBookingData,
|
|
272
|
+
editBookingData: editBookingData,
|
|
273
|
+
createBooking: createBooking,
|
|
274
|
+
editBooking: editBooking,
|
|
275
|
+
goEditPanel: goEditPanel
|
|
276
|
+
};
|
|
277
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const getGroupTotalPrice: (items: any[]) => any;
|
|
2
|
+
/**
|
|
3
|
+
* @title: 创建一个虚拟的组
|
|
4
|
+
* @description:
|
|
5
|
+
* @param {any} items
|
|
6
|
+
* @return {*}
|
|
7
|
+
* @Author: zhiwei.Wang
|
|
8
|
+
*/
|
|
9
|
+
export declare const concatBookings: (items: any[]) => any;
|
|
10
|
+
export declare const createBookingItemsByGroup: (item: any, isBatchEdit?: any) => any[];
|
|
11
|
+
export declare const isGroupBooking: (_id: any) => boolean;
|
|
12
|
+
export declare const getProductByGroupId: (groupId: string, items: any[]) => any[];
|
|
13
|
+
export declare const getGroupBooking: (groupId: string, items: any[]) => any;
|
|
14
|
+
export declare const filterItemByGroupId: (groupId: string, items: any[]) => any[];
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import { getUniqueId } from "@pisell/utils";
|
|
8
|
+
import { getProductTotalPrice } from "../../../utils";
|
|
9
|
+
import { distributeDiscountOrIncrease } from "../../service/serviceManager/distributeDiscount";
|
|
10
|
+
|
|
11
|
+
// 创建group
|
|
12
|
+
|
|
13
|
+
// 拆分group
|
|
14
|
+
|
|
15
|
+
// 编辑group
|
|
16
|
+
|
|
17
|
+
// 合并group
|
|
18
|
+
|
|
19
|
+
export var getGroupTotalPrice = function getGroupTotalPrice(items) {
|
|
20
|
+
return items.reduce(function (prev, next) {
|
|
21
|
+
prev.duration += next._extend.duration;
|
|
22
|
+
prev.total += next._extend.total;
|
|
23
|
+
// prev.price += next._extend.price;
|
|
24
|
+
prev.origin_total += next._extend.origin_total;
|
|
25
|
+
return prev;
|
|
26
|
+
}, {
|
|
27
|
+
total: 0,
|
|
28
|
+
origin_total: 0
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @title: 创建一个虚拟的组
|
|
34
|
+
* @description:
|
|
35
|
+
* @param {any} items
|
|
36
|
+
* @return {*}
|
|
37
|
+
* @Author: zhiwei.Wang
|
|
38
|
+
*/
|
|
39
|
+
export var concatBookings = function concatBookings(items) {
|
|
40
|
+
var firstItem = items[0];
|
|
41
|
+
var lastItem = items[items.length - 1];
|
|
42
|
+
var _items$reduce = items.reduce(function (prev, next) {
|
|
43
|
+
prev.duration += next._extend.duration;
|
|
44
|
+
prev.total += next._extend.total;
|
|
45
|
+
// prev.price += next._extend.price;
|
|
46
|
+
prev.origin_total += next._extend.origin_total;
|
|
47
|
+
return prev;
|
|
48
|
+
}, {
|
|
49
|
+
price: 0,
|
|
50
|
+
total: 0,
|
|
51
|
+
origin_total: 0,
|
|
52
|
+
duration: 0,
|
|
53
|
+
startDate: firstItem._extend.startDate,
|
|
54
|
+
endDate: lastItem._extend.endDate
|
|
55
|
+
}),
|
|
56
|
+
total = _items$reduce.total,
|
|
57
|
+
duration = _items$reduce.duration,
|
|
58
|
+
startDate = _items$reduce.startDate,
|
|
59
|
+
endDate = _items$reduce.endDate,
|
|
60
|
+
origin_total = _items$reduce.origin_total;
|
|
61
|
+
return _objectSpread(_objectSpread({}, firstItem), {}, {
|
|
62
|
+
// 虚拟组, id使用组id
|
|
63
|
+
_id: firstItem._extend.groupId,
|
|
64
|
+
_extend: _objectSpread(_objectSpread({}, firstItem._extend), {}, {
|
|
65
|
+
items: items,
|
|
66
|
+
duration: duration,
|
|
67
|
+
// price: total,
|
|
68
|
+
total: total,
|
|
69
|
+
origin_total: origin_total,
|
|
70
|
+
startDate: startDate,
|
|
71
|
+
endDate: endDate,
|
|
72
|
+
start_date: startDate,
|
|
73
|
+
end_date: endDate
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export var createBookingItemsByGroup = function createBookingItemsByGroup(item, isBatchEdit) {
|
|
78
|
+
var groupId = item._extend.groupId || getUniqueId('bookingGroup_');
|
|
79
|
+
var bookings = [];
|
|
80
|
+
|
|
81
|
+
// 根据时长 进行创建多个商品
|
|
82
|
+
for (var i = 0; i < item._extend.duration; i++) {
|
|
83
|
+
var _extend$multiDayPrice;
|
|
84
|
+
var _extend = _objectSpread({}, item._extend);
|
|
85
|
+
var startDate = _extend.start_date.add(i, 'day');
|
|
86
|
+
var endDate = _extend.start_date.add(i + 1, 'day');
|
|
87
|
+
// 商品原始价格
|
|
88
|
+
var price = ((_extend$multiDayPrice = _extend.multiDayPrices[startDate.format('YYYY-MM-DD')]) === null || _extend$multiDayPrice === void 0 ? void 0 : _extend$multiDayPrice.total) || item._extend.price;
|
|
89
|
+
var cacheItem = _objectSpread(_objectSpread({}, item), {}, {
|
|
90
|
+
// 编辑时组商品需要清空booking_id 否则会重复
|
|
91
|
+
booking_id: isBatchEdit ? 0 : item.booking_id,
|
|
92
|
+
_id: "".concat(item._id, "-").concat(i + 1),
|
|
93
|
+
price: price,
|
|
94
|
+
_extend: _objectSpread(_objectSpread({}, _extend), {}, {
|
|
95
|
+
order_detail_id: isBatchEdit ? 0 : item.order_detail_id,
|
|
96
|
+
groupId: groupId,
|
|
97
|
+
duration: 1,
|
|
98
|
+
price: price,
|
|
99
|
+
startDate: startDate,
|
|
100
|
+
endDate: endDate,
|
|
101
|
+
start_date: startDate,
|
|
102
|
+
end_date: endDate,
|
|
103
|
+
dateKey: "".concat(startDate.format('YYYY-MM-DD'), "~").concat(endDate.format('YYYY-MM-DD'), "}")
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
var totalPrice = getProductTotalPrice(cacheItem);
|
|
107
|
+
cacheItem._extend.total = totalPrice;
|
|
108
|
+
cacheItem._extend.origin_total = totalPrice;
|
|
109
|
+
cacheItem._extend.items = undefined;
|
|
110
|
+
bookings.push(cacheItem);
|
|
111
|
+
}
|
|
112
|
+
if (isBatchEdit) {
|
|
113
|
+
// 当前金额
|
|
114
|
+
var groupTotalPrice = item._extend.total;
|
|
115
|
+
// 原始金额
|
|
116
|
+
var groupOriginTotalPrice = item._extend.origin_total;
|
|
117
|
+
// 折扣金额 转成负数
|
|
118
|
+
var discountAmount = (groupOriginTotalPrice - groupTotalPrice) * -1;
|
|
119
|
+
if (discountAmount !== 0) {
|
|
120
|
+
bookings = distributeDiscountOrIncrease(bookings, discountAmount, groupOriginTotalPrice);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
console.log('bookings', bookings);
|
|
124
|
+
return bookings;
|
|
125
|
+
};
|
|
126
|
+
export var isGroupBooking = function isGroupBooking(_id) {
|
|
127
|
+
return (_id === null || _id === void 0 ? void 0 : _id.indexOf('bookingGroup_')) === 0;
|
|
128
|
+
};
|
|
129
|
+
export var getProductByGroupId = function getProductByGroupId(groupId, items) {
|
|
130
|
+
return items.filter(function (item) {
|
|
131
|
+
var _item$_extend;
|
|
132
|
+
return ((_item$_extend = item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.groupId) === groupId;
|
|
133
|
+
}).map(function (item) {
|
|
134
|
+
return item._id;
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
export var getGroupBooking = function getGroupBooking(groupId, items) {
|
|
138
|
+
var products = getProductByGroupId(groupId, items);
|
|
139
|
+
return concatBookings(products);
|
|
140
|
+
};
|
|
141
|
+
export var filterItemByGroupId = function filterItemByGroupId(groupId, items) {
|
|
142
|
+
return items.filter(function (item) {
|
|
143
|
+
var _item$_extend2;
|
|
144
|
+
return ((_item$_extend2 = item._extend) === null || _item$_extend2 === void 0 ? void 0 : _item$_extend2.groupId) !== groupId;
|
|
145
|
+
});
|
|
146
|
+
};
|