@pisell/pisellos 0.0.9 → 0.0.11

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 (136) hide show
  1. package/dist/core/index.js +4 -1
  2. package/dist/effects/index.d.ts +1 -1
  3. package/dist/effects/index.js +3 -3
  4. package/dist/modules/Account/index.d.ts +5 -3
  5. package/dist/modules/Account/index.js +23 -36
  6. package/dist/modules/Account/types.d.ts +2 -1
  7. package/dist/modules/AccountList/index.d.ts +2 -0
  8. package/dist/modules/AccountList/index.js +34 -11
  9. package/dist/modules/Cart/index.d.ts +17 -11
  10. package/dist/modules/Cart/index.js +179 -121
  11. package/dist/modules/Cart/types.d.ts +98 -9
  12. package/dist/modules/Cart/types.js +8 -0
  13. package/dist/modules/Cart/utils.d.ts +114 -0
  14. package/dist/modules/Cart/utils.js +345 -0
  15. package/dist/modules/Date/index.d.ts +11 -12
  16. package/dist/modules/Date/index.js +104 -60
  17. package/dist/modules/Date/types.d.ts +51 -20
  18. package/dist/modules/Date/types.js +2 -5
  19. package/dist/modules/Date/utils.d.ts +35 -0
  20. package/dist/modules/Date/utils.js +211 -0
  21. package/dist/modules/Discount/index.d.ts +26 -0
  22. package/dist/modules/Discount/index.js +234 -0
  23. package/dist/modules/Discount/types.d.ts +66 -0
  24. package/dist/modules/Discount/types.js +5 -0
  25. package/dist/modules/Order/index.d.ts +16 -12
  26. package/dist/modules/Order/index.js +38 -166
  27. package/dist/modules/Order/types.d.ts +18 -41
  28. package/dist/modules/Order/types.js +0 -14
  29. package/dist/modules/Payment/index.d.ts +0 -2
  30. package/dist/modules/Payment/index.js +45 -76
  31. package/dist/modules/Payment/types.d.ts +0 -2
  32. package/dist/modules/Payment/types.js +2 -0
  33. package/dist/modules/Product/types.d.ts +50 -1
  34. package/dist/modules/ProductList/index.d.ts +1 -0
  35. package/dist/modules/ProductList/index.js +23 -2
  36. package/dist/modules/ProductList/types.d.ts +1 -0
  37. package/dist/modules/Resource/types.d.ts +6 -2
  38. package/dist/modules/Rules/index.d.ts +32 -0
  39. package/dist/modules/Rules/index.js +423 -0
  40. package/dist/modules/Rules/types.d.ts +46 -0
  41. package/dist/modules/Rules/types.js +5 -0
  42. package/dist/modules/Summary/index.d.ts +13 -0
  43. package/dist/modules/Summary/index.js +80 -0
  44. package/dist/modules/Summary/types.d.ts +13 -0
  45. package/dist/modules/Summary/types.js +1 -0
  46. package/dist/modules/Summary/utils.d.ts +19 -0
  47. package/dist/modules/Summary/utils.js +56 -0
  48. package/dist/plugins/index.d.ts +3 -2
  49. package/dist/plugins/index.js +2 -1
  50. package/dist/plugins/request.d.ts +4 -3
  51. package/dist/plugins/request.js +30 -30
  52. package/dist/plugins/shopStore.d.ts +4 -0
  53. package/dist/plugins/shopStore.js +1 -0
  54. package/dist/solution/BookingByStep/index.d.ts +73 -10
  55. package/dist/solution/BookingByStep/index.js +641 -74
  56. package/dist/solution/BookingByStep/types.d.ts +2 -0
  57. package/dist/solution/BookingByStep/types.js +11 -8
  58. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  59. package/dist/solution/BookingByStep/utils/products.js +47 -0
  60. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  61. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  62. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  63. package/dist/solution/ShopDiscount/index.js +546 -0
  64. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  65. package/dist/solution/ShopDiscount/types.js +10 -0
  66. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/utils.js +7 -0
  68. package/dist/solution/index.d.ts +1 -0
  69. package/dist/solution/index.js +2 -1
  70. package/lib/core/index.js +1 -1
  71. package/lib/effects/index.d.ts +1 -1
  72. package/lib/effects/index.js +1 -1
  73. package/lib/modules/Account/index.d.ts +5 -3
  74. package/lib/modules/Account/index.js +14 -3
  75. package/lib/modules/Account/types.d.ts +2 -1
  76. package/lib/modules/AccountList/index.d.ts +2 -0
  77. package/lib/modules/AccountList/index.js +17 -0
  78. package/lib/modules/Cart/index.d.ts +17 -11
  79. package/lib/modules/Cart/index.js +72 -21
  80. package/lib/modules/Cart/types.d.ts +98 -9
  81. package/lib/modules/Cart/utils.d.ts +114 -0
  82. package/lib/modules/Cart/utils.js +320 -0
  83. package/lib/modules/Date/index.d.ts +11 -12
  84. package/lib/modules/Date/index.js +50 -31
  85. package/lib/modules/Date/types.d.ts +51 -20
  86. package/lib/modules/Date/types.js +0 -4
  87. package/lib/modules/Date/utils.d.ts +35 -0
  88. package/lib/modules/Date/utils.js +167 -0
  89. package/lib/modules/Discount/index.d.ts +26 -0
  90. package/lib/modules/Discount/index.js +118 -0
  91. package/lib/modules/Discount/types.d.ts +66 -0
  92. package/lib/modules/Discount/types.js +33 -0
  93. package/lib/modules/Order/index.d.ts +16 -12
  94. package/lib/modules/Order/index.js +23 -51
  95. package/lib/modules/Order/types.d.ts +18 -41
  96. package/lib/modules/Payment/index.d.ts +0 -2
  97. package/lib/modules/Payment/index.js +6 -17
  98. package/lib/modules/Payment/types.d.ts +0 -2
  99. package/lib/modules/Product/types.d.ts +50 -1
  100. package/lib/modules/ProductList/index.d.ts +1 -0
  101. package/lib/modules/ProductList/index.js +6 -1
  102. package/lib/modules/ProductList/types.d.ts +1 -0
  103. package/lib/modules/Resource/types.d.ts +6 -2
  104. package/lib/modules/Rules/index.d.ts +32 -0
  105. package/lib/modules/Rules/index.js +283 -0
  106. package/lib/modules/Rules/types.d.ts +46 -0
  107. package/lib/modules/Rules/types.js +33 -0
  108. package/lib/modules/Summary/index.d.ts +13 -0
  109. package/lib/modules/Summary/index.js +49 -0
  110. package/lib/modules/Summary/types.d.ts +13 -0
  111. package/lib/modules/Summary/types.js +17 -0
  112. package/lib/modules/Summary/utils.d.ts +19 -0
  113. package/lib/modules/Summary/utils.js +79 -0
  114. package/lib/plugins/index.d.ts +3 -2
  115. package/lib/plugins/index.js +3 -1
  116. package/lib/plugins/request.d.ts +4 -3
  117. package/lib/plugins/request.js +4 -20
  118. package/lib/plugins/shopStore.d.ts +4 -0
  119. package/lib/plugins/shopStore.js +17 -0
  120. package/lib/solution/BookingByStep/index.d.ts +73 -10
  121. package/lib/solution/BookingByStep/index.js +452 -20
  122. package/lib/solution/BookingByStep/types.d.ts +2 -0
  123. package/lib/solution/BookingByStep/types.js +3 -0
  124. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  125. package/lib/solution/BookingByStep/utils/products.js +60 -0
  126. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  127. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  128. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  129. package/lib/solution/ShopDiscount/index.js +321 -0
  130. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  131. package/lib/solution/ShopDiscount/types.js +38 -0
  132. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  133. package/lib/solution/ShopDiscount/utils.js +32 -0
  134. package/lib/solution/index.d.ts +1 -0
  135. package/lib/solution/index.js +3 -1
  136. package/package.json +8 -7
