@pisell/pisellos 2.0.3 → 2.0.5

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.
Files changed (146) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +111 -12
  17. package/dist/modules/Cart/utils.js +286 -73
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +2 -2
  37. package/dist/modules/Rules/index.js +97 -29
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +90 -24
  61. package/dist/solution/BookingByStep/index.js +989 -317
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +111 -12
  88. package/lib/modules/Cart/utils.js +186 -43
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +2 -2
  111. package/lib/modules/Rules/index.js +100 -25
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +90 -24
  135. package/lib/solution/BookingByStep/index.js +667 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. package/package.json +4 -2
@@ -1,10 +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 _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; } } }; }
3
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
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."); }
5
- 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); }
6
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; } } }; }
7
+ 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); }
8
8
  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; }
9
9
  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; }
10
10
  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; }
@@ -27,10 +27,12 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { BookingByStepHooks, createModule } from "./types";
29
29
  import { getAvailableProductResources } from "./utils/products";
30
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem } from "./utils/resources";
31
- import dayjs from "dayjs";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources } from "./utils/resources";
31
+ import dayjs from 'dayjs';
32
32
  import { getResourcesMap } from "../../modules/Resource/utils";
33
- import { cloneDeep } from "lodash-es";
33
+ import { cloneDeep } from 'lodash-es';
34
+ import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
35
+ import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates } from "../../modules/Date/utils";
34
36
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
35
37
  _inherits(BookingByStepImpl, _BaseModule);
36
38
  var _super = _createSuper(BookingByStepImpl);
@@ -41,8 +43,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
41
43
  args[_key] = arguments[_key];
42
44
  }
43
45
  _this = _super.call.apply(_super, [this].concat(args));
44
- _defineProperty(_assertThisInitialized(_this), "defaultName", "bookingByStep");
45
- _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
46
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'bookingByStep');
47
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
46
48
  _defineProperty(_assertThisInitialized(_this), "isSolution", true);
47
49
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
48
50
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
@@ -50,32 +52,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
50
52
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
51
53
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
52
54
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
55
+ _defineProperty(_assertThisInitialized(_this), "otherData", {});
53
56
  return _this;
54
57
  }
55
58
  _createClass(BookingByStepImpl, [{
56
59
  key: "initialize",
57
- value: function () {
60
+ value: // 提供给 UI 层的临时数据存储,会进缓存
61
+ function () {
58
62
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
59
63
  var _this$otherParams,
60
64
  _this$otherParams2,
61
65
  _this2 = this;
62
- var targetCacheData, sessionData, data, moduleArr;
66
+ var targetCacheData, sessionData, _data$this$otherParam, data, moduleArr;
63
67
  return _regeneratorRuntime().wrap(function _callee$(_context) {
64
68
  while (1) switch (_context.prev = _context.next) {
65
69
  case 0:
66
70
  this.core = core;
67
71
  this.store = options.store || {};
68
72
  this.otherParams = options.otherParams || {};
69
- console.log("[BookingByStep] 初始化完成");
73
+ console.log('[BookingByStep] 初始化完成');
70
74
  // 获取依赖的插件
71
- this.request = core.getPlugin("request");
72
- this.window = core.getPlugin("window");
73
- this.shopStore = core.getPlugin("shopStore");
75
+ this.request = core.getPlugin('request');
76
+ this.window = core.getPlugin('window');
77
+ this.shopStore = core.getPlugin('shopStore');
74
78
  if (this.request) {
75
79
  _context.next = 9;
76
80
  break;
77
81
  }
78
- throw new Error("bookingByStep解决方案需要 request 插件支持");
82
+ throw new Error('bookingByStep解决方案需要 request 插件支持');
79
83
  case 9:
80
84
  // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
81
85
  // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
@@ -87,9 +91,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
87
91
  data = JSON.parse(sessionData); // 匹配 cacheid,如果匹配不到,直接把 sessionData 清掉即可
88
92
  // 如果匹配到了,则把 sessionData 里的数据按模块塞到 store 里去
89
93
  targetCacheData = data[this.otherParams.cacheId];
94
+ this.otherData = ((_data$this$otherParam = data[this.otherParams.cacheId]) === null || _data$this$otherParam === void 0 || (_data$this$otherParam = _data$this$otherParam[this.name]) === null || _data$this$otherParam === void 0 ? void 0 : _data$this$otherParam['otherData']) || {};
90
95
  }
91
96
  }
92
- moduleArr = ["accountList", "cart", "summary", "step", "products", "date", "order", "payment"];
97
+ moduleArr = ['accountList', 'cart', 'schedule', 'summary', 'step', 'products', 'date', 'order', 'payment'];
93
98
  moduleArr.forEach(function (step) {
94
99
  var targetModule = createModule(step, _this2.name);
95
100
  if (targetModule) {
@@ -160,6 +165,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
160
165
  return this.store.step.getStepList();
161
166
  }
162
167
 
168
+ /**
169
+ * 添加step
170
+ */
171
+ }, {
172
+ key: "addStep",
173
+ value: function addStep(step, key) {
174
+ this.store.step.addStep(step, key);
175
+ }
176
+
177
+ /**
178
+ * 删除step
179
+ */
180
+ }, {
181
+ key: "removeStep",
182
+ value: function removeStep(key) {
183
+ this.store.step.removeStep(key);
184
+ }
163
185
  // 获取购物车里 temp.xxx的方法
164
186
  // async getStoreCart(key?: string) {
165
187
  // return this.store.cart.getTemp(key);
@@ -170,32 +192,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
170
192
  key: "loadProducts",
171
193
  value: function () {
172
194
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
173
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, productsData;
195
+ var _schedule_ids;
196
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_ids_data, productsData;
174
197
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
175
198
  while (1) switch (_context2.prev = _context2.next) {
176
199
  case 0:
177
- _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection;
178
- _context2.next = 3;
200
+ _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids;
201
+ // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
202
+ if (!((_schedule_ids = schedule_ids) !== null && _schedule_ids !== void 0 && _schedule_ids.length)) {
203
+ schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map(function (n) {
204
+ return n.id;
205
+ });
206
+ if (schedule_ids_data.length) {
207
+ schedule_ids = schedule_ids_data;
208
+ }
209
+ }
210
+ _context2.next = 4;
179
211
  return this.request.post("/product/query", {
180
212
  open_quotation: 1,
181
213
  open_bundle: 1,
182
- extension_type: ["product_appointment", "appointment_ticket"],
183
- with: ["category", "collection"],
184
- status: "published",
214
+ extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket'],
215
+ with: ['category', 'collection', 'resourceRelation'],
216
+ status: 'published',
185
217
  num: 500,
186
218
  skip: 1,
187
219
  category_ids: category_ids,
188
220
  ids: product_ids,
189
221
  collection: collection,
190
- front_end_cache_id: this.cacheId
222
+ front_end_cache_id: this.cacheId,
223
+ client_schedule_ids: schedule_ids
191
224
  }, {
192
225
  useCache: true
193
226
  });
194
- case 3:
227
+ case 4:
195
228
  productsData = _context2.sent;
196
229
  this.store.products.addProduct(productsData.data.list);
197
230
  return _context2.abrupt("return", productsData.data.list);
198
- case 6:
231
+ case 7:
199
232
  case "end":
200
233
  return _context2.stop();
201
234
  }
@@ -207,81 +240,282 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
207
240
  return loadProducts;
208
241
  }()
209
242
  }, {
210
- key: "storeProduct",
243
+ key: "loadProductByScheduleDate",
211
244
  value: function () {
212
- var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(productData) {
213
- var activeAccount, _ref2, bundle, options, origin, product_variant_id, product;
245
+ var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
246
+ var date, product_ids, scheduleList, scheduleIds;
214
247
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
215
248
  while (1) switch (_context3.prev = _context3.next) {
216
249
  case 0:
217
- // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
218
- activeAccount = this.getActiveAccount();
219
- if (activeAccount) {
220
- _context3.next = 3;
250
+ date = _ref2.date, product_ids = _ref2.product_ids;
251
+ scheduleList = this.store.schedule.getAvailabilityScheduleDateList(); // 缓存下这次选择的结果,如果是先选日期再选 duration 类商品,后面用得到
252
+ this.setDateRange([{
253
+ date: date,
254
+ status: 'available',
255
+ week: '',
256
+ weekNum: 0
257
+ }, {
258
+ date: date,
259
+ status: 'available',
260
+ week: '',
261
+ weekNum: 0
262
+ }]);
263
+ scheduleIds = scheduleList.filter(function (n) {
264
+ return n.date === date;
265
+ }).flatMap(function (n) {
266
+ return n.schedule_id;
267
+ });
268
+ _context3.next = 6;
269
+ return this.loadProducts({
270
+ schedule_ids: scheduleIds,
271
+ product_ids: product_ids
272
+ });
273
+ case 6:
274
+ return _context3.abrupt("return", _context3.sent);
275
+ case 7:
276
+ case "end":
277
+ return _context3.stop();
278
+ }
279
+ }, _callee3, this);
280
+ }));
281
+ function loadProductByScheduleDate(_x4) {
282
+ return _loadProductByScheduleDate.apply(this, arguments);
283
+ }
284
+ return loadProductByScheduleDate;
285
+ }() // 加载当前店铺下所有 schedule
286
+ }, {
287
+ key: "loadAllSchedule",
288
+ value: function () {
289
+ var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
290
+ var _scheduleList$data;
291
+ var scheduleList;
292
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
293
+ while (1) switch (_context4.prev = _context4.next) {
294
+ case 0:
295
+ _context4.next = 2;
296
+ return this.request.get("/schedule");
297
+ case 2:
298
+ scheduleList = _context4.sent;
299
+ this.store.schedule.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
300
+ case 4:
301
+ case "end":
302
+ return _context4.stop();
303
+ }
304
+ }, _callee4, this);
305
+ }));
306
+ function loadAllSchedule() {
307
+ return _loadAllSchedule.apply(this, arguments);
308
+ }
309
+ return loadAllSchedule;
310
+ }() // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
311
+ }, {
312
+ key: "loadScheduleAvailableDate",
313
+ value: function () {
314
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref3) {
315
+ var _res$data$date_list;
316
+ var startDate, endDate, custom_page_id, dates, res;
317
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
318
+ while (1) switch (_context5.prev = _context5.next) {
319
+ case 0:
320
+ startDate = _ref3.startDate, endDate = _ref3.endDate, custom_page_id = _ref3.custom_page_id;
321
+ // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
322
+ if (dayjs(startDate).isBefore(dayjs(), 'day')) {
323
+ startDate = dayjs().format('YYYY-MM-DD');
324
+ }
325
+ // 1.生成当前月份的所有日期,默认都不可用
326
+ dates = generateMonthDates(startDate, endDate);
327
+ dates = disableAllDates(dates);
328
+ // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
329
+ if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
330
+ _context5.next = 6;
221
331
  break;
222
332
  }
223
- throw new Error("没有找到当前账户");
224
- case 3:
225
- _ref2 = productData || {}, bundle = _ref2.bundle, options = _ref2.options, origin = _ref2.origin, product_variant_id = _ref2.product_variant_id;
333
+ return _context5.abrupt("return", dates);
334
+ case 6:
335
+ _context5.next = 8;
336
+ return this.request.get("/schedule/product/availability", {
337
+ start_date: startDate,
338
+ end_date: endDate,
339
+ custom_page_id: custom_page_id
340
+ });
341
+ case 8:
342
+ res = _context5.sent;
343
+ this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
344
+ // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
345
+ if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
346
+ _context5.next = 12;
347
+ break;
348
+ }
349
+ return _context5.abrupt("return", dates);
350
+ case 12:
351
+ res.data.date_list.forEach(function (n) {
352
+ if (n.schedule_id && n.schedule_id.length) {
353
+ var index = dates.findIndex(function (m) {
354
+ return m.date === n.date;
355
+ });
356
+ if (index !== -1) {
357
+ dates[index].status = 'available';
358
+ }
359
+ }
360
+ });
361
+ dates = disableDatesBeforeOneDay(dates);
362
+ return _context5.abrupt("return", dates);
363
+ case 15:
364
+ case "end":
365
+ return _context5.stop();
366
+ }
367
+ }, _callee5, this);
368
+ }));
369
+ function loadScheduleAvailableDate(_x5) {
370
+ return _loadScheduleAvailableDate.apply(this, arguments);
371
+ }
372
+ return loadScheduleAvailableDate;
373
+ }()
374
+ }, {
375
+ key: "storeProduct",
376
+ value: function () {
377
+ var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(productData) {
378
+ var activeAccount, _ref4, bundle, options, origin, product_variant_id, product, addCartItem;
379
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
380
+ while (1) switch (_context6.prev = _context6.next) {
381
+ case 0:
382
+ // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
383
+ activeAccount = this.getActiveAccount();
384
+ _ref4 = productData || {}, bundle = _ref4.bundle, options = _ref4.options, origin = _ref4.origin, product_variant_id = _ref4.product_variant_id;
226
385
  product = _objectSpread(_objectSpread({}, origin), {}, {
227
386
  product_variant_id: product_variant_id
228
387
  });
229
- this.store.cart.addItem({
230
- account: activeAccount,
388
+ addCartItem = {
231
389
  product: product,
232
390
  bundle: bundle,
233
391
  options: options
234
- });
392
+ };
393
+ if (activeAccount) {
394
+ addCartItem.account = activeAccount;
395
+ }
396
+ this.store.cart.addItem(addCartItem);
235
397
  case 6:
236
398
  case "end":
237
- return _context3.stop();
399
+ return _context6.stop();
238
400
  }
239
- }, _callee3, this);
401
+ }, _callee6, this);
240
402
  }));
