@pisell/pisellos 3.0.40 → 3.0.42

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.
@@ -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
+ }
@@ -121,11 +121,11 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
121
121
  key: "fetchResourceDates",
122
122
  value: function () {
123
123
  var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
124
- var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
124
+ var url, query, _params$useCache, useCache, fetchUrl, _ref, start_date, end_date, resource_ids, res;
125
125
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
126
126
  while (1) switch (_context3.prev = _context3.next) {
127
127
  case 0:
128
- url = params.url, query = params.query;
128
+ url = params.url, query = params.query, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache;
129
129
  fetchUrl = url || '/schedule/resource/list';
130
130
  _ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
131
131
  _context3.prev = 3;
@@ -134,9 +134,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
134
134
  start_date: start_date,
135
135
  end_date: end_date,
136
136
  resource_ids: resource_ids,
137
- front_end_cache_id: this.cacheId
137
+ front_end_cache_id: useCache && this.cacheId
138
138
  }, {
139
- useCache: true
139
+ useCache: useCache
140
140
  });
141
141
  case 6:
142
142
  res = _context3.sent;
@@ -43,6 +43,8 @@ export interface DateModuleAPI {
43
43
  }
44
44
  export interface IGetAvailableTimeListParams {
45
45
  url?: string;
46
+ /** 是否使用缓存 */
47
+ useCache?: boolean;
46
48
  /** 查询参数 */
47
49
  query?: {
48
50
  /** 开始日期 */
@@ -140,7 +140,11 @@ var getDaysByRepeatWeek = function getDaysByRepeatWeek(params, isGetRange) {
140
140
  for (var i = 0; i < frequency_date.length; i++) {
141
141
  var item = frequency_date[i];
142
142
  var _start = startTmp.day(item);
143
+ // 如果周结束的那一天还超过了deadline,则需要把_end置为deadline
143
144
  var _end = _start.add(scheduleDiff, 'second');
145
+ if (_end.isAfter(deadline, 'day')) {
146
+ _end = deadline;
147
+ }
144
148
  if (isGetRange) {
145
149
  if (excludedDaysMap.has(_start.format('YYYY-MM-DD'))) {
146
150
  startTmp = startTmp.day(1).add(frequency, 'day');
@@ -86,6 +86,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
86
86
  getCart(): CartItem[];
87
87
  getAvailableDate(params?: {
88
88
  url?: string;
89
+ useCache?: boolean;
89
90
  products?: ProductData[];
90
91
  startDate?: string;
91
92
  endDate?: string;
@@ -279,7 +279,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
279
279
  value: function () {
280
280
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
281
281
  var _schedule$product_ids;
282
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
282
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, newProductIds, schedule, otherProductsIds, allProductIds;
283
283
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
284
284
  while (1) switch (_context3.prev = _context3.next) {
285
285
  case 0:
@@ -296,11 +296,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
296
296
  week: '',
297
297
  weekNum: 0
298
298
  }]);
299
- // const scheduleIds = scheduleList
299
+ newProductIds = []; // const scheduleIds = scheduleList
300
300
  // .filter((n) => n.date === date)
301
301
  // .flatMap((n) => n.schedule_id)
302
302
  // .filter((n) => n !== null && n !== undefined);
303
-
304
303
  // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
305
304
  // if (!product_ids?.length) {
306
305
  // const schedule = scheduleList.find((n) => n.date === date);
@@ -313,23 +312,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
313
312
  return n.date === date;
314
313
  });
315
314
  if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
316
- product_ids = schedule.product_ids;
315
+ newProductIds = schedule.product_ids;
317
316
  }
318
317
  // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
319
318
  otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
320
- allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
319
+ allProductIds = [].concat(_toConsumableArray(newProductIds), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
321
320
  return self.indexOf(n) === index;
322
321
  });
323
- _context3.next = 9;
322
+ _context3.next = 10;
324
323
  return this.loadProducts({
325
324
  // schedule_ids: scheduleIds,
326
325
  product_ids: allProductIds,
327
326
  category_ids: category_ids,
328
327
  schedule_date: date
329
328
  });
330
- case 9:
331
- return _context3.abrupt("return", _context3.sent);
332
329
  case 10:
330
+ return _context3.abrupt("return", _context3.sent);
331
+ case 11:
333
332
  case "end":
334
333
  return _context3.stop();
335
334
  }
@@ -870,6 +869,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
870
869
  startDate,
871
870
  endDate,
872
871
  type,
872
+ _params$useCache,
873
+ useCache,
873
874
  tempProducts,
874
875
  dateRange,
875
876
  tempStartDate,
@@ -885,7 +886,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
885
886
  case 0:
886
887
  params = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
887
888
  // 开始日期如果小于今天,直接以今天当做开始日期
888
- products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
889
+ products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
889
890
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
890
891
  startDate = dayjs().format('YYYY-MM-DD');
891
892
  }
@@ -927,7 +928,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
927
928
  resource_ids: resourceIds
928
929
  },