@@ -1,4 +1,11 @@
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ 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
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
2
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
11
  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; }
@@ -19,6 +26,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
19
26
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
27
  import { BaseModule } from "../../modules/BaseModule";
21
28
  import { BookingByStepHooks, createModule } from "./types";
29
+ import { getAvailableProductResources } from "./utils/products";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem } from "./utils/resources";
31
+ import dayjs from "dayjs";
32
+ import { getResourcesMap } from "../../modules/Resource/utils";
33
+ import { cloneDeep } from "lodash-es";
22
34
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
23
35
  _inherits(BookingByStepImpl, _BaseModule);
24
36
  var _super = _createSuper(BookingByStepImpl);
@@ -34,6 +46,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
34
46
  _defineProperty(_assertThisInitialized(_this), "isSolution", true);
35
47
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
36
48
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
49
+ _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
37
50
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
38
51
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
39
52
  return _this;
@@ -54,13 +67,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
54
67
  // 获取依赖的插件
55
68
  this.request = core.getPlugin("request");
56
69
  this.window = core.getPlugin("window");
70
+ this.shopStore = core.getPlugin("shopStore");
57
71
  if (this.request) {
58
- _context.next = 8;
72
+ _context.next = 9;
59
73
  break;
60
74
  }
61
75
  throw new Error("bookingByStep解决方案需要 request 插件支持");
62
- case 8:
63
- moduleArr = ["cart", "step", "products", "guests", "date", "accountList", "order", "payment"];
76
+ case 9:
77
+ moduleArr = ["cart", "summary", "step", "products", "guests", "date", "accountList", "order", "payment"];
64
78
  moduleArr.forEach(function (step) {
65
79
  var targetModule = createModule(step, _this2.name);
66
80
  if (targetModule) {
@@ -71,7 +85,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
71
85
  }
72
86
  });
73
87
  this.core.effects.emit(BookingByStepHooks.onInited, {});
74
- case 11:
88
+ case 12:
75
89
  case "end":
76
90
  return _context.stop();
77
91
  }
@@ -95,11 +109,33 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
95
109
  step: this.store.step.getCurrentStep()
96
110
  };
97
111
  }