241
- function storeProduct(_x4) {
403
+ function storeProduct(_x6) {
242
404
  return _storeProduct.apply(this, arguments);
243
405
  }
244
406
  return storeProduct;
245
- }() // 添加账户或者 guest
407
+ }() // 添加单个账户或者 guest
246
408
  }, {
247
409
  key: "addAccount",
248
410
  value: function () {
249
- var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(accounts) {
250
- var _this3 = this;
251
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
252
- while (1) switch (_context4.prev = _context4.next) {
411
+ var _addAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(account, extra) {
412
+ var accountModules, newAccount;
413
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
414
+ while (1) switch (_context7.prev = _context7.next) {
253
415
  case 0:
254
- accounts.forEach(function (account) {
255
- _this3.store.accountList.addAccount(account);
256
- });
257
- case 1:
416
+ if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
417
+ _context7.next = 5;
418
+ break;
419
+ }
420
+ _context7.next = 3;
421
+ return this.store.accountList.addHolderAccounts([account], extra.customerId);
422
+ case 3:
423
+ accountModules = _context7.sent;
424
+ return _context7.abrupt("return", accountModules[0].getAccount());
425
+ case 5:
426
+ _context7.next = 7;
427
+ return this.store.accountList.addAccount(account);
428
+ case 7:
429
+ newAccount = _context7.sent;
430
+ return _context7.abrupt("return", newAccount.getAccount());
431
+ case 9:
258
432
  case "end":
259
- return _context4.stop();
433
+ return _context7.stop();
260
434
  }
261
- }, _callee4);
435
+ }, _callee7, this);
262
436
  }));
263
- function addAccount(_x5) {
437
+ function addAccount(_x7, _x8) {
264
438
  return _addAccount.apply(this, arguments);
265
439
  }
266
440
  return addAccount;
441
+ }() // 添加账户或者 guest
442
+ }, {
443
+ key: "addAccounts",
444
+ value: function () {
445
+ var _addAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(accounts, extra) {
446
+ var res, _iterator, _step, account, accountModule, accountData;
447
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
448
+ while (1) switch (_context8.prev = _context8.next) {
449
+ case 0:
450
+ if (!((extra === null || extra === void 0 ? void 0 : extra.type) === 'holder')) {
451
+ _context8.next = 3;
452
+ break;
453
+ }
454
+ this.store.accountList.addHolderAccounts(accounts, extra.customerId);
455
+ return _context8.abrupt("return");
456
+ case 3:
457
+ res = [];
458
+ _iterator = _createForOfIteratorHelper(accounts);
459
+ _context8.prev = 5;
460
+ _iterator.s();
461
+ case 7:
462
+ if ((_step = _iterator.n()).done) {
463
+ _context8.next = 16;
464
+ break;
465
+ }
466
+ account = _step.value;
467
+ _context8.next = 11;
468
+ return this.store.accountList.addAccount(account);
469
+ case 11:
470
+ accountModule = _context8.sent;
471
+ accountData = accountModule.getAccount();
472
+ if (accountData) {
473
+ res.push(accountData);
474
+ }
475
+ case 14:
476
+ _context8.next = 7;
477
+ break;
478
+ case 16:
479
+ _context8.next = 21;
480
+ break;
481
+ case 18:
482
+ _context8.prev = 18;
483
+ _context8.t0 = _context8["catch"](5);
484
+ _iterator.e(_context8.t0);
485
+ case 21:
486
+ _context8.prev = 21;
487
+ _iterator.f();
488
+ return _context8.finish(21);
489
+ case 24:
490
+ return _context8.abrupt("return", res);
491
+ case 25:
492
+ case "end":
493
+ return _context8.stop();
494
+ }
495
+ }, _callee8, this, [[5, 18, 21, 24]]);
496
+ }));
497
+ function addAccounts(_x9, _x10) {
498
+ return _addAccounts.apply(this, arguments);
499
+ }
500
+ return addAccounts;
267
501
  }() // 获取所有账户
268
502
  }, {
269
503
  key: "getAccounts",
270
504
  value: function () {
271
- var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
505
+ var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
272
506
  var accounts;
273
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
274
- while (1) switch (_context5.prev = _context5.next) {
507
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
508
+ while (1) switch (_context9.prev = _context9.next) {
275
509
  case 0:
276
510
  accounts = this.store.accountList.getAccounts();
277
- return _context5.abrupt("return", accounts.map(function (account) {
511
+ return _context9.abrupt("return", accounts.map(function (account) {
278
512
  return account.getAccount();
279
513
  }));
280
514
  case 2:
281
515
  case "end":
282
- return _context5.stop();
516
+ return _context9.stop();
283
517
  }
284
- }, _callee5, this);
518
+ }, _callee9, this);
285
519
  }));
286
520
  function getAccounts() {
287
521
  return _getAccounts.apply(this, arguments);
@@ -315,22 +549,45 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
315
549
  this.clearCartByAccount(id);
316
550
  }
317
551
 