929
930
  rules: rules,
930
- type: type
931
+ type: type,
932
+ useCache: useCache
931
933
  });
932
934
  case 15:
933
935
  res = _context15.sent;
@@ -2649,6 +2651,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2649
2651
  _this13.store.cart.removeItem(n._id);
2650
2652
  });
2651
2653
  }
2654
+ // 如果 date.startTime 和 dateRange 里的 startTime 不一样,需要修正 dateRange
2655
+ var dateRange = this.store.date.getDateRange();
2656
+ if (dateRange !== null && dateRange !== void 0 && dateRange[0] && !dayjs(dateRange[0].date).isSame(dayjs(date.startTime), 'day')) {
2657
+ this.setDateRange([{
2658
+ date: dayjs(date.startTime).format('YYYY-MM-DD'),
2659
+ status: 'available',
2660
+ week: '',
2661
+ weekNum: 0
2662
+ }, {
2663
+ date: dayjs(date.endTime).format('YYYY-MM-DD'),
2664
+ status: 'available',
2665
+ week: '',
2666
+ weekNum: 0
2667
+ }]);
2668
+ }
2652
2669
  }
2653
2670
  }
2654
2671
  }, {
@@ -3138,7 +3155,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3138
3155
  });
3139
3156
 
3140
3157
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
3141
- if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 14)) {
3158
+ if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
3142
3159
  _context31.next = 9;
3143
3160
  break;
3144
3161
  }
@@ -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,78 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/Cart/utils/changePrice.ts
30
+ var changePrice_exports = {};
31
+ __export(changePrice_exports, {
32
+ updateAllCartItemPrice: () => updateAllCartItemPrice
33
+ });
34
+ module.exports = __toCommonJS(changePrice_exports);
35
+ var import_decimal = __toESM(require("decimal.js"));
36
+ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
37
+ for (const item of cartItems) {
38
+ const targetProduct = priceData.find((n) => n.id === item.id);
39
+ const cartProduct = await getProduct(
40
+ item.id
41
+ );
42
+ const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
43
+ let bundle = item._bundleOrigin;
44
+ productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
45
+ productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
46
+ bundle = bundle == null ? void 0 : bundle.map((n) => {
47
+ var _a;
48
+ const targetBundle = (_a = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a.find(
49
+ (m) => m.id === n.group_id
50
+ );
51
+ if (targetBundle) {
52
+ const targetBundleItem = targetBundle.bundle_item.find(
53
+ (m) => m.id === n.id
54
+ );
55
+ if (targetBundleItem.price_type === "markdown") {
56
+ targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
57
+ }
58
+ if (targetBundleItem) {
59
+ return {
60
+ ...n,
61
+ price: targetBundleItem.price,
62
+ base_price: targetBundleItem.base_price
63
+ };
64
+ }
65
+ }
66
+ return n;
67
+ });
68
+ updateCart({
69
+ _id: item._id,
70
+ product: productInfo,
71
+ bundle
72
+ });
73
+ }
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ updateAllCartItemPrice
78
+ });
@@ -69,7 +69,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
69
69
  this.store.dateList = dateList;
70
70
  }