112
+
113
+ // step: 下一个
98
114
  }, {
99
115
  key: "next",
100
116
  value: function next() {
101
117
  this.store.step.nextStep();
102
118
  }
119
+ // step: 上一个
120
+ }, {
121
+ key: "back",
122
+ value: function back() {
123
+ this.store.step.prevStep();
124
+ }
125
+
126
+ // 跳转到指定步骤
127
+ }, {
128
+ key: "gotoStep",
129
+ value: function gotoStep(index) {
130
+ this.store.step.gotoStep(index);
131
+ }
132
+
133
+ // 获取所有step
134
+ }, {
135
+ key: "getStepList",
136
+ value: function getStepList() {
137
+ return this.store.step.getStepList();
138
+ }
103
139
 
104
140
  // 获取购物车里 temp.xxx的方法
105
141
  }, {
@@ -125,26 +161,28 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
125
161
  key: "loadProducts",
126
162
  value: function () {
127
163
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
128
- var category_ids, product_ids, productsData;
164
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, productsData;
129
165
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
130
166
  while (1) switch (_context3.prev = _context3.next) {
131
167
  case 0:
132
- category_ids = _ref.category_ids, product_ids = _ref.product_ids;
168
+ _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;
133
169
  _context3.next = 3;
134
170
  return this.request.post("/product/query", {
135
171
  open_quotation: 1,
136
172
  open_bundle: 1,
137
- extension_type: ['product_appointment', 'appointment_ticket'],
173
+ extension_type: ["product_appointment", "appointment_ticket"],
138
174
  status: "published",
139
175
  num: 500,
140
176
  skip: 1,
141
177
  category_ids: category_ids,
142
- ids: product_ids
178
+ ids: product_ids,
179
+ collection: collection
143
180
  });
144
181
  case 3:
145
182
  productsData = _context3.sent;
146
183
  this.store.products.addProduct(productsData.data.list);
147
- case 5:
184
+ return _context3.abrupt("return", productsData.data.list);
185
+ case 6:
148
186
  case "end":
149
187
  return _context3.stop();
150
188
  }
@@ -154,25 +192,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
154
192
  return _loadProducts.apply(this, arguments);
155
193
  }
156
194
  return loadProducts;
157
- }() // 往购物车里加一些商品/服务相关的选中数据
195
+ }()
158
196
  }, {
159
- key: "storeProducts",
197
+ key: "storeProduct",
160
198
  value: function () {
161
- var _storeProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(productData) {
199
+ var _storeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(productData) {
200
+ var activeAccount, _ref2, bundle, options, origin, product_variant_id, product;
162
201
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
163
202
  while (1) switch (_context4.prev = _context4.next) {
164
203
  case 0:
165
- this.store.cart.storeTemp("products", productData);
166
- case 1:
204
+ // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
205
+ activeAccount = this.getActiveAccount();
206
+ if (activeAccount) {
207
+ _context4.next = 3;
208
+ break;
209
+ }
210
+ throw new Error("没有找到当前账户");
211
+ case 3:
212
+ _ref2 = productData || {}, bundle = _ref2.bundle, options = _ref2.options, origin = _ref2.origin, product_variant_id = _ref2.product_variant_id;
213
+ product = _objectSpread(_objectSpread({}, origin), {}, {
214
+ product_variant_id: product_variant_id
215
+ });
216
+ this.store.cart.addItem({
217
+ account: activeAccount,
218
+ product: product,
219
+ bundle: bundle,
220
+ options: options
221
+ });
222
+ case 6:
167
223
  case "end":
168
224
  return _context4.stop();
169
225
  }
170
226
  }, _callee4, this);
171
227
  }));
172
- function storeProducts(_x5) {
173
- return _storeProducts.apply(this, arguments);
228
+ function storeProduct(_x5) {
229
+ return _storeProduct.apply(this, arguments);
174
230
  }
175
- return storeProducts;
231
+ return storeProduct;
176
232
  }() // 添加账户或者 guest
177
233
  }, {
178
234
  key: "addAccount",
@@ -200,11 +256,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
200
256
  key: "getAccounts",
201
257
  value: function () {
202
258
  var _getAccounts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
259
+ var accounts;
203
260
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
204
261
  while (1) switch (_context6.prev = _context6.next) {
205
262
  case 0:
206
- return _context6.abrupt("return", this.store.accountList.getAccounts());
207
- case 1:
263
+ accounts = this.store.accountList.getAccounts();
264
+ return _context6.abrupt("return", accounts.map(function (account) {
265
+ return account.getAccount();
266
+ }));
267
+ case 2:
208
268
  case "end":
209
269
  return _context6.stop();
210
270
  }
@@ -214,7 +274,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
214
274
  return _getAccounts.apply(this, arguments);
215
275
  }
216
276
  return getAccounts;
217
- }() // 设置日期范围,注入到日期模块中
277
+ }()
278
+ }, {
279
+ key: "checkHasLoginAccount",
280
+ value: function checkHasLoginAccount() {
281
+ var accounts = this.store.accountList.getAccounts();
282
+ return accounts.some(function (account) {
283
+ return account.getLoginStatus();
284
+ });
285
+ }
286
+ }, {
287
+ key: "setActiveAccount",
288
+ value: function setActiveAccount(id) {
289
+ this.store.accountList.setActiveAccount(id);
290
+ }
291
+ }, {
292
+ key: "getActiveAccount",
293
+ value: function getActiveAccount() {
294
+ var activeAccount = this.store.accountList.getActiveAccount();
295
+ return activeAccount ? activeAccount.getAccount() : null;
296
+ }
297
+ }, {
298
+ key: "removeAccount",
299
+ value: function removeAccount(id) {
300
+ this.store.accountList.removeAccount(id);
301
+ // 还需要把对应账号的商品给她删了
302
+ this.clearCartByAccount(id);
303
+ }
304
+
305
+ // 设置日期范围,注入到日期模块中
218
306
  }, {
219
307
  key: "setDateRange",
220
308
  value: function () {
@@ -222,10 +310,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
222
310
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
223
311
  while (1) switch (_context7.prev = _context7.next) {
224
312
  case 0:
313
+ this.store.date.setDateRange(dateRange);
314
+ case 1:
225
315
  case "end":
226
316
  return _context7.stop();
227
317
  }
228
- }, _callee7);
318
+ }, _callee7, this);
229
319
  }));