318
- // 设置日期范围,注入到日期模块中
552
+ /**
553
+ * 获取holder类型账户列表
554
+ * @param params
555
+ */
556
+ }, {
557
+ key: "fetchHolderAccountsAsync",
558
+ value: (function () {
559
+ var _fetchHolderAccountsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
560
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
561
+ while (1) switch (_context10.prev = _context10.next) {
562
+ case 0:
563
+ return _context10.abrupt("return", this.store.accountList.fetchHolderAccounts(params));
564
+ case 1:
565
+ case "end":
566
+ return _context10.stop();
567
+ }
568
+ }, _callee10, this);
569
+ }));
570
+ function fetchHolderAccountsAsync(_x11) {
571
+ return _fetchHolderAccountsAsync.apply(this, arguments);
572
+ }
573
+ return fetchHolderAccountsAsync;
574
+ }() // 设置日期范围,注入到日期模块中
575
+ )
319
576
  }, {
320
577
  key: "setDateRange",
321
578
  value: function () {
322
- var _setDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(dateRange) {
323
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
324
- while (1) switch (_context6.prev = _context6.next) {
579
+ var _setDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(dateRange) {
580
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
581
+ while (1) switch (_context11.prev = _context11.next) {
325
582
  case 0:
326
583
  this.store.date.setDateRange(dateRange);
327
584
  case 1:
328
585
  case "end":
329
- return _context6.stop();
586
+ return _context11.stop();
330
587
  }
331
- }, _callee6, this);
588
+ }, _callee11, this);
332
589
  }));
333
- function setDateRange(_x6) {
590
+ function setDateRange(_x12) {
334
591
  return _setDateRange.apply(this, arguments);
335
592
  }
336
593
  return setDateRange;
@@ -345,16 +602,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
345
602
  }, {
346
603
  key: "getDateRange",
347
604
  value: function () {
348
- var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
349
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
350
- while (1) switch (_context7.prev = _context7.next) {
605
+ var _getDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
606
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
607
+ while (1) switch (_context12.prev = _context12.next) {
351
608
  case 0:
352
- return _context7.abrupt("return", this.store.date.getDateRange());
609
+ return _context12.abrupt("return", this.store.date.getDateRange());
353
610
  case 1:
354
611
  case "end":
355
- return _context7.stop();
612
+ return _context12.stop();
356
613
  }
357
- }, _callee7, this);
614
+ }, _callee12, this);
358
615
  }));
359
616
  function getDateRange() {
360
617
  return _getDateRange.apply(this, arguments);
@@ -371,59 +628,80 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
371
628
  }, {
372
629
  key: "getAvailableDate",
373
630
  value: function () {
374
- var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
375
- var _this$otherParams3, _this$otherParams4;
631
+ var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
632
+ var _this3 = this;
376
633
  var params,
377
634
  products,
378
635
  startDate,
379
636
  endDate,
637
+ type,
380
638
  tempProducts,
639
+ dateRange,
381
640
  tempStartDate,
382
641
  tempEndDate,
383
- _ref3,
642
+ _ref5,
384
643
  resourceIds,
385
644
  rules,
386
645
  resourcesMap,
387
646
  res,
388
- _args8 = arguments;
389
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
390
- while (1) switch (_context8.prev = _context8.next) {
647
+ _args13 = arguments;
648
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
649
+ while (1) switch (_context13.prev = _context13.next) {
391
650
  case 0:
392
- params = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
651
+ params = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
393
652
  // 开始日期如果小于今天,直接以今天当做开始日期
394
- products = params.products, startDate = params.startDate, endDate = params.endDate;
653
+ products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
654
+ if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
655
+ startDate = dayjs().format('YYYY-MM-DD');
656
+ }
395
657
  tempProducts = products || this.store.cart.getItems().map(function (p) {
396
658
  return p._productOrigin;
397
659
  });
398
- tempStartDate = startDate || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 || (_this$otherParams3 = _this$otherParams3.dateRange) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3[0]);
399
- tempEndDate = endDate || ((_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 || (_this$otherParams4 = _this$otherParams4.dateRange) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4[1]);
400
660
  if (tempProducts.length) {
401
- _context8.next = 7;
661
+ tempProducts.forEach(function (p) {
662
+ if (p !== null && p !== void 0 && p['schedule.ids']) {
663
+ var scheduleData = _this3.getScheduleDataByIds(p['schedule.ids']);
664
+ p['_schedule'] = scheduleData;
665
+ }
666
+ });
667
+ }
668
+ // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
669
+ if (this.store.currentProduct) {
670
+ tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
671
+ _schedule: this.store.currentProduct.getOtherParams()['schedule']
672
+ })];
673
+ }
674
+ dateRange = this.store.date.getDateRange();
675
+ tempStartDate = startDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[0].date);
676
+ tempEndDate = endDate || (dateRange === null || dateRange === void 0 ? void 0 : dateRange[1].date);
677
+ if (tempProducts.length) {
678
+ _context13.next = 11;
402
679
  break;
403
680
  }
404
- return _context8.abrupt("return", []);
405
- case 7:
681
+ return _context13.abrupt("return", []);
682
+ case 11:
406
683
  // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
407
- _ref3 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref3.resourceIds, rules = _ref3.rules, resourcesMap = _ref3.resourcesMap;
408
- console.log("resourceIds", tempProducts);
684
+ _ref5 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref5.resourceIds, rules = _ref5.rules, resourcesMap = _ref5.resourcesMap;
409
685
  this.otherParams.currentResourcesMap = resourcesMap;
410
- _context8.next = 12;
411
- return this.store.date.getMonthDates({
686
+ _context13.next = 15;
687
+ return this.store.date.getResourceDates({
688
+ url: params.url,
412
689
  query: {
413
690
  start_date: tempStartDate,
414
691
  end_date: tempEndDate,
415
692
  resource_ids: resourceIds
416
693
  },
417
- rules: rules
694
+ rules: rules,
695
+ type: type
418
696
  });
419
- case 12:
420
- res = _context8.sent;
421
- return _context8.abrupt("return", res);
422
- case 14:
697
+ case 15:
698
+ res = _context13.sent;
699
+ return _context13.abrupt("return", res);
700
+ case 17:
423
701
  case "end":
424
- return _context8.stop();
702
+ return _context13.stop();
425
703
  }
426
- }, _callee8, this);
704
+ }, _callee13, this);
427
705
  }));
428
706
  function getAvailableDate() {
429
707
  return _getAvailableDate.apply(this, arguments);
@@ -436,42 +714,65 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
436
714
  }, {
437
715
  key: "getSummary",
438
716
  value: (function () {
439
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
717
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
440
718
  var cartItems, summary;
441
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
442
- while (1) switch (_context9.prev = _context9.next) {
719
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
720
+ while (1) switch (_context14.prev = _context14.next) {
443
721
  case 0:
444
722
  cartItems = this.store.cart.getItems();
445
- _context9.next = 3;
723
+ _context14.next = 3;
446
724
  return this.store.summary.getSummary(cartItems);
447
725
  case 3:
448
- summary = _context9.sent;
449
- return _context9.abrupt("return", summary);
726
+ summary = _context14.sent;
727
+ return _context14.abrupt("return", summary);
450
728
  case 5:
451
729
  case "end":
452
- return _context9.stop();
730
+ return _context14.stop();
453
731
  }
454
- }, _callee9, this);
732
+ }, _callee14, this);
455
733
  }));
456
734
  function getSummary() {
457
735
  return _getSummary.apply(this, arguments);
458
736
  }
459
737
  return getSummary;
738
+ }()
739
+ /**
740
+ * 获取协议
741
+ */
742
+ )
743
+ }, {
744
+ key: "getProtocol",
745
+ value: (function () {
746
+ var _getProtocol = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(protocolId) {
747
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
748
+ while (1) switch (_context15.prev = _context15.next) {
749
+ case 0:
750
+ return _context15.abrupt("return", this.store.summary.getProtocol(protocolId));
751
+ case 1:
752
+ case "end":
753
+ return _context15.stop();
754
+ }
755
+ }, _callee15, this);
756
+ }));
757
+ function getProtocol(_x13) {
758
+ return _getProtocol.apply(this, arguments);
759
+ }
760
+ return getProtocol;
460
761
  }() // 获取可选择的商品、服务列表
461
762
  )
462
763
  }, {
463
764
  key: "getProducts",
464
765
  value: function () {
465
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
466
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
467
- while (1) switch (_context10.prev = _context10.next) {
766
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
767
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
768
+ while (1) switch (_context16.prev = _context16.next) {
468
769
  case 0:
469
- return _context10.abrupt("return", this.store.products.getProducts());
770
+ return _context16.abrupt("return", this.store.products.getProducts());
470
771
  case 1:
471
772
  case "end":
472
- return _context10.stop();
773
+ return _context16.stop();
473
774
  }
474
- }, _callee10, this);
775
+ }, _callee16, this);
475
776
  }));
476
777
  function getProducts() {
477
778
  return _getProducts.apply(this, arguments);
@@ -481,15 +782,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
481
782
  }, {
482
783
  key: "setLoginAccount",
483
784
  value: function () {
484
- var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(accountId, accountInfo) {
785
+ var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(accountId, accountInfo) {
485
786
  var _this4 = this;
486
787
  var account, stateAccountId, cartItems;
487
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
488
- while (1) switch (_context11.prev = _context11.next) {
788
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
789
+ while (1) switch (_context17.prev = _context17.next) {
489
790
  case 0:
490
791
  account = this.store.accountList.getAccount(accountId);
491
792
  if (!account) {
492
- _context11.next = 9;
793
+ _context17.next = 9;
493
794
  break;
494
795
  }
495
796
  stateAccountId = account.getId();
@@ -505,17 +806,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
505
806
  }
506
807
  });
507
808
  this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
508
- _context11.next = 10;
809
+ _context17.next = 10;
509
810
  break;
510
811
  case 9:
511
812
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
512
813
  case 10:
513
814
  case "end":
514
- return _context11.stop();
815
+ return _context17.stop();
515
816
  }
516
- }, _callee11, this);
817
+ }, _callee17, this);
517
818
  }));