71
71
  async fetchResourceDates(params) {
72
- const { url, query } = params;
72
+ const { url, query, useCache = true } = params;
73
73
  const fetchUrl = url || "/schedule/resource/list";
74
74
  const { start_date, end_date, resource_ids } = query || {};
75
75
  try {
@@ -77,9 +77,9 @@ var DateModule = class extends import_BaseModule.BaseModule {
77
77
  start_date,
78
78
  end_date,
79
79
  resource_ids,
80
- front_end_cache_id: this.cacheId
80
+ front_end_cache_id: useCache && this.cacheId
81
81
  }, {
82
- useCache: true
82
+ useCache
83
83
  });
84
84
  return res;
85
85
  } catch (error) {
@@ -43,6 +43,8 @@ export interface DateModuleAPI {
43
43
  }
44
44
  export interface IGetAvailableTimeListParams {
45
45
  url?: string;
46
+ /** 是否使用缓存 */
47
+ useCache?: boolean;
46
48
  /** 查询参数 */
47
49
  query?: {
48
50
  /** 开始日期 */
@@ -140,7 +140,10 @@ var getDaysByRepeatWeek = (params, isGetRange) => {
140
140
  for (let i = 0; i < frequency_date.length; i++) {
141
141
  const item = frequency_date[i];
142
142
  const _start = startTmp.day(item);
143
- const _end = _start.add(scheduleDiff, "second");
143
+ let _end = _start.add(scheduleDiff, "second");
144
+ if (_end.isAfter(deadline, "day")) {
145
+ _end = deadline;
146
+ }
144
147
  if (isGetRange) {
145
148
  if (excludedDaysMap.has(_start.format("YYYY-MM-DD"))) {
146
149
  startTmp = startTmp.day(1).add(frequency, "day");
@@ -86,6 +86,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
86
86
  getCart(): CartItem[];
87
87
  getAvailableDate(params?: {
88
88
  url?: string;
89
+ useCache?: boolean;
89
90
  products?: ProductData[];
90
91
  startDate?: string;
91
92
  endDate?: string;
@@ -219,12 +219,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
219
219
  { date, status: "available", week: "", weekNum: 0 },
220
220
  { date, status: "available", week: "", weekNum: 0 }
221
221
  ]);
222
+ let newProductIds = [];
222
223
  const schedule = scheduleList.find((n) => n.date === date);
223
224
  if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
224
- product_ids = schedule.product_ids;
225
+ newProductIds = schedule.product_ids;
225
226
  }
226
227
  const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
227
- const allProductIds = [...product_ids, ...otherProductsIds].filter(
228
+ const allProductIds = [...newProductIds, ...otherProductsIds].filter(
228
229
  (n, index, self) => self.indexOf(n) === index
229
230
  );
230
231
  return await this.loadProducts({
@@ -468,7 +469,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
468
469
  // 获取商品/服务的可用日期
469
470
  async getAvailableDate(params = {}) {
470
471
  var _a, _b, _c;
471
- let { products, startDate, endDate, type } = params;
472
+ let { products, startDate, endDate, type, useCache = true } = params;
472
473
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
473
474
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
474
475
  }
@@ -505,7 +506,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
505
506
  resource_ids: resourceIds
506
507
  },
507
508
  rules,
508
- type
509
+ type,
510
+ useCache
509
511
  });
510
512
  return res;
511
513
  }
@@ -1846,6 +1848,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1846
1848
  this.store.cart.removeItem(n._id);
1847
1849
  });
1848
1850
  }
1851
+ const dateRange = this.store.date.getDateRange();
1852
+ if ((dateRange == null ? void 0 : dateRange[0]) && !(0, import_dayjs.default)(dateRange[0].date).isSame((0, import_dayjs.default)(date.startTime), "day")) {
1853
+ this.setDateRange([
1854
+ { date: (0, import_dayjs.default)(date.startTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 },
1855
+ { date: (0, import_dayjs.default)(date.endTime).format("YYYY-MM-DD"), status: "available", week: "", weekNum: 0 }
1856
+ ]);
1857
+ }
1849
1858
  }
1850
1859
  }
1851
1860
  setOtherData(key, value) {
@@ -2210,7 +2219,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2210
2219
  weekNum: (0, import_dayjs.default)(currentDate).day(),
2211
2220
  status
2212
2221
  });
2213
- if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
2222
+ if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 31) {
2214
2223
  break;
2215
2224
  }
2216
2225
  currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.40",
4
+ "version": "3.0.42",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",