230
320
  function setDateRange(_x7) {
231
321
  return _setDateRange.apply(this, arguments);
@@ -239,7 +329,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
239
329
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
240
330
  while (1) switch (_context8.prev = _context8.next) {
241
331
  case 0:
242
- return _context8.abrupt("return", '2024-01-01');
332
+ return _context8.abrupt("return", "2024-01-01");
243
333
  case 1:
244
334
  case "end":
245
335
  return _context8.stop();
@@ -250,109 +340,172 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
250
340
  return _getRangeDate.apply(this, arguments);
251
341
  }
252
342
  return getRangeDate;
253
- }() // 获取商品/服务的可用日期
343
+ }()
254
344
  }, {
255
- key: "getAvailableDate",
345
+ key: "getCart",
256
346
  value: function () {
257
- var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
258
- var products;
347
+ var _getCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
259
348
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
260
349
  while (1) switch (_context9.prev = _context9.next) {
261
350
  case 0:
262
- _context9.next = 2;
263
- return this.getStoreCart('products');
264
- case 2:
265
- products = _context9.sent;
266
- console.log(products);
267
- case 4:
351
+ return _context9.abrupt("return", this.store.cart.getItems());
352
+ case 1:
268
353
  case "end":
269
354
  return _context9.stop();
270
355
  }
271
356
  }, _callee9, this);
272
357
  }));
273
- function getAvailableDate() {
274
- return _getAvailableDate.apply(this, arguments);
358
+ function getCart() {
359
+ return _getCart.apply(this, arguments);
275
360
  }
276
- return getAvailableDate;
277
- }() // 获取具体资源的可用时段
361
+ return getCart;
362
+ }() // 获取商品/服务的可用日期
278
363
  }, {
279
- key: "getResourceTimeslot",
364
+ key: "getAvailableDate",
280
365
  value: function () {
281
- var _getResourceTimeslot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
366
+ var _getAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
367
+ var _this$otherParams, _this$otherParams2;
368
+ var params,
369
+ products,
370
+ startDate,
371
+ endDate,
372
+ tempProducts,
373
+ tempStartDate,
374
+ tempEndDate,
375
+ _ref3,
376
+ resourceIds,
377
+ rules,
378
+ resourcesMap,
379
+ res,
380
+ _args10 = arguments;
282
381
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
283
382
  while (1) switch (_context10.prev = _context10.next) {
284
383
  case 0:
384
+ params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
385
+ // 开始日期如果小于今天,直接以今天当做开始日期
386
+ products = params.products, startDate = params.startDate, endDate = params.endDate;
387
+ tempProducts = products || this.store.cart.getItems().map(function (p) {
388
+ return p._productOrigin;
389
+ });
390
+ tempStartDate = startDate || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams = _this$otherParams.dateRange) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams[0]);
391
+ tempEndDate = endDate || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 || (_this$otherParams2 = _this$otherParams2.dateRange) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2[1]);
392
+ if (tempProducts.length) {
393
+ _context10.next = 7;
394
+ break;
395
+ }
396
+ return _context10.abrupt("return", []);
397
+ case 7:
398
+ // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
399
+ _ref3 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref3.resourceIds, rules = _ref3.rules, resourcesMap = _ref3.resourcesMap;
400
+ console.log("resourceIds", tempProducts);
401
+ this.otherParams.currentResourcesMap = resourcesMap;
402
+ _context10.next = 12;
403
+ return this.store.date.getMonthDates({
404
+ query: {
405
+ start_date: tempStartDate,
406
+ end_date: tempEndDate,
407
+ resource_ids: resourceIds
408
+ },
409
+ rules: rules
410
+ });
411
+ case 12:
412
+ res = _context10.sent;
413
+ return _context10.abrupt("return", res);
414
+ case 14:
285
415
  case "end":
286
416
  return _context10.stop();
287
417
  }
288
- }, _callee10);
418
+ }, _callee10, this);
289
419
  }));
290
- function getResourceTimeslot() {
291
- return _getResourceTimeslot.apply(this, arguments);
420
+ function getAvailableDate() {
421
+ return _getAvailableDate.apply(this, arguments);
292
422
  }
293
- return getResourceTimeslot;
294
- }() // 获取可选择的商品、服务列表
423
+ return getAvailableDate;
424
+ }()
425
+ /**
426
+ * 获取购物车汇总信息
427
+ */
295
428
  }, {
296
- key: "getProducts",
297
- value: function () {
298
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
429
+ key: "getSummary",
430
+ value: (function () {
431
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
432
+ var cartItems, summary;
299
433
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
300
434
  while (1) switch (_context11.prev = _context11.next) {
301
435
  case 0:
302
- return _context11.abrupt("return", this.store.products.getProducts());
303
- case 1:
436
+ cartItems = this.store.cart.getItems();
437
+ _context11.next = 3;
438
+ return this.store.summary.getSummary(cartItems);
439
+ case 3:
440
+ summary = _context11.sent;
441
+ return _context11.abrupt("return", summary);
442
+ case 5:
304
443
  case "end":
305
444
  return _context11.stop();
306
445
  }
307
446
  }, _callee11, this);
308
447
  }));