518
- function setLoginAccount(_x7, _x8) {
819
+ function setLoginAccount(_x14, _x15) {
519
820
  return _setLoginAccount.apply(this, arguments);
520
821
  }
521
822
  return setLoginAccount;
@@ -523,14 +824,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
523
824
  }, {
524
825
  key: "generateCartData",
525
826
  value: function () {
526
- var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
527
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
528
- while (1) switch (_context12.prev = _context12.next) {
827
+ var _generateCartData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
828
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
829
+ while (1) switch (_context18.prev = _context18.next) {
529
830
  case 0:
530
831
  case "end":
531
- return _context12.stop();
832
+ return _context18.stop();
532
833
  }
533
- }, _callee12);
834
+ }, _callee18);
534
835
  }));
535
836
  function generateCartData() {
536
837
  return _generateCartData.apply(this, arguments);
@@ -540,38 +841,54 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
540
841
  }, {
541
842
  key: "getFreeProduct",
542
843
  value: function () {
543
- var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(id) {
844
+ var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(id) {
544
845
  var res;
545
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
546
- while (1) switch (_context13.prev = _context13.next) {
846
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
847
+ while (1) switch (_context19.prev = _context19.next) {
547
848
  case 0:
548
- _context13.next = 2;
849
+ _context19.next = 2;
549
850
  return this.request.post("/pay/order/free-pay/".concat(id));
550
851
  case 2:
551
- res = _context13.sent;
552
- return _context13.abrupt("return", res);
852
+ res = _context19.sent;
853
+ return _context19.abrupt("return", res);
553
854
  case 4:
554
855
  case "end":
555
- return _context13.stop();
856
+ return _context19.stop();
556
857
  }
557
- }, _callee13, this);
858
+ }, _callee19, this);
558
859
  }));
559
- function getFreeProduct(_x9) {
860
+ function getFreeProduct(_x16) {
560
861
  return _getFreeProduct.apply(this, arguments);
561
862
  }
562
863
  return getFreeProduct;
563
- }() // 购物车提交订单
864
+ }()
865
+ /**
866
+ * 检查购物车提交订单前是否符合条件
867
+ * @param type 类型 "holder" | "account"
868
+ * @returns boolean
869
+ */
870
+ }, {
871
+ key: "checkBeforeSubmitOrder",
872
+ value: function checkBeforeSubmitOrder(type) {
873
+ return this.store.order.checkBeforeSubmitOrder({
874
+ type: type,
875
+ cartItems: this.store.cart.getItems()
876
+ });
877
+ }
878
+
879
+ // 购物车提交订单
564
880
  }, {
565
881
  key: "submitOrder",
566
882
  value: function () {
567
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
883
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
568
884
  var cartItems, newCartItems;
569
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
570
- while (1) switch (_context14.prev = _context14.next) {
885
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
886
+ while (1) switch (_context20.prev = _context20.next) {
571
887
  case 0:
572
888
  cartItems = this.store.cart.getItems();
573
889
  newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
574
890
  newCartItems.forEach(function (item) {
891
+ var _item$_productOrigin, _item$_origin;
575
892
  item._origin.resources = item._origin.resources.map(function (n) {
576
893
  var newResourcesItem = cloneDeep(n);
577
894
  delete newResourcesItem.id;
@@ -579,17 +896,29 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
579
896
  delete newResourcesItem.resourceType;
580
897
  return _objectSpread({}, newResourcesItem);
581
898
  });
899
+ var formatCapacity = formatDefaultCapacitys({
900
+ capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
901
+ product_bundle: item._origin.product.product_bundle
902
+ });
903
+ var currentCapacity = getSumCapacity({
904
+ capacity: formatCapacity
905
+ });
906
+ if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
907
+ item._origin.metadata = {};
908
+ }
909
+ item._origin.metadata.capacity = formatCapacity;
910
+ item._origin.number = currentCapacity;
582
911
  });
583
- return _context14.abrupt("return", this.store.order.commitOrder({
912
+ return _context20.abrupt("return", this.store.order.submitOrder({
584
913
  query: {
585
914
  cartItems: newCartItems
586
915
  }
587
916
  }));
588
917
  case 4:
589
918
  case "end":
590
- return _context14.stop();
919
+ return _context20.stop();
591
920
  }
592
- }, _callee14, this);
921
+ }, _callee20, this);
593
922
  }));
594
923
  function submitOrder() {
595
924
  return _submitOrder.apply(this, arguments);
@@ -599,14 +928,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
599
928
  }, {
600
929
  key: "pay",
601
930
  value: function () {
602
- var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
603
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
604
- while (1) switch (_context15.prev = _context15.next) {
931
+ var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
932
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
933
+ while (1) switch (_context21.prev = _context21.next) {
605
934
  case 0:
606
935
  case "end":
607
- return _context15.stop();
936
+ return _context21.stop();
608
937
  }
609
- }, _callee15);
938
+ }, _callee21);
610
939
  }));
611
940
  function pay() {
612
941
  return _pay.apply(this, arguments);
@@ -616,14 +945,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
616
945
  }, {
617
946
  key: "getPayInfo",
618
947
  value: function () {
619
- var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
620
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
621
- while (1) switch (_context16.prev = _context16.next) {
948
+ var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
949
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
950
+ while (1) switch (_context22.prev = _context22.next) {
622
951
  case 0:
623
952
  case "end":
624
- return _context16.stop();
953
+ return _context22.stop();
625
954
  }
626
- }, _callee16);
955
+ }, _callee22);
627
956
  }));
628
957
  function getPayInfo() {
629
958
  return _getPayInfo.apply(this, arguments);
@@ -633,15 +962,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
633
962
  }, {
634
963
  key: "setOtherParams",
635
964
  value: function () {
636
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
637
- var _ref4,
638
- _ref4$cover,
965
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
966
+ var _ref6,
967
+ _ref6$cover,
639
968
  cover,
640
- _args17 = arguments;
641
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
642
- while (1) switch (_context17.prev = _context17.next) {
969
+ _args23 = arguments;
970
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
971
+ while (1) switch (_context23.prev = _context23.next) {
643
972
  case 0:
644
- _ref4 = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
973
+ _ref6 = _args23.length > 1 && _args23[1] !== undefined ? _args23[1] : {}, _ref6$cover = _ref6.cover, cover = _ref6$cover === void 0 ? false : _ref6$cover;
645
974
  if (cover) {
646
975
  this.otherParams = params;
647
976
  } else {
@@ -649,11 +978,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
649
978
  }
650
979
  case 2:
651
980
  case "end":
652
- return _context17.stop();
981
+ return _context23.stop();
653
982
  }
654
- }, _callee17, this);
983
+ }, _callee23, this);
655
984
  }));
656
- function setOtherParams(_x10) {
985
+ function setOtherParams(_x17) {
657
986
  return _setOtherParams.apply(this, arguments);
658
987
  }
659
988
  return setOtherParams;
@@ -661,16 +990,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
661
990
  }, {
662
991
  key: "getOtherParams",
663
992
  value: function () {
664
- var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
665
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
666
- while (1) switch (_context18.prev = _context18.next) {
993
+ var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
994
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
995
+ while (1) switch (_context24.prev = _context24.next) {
667
996
  case 0:
668
- return _context18.abrupt("return", this.otherParams);
997
+ return _context24.abrupt("return", this.otherParams);
669
998
  case 1:
670
999
  case "end":
671
- return _context18.stop();
1000
+ return _context24.stop();
672
1001
  }
673
- }, _callee18, this);
1002
+ }, _callee24, this);
674
1003
  }));