309
- function getProducts() {
310
- return _getProducts.apply(this, arguments);
448
+ function getSummary() {
449
+ return _getSummary.apply(this, arguments);
311
450
  }
312
- return getProducts;
313
- }() // 往购物车里加一些资源相关的选中数据
451
+ return getSummary;
452
+ }() // 获取可选择的商品、服务列表
453
+ )
314
454
  }, {
315
- key: "storeResources",
455
+ key: "getProducts",
316
456
  value: function () {
317
- var _storeResources = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(resources) {
457
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
318
458
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
319
459
  while (1) switch (_context12.prev = _context12.next) {
320
460
  case 0:
321
- this.store.cart.storeTemp("resources", resources);
461
+ return _context12.abrupt("return", this.store.products.getProducts());
322
462
  case 1:
323
463
  case "end":
324
464
  return _context12.stop();
325
465
  }
326
466
  }, _callee12, this);
327
467
  }));
328
- function storeResources(_x8) {
329
- return _storeResources.apply(this, arguments);
468
+ function getProducts() {
469
+ return _getProducts.apply(this, arguments);
330
470
  }
331
- return storeResources;
471
+ return getProducts;
332
472
  }() // 如果用户登录
333
473
  }, {
334
474
  key: "setLoginAccount",
335
475
  value: function () {
336
- var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(account) {
337
- var accounts, mainAccount;
476
+ var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(accountId, accountInfo) {
477
+ var _this4 = this;
478
+ var account, cartItems;
338
479
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
339
480
  while (1) switch (_context13.prev = _context13.next) {
340
481
  case 0:
341
- _context13.next = 2;
342
- return this.getAccounts();
343
- case 2:
344
- accounts = _context13.sent;
345
- mainAccount = accounts.find(function (n) {
346
- return n.getLoginStatus();
482
+ account = this.store.accountList.getAccount(accountId);
483
+ if (!account) {
484
+ _context13.next = 7;
485
+ break;
486
+ }
487
+ account.setAccountInfo(accountInfo);
488
+ // 然后去购物车,把原先关联了 holder_id 为 accountId 的商品,替换为 holder_id = accountInfo.id
489
+ cartItems = this.store.cart.getItems();
490
+ cartItems.forEach(function (item) {
491
+ if (item.holder_id === accountId) {
492
+ _this4.store.cart.updateItem({
493
+ _id: item._id,
494
+ account: accountInfo
495
+ });
496
+ }
347
497
  });
348
- mainAccount === null || mainAccount === void 0 || mainAccount.setAccountInfo(account);
349
- case 5:
498
+ _context13.next = 8;
499
+ break;
500
+ case 7:
501
+ throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
502
+ case 8:
350
503
  case "end":
351
504
  return _context13.stop();
352
505
  }
353
506
  }, _callee13, this);
354
507
  }));
355
- function setLoginAccount(_x9) {
508
+ function setLoginAccount(_x8, _x9) {
356
509
  return _setLoginAccount.apply(this, arguments);
357
510
  }
358
511
  return setLoginAccount;
@@ -378,13 +531,30 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
378
531
  key: "submitOrder",
379
532
  value: function () {
380
533
  var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
534
+ var cartItems;
381
535
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
382
536
  while (1) switch (_context15.prev = _context15.next) {
383
537
  case 0:
538
+ cartItems = this.store.cart.getItems(); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
539
+ cartItems.forEach(function (item) {
540
+ item._origin.resources = item._origin.resources.map(function (n) {
541
+ var newResourcesItem = cloneDeep(n);
542
+ delete newResourcesItem.id;
543
+ delete newResourcesItem.main_field;
544
+ delete newResourcesItem.resourceType;
545
+ return _objectSpread({}, newResourcesItem);
546
+ });
547
+ });
548
+ return _context15.abrupt("return", this.store.order.commitOrder({
549
+ query: {
550
+ cartItems: cartItems
551
+ }
552
+ }));
553
+ case 3:
384
554
  case "end":
385
555
  return _context15.stop();
386
556
  }
387
- }, _callee15);
557
+ }, _callee15, this);
388
558
  }));
389
559
  function submitOrder() {
390
560
  return _submitOrder.apply(this, arguments);
@@ -429,14 +599,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
429
599
  key: "setOtherParams",
430
600
  value: function () {
431
601
  var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
432
- var _ref2,
433
- _ref2$cover,
602
+ var _ref4,
603
+ _ref4$cover,
434
604
  cover,
435
605
  _args18 = arguments;
436
606
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
437
607
  while (1) switch (_context18.prev = _context18.next) {
438
608
  case 0:
439
- _ref2 = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {}, _ref2$cover = _ref2.cover, cover = _ref2$cover === void 0 ? false : _ref2$cover;
609
+ _ref4 = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
440
610
  if (cover) {
441
611
  this.otherParams = params;
442
612
  } else {
@@ -471,7 +641,404 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
471
641
  return _getOtherParams.apply(this, arguments);
472
642
  }
473
643
  return getOtherParams;
474
- }()
644
+ }() // 更新购物车
645
+ }, {
646
+ key: "updateCart",
647
+ value: function updateCart(params) {
648
+ this.store.cart.updateItem(params);
649
+ }
650
+
651
+ // 删除购物车里某个商品
652
+ }, {
653
+ key: "deleteCart",
654
+ value: function deleteCart(product_id) {}
655
+
656
+ // 清空购物车
657
+ }, {
658
+ key: "clearCart",
659
+ value: function clearCart() {
660
+ this.store.cart.clear();
661
+ }
662
+
663
+ // 基于账户清空购物车
664
+ }, {
665
+ key: "clearCartByAccount",
666
+ value: function clearCartByAccount(account_id) {
667
+ this.store.cart.clearCartByAccount(account_id);
668
+ }
669
+ }, {
670
+ key: "destory",
671
+ value: function destory() {
672
+ var _this$store$cart, _this$store$step, _this$store$products, _this$store$guests, _this$store$date, _this$store$accountLi;
673
+ (_this$store$cart = this.store.cart) === null || _this$store$cart === void 0 || _this$store$cart.destory();
674
+ (_this$store$step = this.store.step) === null || _this$store$step === void 0 || _this$store$step.destory();
675
+ (_this$store$products = this.store.products) === null || _this$store$products === void 0 || _this$store$products.destory();
676
+ (_this$store$guests = this.store.guests) === null || _this$store$guests === void 0 || _this$store$guests.destory();
677
+ (_this$store$date = this.store.date) === null || _this$store$date === void 0 || _this$store$date.destory();
678
+ (_this$store$accountLi = this.store.accountList) === null || _this$store$accountLi === void 0 || _this$store$accountLi.destory();
679
+ this.core.effects.offByModuleDestroy(this.name);
680
+ this.core.unregisterModule(this);
681
+ }
682
+
683
+ // 获取当前购物车内所有关联的资源列表,拼装数据格式
684
+ }, {
685
+ key: "getResourcesList",
686
+ value: function getResourcesList() {
687
+ var dateRange = this.store.date.getDateRange();
688
+ var resources = [];
689
+ dateRange.forEach(function (n) {
690
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
691
+ });
692
+ var resourcesMap = getResourcesMap(resources);
693
+ var cartItems = this.store.cart.getItems();
694
+ var arr = [];
695
+ cartItems.forEach(function (cartItem) {
696
+ var productResources = getResourcesByProduct(resourcesMap, cartItem, cartItems);
697
+ arr.push({
698
+ id: cartItem.id,
699
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
700
+ _id: cartItem._id,
701
+ // 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
702
+ product: cartItem._productOrigin,
703
+ resources: productResources,
704
+ holder_id: cartItem.holder_id,
705
+ holder_name: cartItem.holder_title
706
+ });
707
+ });
708
+ return arr;
709
+ }
710
+
711
+ // 通过资源列表和指定的资源 id,获取指定资源的时间切片
712
+ }, {
713
+ key: "getResourceTimeSlot",
714
+ value: function getResourceTimeSlot(_ref5) {
715
+ var product = _ref5.product,
716
+ resources = _ref5.resources,
717
+ currentResourceId = _ref5.currentResourceId;
718
+ var dateRange = this.store.date.getDateRange();
719
+ var timeSlots = getTimeSlicesByResource({
720
+ resource: resources.find(function (n) {
721
+ return n.id === currentResourceId;
722
+ }),
723
+ duration: product.duration.value,
724
+ split: 10,
725
+ currentDate: dateRange[0].date
726
+ });
727
+ return timeSlots;
728
+ }
729
+
730
+ // 自动分派可用的资源-单种资源类型
731
+ }, {
732
+ key: "autoSelectResource",
733
+ value: function autoSelectResource(_ref6) {
734
+ var resourceProductData = _ref6.resourceProductData,
735
+ resources = _ref6.resources,
736
+ timeSlots = _ref6.timeSlots;
737
+ var dateRange = this.store.date.getDateRange();
738
+ if (timeSlots) {
739
+ // 如果 start_time 存在,则直接根据 start_time 算出商品总共需要的时长,然后根据时长去匹配资源
740
+ var duration = resourceProductData.product.duration.value;
741
+ var start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
742
+ var end_time = dayjs("".concat(dateRange[0].date, " ").concat(start_time)).add(duration, resourceProductData.product.duration.type).format("HH:mm");
743
+ // 根据 start_time 和 end_time 去匹配资源
744
+ var targetResource = null;
745
+ var _iterator = _createForOfIteratorHelper(resources),
746
+ _step;
747
+ try {
748
+ var _loop = function _loop() {
749
+ var n = _step.value;
750
+ var canUseTime = n.times.find(function (item) {
751
+ return getIsUsableByTimeItem({
752
+ timeSlice: item,
753
+ time: {
754
+ start_time: start_time,
755
+ end_time: end_time
756
+ },
757
+ resource: n,
758
+ currentCount: 1
759
+ });
760
+ });
761
+ if (canUseTime) {
762
+ targetResource = n;
763
+ return 1; // break
764
+ }
765
+ };
766
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
767
+ if (_loop()) break;
768
+ }
769
+ } catch (err) {
770
+ _iterator.e(err);
771
+ } finally {
772
+ _iterator.f();
773
+ }
774
+ return {
775
+ selectedResource: targetResource
776
+ };
777
+ } else {
778
+ // 如果没有传递 timeSlots,证明是第一个资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
779
+ var _duration = resourceProductData.product.duration.value;
780
+ var resourcesMap = getResourcesMap(resources);
781
+ var resourceIds = resources.map(function (n) {
782
+ return n.id;
783
+ });
784
+ var _timeSlots = getTimeSlicesByResources({
785
+ resourceIds: resourceIds,
786
+ resourcesMap: resourcesMap,
787
+ duration: _duration,
788
+ currentDate: dateRange[0].date,
789
+ split: 10
790
+ });
791
+ // 如果timeSlots返回了 空数组,代表没有可用的资源了
792
+ if (!_timeSlots) {
793
+ return; // 给一个提示?
794
+ }
795
+ return {
796
+ timeSlots: _timeSlots,
797
+ selectedResource: resources[0]
798
+ };
799
+ }
800
+ }
801
+
802
+ // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
803
+ }, {
804
+ key: "autoSelectAccountResources",
805
+ value: function autoSelectAccountResources(_ref7) {
806
+ var _accountCartItems$;
807
+ var holder_id = _ref7.holder_id,
808
+ resources_code = _ref7.resources_code,
809
+ timeSlots = _ref7.timeSlots;
810
+ var dateRange = this.store.date.getDateRange();
811
+ var cartItems = this.store.cart.getItems();
812
+ // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
813
+ var accountCartItems = cartItems.filter(function (n) {
814
+ return n.holder_id === holder_id;
815
+ });
816
+ // duration=所有商品时间的集合
817
+ var duration = accountCartItems.reduce(function (acc, n) {
818
+ return acc + n._productOrigin.duration.value;
819
+ }, 0);
820
+ // 正常来说,能进这个业务的所有商品的 duration 类型都是一样的,所以这里取第一个商品的 duration 类型
821
+ var durationType = (accountCartItems === null || accountCartItems === void 0 || (_accountCartItems$ = accountCartItems[0]) === null || _accountCartItems$ === void 0 ? void 0 : _accountCartItems$._productOrigin.duration.type) || "minutes";
822
+ // 取出账号下所对应类型的所有的可用资源
823
+ var resources = [];
824
+ accountCartItems.forEach(function (item) {
825
+ var _item$_productOrigin$;
826
+ (_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) {
827
+ if (n.code === resources_code) {
828
+ resources.push.apply(resources, _toConsumableArray(n.renderList || []));
829
+ }
830
+ });
831
+ });
832
+
833
+ // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
834
+ if (timeSlots) {
835
+ var start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
836
+ var end_time = dayjs("".concat(dateRange[0].date, " ").concat(start_time)).add(duration, durationType).format("HH:mm");
837
+ // 根据 start_time 和 end_time 去匹配资源
838
+ var targetResource = null;
839
+ var _iterator2 = _createForOfIteratorHelper(resources),
840
+ _step2;
841
+ try {
842
+ var _loop2 = function _loop2() {
843
+ var n = _step2.value;
844
+ var canUseTime = n.times.find(function (item) {
845
+ return getIsUsableByTimeItem({
846
+ timeSlice: item,
847
+ time: {
848
+ start_time: start_time,
849
+ end_time: end_time
850
+ },
851
+ resource: n,
852
+ currentCount: 1
853
+ });
854
+ });
855
+ if (canUseTime) {
856
+ targetResource = n;
857
+ return 1; // break
858
+ }
859
+ };
860
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
861
+ if (_loop2()) break;
862
+ }
863
+ } catch (err) {
864
+ _iterator2.e(err);
865
+ } finally {
866
+ _iterator2.f();
867
+ }
868
+ return {
869
+ selectedResource: targetResource
870
+ };
871
+ } else {
872
+ var resourcesMap = getResourcesMap(resources);
873
+ var resourceIds = resources.map(function (n) {
874
+ return n.id;
875
+ });
876
+ var _timeSlots2 = getTimeSlicesByResources({
877
+ resourceIds: resourceIds,
878
+ resourcesMap: resourcesMap,
879
+ duration: duration,
880
+ currentDate: dateRange[0].date,
881
+ split: 10
882
+ });
883
+ // 如果timeSlots返回了 空数组,代表没有可用的资源了
884
+ if (!_timeSlots2) {
885
+ return; // 给一个提示?
886
+ }
887
+ return {
888
+ timeSlots: _timeSlots2,
889
+ selectedResource: resources[0]
890
+ };
891
+ }
892
+ }
893
+
894
+ // 给所有购物车里的商品先分配一个资源
895
+ }, {
896
+ key: "autoSelectAllProductResources",
897
+ value: function autoSelectAllProductResources(resources_code, timeSlots) {
898
+ var _this5 = this;
899
+ var dateRange = this.store.date.getDateRange();
900
+ var resources = [];
901
+ dateRange.forEach(function (n) {
902
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
903
+ });
904
+ var resourcesMap = getResourcesMap(resources);
905
+ // 一个账号一个账号处理
906
+ var errorList = [];
907
+ this.store.accountList.getAccounts().forEach(function (account) {
908
+ var cartItems = _this5.store.cart.getCartByAccount(account.getId());
909
+ // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
910
+ var allCartItems = _this5.store.cart.getItems();
911
+ cartItems.forEach(function (item) {
912
+ if (timeSlots) {
913
+ // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
914
+ var res = _this5.autoSelectAccountResources({
915
+ holder_id: item.holder_id,
916
+ resources_code: resources_code,
917
+ timeSlots: timeSlots
918
+ });
919
+ if (res !== null && res !== void 0 && res.selectedResource) {
920
+ console.log(_this5.store.cart.getItems());
921
+ _this5.store.cart.updateItem({
922
+ _id: item._id,
923
+ resources: [].concat(_toConsumableArray(item._origin.resources || []), [res.selectedResource])
924
+ });
925
+ console.log(_this5.store.cart.getItems());
926
+ } else {
927
+ // 如果没有可用的技师了,推到错误列表里让 UI 去提示
928
+ errorList.push(item._id);
929
+ }
930
+ } else {
931
+ var _productResources$fin;
932
+ // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
933
+ var productResources = getResourcesByProduct(resourcesMap, item, allCartItems);
934
+ // 自动选择 productResources 中对应 resources_code 的资源
935
+ var targetRenderList = (_productResources$fin = productResources.find(function (n) {
936
+ return n.code === resources_code;
937
+ })) === null || _productResources$fin === void 0 ? void 0 : _productResources$fin.renderList;
938
+ if (targetRenderList && targetRenderList.length > 0) {
939
+ _this5.store.cart.updateItem({
940
+ _id: item._id,
941
+ resources: [].concat(_toConsumableArray(item._origin.resources || []), [targetRenderList[0]])
942
+ });
943
+ } else {
944
+ // 如果没有可用的技师了,推到错误列表里让 UI 去提示
945
+ errorList.push(item._id);
946
+ }
947
+ }
948
+ });
949
+ });
950
+ return {
951
+ errorList: errorList
952
+ };
953
+ }
954
+ // 从购物车中获取已经分配好第一步资源的所有时间片
955
+ }, {
956
+ key: "getTimeSlotByAllResources",
957
+ value: function getTimeSlotByAllResources(resources_code) {
958
+ var _this6 = this;
959
+ var dateRange = this.store.date.getDateRange();
960
+ // 取出购物车中所有一已选择的第一步资源
961
+ var resources = [];
962
+ var cartItems = this.store.cart.getItems();
963
+ var resourceIds = [];
964
+ cartItems.forEach(function (item) {
965
+ var _item$_productOrigin$2, _item$_origin$resourc;
966
+ (_item$_productOrigin$2 = item._productOrigin.product_resource) === null || _item$_productOrigin$2 === void 0 || (_item$_productOrigin$2 = _item$_productOrigin$2.resources) === null || _item$_productOrigin$2 === void 0 || _item$_productOrigin$2.forEach(function (n) {
967
+ if (n.code === resources_code) {
968
+ resources.push.apply(resources, _toConsumableArray(n.renderList || []));
969
+ }
970
+ });
971
+ (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 || _item$_origin$resourc.forEach(function (n) {
972
+ resourceIds.push(n.relation_id);
973
+ });
974
+ });
975
+ var resourcesMap = getResourcesMap(resources);
976
+ var duration = 0;
977
+ // duration = 不同账号的最长时间
978
+ this.store.accountList.getAccounts().forEach(function (account) {
979
+ var accountDuration = 0;
980
+ var cartItems = _this6.store.cart.getCartByAccount(account.getId());
981
+ cartItems.forEach(function (item) {
982
+ accountDuration += item._productOrigin.duration.value;
983
+ });
984
+ if (accountDuration > duration) {
985
+ duration = accountDuration;
986
+ }
987
+ });
988
+ var timeSlots = getTimeSlicesByResources({
989
+ resourceIds: resourceIds,
990
+ resourcesMap: resourcesMap,
991
+ duration: duration,
992
+ currentDate: dateRange[0].date,
993
+ split: 10
994
+ });
995
+ return timeSlots;
996
+ }
997
+
998
+ // 提交时间切片,绑定到对应购物车的商品上,更新购物车
999
+ // submitTimeSlot({
1000
+ // resourceProductData,
1001
+ // selectedResources,
1002
+ // timeSlots,
1003
+ // }: {
1004
+ // resourceProductData: any;
1005
+ // selectedResources: any[];
1006
+ // timeSlots: TimeSliceItem;
1007
+ // }) {
1008
+ // const newResources = cloneDeep(selectedResources);
1009
+ // newResources.forEach((n) => {
1010
+ // n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1011
+ // n.endTime = dayjs(n.startTime)
1012
+ // .add(
1013
+ // resourceProductData.product.duration.value,
1014
+ // resourceProductData.product.duration.type
1015
+ // )
1016
+ // .format("YYYY-MM-DD HH:mm");
1017
+ // delete n.times;
1018
+ // });
1019
+ // this.store.cart.updateItem({
1020
+ // _id: resourceProductData._id,
1021
+ // resources: newResources,
1022
+ // });
1023
+ // }
1024
+ }, {
1025
+ key: "submitTimeSlot",
1026
+ value: function submitTimeSlot(timeSlots) {
1027
+ var _this7 = this;
1028
+ var cartItems = this.store.cart.getItems();
1029
+ cartItems.forEach(function (item) {
1030
+ var newResources = cloneDeep(item._origin.resources);
1031
+ newResources.forEach(function (n) {
1032
+ n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1033
+ n.endTime = dayjs(n.startTime).add(item._productOrigin.duration.value, item._productOrigin.duration.type).format("YYYY-MM-DD HH:mm");
1034
+ delete n.times;
1035
+ });
1036
+ _this7.store.cart.updateItem({
1037
+ _id: item._id,
1038
+ resources: newResources
1039
+ });
1040
+ });
1041
+ }
475
1042
  }]);
476
1043
  return BookingByStepImpl;
477
1044
  }(BaseModule);