675
1004
  function getOtherParams() {
676
1005
  return _getOtherParams.apply(this, arguments);
@@ -681,25 +1010,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
681
1010
  key: "updateCart",
682
1011
  value: function updateCart(params) {
683
1012
  var _this5 = this;
1013
+ var targetCartItem = this.store.cart.getItem(params._id);
1014
+ if (!targetCartItem) {
1015
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1016
+ }
684
1017
  if (params.resources) {
1018
+ var _targetCartItem$_prod;
1019
+ var formatCapacity = formatDefaultCapacitys({
1020
+ capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1021
+ product_bundle: targetCartItem._origin.product.product_bundle
1022
+ });
1023
+ var currentCapacity = getSumCapacity({
1024
+ capacity: formatCapacity
1025
+ });
685
1026
  params.resources = params.resources.map(function (n) {
686
- n.capacity = 1;
1027
+ n.capacity = currentCapacity || 1;
1028
+ checkSubResourcesCapacity(n);
687
1029
  return n;
688
1030
  });
689
1031
  }
690
1032
  this.store.cart.updateItem(params);
691
- var targetCartItem = this.store.cart.getItem(params._id);
692
- if (!targetCartItem) {
693
- throw new Error("\u6CA1\u6709\u627E\u5230".concat(params._id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
694
- }
695
1033
  // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,则要把选择了相同资源的 product._origin.resources 给去除
696
1034
  var cartItems = this.store.cart.getItems();
697
1035
  cartItems.forEach(function (item) {
698
1036
  if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
699
1037
  var _item$_origin$resourc;
700
1038
  var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1039
+ // 检查当前资源是否与目标资源的任何资源匹配
701
1040
  return !targetCartItem._origin.resources.some(function (targetRes) {
702
- return targetRes.id === m.id;
1041
+ var _targetRes$metadata$c, _m$metadata$combined_;
1042
+ // 检查主资源ID是否匹配
1043
+ if (targetRes.id === m.id) return true;
1044
+ // 检查组合资源的情况
1045
+ if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && targetRes.metadata.combined_resource.resource_ids.includes(m.id)) return true;
1046
+ if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1047
+ return false;
703
1048
  });
704
1049
  });
705
1050
  _this5.store.cart.updateItem({
@@ -751,8 +1096,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
751
1096
  */
752
1097
  }, {
753
1098
  key: "deleteCartItemInfo",
754
- value: function deleteCartItemInfo(types) {
755
- this.store.cart.deleteCartItemInfo(types);
1099
+ value: function deleteCartItemInfo(type, _id) {
1100
+ this.store.cart.deleteCartItemInfo(type, _id);
1101
+ }
1102
+ }, {
1103
+ key: "checkCartItemByType",
1104
+ value: function checkCartItemByType(cartItem, type) {
1105
+ return this.store.cart.checkCartItemByType(cartItem, type);
756
1106
  }
757
1107
  }, {
758
1108
  key: "destroy",
@@ -774,14 +1124,78 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
774
1124
  value: function getResourcesList() {
775
1125
  var dateRange = this.store.date.getDateRange();
776
1126
  var resources = [];
777
- dateRange.forEach(function (n) {
778
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
779
- });
780
- var resourcesMap = getResourcesMap(resources);
1127
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
1128
+ dateRange.forEach(function (n) {
1129
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1130
+ });
1131
+ }
1132
+ // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1133
+ if (!resources.length) {
1134
+ var dateList = this.store.date.getDateList();
1135
+ dateList.forEach(function (n) {
1136
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1137
+ });
1138
+ }
1139
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
781
1140
  var cartItems = this.store.cart.getItems();
782
1141
  var arr = [];
1142
+ var capacityMap = {};
783
1143
  cartItems.forEach(function (cartItem) {
784
- var productResources = getResourcesByProduct(resourcesMap, cartItem, cartItems);
1144
+ var _cartItem$_productOri, _cartItem$_productOri2;
1145
+ var selectedResources = [];
1146
+ if (cartItem.holder_id) {
1147
+ selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1148
+ } else {
1149
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1150
+ }
1151
+ var formatCapacity = formatDefaultCapacitys({
1152
+ capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
1153
+ product_bundle: cartItem._origin.product.product_bundle
1154
+ });
1155
+ cartItem._origin.metadata.capacity = formatCapacity;
1156
+ var currentCapacity = getSumCapacity({
1157
+ capacity: formatCapacity
1158
+ });
1159
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri2 = cartItem._productOrigin) === null || _cartItem$_productOri2 === void 0 || (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) === null || _cartItem$_productOri2 === void 0 ? void 0 : _cartItem$_productOri2.resources) || [], selectedResources, currentCapacity);
1160
+ // 如果购物车里已经有了时间片,则需要按照时间片过滤
1161
+ if (cartItem._origin.start_time) {
1162
+ var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
1163
+ var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
1164
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1165
+ productResources.sort(function (a, b) {
1166
+ var _a$metadata, _b$metadata;
1167
+ var aIsCombined = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 || (_a$metadata = _a$metadata.combined_resource) === null || _a$metadata === void 0 ? void 0 : _a$metadata.status) === 1;
1168
+ var bIsCombined = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 || (_b$metadata = _b$metadata.combined_resource) === null || _b$metadata === void 0 ? void 0 : _b$metadata.status) === 1;
1169
+ if (aIsCombined && !bIsCombined) return 1;
1170
+ if (!aIsCombined && bIsCombined) return -1;
1171
+ return 0;
1172
+ });
1173
+ var resourcesUseableMap = {};
1174
+ productResources.forEach(function (n) {
1175
+ n.renderList = n.renderList.filter(function (m) {
1176
+ var recordCount = capacityMap[m.id] || 0;
1177
+ var canUseTime = m.times.find(function (item) {
1178
+ var res = getIsUsableByTimeItem({
1179
+ timeSlice: {
1180
+ start_time: startTime.format('HH:mm'),
1181
+ end_time: endTime.format('HH:mm'),
1182
+ start_at: startTime,
1183
+ end_at: endTime
1184
+ },
1185
+ time: item,
1186
+ resource: m,
1187
+ currentCount: recordCount + (currentCapacity || 0),
1188
+ resourcesUseableMap: resourcesUseableMap
1189
+ });
1190
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1191
+ resourcesUseableMap[m.id] = res.usable;
1192
+ }
1193
+ return res.usable;
1194
+ });
1195
+ return canUseTime;
1196
+ });
1197
+ });
1198
+ }
785
1199
  arr.push({
786
1200
  id: cartItem.id,
787
1201
  // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
@@ -800,21 +1214,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
800
1214
  }, {
801
1215
  key: "getResourcesListByCartItem",
802
1216
  value: function getResourcesListByCartItem(id) {
803
- var cartItems = this.store.cart.getItems();
1217
+ var _targetCartItem$_prod2, _targetCartItem$_prod3;
1218
+ var cartItems = cloneDeep(this.store.cart.getItems());
804
1219
  var dateRange = this.store.date.getDateRange();
805
1220
  var resources = [];
806
1221
  dateRange.forEach(function (n) {
807
1222
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
808
1223
  });
809
- var resourcesMap = getResourcesMap(resources);
810
- var arr = [];
1224
+ // 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap capacity
1225
+ // 用于确保后续分配的容量不会超出
1226
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
811
1227
  var targetCartItem = cartItems.find(function (n) {
812
1228
  return n._id === id;
813
1229
  });
814
1230
  if (!targetCartItem) {
815
1231
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
816
1232
  }
817
- var productResources = getResourcesByProduct(resourcesMap, targetCartItem, cartItems);
1233
+ var selectedResources = [];
1234
+ if (targetCartItem.holder_id) {
1235
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1236
+ } else {
1237
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1238
+ }
1239
+ var formatCapacity = formatDefaultCapacitys({
1240
+ capacity: (_targetCartItem$_prod2 = targetCartItem._productOrigin) === null || _targetCartItem$_prod2 === void 0 ? void 0 : _targetCartItem$_prod2.capacity,
1241
+ product_bundle: targetCartItem._origin.product.product_bundle
1242
+ });
1243
+ var currentCapacity = getSumCapacity({
1244
+ capacity: formatCapacity
1245
+ });
1246
+ var productResources = getResourcesByProduct(resourcesMap, ((_targetCartItem$_prod3 = targetCartItem._productOrigin) === null || _targetCartItem$_prod3 === void 0 || (_targetCartItem$_prod3 = _targetCartItem$_prod3.product_resource) === null || _targetCartItem$_prod3 === void 0 ? void 0 : _targetCartItem$_prod3.resources) || [], selectedResources, currentCapacity);
818
1247
  if (productResources) {
819
1248
  return {
820
1249
  id: targetCartItem.id,
@@ -832,10 +1261,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
832
1261
  // 通过资源列表和指定的资源 id,获取指定资源的时间切片
833
1262
  }, {
834
1263
  key: "getResourceTimeSlot",
835
- value: function getResourceTimeSlot(_ref5) {
836
- var product = _ref5.product,
837
- resources = _ref5.resources,
838
- currentResourceId = _ref5.currentResourceId;
1264
+ value: function getResourceTimeSlot(_ref7) {
1265
+ var product = _ref7.product,
1266
+ resources = _ref7.resources,
1267
+ currentResourceId = _ref7.currentResourceId;
839
1268
  var dateRange = this.store.date.getDateRange();
840
1269
  var timeSlots = getTimeSlicesByResource({
841
1270
  resource: resources.find(function (n) {
@@ -848,98 +1277,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
848
1277
  return timeSlots;
849
1278
  }
850
1279
 
851
- // 自动分派可用的资源-单种资源类型
852
- }, {
853
- key: "autoSelectResource",
854
- value: function autoSelectResource(_ref6) {
855
- var resourceProductData = _ref6.resourceProductData,
856
- resources = _ref6.resources,
857
- timeSlots = _ref6.timeSlots;
858
- var dateRange = this.store.date.getDateRange();
859
- if (timeSlots) {
860
- // 如果 start_time 存在,则直接根据 start_time 算出商品总共需要的时长,然后根据时长去匹配资源
861
- // const duration = resourceProductData.product.duration.value;
862
- // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
863
- // const end_time = dayjs(`${dateRange[0].date} ${start_time}`)
864
- // .add(duration, resourceProductData.product.duration.type)
865
- // .format("HH:mm");
866
- // 根据 start_time 和 end_time 去匹配资源
867
- var targetResource = null;
868
- var _iterator = _createForOfIteratorHelper(resources),
869
- _step;
870
- try {
871
- var _loop = function _loop() {
872
- var n = _step.value;
873
- var canUseTime = n.times.find(function (item) {
874
- var res = getIsUsableByTimeItem({
875
- timeSlice: timeSlots,
876
- time: item,
877
- resource: n,
878
- currentCount: 1
879
- });
880
- return res.usable;
881
- });
882
- if (canUseTime) {
883
- targetResource = n;
884
- return 1; // break
885
- }
886
- };
887
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
888
- if (_loop()) break;
889
- }
890
- } catch (err) {
891
- _iterator.e(err);
892
- } finally {
893
- _iterator.f();
894
- }
895
- return {
896
- selectedResource: targetResource
897
- };
898
- } else {
899
- // 如果没有传递 timeSlots,证明是第一个资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
900
- var duration = resourceProductData.product.duration.value;
901
- var resourcesMap = getResourcesMap(resources);
902
- var resourceIds = resources.map(function (n) {
903
- return n.id;
904
- });
905
- var _timeSlots = getTimeSlicesByResources({
906
- resourceIds: resourceIds,
907
- resourcesMap: resourcesMap,
908
- duration: duration,
909
- currentDate: dateRange[0].date,
910
- split: 10
911
- });
912
- // 如果timeSlots返回了 空数组,代表没有可用的资源了
913
- if (!_timeSlots) {
914
- return; // 给一个提示?
915
- }
916
- return {
917
- timeSlots: _timeSlots,
918
- selectedResource: resources[0]
919
- };
920
- }
921
- }
922
-
923
1280
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
924
1281
  }, {
925
1282
  key: "autoSelectAccountResources",
926
- value: function autoSelectAccountResources(_ref7) {
927
- var _accountCartItems$0$_, _accountCartItems$;
928
- var holder_id = _ref7.holder_id,
929
- resources_code = _ref7.resources_code,
930
- timeSlots = _ref7.timeSlots,
931
- countMap = _ref7.countMap;
1283
+ value: function autoSelectAccountResources(_ref8) {
1284
+ var holder_id = _ref8.holder_id,
1285
+ resources_code = _ref8.resources_code,
1286
+ timeSlots = _ref8.timeSlots,
1287
+ countMap = _ref8.countMap,
1288
+ capacity = _ref8.capacity;
932
1289
  var dateRange = this.store.date.getDateRange();
933
- var cartItems = this.store.cart.getItems();
1290
+ var cartItems = cloneDeep(this.store.cart.getItems());
934
1291
  // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
935
1292
  var accountCartItems = cartItems.filter(function (n) {
936
1293
  return n.holder_id === holder_id;
937
1294
  }) || [];
938
- // 账号下没商品则不用处理
1295
+ // 账号下没商品则处理所有购物车
939
1296
  if (!accountCartItems.length) {
940
- return {
941
- selectedResource: null
942
- };
1297
+ accountCartItems = cartItems;
943
1298
  }
944
1299
  // duration=所有商品时间的集合
945
1300
  var duration = accountCartItems.reduce(function (acc, n) {
@@ -947,17 +1302,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
947
1302
  return acc + ((_n$_productOrigin$dur = (_n$_productOrigin = n._productOrigin) === null || _n$_productOrigin === void 0 || (_n$_productOrigin = _n$_productOrigin.duration) === null || _n$_productOrigin === void 0 ? void 0 : _n$_productOrigin.value) !== null && _n$_productOrigin$dur !== void 0 ? _n$_productOrigin$dur : 0);
948
1303
  }, 0);
949
1304
  // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
950
- var durationType = (_accountCartItems$0$_ = (_accountCartItems$ = accountCartItems[0]) === null || _accountCartItems$ === void 0 || (_accountCartItems$ = _accountCartItems$._productOrigin) === null || _accountCartItems$ === void 0 || (_accountCartItems$ = _accountCartItems$.duration) === null || _accountCartItems$ === void 0 ? void 0 : _accountCartItems$.type) !== null && _accountCartItems$0$_ !== void 0 ? _accountCartItems$0$_ : "minutes";
1305
+ // let durationType = accountCartItems[0]?._productOrigin?.duration?.type ?? "minutes";
951
1306
  // 取出账号下所对应类型的所有的可用资源
952
1307
  var resources = [];
953
1308
  accountCartItems.forEach(function (item) {
954
- var _item$_productOrigin;
955
- (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.product_resource) === null || _item$_productOrigin === void 0 || (_item$_productOrigin = _item$_productOrigin.resources) === null || _item$_productOrigin === void 0 || _item$_productOrigin.forEach(function (n) {
1309
+ var _item$_productOrigin2;
1310
+ (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.product_resource) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.resources) === null || _item$_productOrigin2 === void 0 || _item$_productOrigin2.forEach(function (n) {
956
1311
  if (n.code === resources_code) {
957
1312
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
958
1313
  }
959
1314
  });
960
1315
  });
1316
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1317
+ resources.sort(function (a, b) {
1318
+ var _a$metadata2, _b$metadata2;
1319
+ var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
1320
+ var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
1321
+ if (aIsCombined && !bIsCombined) return 1;
1322
+ if (!aIsCombined && bIsCombined) return -1;
1323
+ return 0;
1324
+ });
1325
+ var resourcesUseableMap = {};
961
1326
 
962
1327
  // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
963
1328
  // 每个商品
@@ -971,7 +1336,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
971
1336
  var _iterator2 = _createForOfIteratorHelper(resources),
972
1337
  _step2;
973
1338
  try {
974
- var _loop2 = function _loop2() {
1339
+ var _loop = function _loop() {
975
1340
  var n = _step2.value;
976
1341
  var recordCount = countMap[n.id] || 0;
977
1342
  var canUseTime = n.times.find(function (item) {
@@ -979,8 +1344,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
979
1344
  timeSlice: timeSlots,
980
1345
  time: item,
981
1346
  resource: n,
982
- currentCount: recordCount + 1
1347
+ currentCount: recordCount + (capacity || 0),
1348
+ resourcesUseableMap: resourcesUseableMap
983
1349
  });
1350
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[n.id]) !== false) {
1351
+ resourcesUseableMap[n.id] = res.usable;
1352
+ }
984
1353
  return res.usable;
985
1354
  });
986
1355
  if (canUseTime) {
@@ -989,7 +1358,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
989
1358
  }
990
1359
  };
991
1360
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
992
- if (_loop2()) break;
1361
+ if (_loop()) break;
993
1362
  }
994
1363
  } catch (err) {
995
1364
  _iterator2.e(err);
@@ -1004,19 +1373,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1004
1373
  var resourceIds = resources.map(function (n) {
1005
1374
  return n.id;
1006
1375
  });
1007
- var _timeSlots2 = getTimeSlicesByResources({
1376
+ var _timeSlots = getTimeSlicesByResources({
1008
1377
  resourceIds: resourceIds,
1009
1378
  resourcesMap: resourcesMap,
1010
1379
  duration: duration,
1011
1380
  currentDate: dateRange[0].date,
1012
- split: 10
1381
+ split: 10,
1382
+ capacity: capacity,
1383
+ resourcesUseableMap: resourcesUseableMap
1013
1384
  });
1014
1385
  // 如果timeSlots返回了 空数组,代表没有可用的资源了
1015
- if (!_timeSlots2) {
1386
+ if (!_timeSlots) {
1016
1387
  return; // 给一个提示?
1017
1388
  }
1018
1389
  return {
1019
- timeSlots: _timeSlots2,
1390
+ timeSlots: _timeSlots,
1020
1391
  selectedResource: resources[0]
1021
1392
  };
1022
1393
  }
@@ -1026,34 +1397,52 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1026
1397
  }, {
1027
1398
  key: "autoSelectAllProductResources",
1028
1399
  value: function autoSelectAllProductResources(resources_code, timeSlots) {
1029
- var _this7 = this;
1400
+ var _dateRange$,
1401
+ _this7 = this;
1030
1402
  var dateRange = this.store.date.getDateRange();
1031
1403
  var resources = [];
1032
- dateRange.forEach(function (n) {
1033
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1034
- });
1035
- var resourcesMap = getResourcesMap(resources);
1404
+ if (dateRange !== null && dateRange !== void 0 && (_dateRange$ = dateRange[0]) !== null && _dateRange$ !== void 0 && _dateRange$.date) {
1405
+ dateRange.forEach(function (n) {
1406
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1407
+ });
1408
+ }
1409
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1036
1410
  // 一个账号一个账号处理
1037
1411
  var errorList = [];
1038
1412
  var selectResourcesMap = {};
1039
- this.store.accountList.getAccounts().forEach(function (account) {
1040
- var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1041
- // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1042
- var allCartItems = _this7.store.cart.getItems();
1413
+ var accountList = this.store.accountList.getAccounts();
1414
+ var selectForCartResources = function selectForCartResources(cartItems) {
1043
1415
  var recordTimeSlots = cloneDeep(timeSlots);
1044
1416
  // timeSlots 传进来的只是用户选中的时间片,但是实际上需要根据多个商品时间进行累加
1045
1417
  // 假设 timeSlots.start_time 是15:40 duration 是 30min
1046
1418
  // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1047
1419
 
1048
1420
  cartItems.forEach(function (item, index) {
1049
- if (timeSlots) {
1421
+ var _item$_productOrigin3;
1422
+ var formatCapacity = formatDefaultCapacitys({
1423
+ capacity: (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.capacity,
1424
+ product_bundle: item._origin.product.product_bundle
1425
+ });
1426
+ var currentCapacity = getSumCapacity({
1427
+ capacity: formatCapacity
1428
+ });
1429
+ // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
1430
+ if (item._origin.start_time && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time)) {
1431
+ recordTimeSlots = {
1432
+ start_time: item._origin.start_time,
1433
+ end_time: item._origin.end_time,
1434
+ start_at: dayjs("".concat(item.start_date, " ").concat(item._origin.start_time)),
1435
+ end_at: dayjs("".concat(item.end_date, " ").concat(item._origin.end_time))
1436
+ };
1437
+ }
1438
+ if (recordTimeSlots) {
1050
1439
  if (index !== 0 && recordTimeSlots) {
1051
- var _item$_productOrigin$, _item$_productOrigin2, _ref8, _item$_productOrigin3, _item$_productOrigin$2, _item$_productOrigin4, _ref9, _item$_productOrigin5;
1052
- var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 || (_item$_productOrigin2 = _item$_productOrigin2.duration) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref8 = (_item$_productOrigin3 = item._productOrigin) === null || _item$_productOrigin3 === void 0 || (_item$_productOrigin3 = _item$_productOrigin3.duration) === null || _item$_productOrigin3 === void 0 ? void 0 : _item$_productOrigin3.type) !== null && _ref8 !== void 0 ? _ref8 : "minutes");
1053
- var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref9 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref9 !== void 0 ? _ref9 : "minutes");
1440
+ var _item$_productOrigin$, _item$_productOrigin4, _ref9, _item$_productOrigin5, _item$_productOrigin$2, _item$_productOrigin6, _ref10, _item$_productOrigin7;
1441
+ var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1442
+ var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
1054
1443
  recordTimeSlots = {
1055
- start_time: start_at.format("HH:mm"),
1056
- end_time: end_at.format("HH:mm"),
1444
+ start_time: start_at.format('HH:mm'),
1445
+ end_time: end_at.format('HH:mm'),
1057
1446
  start_at: start_at,
1058
1447
  end_at: end_at
1059
1448
  };
@@ -1063,7 +1452,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1063
1452
  holder_id: item.holder_id,
1064
1453
  resources_code: resources_code,
1065
1454
  timeSlots: recordTimeSlots,
1066
- countMap: selectResourcesMap
1455
+ countMap: selectResourcesMap,
1456
+ capacity: currentCapacity
1067
1457
  });
1068
1458
  // // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1069
1459
  // if (item._origin.resources?.some((n: any) => n.form_id === res?.selectedResource?.form_id)) {
@@ -1071,12 +1461,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1071
1461
  // }
1072
1462
  if (res !== null && res !== void 0 && res.selectedResource) {
1073
1463
  if (!selectResourcesMap[res.selectedResource.id]) {
1074
- selectResourcesMap[res.selectedResource.id] = 1;
1464
+ selectResourcesMap[res.selectedResource.id] = currentCapacity;
1075
1465
  } else {
1076
- selectResourcesMap[res.selectedResource.id]++;
1466
+ selectResourcesMap[res.selectedResource.id] += currentCapacity;
1077
1467
  }
1078
- console.log(_this7.store.cart.getItems());
1079
- res.selectedResource.capacity = 1;
1468
+ res.selectedResource.capacity = currentCapacity;
1469
+ checkSubResourcesCapacity(res.selectedResource);
1080
1470
  _this7.store.cart.updateItem({
1081
1471
  _id: item._id,
1082
1472
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
@@ -1084,15 +1474,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1084
1474
  return existingRes.form_id !== res.selectedResource.form_id;
1085
1475
  })), [res.selectedResource])
1086
1476
  });
1087
- console.log(_this7.store.cart.getItems());
1088
1477
  } else {
1089
1478
  // 如果没有可用的技师了,推到错误列表里让 UI 去提示
1090
1479
  errorList.push(item._id);
1091
1480
  }
1092
1481
  } else {
1093
- var _productResources$fin;
1482
+ var _item$_productOrigin8, _productResources$fin;
1483
+ // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1484
+ var allCartItems = cloneDeep(_this7.store.cart.getItems());
1094
1485
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1095
- var productResources = getResourcesByProduct(resourcesMap, item, allCartItems);
1486
+ var selectedResources = [];
1487
+ if (item.holder_id) {
1488
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1489
+ } else {
1490
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1491
+ }
1492
+ var productResources = getResourcesByProduct(resourcesMap, ((_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.resources) || [], selectedResources, currentCapacity);
1096
1493
  // 自动选择 productResources 中对应 resources_code 的资源
1097
1494
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
1098
1495
  return n.code === resources_code;
@@ -1106,7 +1503,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1106
1503
  return;
1107
1504
  }
1108
1505
  var targetResource = targetRenderList[0];
1109
- targetResource.capacity = 1;
1506
+ targetResource.capacity = currentCapacity;
1507
+ // 在这里处理 children 的数据
1508
+ checkSubResourcesCapacity(targetResource);
1110
1509
  _this7.store.cart.updateItem({
1111
1510
  _id: item._id,
1112
1511
  resources: [].concat(_toConsumableArray((item._origin.resources || []).filter(function (existingRes) {
@@ -1119,7 +1518,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1119
1518
  }
1120
1519
  }
1121
1520
  });
1122
- });
1521
+ };
1522
+ var cartItems = cloneDeep(this.store.cart.getItems());
1523
+
1524
+ // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
1525
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1526
+ accountList.forEach(function (account) {
1527
+ var cartItems = _this7.store.cart.getCartByAccount(account.getId());
1528
+ selectForCartResources(cartItems);
1529
+ });
1530
+ } else {
1531
+ selectForCartResources(cartItems);
1532
+ }
1123
1533
  return {
1124
1534
  errorList: errorList
1125
1535
  };
@@ -1128,15 +1538,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1128
1538
  }, {
1129
1539
  key: "getTimeSlotByAllResources",
1130
1540
  value: function getTimeSlotByAllResources(resources_code) {
1131
- var _this8 = this;
1541
+ var _this8 = this,
1542
+ _cartItems$,
1543
+ _cartItems$2;
1132
1544
  var dateRange = this.store.date.getDateRange();
1133
1545
  // 取出购物车中所有一已选择的第一步资源
1134
1546
  var resources = [];
1135
- var cartItems = this.store.cart.getItems();
1547
+ var cartItems = cloneDeep(this.store.cart.getItems());
1548
+ // if (cartItems?.[0].start_date) return [];
1136
1549
  var resourceIds = [];
1137
1550
  cartItems.forEach(function (item) {
1138
- var _item$_productOrigin6;
1139
- (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.product_resource) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.resources) === null || _item$_productOrigin6 === void 0 || _item$_productOrigin6.forEach(function (n) {
1551
+ var _item$_productOrigin9;
1552
+ (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.product_resource) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.resources) === null || _item$_productOrigin9 === void 0 || _item$_productOrigin9.forEach(function (n) {
1140
1553
  if (n.code === resources_code) {
1141
1554
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
1142
1555
  }
@@ -1151,23 +1564,52 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1151
1564
  var resourcesMap = getResourcesMap(resources);
1152
1565
  var duration = 0;
1153
1566
  // duration = 不同账号的最长时间
1154
- this.store.accountList.getAccounts().forEach(function (account) {
1567
+ var accountList = this.store.accountList.getAccounts();
1568
+ var checkDuration = function checkDuration(cartItems) {
1155
1569
  var accountDuration = 0;
1156
- var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1157
1570
  cartItems.forEach(function (item) {
1158
- var _item$_productOrigin$3, _item$_productOrigin7;
1159
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1571
+ var _item$_productOrigin$3, _item$_productOrigin10;
1572
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin10 = item._productOrigin) === null || _item$_productOrigin10 === void 0 || (_item$_productOrigin10 = _item$_productOrigin10.duration) === null || _item$_productOrigin10 === void 0 ? void 0 : _item$_productOrigin10.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
1160
1573
  });
1161
1574
  if (accountDuration > duration) {
1162
1575
  duration = accountDuration;
1163
1576
  }
1164
- });
1577
+ };
1578
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
1579
+ accountList.forEach(function (account) {
1580
+ var cartItems = _this8.store.cart.getCartByAccount(account.getId());
1581
+ checkDuration(cartItems);
1582
+ });
1583
+ } else {
1584
+ checkDuration(cartItems);
1585
+ }
1586
+ // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
1587
+ // 同时 session 类商品的流程也不应该调用这个方法
1588
+ if (!(cartItems !== null && cartItems !== void 0 && (_cartItems$ = cartItems[0]) !== null && _cartItems$ !== void 0 && _cartItems$.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$2 = cartItems[0]) !== null && _cartItems$2 !== void 0 && _cartItems$2.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration)) {
1589
+ return [];
1590
+ }
1591
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].start_date && !dateRange) {
1592
+ var _cartItems$3, _cartItems$4;
1593
+ dateRange = [{
1594
+ date: cartItems === null || cartItems === void 0 ? void 0 : cartItems[0].start_date,
1595
+ status: 'available',
1596
+ week: '',
1597
+ weekNum: 0
1598
+ }, {
1599
+ date: (cartItems === null || cartItems === void 0 || (_cartItems$3 = cartItems[0]) === null || _cartItems$3 === void 0 ? void 0 : _cartItems$3.end_date) || (cartItems === null || cartItems === void 0 || (_cartItems$4 = cartItems[0]) === null || _cartItems$4 === void 0 ? void 0 : _cartItems$4.start_date) || '',
1600
+ status: 'available',
1601
+ week: '',
1602
+ weekNum: 0
1603
+ }];
1604
+ }
1605
+ var resourcesUseableMap = {};
1165
1606
  var timeSlots = getTimeSlicesByResources({
1166
1607
  resourceIds: resourceIds,
1167
1608
  resourcesMap: resourcesMap,
1168
1609
  duration: duration,
1169
1610
  currentDate: dateRange[0].date,
1170
- split: 10
1611
+ split: 10,
1612
+ resourcesUseableMap: resourcesUseableMap
1171
1613
  });
1172
1614
  return timeSlots;
1173
1615
  }
@@ -1178,7 +1620,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1178
1620
  value: function submitTimeSlot(timeSlots) {
1179
1621
  var _this9 = this;
1180
1622
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
1181
- var cartItems = this.store.cart.getItems();
1623
+ var cartItems = cloneDeep(this.store.cart.getItems());
1182
1624
 
1183
1625
  // 按账号分组
1184
1626
  var itemsByAccount = cartItems.reduce(function (acc, item) {
@@ -1192,13 +1634,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1192
1634
 
1193
1635
  // 处理每个账号的商品
1194
1636
  Object.values(itemsByAccount).forEach(function (accountItems) {
1195
- var currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1637
+ var currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1196
1638
  accountItems.forEach(function (item, index) {
1197
1639
  var newResources = cloneDeep(item._origin.resources);
1198
1640
  newResources.forEach(function (resource) {
1199
- var _item$_productOrigin$4, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1641
+ var _item$_productOrigin$4, _item$_productOrigin11, _ref11, _item$_productOrigin12;
1200
1642
  resource.startTime = currentStartTime;
1201
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : "minutes").format("YYYY-MM-DD HH:mm");
1643
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$4 = (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.duration) === null || _item$_productOrigin11 === void 0 ? void 0 : _item$_productOrigin11.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0, (_ref11 = (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.duration) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
1202
1644
  delete resource.times;
1203
1645
  });
1204
1646
  _this9.store.cart.updateItem({
@@ -1219,6 +1661,236 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1219
1661
  }, {
1220
1662
  key: "clearCacheByModule",
1221
1663
  value: function clearCacheByModule(module) {}
1664
+ }, {
1665
+ key: "getScheduleDataByIds",
1666
+ value: function getScheduleDataByIds(scheduleIds) {
1667
+ var targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1668
+ var targetSchedulesData = targetSchedules.map(function (item) {
1669
+ return calcCalendarDataByScheduleResult(item);
1670
+ });
1671
+ var newSchedule = {};
1672
+ targetSchedulesData.forEach(function (item) {
1673
+ item.forEach(function (n) {
1674
+ if (!newSchedule[n.date]) {
1675
+ newSchedule[n.date] = n;
1676
+ } else {
1677
+ if (!n.isExcluded) {
1678
+ newSchedule[n.date].isExcluded = false;
1679
+ }
1680
+ }
1681
+ });
1682
+ });
1683
+ var newScheduleArr = Object.values(newSchedule);
1684
+ return newScheduleArr;
1685
+ }
1686
+ // 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
1687
+ }, {
1688
+ key: "openProductDetail",
1689
+ value: function () {
1690
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
1691
+ var targetProduct, targetProductData, newScheduleArr;
1692
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1693
+ while (1) switch (_context25.prev = _context25.next) {
1694
+ case 0:
1695
+ _context25.next = 2;
1696
+ return this.store.products.getProduct(productId);
1697
+ case 2:
1698
+ targetProduct = _context25.sent;
1699
+ if (targetProduct) {
1700
+ targetProductData = targetProduct.getData();
1701
+ this.store.currentProduct = targetProduct;
1702
+ newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
1703
+ targetProduct.setOtherParams('schedule', newScheduleArr);
1704
+ }
1705
+ case 4:
1706
+ case "end":
1707
+ return _context25.stop();
1708
+ }
1709
+ }, _callee25, this);
1710
+ }));
1711
+ function openProductDetail(_x18) {
1712
+ return _openProductDetail.apply(this, arguments);
1713
+ }
1714
+ return openProductDetail;
1715
+ }()
1716
+ }, {
1717
+ key: "closeProductDetail",
1718
+ value: function closeProductDetail() {
1719
+ var _this$store$currentPr;
1720
+ (_this$store$currentPr = this.store.currentProduct) === null || _this$store$currentPr === void 0 || _this$store$currentPr.setOtherParams('schedule', []);
1721
+ this.store.currentProduct = undefined;
1722
+ }
1723
+ }, {
1724
+ key: "getTimeslotBySchedule",
1725
+ value: function getTimeslotBySchedule(_ref12) {
1726
+ var _this$store$currentPr2;
1727
+ var date = _ref12.date,
1728
+ scheduleIds = _ref12.scheduleIds,
1729
+ resources = _ref12.resources;
1730
+ var targetProduct = this.store.currentProduct;
1731
+ var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
1732
+ var targetSchedules = [];
1733
+ // 如果外面传递了 scheduleIds,优先取入参
1734
+ if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
1735
+ targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1736
+ } else {
1737
+ targetSchedules = this.store.schedule.getScheduleListByIds(targetProductData['schedule.ids']);
1738
+ }
1739
+ var resourcesDates = this.store.date.getDateList();
1740
+ var targetResourceDate = resourcesDates.find(function (n) {
1741
+ return n.date === date;
1742
+ });
1743
+ var cartItems = cloneDeep(this.store.cart.getItems());
1744
+ var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
1745
+ var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
1746
+ var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.getData()) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
1747
+ var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
1748
+ var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
1749
+ console.log('scheduleTimeSlots:', scheduleTimeSlots, productResources);
1750
+ // 当前所有待选择资源的集合,先提出来,提升性能
1751
+ var allProductResources = productResources.flatMap(function (n) {
1752
+ return n.renderList;
1753
+ });
1754
+ // 资源排下序,把单个资源靠前,组合资源排在后面
1755
+ allProductResources.sort(function (a, b) {
1756
+ var _a$metadata3, _b$metadata3;
1757
+ var aIsCombined = ((_a$metadata3 = a.metadata) === null || _a$metadata3 === void 0 || (_a$metadata3 = _a$metadata3.combined_resource) === null || _a$metadata3 === void 0 ? void 0 : _a$metadata3.status) === 1;
1758
+ var bIsCombined = ((_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 || (_b$metadata3 = _b$metadata3.combined_resource) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.status) === 1;
1759
+ if (aIsCombined && !bIsCombined) return 1;
1760
+ if (!aIsCombined && bIsCombined) return -1;
1761
+ return 0;
1762
+ });
1763
+ var resourcesUseableMap = {};
1764
+ // 计算每个日程切片下日程可用的资源的容量总和
1765
+ var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
1766
+ var count = 0;
1767
+ // 遍历所有资源
1768
+ allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
1769
+ // 遍历所有资源的上工时间片
1770
+ m.times.forEach(function (childTiem) {
1771
+ // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
1772
+ var res = getIsUsableByTimeItem({
1773
+ timeSlice: {
1774
+ start_time: item.start,
1775
+ end_time: item.end,
1776
+ start_at: dayjs(item.start),
1777
+ end_at: dayjs(item.end)
1778
+ },
1779
+ time: childTiem,
1780
+ resource: m,
1781
+ currentCount: 1,
1782
+ resourcesUseableMap: resourcesUseableMap
1783
+ });
1784
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false) {
1785
+ resourcesUseableMap[m.id] = res.usable;
1786
+ }
1787
+ // 如果资源可用,且是独占资源,remainingCapacity 始终为 1
1788
+ if (res.usable && res.remainingCapacity >= count) {
1789
+ count = res.remainingCapacity;
1790
+ }
1791
+ });
1792
+ });
1793
+ var startDayJs = dayjs(item.start);
1794
+ var endDayJs = dayjs(item.end);
1795
+ return {
1796
+ start_time: startDayJs.format('HH:mm'),
1797
+ end_time: endDayJs.format('HH:mm'),
1798
+ start_at: startDayJs,
1799
+ end_at: endDayJs,
1800
+ count: count
1801
+ };
1802
+ });
1803
+ return formatScheduleTimeSlots;
1804
+ }
1805
+ }, {
1806
+ key: "addProductToCart",
1807
+ value: function addProductToCart(_ref13) {
1808
+ var _this10 = this;
1809
+ var product = _ref13.product,
1810
+ date = _ref13.date,
1811
+ account = _ref13.account;
1812
+ var _ref14 = product || {},
1813
+ bundle = _ref14.bundle,
1814
+ options = _ref14.options,
1815
+ origin = _ref14.origin,
1816
+ product_variant_id = _ref14.product_variant_id;
1817
+ var productData = _objectSpread(_objectSpread({}, origin), {}, {
1818
+ product_variant_id: product_variant_id
1819
+ });
1820
+ if (!account) {
1821
+ var activeAccount = this.getActiveAccount();
1822
+ if (activeAccount) {
1823
+ account = activeAccount;
1824
+ }
1825
+ }
1826
+ this.store.cart.addItem({
1827
+ product: productData,
1828
+ date: date,
1829
+ account: account,
1830
+ bundle: bundle,
1831
+ options: options
1832
+ });
1833
+ // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
1834
+ if (date) {
1835
+ var cartItems = cloneDeep(this.store.cart.getItems());
1836
+ var cartItemsByDate = cartItems.filter(function (n) {
1837
+ return !dayjs(n.start_date).isSame(dayjs(date.startTime), 'day');
1838
+ });
1839
+ if (cartItemsByDate.length) {
1840
+ cartItemsByDate.forEach(function (n) {
1841
+ _this10.store.cart.removeItem(n._id);
1842
+ });
1843
+ }
1844
+ }
1845
+ }
1846
+ }, {
1847
+ key: "setOtherData",
1848
+ value: function setOtherData(key, value) {
1849
+ this.otherData[key] = value;
1850
+ this.checkSaveCache({
1851
+ cacheId: this.cacheId,
1852
+ fatherModule: this.name,
1853
+ store: {
1854
+ otherData: this.otherData
1855
+ },
1856
+ cacheKey: ['otherData']
1857
+ });
1858
+ }
1859
+ }, {
1860
+ key: "getOtherData",
1861
+ value: function getOtherData(key) {
1862
+ return this.otherData[key];
1863
+ }
1864
+ }, {
1865
+ key: "getProductTypeById",
1866
+ value: function () {
1867
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
1868
+ var product;
1869
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1870
+ while (1) switch (_context26.prev = _context26.next) {
1871
+ case 0:
1872
+ _context26.next = 2;
1873
+ return this.store.products.getProduct(id);
1874
+ case 2:
1875
+ product = _context26.sent;
1876
+ if (!product) {
1877
+ _context26.next = 5;
1878
+ break;
1879
+ }
1880
+ return _context26.abrupt("return", product.getProductType());
1881
+ case 5:
1882
+ return _context26.abrupt("return", 'normal');
1883
+ case 6:
1884
+ case "end":
1885
+ return _context26.stop();
1886
+ }
1887
+ }, _callee26, this);
1888
+ }));
1889
+ function getProductTypeById(_x19) {
1890
+ return _getProductTypeById.apply(this, arguments);
1891
+ }
1892
+ return getProductTypeById;
1893
+ }()
1222
1894
  }]);
1223
1895
  return BookingByStepImpl;
1224
1896
  }(BaseModule);