@pisell/pisellos 2.2.181 → 2.2.183

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 (173) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.js +4 -3
  35. package/dist/modules/Discount/types.d.ts +1 -0
  36. package/dist/modules/Order/index.d.ts +100 -9
  37. package/dist/modules/Order/index.js +1447 -499
  38. package/dist/modules/Order/types.d.ts +201 -18
  39. package/dist/modules/Order/types.js +31 -0
  40. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  42. package/dist/modules/Order/utils.d.ts +83 -1
  43. package/dist/modules/Order/utils.js +405 -61
  44. package/dist/modules/Product/index.d.ts +1 -1
  45. package/dist/modules/Quotation/index.d.ts +0 -1
  46. package/dist/modules/Quotation/index.js +23 -21
  47. package/dist/modules/Rules/index.d.ts +4 -0
  48. package/dist/modules/Rules/index.js +43 -39
  49. package/dist/modules/Rules/types.d.ts +1 -0
  50. package/dist/modules/SalesSummary/index.js +4 -2
  51. package/dist/modules/SalesSummary/utils.js +21 -7
  52. package/dist/modules/Schedule/index.js +6 -2
  53. package/dist/modules/index.d.ts +1 -0
  54. package/dist/modules/index.js +2 -1
  55. package/dist/server/index.js +87 -29
  56. package/dist/server/modules/order/index.d.ts +23 -0
  57. package/dist/server/modules/order/index.js +123 -46
  58. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  59. package/dist/server/modules/products/index.d.ts +1 -1
  60. package/dist/server/modules/products/index.js +130 -113
  61. package/dist/server/modules/schedule/index.js +13 -6
  62. package/dist/solution/BaseSales/index.d.ts +89 -7
  63. package/dist/solution/BaseSales/index.js +1504 -380
  64. package/dist/solution/BaseSales/types.d.ts +67 -1
  65. package/dist/solution/BaseSales/types.js +3 -1
  66. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  67. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  68. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  69. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  70. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  71. package/dist/solution/BaseSales/utils.js +46 -8
  72. package/dist/solution/BookingByStep/index.d.ts +1 -1
  73. package/dist/solution/BookingTicket/index.d.ts +151 -1
  74. package/dist/solution/BookingTicket/index.js +848 -184
  75. package/dist/solution/BookingTicket/types.d.ts +2 -0
  76. package/dist/solution/BookingTicket/types.js +3 -0
  77. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  78. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  79. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  80. package/dist/solution/ScanOrder/index.d.ts +9 -3
  81. package/dist/solution/ScanOrder/index.js +231 -128
  82. package/dist/solution/ScanOrder/utils.js +46 -8
  83. package/dist/solution/VenueBooking/index.d.ts +5 -2
  84. package/dist/solution/VenueBooking/index.js +103 -55
  85. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  86. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  87. package/lib/modules/BookingContext/index.d.ts +37 -0
  88. package/lib/modules/BookingContext/index.js +297 -0
  89. package/lib/modules/BookingContext/types.d.ts +102 -0
  90. package/lib/modules/BookingContext/types.js +34 -0
  91. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  92. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +271 -0
  93. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  94. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  95. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  96. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  97. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  98. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  99. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  100. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  101. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  102. package/lib/modules/BookingContext/utils/index.js +43 -0
  103. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  104. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  105. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  106. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  107. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  108. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  109. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  110. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  111. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  112. package/lib/modules/BookingContext/utils/resources.js +377 -0
  113. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  114. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  115. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  116. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  117. package/lib/modules/Customer/index.d.ts +6 -0
  118. package/lib/modules/Customer/index.js +26 -11
  119. package/lib/modules/Customer/types.d.ts +2 -0
  120. package/lib/modules/Discount/index.js +5 -1
  121. package/lib/modules/Discount/types.d.ts +1 -0
  122. package/lib/modules/Order/index.d.ts +100 -9
  123. package/lib/modules/Order/index.js +751 -160
  124. package/lib/modules/Order/types.d.ts +201 -18
  125. package/lib/modules/Order/types.js +1 -0
  126. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  128. package/lib/modules/Order/utils.d.ts +83 -1
  129. package/lib/modules/Order/utils.js +340 -22
  130. package/lib/modules/Product/index.d.ts +1 -1
  131. package/lib/modules/Quotation/index.d.ts +0 -1
  132. package/lib/modules/Quotation/index.js +18 -15
  133. package/lib/modules/Rules/index.d.ts +4 -0
  134. package/lib/modules/Rules/index.js +26 -27
  135. package/lib/modules/Rules/types.d.ts +1 -0
  136. package/lib/modules/SalesSummary/index.js +4 -2
  137. package/lib/modules/SalesSummary/utils.js +21 -7
  138. package/lib/modules/Schedule/index.js +3 -1
  139. package/lib/modules/index.d.ts +1 -0
  140. package/lib/modules/index.js +3 -1
  141. package/lib/server/index.js +41 -4
  142. package/lib/server/modules/order/index.d.ts +23 -0
  143. package/lib/server/modules/order/index.js +46 -14
  144. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  145. package/lib/server/modules/products/index.d.ts +1 -1
  146. package/lib/server/modules/products/index.js +30 -20
  147. package/lib/server/modules/schedule/index.js +2 -1
  148. package/lib/solution/BaseSales/index.d.ts +89 -7
  149. package/lib/solution/BaseSales/index.js +743 -23
  150. package/lib/solution/BaseSales/types.d.ts +67 -1
  151. package/lib/solution/BaseSales/types.js +3 -1
  152. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  153. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  154. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  155. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  156. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  157. package/lib/solution/BaseSales/utils.js +46 -6
  158. package/lib/solution/BookingByStep/index.d.ts +1 -1
  159. package/lib/solution/BookingTicket/index.d.ts +151 -1
  160. package/lib/solution/BookingTicket/index.js +389 -9
  161. package/lib/solution/BookingTicket/types.d.ts +2 -0
  162. package/lib/solution/BookingTicket/types.js +6 -0
  163. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  164. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  165. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  166. package/lib/solution/ScanOrder/index.d.ts +9 -3
  167. package/lib/solution/ScanOrder/index.js +147 -66
  168. package/lib/solution/ScanOrder/utils.js +46 -6
  169. package/lib/solution/VenueBooking/index.d.ts +5 -2
  170. package/lib/solution/VenueBooking/index.js +50 -14
  171. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  172. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  173. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import { Module, ModuleOptions, PisellCore } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { BookingContextConfig, BookingContextDateInput, BookingContextModuleAPI, BookingContextResource, BookingContextResourceMap, BookingContextState, InitBookingContextParams, LoadBookingConfigParams, LoadBookingResourcesParams } from './types';
4
+ export * from './types';
5
+ export * from './utils';
6
+ /** 稳定序列化 config 查询参数,用于判断是否与上次 loadBookingConfig 一致。 */
7
+ export declare function buildBookingConfigQueryKey(params?: LoadBookingConfigParams): string;
8
+ /** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
9
+ export declare function buildBookingResourcesQueryKey(params?: LoadBookingResourcesParams): string;
10
+ export declare class BookingContextModule extends BaseModule implements Module, BookingContextModuleAPI {
11
+ protected defaultName: string;
12
+ protected defaultVersion: string;
13
+ private request;
14
+ private store;
15
+ /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
16
+ private lastConfigQueryKey;
17
+ /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
18
+ private lastResourcesQueryKey;
19
+ constructor(name?: string, version?: string);
20
+ initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
21
+ loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
22
+ loadResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
23
+ /**
24
+ * store 内是否已具备与本次 init 入参等价的 config / resources(不再打接口)。
25
+ */
26
+ isBookingContextReady(params?: InitBookingContextParams): boolean;
27
+ initBookingContext(params?: InitBookingContextParams): Promise<BookingContextState>;
28
+ setBookingConfig(config: BookingContextConfig | null): void;
29
+ getBookingConfig(): BookingContextConfig | null;
30
+ setResources(resources: BookingContextResource[] | null | undefined): void;
31
+ getResourcesOrigin(): BookingContextResource[];
32
+ getResourcesOriginMap(): BookingContextResourceMap;
33
+ setDate(date: BookingContextDateInput): void;
34
+ getDate(): string | null;
35
+ getState(): BookingContextState;
36
+ clear(): void;
37
+ }
@@ -0,0 +1,436 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ 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; }
22
+ 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; }
23
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
+ 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); }
26
+ import dayjs from 'dayjs';
27
+ import { BaseModule } from "../BaseModule";
28
+ import { RequestModeENUM } from "../../plugins/request";
29
+ import { BookingContextEvent } from "./types";
30
+ import { formatResourceListAndMap } from "./utils/formatResourceList";
31
+ export * from "./types";
32
+ export * from "./utils";
33
+ var EMPTY_STATE = {
34
+ bookingConfig: null,
35
+ resourcesOrigin: [],
36
+ resourcesOriginMap: {},
37
+ date: null
38
+ };
39
+ var DEFAULT_BOOKING_CONFIG_PARAMS = {
40
+ item_type: 'appointment_booking',
41
+ sub_type: 'ticket'
42
+ };
43
+ var BOARD_CONFIG_CACHE = {
44
+ useCache: true,
45
+ cache: {
46
+ mode: RequestModeENUM.REMOTE_LOCAL,
47
+ type: 'indexDB',
48
+ updateCache: true
49
+ }
50
+ };
51
+ var RESOURCE_LIST_CACHE = {
52
+ useCache: true,
53
+ cache: {
54
+ mode: RequestModeENUM.REMOTE_LOCAL,
55
+ type: 'memory'
56
+ }
57
+ };
58
+
59
+ /**
60
+ * 把多形态 date 入参 normalize 成字符串。
61
+ * - dayjs 实例:调用 format()(无参 ISO)。
62
+ * - Date 实例:toISOString()。
63
+ * - 字符串:原样保留。
64
+ * - null/undefined/空串:→ null。
65
+ */
66
+ function normalizeDate(input) {
67
+ if (input === null || input === undefined) return null;
68
+ if (typeof input === 'string') return input || null;
69
+ if (input instanceof Date) return input.toISOString();
70
+ if (typeof input.format === 'function') {
71
+ try {
72
+ return input.format() || null;
73
+ } catch (_unused) {
74
+ return null;
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+
80
+ /** 资源接口使用的 `YYYY-MM-DD` 日期串。 */
81
+ function toScheduleQueryDate(input) {
82
+ var normalized = normalizeDate(input);
83
+ if (!normalized) return dayjs().format('YYYY-MM-DD');
84
+ var parsed = dayjs(normalized);
85
+ return parsed.isValid() ? parsed.format('YYYY-MM-DD') : dayjs().format('YYYY-MM-DD');
86
+ }
87
+
88
+ /**
89
+ * 由 resources 数组派生出以 id 为 key 的 map,便于 `getResourceByIds` 直接命中。
90
+ */
91
+ function buildResourcesMap(resources) {
92
+ var map = {};
93
+ resources.forEach(function (resource) {
94
+ if (resource && resource.id !== undefined && resource.id !== null) {
95
+ map[String(resource.id)] = resource;
96
+ }
97
+ });
98
+ return map;
99
+ }
100
+
101
+ /** 稳定序列化 config 查询参数,用于判断是否与上次 loadBookingConfig 一致。 */
102
+ export function buildBookingConfigQueryKey() {
103
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
104
+ var merged = _objectSpread(_objectSpread({}, DEFAULT_BOOKING_CONFIG_PARAMS), params);
105
+ var keys = Object.keys(merged).sort();
106
+ var sorted = {};
107
+ keys.forEach(function (k) {
108
+ sorted[k] = merged[k];
109
+ });
110
+ return JSON.stringify(sorted);
111
+ }
112
+
113
+ /** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
114
+ export function buildBookingResourcesQueryKey() {
115
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
116
+ var date = toScheduleQueryDate(params.date);
117
+ var ids = (params.bookingIds || []).filter(function (id) {
118
+ return typeof id === 'number' && Number.isFinite(id);
119
+ }).sort(function (a, b) {
120
+ return a - b;
121
+ });
122
+ return "".concat(date, "|").concat(ids.join(','));
123
+ }
124
+ export var BookingContextModule = /*#__PURE__*/function (_BaseModule) {
125
+ _inherits(BookingContextModule, _BaseModule);
126
+ var _super = _createSuper(BookingContextModule);
127
+ function BookingContextModule(name, version) {
128
+ var _this;
129
+ _classCallCheck(this, BookingContextModule);
130
+ _this = _super.call(this, name, version);
131
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'bookingContext');
132
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
133
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
134
+ _defineProperty(_assertThisInitialized(_this), "store", _objectSpread({}, EMPTY_STATE));
135
+ /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
136
+ _defineProperty(_assertThisInitialized(_this), "lastConfigQueryKey", null);
137
+ /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
138
+ _defineProperty(_assertThisInitialized(_this), "lastResourcesQueryKey", null);
139
+ return _this;
140
+ }
141
+ _createClass(BookingContextModule, [{
142
+ key: "initialize",
143
+ value: function () {
144
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
145
+ var options,
146
+ initialState,
147
+ _args = arguments;
148
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
149
+ while (1) switch (_context.prev = _context.next) {
150
+ case 0:
151
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
152
+ this.core = core;
153
+ this.request = core.getPlugin('request');
154
+ if (this.request) {
155
+ _context.next = 5;
156
+ break;
157
+ }
158
+ throw new Error('BookingContextModule 需要 request 插件支持');
159
+ case 5:
160
+ this.store = {
161
+ bookingConfig: null,
162
+ resourcesOrigin: [],
163
+ resourcesOriginMap: {},
164
+ date: null
165
+ };
166
+ initialState = options.initialState || {};
167
+ if (initialState.bookingConfig) {
168
+ this.store.bookingConfig = initialState.bookingConfig;
169
+ }
170
+ if (Array.isArray(initialState.resourcesOrigin)) {
171
+ this.store.resourcesOrigin = initialState.resourcesOrigin;
172
+ this.store.resourcesOriginMap = buildResourcesMap(initialState.resourcesOrigin);
173
+ }
174
+ if (initialState.date) {
175
+ this.store.date = initialState.date;
176
+ }
177
+ case 10:
178
+ case "end":
179
+ return _context.stop();
180
+ }
181
+ }, _callee, this);
182
+ }));
183
+ function initialize(_x) {
184
+ return _initialize.apply(this, arguments);
185
+ }
186
+ return initialize;
187
+ }()
188
+ }, {
189
+ key: "loadBookingConfig",
190
+ value: function () {
191
+ var _loadBookingConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
192
+ var _res$data;
193
+ var params,
194
+ configKey,
195
+ query,
196
+ res,
197
+ config,
198
+ _args2 = arguments;
199
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
200
+ while (1) switch (_context2.prev = _context2.next) {
201
+ case 0:
202
+ params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
203
+ configKey = buildBookingConfigQueryKey(params);
204
+ if (!(this.store.bookingConfig != null && this.lastConfigQueryKey === configKey)) {
205
+ _context2.next = 4;
206
+ break;
207
+ }
208
+ return _context2.abrupt("return", this.store.bookingConfig);
209
+ case 4:
210
+ query = _objectSpread(_objectSpread({}, DEFAULT_BOOKING_CONFIG_PARAMS), params);
211
+ _context2.next = 7;
212
+ return this.request.get('/core/board/management/config', query, BOARD_CONFIG_CACHE);
213
+ case 7:
214
+ res = _context2.sent;
215
+ config = (_res$data = res === null || res === void 0 ? void 0 : res.data) !== null && _res$data !== void 0 ? _res$data : null;
216
+ console.log('config123', config);
217
+ this.setBookingConfig(config);
218
+ this.lastConfigQueryKey = buildBookingConfigQueryKey(params);
219
+ return _context2.abrupt("return", config);
220
+ case 13:
221
+ case "end":
222
+ return _context2.stop();
223
+ }
224
+ }, _callee2, this);
225
+ }));
226
+ function loadBookingConfig() {
227
+ return _loadBookingConfig.apply(this, arguments);
228
+ }
229
+ return loadBookingConfig;
230
+ }()
231
+ }, {
232
+ key: "loadResources",
233
+ value: function () {
234
+ var _loadResources = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
235
+ var _params$date;
236
+ var params,
237
+ date,
238
+ resourcesKey,
239
+ res,
240
+ _formatResourceListAn,
241
+ list,
242
+ _args3 = arguments;
243
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
244
+ while (1) switch (_context3.prev = _context3.next) {
245
+ case 0:
246
+ params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
247
+ date = toScheduleQueryDate((_params$date = params.date) !== null && _params$date !== void 0 ? _params$date : this.store.date);
248
+ resourcesKey = buildBookingResourcesQueryKey({
249
+ date: date,
250
+ bookingIds: params.bookingIds
251
+ });
252
+ if (!(this.lastResourcesQueryKey === resourcesKey)) {
253
+ _context3.next = 5;
254
+ break;
255
+ }
256
+ return _context3.abrupt("return", this.getResourcesOrigin());
257
+ case 5:
258
+ _context3.next = 7;
259
+ return this.request.get('/schedule/resource/list', {
260
+ date: date
261
+ }, RESOURCE_LIST_CACHE);
262
+ case 7:
263
+ res = _context3.sent;
264
+ _formatResourceListAn = formatResourceListAndMap(res === null || res === void 0 ? void 0 : res.data, params.bookingIds || []), list = _formatResourceListAn.list;
265
+ this.setResources(list);
266
+ this.lastResourcesQueryKey = buildBookingResourcesQueryKey({
267
+ date: date,
268
+ bookingIds: params.bookingIds
269
+ });
270
+ return _context3.abrupt("return", list);
271
+ case 12:
272
+ case "end":
273
+ return _context3.stop();
274
+ }
275
+ }, _callee3, this);
276
+ }));
277
+ function loadResources() {
278
+ return _loadResources.apply(this, arguments);
279
+ }
280
+ return loadResources;
281
+ }()
282
+ /**
283
+ * store 内是否已具备与本次 init 入参等价的 config / resources(不再打接口)。
284
+ */
285
+ }, {
286
+ key: "isBookingContextReady",
287
+ value: function isBookingContextReady() {
288
+ var _ref, _params$date2;
289
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
290
+ var configKey = buildBookingConfigQueryKey(params.bookingConfigParams);
291
+ var dateInput = (_ref = (_params$date2 = params.date) !== null && _params$date2 !== void 0 ? _params$date2 : this.store.date) !== null && _ref !== void 0 ? _ref : dayjs();
292
+ var queryDate = toScheduleQueryDate(dateInput);
293
+ var resourcesKey = buildBookingResourcesQueryKey({
294
+ date: queryDate,
295
+ bookingIds: params.bookingIds
296
+ });
297
+ var configReady = this.store.bookingConfig != null && this.lastConfigQueryKey === configKey;
298
+ var resourcesReady = params.loadResources === false || this.lastResourcesQueryKey === resourcesKey;
299
+ return configReady && resourcesReady;
300
+ }
301
+ }, {
302
+ key: "initBookingContext",
303
+ value: function () {
304
+ var _initBookingContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
305
+ var _ref2, _params$date3;
306
+ var params,
307
+ dateInput,
308
+ queryDate,
309
+ configKey,
310
+ resourcesKey,
311
+ needConfig,
312
+ needResources,
313
+ _args4 = arguments;
314
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
315
+ while (1) switch (_context4.prev = _context4.next) {
316
+ case 0:
317
+ params = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
318
+ dateInput = (_ref2 = (_params$date3 = params.date) !== null && _params$date3 !== void 0 ? _params$date3 : this.store.date) !== null && _ref2 !== void 0 ? _ref2 : dayjs();
319
+ queryDate = toScheduleQueryDate(dateInput);
320
+ this.setDate(dateInput);
321
+ if (!(!params.forceRefresh && this.isBookingContextReady(params))) {
322
+ _context4.next = 6;
323
+ break;
324
+ }
325
+ return _context4.abrupt("return", this.getState());
326
+ case 6:
327
+ configKey = buildBookingConfigQueryKey(params.bookingConfigParams);
328
+ resourcesKey = buildBookingResourcesQueryKey({
329
+ date: queryDate,
330
+ bookingIds: params.bookingIds
331
+ });
332
+ needConfig = params.forceRefresh || this.store.bookingConfig == null || this.lastConfigQueryKey !== configKey;
333
+ needResources = params.loadResources !== false && (params.forceRefresh || this.lastResourcesQueryKey !== resourcesKey);
334
+ if (!needConfig) {
335
+ _context4.next = 13;
336
+ break;
337
+ }
338
+ _context4.next = 13;
339
+ return this.loadBookingConfig(params.bookingConfigParams);
340
+ case 13:
341
+ if (!needResources) {
342
+ _context4.next = 16;
343
+ break;
344
+ }
345
+ _context4.next = 16;
346
+ return this.loadResources({
347
+ date: queryDate,
348
+ bookingIds: params.bookingIds
349
+ });
350
+ case 16:
351
+ return _context4.abrupt("return", this.getState());
352
+ case 17:
353
+ case "end":
354
+ return _context4.stop();
355
+ }
356
+ }, _callee4, this);
357
+ }));
358
+ function initBookingContext() {
359
+ return _initBookingContext.apply(this, arguments);
360
+ }
361
+ return initBookingContext;
362
+ }()
363
+ }, {
364
+ key: "setBookingConfig",
365
+ value: function setBookingConfig(config) {
366
+ this.store.bookingConfig = config || null;
367
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnBookingConfigChange), this.store.bookingConfig);
368
+ }
369
+ }, {
370
+ key: "getBookingConfig",
371
+ value: function getBookingConfig() {
372
+ return this.store.bookingConfig;
373
+ }
374
+ }, {
375
+ key: "setResources",
376
+ value: function setResources(resources) {
377
+ var list = Array.isArray(resources) ? resources : [];
378
+ this.store.resourcesOrigin = list;
379
+ this.store.resourcesOriginMap = buildResourcesMap(list);
380
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnResourcesChange), {
381
+ resourcesOrigin: this.store.resourcesOrigin,
382
+ resourcesOriginMap: this.store.resourcesOriginMap
383
+ });
384
+ }
385
+ }, {
386
+ key: "getResourcesOrigin",
387
+ value: function getResourcesOrigin() {
388
+ return _toConsumableArray(this.store.resourcesOrigin);
389
+ }
390
+ }, {
391
+ key: "getResourcesOriginMap",
392
+ value: function getResourcesOriginMap() {
393
+ return this.store.resourcesOriginMap;
394
+ }
395
+ }, {
396
+ key: "setDate",
397
+ value: function setDate(date) {
398
+ this.store.date = normalizeDate(date);
399
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnDateChange), this.store.date);
400
+ }
401
+ }, {
402
+ key: "getDate",
403
+ value: function getDate() {
404
+ return this.store.date;
405
+ }
406
+ }, {
407
+ key: "getState",
408
+ value: function getState() {
409
+ return {
410
+ bookingConfig: this.store.bookingConfig,
411
+ resourcesOrigin: _toConsumableArray(this.store.resourcesOrigin),
412
+ resourcesOriginMap: this.store.resourcesOriginMap,
413
+ date: this.store.date
414
+ };
415
+ }
416
+ }, {
417
+ key: "clear",
418
+ value: function clear() {
419
+ this.lastConfigQueryKey = null;
420
+ this.lastResourcesQueryKey = null;
421
+ this.store = {
422
+ bookingConfig: null,
423
+ resourcesOrigin: [],
424
+ resourcesOriginMap: {},
425
+ date: null
426
+ };
427
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnBookingConfigChange), null);
428
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnResourcesChange), {
429
+ resourcesOrigin: [],
430
+ resourcesOriginMap: {}
431
+ });
432
+ this.core.effects.emit("".concat(this.name, ":").concat(BookingContextEvent.OnDateChange), null);
433
+ }
434
+ }]);
435
+ return BookingContextModule;
436
+ }(BaseModule);
@@ -0,0 +1,102 @@
1
+ /**
2
+ * BookingContext 子模块:承载「预约 UI 上下文」三件套。
3
+ *
4
+ * - bookingConfig:来自 `/core/board/management/config` 的整套预约配置(service_time / resource_tab /
5
+ * appointment_subject / subject_require / stock_setting / basic / capacity 等)。
6
+ * - resourcesOrigin / resourcesOriginMap:来自 `/schedule/resource/list` 的资源全集,含 times / event_list /
7
+ * combined_resource 等运行态信息,是 getResourceByIds / getResourceTimeIsUsable 的输入。
8
+ * - date:当前选择的日期(dayjs 或 ISO 字符串,迁移后内部统一存原始 ISO 字符串,UI 可自行解析)。
9
+ *
10
+ * 设计原则(与 BookingTicket 现状对齐):
11
+ * - 默认由 `loadBookingConfig` / `loadResources` 拉取并写入 store;也支持消费方 `set*` 直接灌入(复用 ticketBooking 已拉到的数据)。
12
+ * - 所有读 API 返回浅克隆(数组)或原引用(map / config),避免 UI 写穿。
13
+ */
14
+ /** `loadBookingConfig` 入参,与 ticketBooking `getBookingConfig` 一致。 */
15
+ export interface LoadBookingConfigParams {
16
+ item_type?: string;
17
+ sub_type?: string;
18
+ source_type?: string;
19
+ [key: string]: any;
20
+ }
21
+ /** `loadResources` 入参,与 info2 `getResourceList` 一致。 */
22
+ export interface LoadBookingResourcesParams {
23
+ /** 查询日期,`YYYY-MM-DD`;缺省用 store 内已 set 的 date,再缺省为当天。 */
24
+ date?: string;
25
+ /** 编辑态排除容量占用用的 booking id 列表。 */
26
+ bookingIds?: number[];
27
+ }
28
+ /** `initBookingContext` 入参(BookingTicket 聚合入口)。 */
29
+ export interface InitBookingContextParams {
30
+ bookingConfigParams?: LoadBookingConfigParams;
31
+ date?: BookingContextDateInput;
32
+ /** 是否拉资源列表,默认 true。 */
33
+ loadResources?: boolean;
34
+ bookingIds?: number[];
35
+ /** 为 true 时忽略内存命中,强制重新请求(默认 false)。 */
36
+ forceRefresh?: boolean;
37
+ }
38
+ /**
39
+ * 资源全集 map:key 为资源 id(数字),value 为资源原始对象,含 times / event_list 等运行态。
40
+ * 这里只声明 Record 形态;具体字段保留 `any`,与 ticketBooking 现网传入的数据形状兼容。
41
+ */
42
+ export type BookingContextResource = Record<string, any>;
43
+ export type BookingContextResourceMap = Record<string, BookingContextResource>;
44
+ /**
45
+ * 形参 booking_config(结构来自 `/core/board/management/config` 接口)。
46
+ * OS 不强制 schema,保留 `Record<string, any>` 兼容现网;常用路径文档化在 SDK docs。
47
+ */
48
+ export type BookingContextConfig = Record<string, any>;
49
+ /**
50
+ * 日期入参:接受 dayjs 实例、ISO 字符串、Date 实例;内部统一 normalize 为 ISO 字符串保存。
51
+ */
52
+ export type BookingContextDateInput = string | Date | {
53
+ format?: (fmt?: string) => string;
54
+ } | null | undefined;
55
+ /**
56
+ * 内部 store 形态。`resourcesOriginMap` 由 `setResources` 派生,不允许外部直接 set。
57
+ */
58
+ export interface BookingContextState {
59
+ bookingConfig: BookingContextConfig | null;
60
+ resourcesOrigin: BookingContextResource[];
61
+ resourcesOriginMap: BookingContextResourceMap;
62
+ /**
63
+ * 当前选择的日期,统一 ISO 字符串('YYYY-MM-DD HH:mm:ss' 或 'YYYY-MM-DD')。
64
+ * UI 取出后可自行 dayjs 解析;OS 内的计算 helper 都接受 string,不做 dayjs 依赖。
65
+ */
66
+ date: string | null;
67
+ }
68
+ /**
69
+ * BookingContextModule 对外 API(给 BookingTicket / SDK Provider 透传消费)。
70
+ */
71
+ export interface BookingContextModuleAPI {
72
+ setBookingConfig(config: BookingContextConfig | null): void;
73
+ getBookingConfig(): BookingContextConfig | null;
74
+ setResources(resources: BookingContextResource[] | null | undefined): void;
75
+ getResourcesOrigin(): BookingContextResource[];
76
+ getResourcesOriginMap(): BookingContextResourceMap;
77
+ setDate(date: BookingContextDateInput): void;
78
+ getDate(): string | null;
79
+ /** 当前 store 的浅克隆,调试 / 测试用。 */
80
+ getState(): BookingContextState;
81
+ /** 一键清空,destroy / 切租户场景用。 */
82
+ clear(): void;
83
+ /** 拉取 board config 并写入 store(`/core/board/management/config`)。 */
84
+ loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
85
+ /** 拉取资源全集并写入 store(`/schedule/resource/list`)。 */
86
+ loadResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
87
+ /**
88
+ * 依次 setDate → loadBookingConfig → loadResources。
89
+ * SalesSdkProvider 挂载时默认调用 BookingTicket.initBookingContext。
90
+ */
91
+ initBookingContext(params?: InitBookingContextParams): Promise<BookingContextState>;
92
+ /** store 是否已具备与入参等价的 config / resources(无需再请求)。 */
93
+ isBookingContextReady(params?: InitBookingContextParams): boolean;
94
+ }
95
+ /**
96
+ * BookingContextModule 事件名常量(采用 `${this.name}:` 前缀,与现有模块一致)。
97
+ */
98
+ export declare enum BookingContextEvent {
99
+ OnBookingConfigChange = "onBookingConfigChange",
100
+ OnResourcesChange = "onResourcesChange",
101
+ OnDateChange = "onDateChange"
102
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * BookingContext 子模块:承载「预约 UI 上下文」三件套。
3
+ *
4
+ * - bookingConfig:来自 `/core/board/management/config` 的整套预约配置(service_time / resource_tab /
5
+ * appointment_subject / subject_require / stock_setting / basic / capacity 等)。
6
+ * - resourcesOrigin / resourcesOriginMap:来自 `/schedule/resource/list` 的资源全集,含 times / event_list /
7
+ * combined_resource 等运行态信息,是 getResourceByIds / getResourceTimeIsUsable 的输入。
8
+ * - date:当前选择的日期(dayjs 或 ISO 字符串,迁移后内部统一存原始 ISO 字符串,UI 可自行解析)。
9
+ *
10
+ * 设计原则(与 BookingTicket 现状对齐):
11
+ * - 默认由 `loadBookingConfig` / `loadResources` 拉取并写入 store;也支持消费方 `set*` 直接灌入(复用 ticketBooking 已拉到的数据)。
12
+ * - 所有读 API 返回浅克隆(数组)或原引用(map / config),避免 UI 写穿。
13
+ */
14
+
15
+ /** `loadBookingConfig` 入参,与 ticketBooking `getBookingConfig` 一致。 */
16
+
17
+ /** `loadResources` 入参,与 info2 `getResourceList` 一致。 */
18
+
19
+ /** `initBookingContext` 入参(BookingTicket 聚合入口)。 */
20
+
21
+ /**
22
+ * 资源全集 map:key 为资源 id(数字),value 为资源原始对象,含 times / event_list 等运行态。
23
+ * 这里只声明 Record 形态;具体字段保留 `any`,与 ticketBooking 现网传入的数据形状兼容。
24
+ */
25
+
26
+ /**
27
+ * 形参 booking_config(结构来自 `/core/board/management/config` 接口)。
28
+ * OS 不强制 schema,保留 `Record<string, any>` 兼容现网;常用路径文档化在 SDK docs。
29
+ */
30
+
31
+ /**
32
+ * 日期入参:接受 dayjs 实例、ISO 字符串、Date 实例;内部统一 normalize 为 ISO 字符串保存。
33
+ */
34
+
35
+ /**
36
+ * 内部 store 形态。`resourcesOriginMap` 由 `setResources` 派生,不允许外部直接 set。
37
+ */
38
+
39
+ /**
40
+ * BookingContextModule 对外 API(给 BookingTicket / SDK Provider 透传消费)。
41
+ */
42
+
43
+ /**
44
+ * BookingContextModule 事件名常量(采用 `${this.name}:` 前缀,与现有模块一致)。
45
+ */
46
+ export var BookingContextEvent = /*#__PURE__*/function (BookingContextEvent) {
47
+ BookingContextEvent["OnBookingConfigChange"] = "onBookingConfigChange";
48
+ BookingContextEvent["OnResourcesChange"] = "onResourcesChange";
49
+ BookingContextEvent["OnDateChange"] = "onDateChange";
50
+ return BookingContextEvent;
51
+ }({});
@@ -0,0 +1,16 @@
1
+ import type { OrderProduct } from '../../Order/types';
2
+ export interface BuildCacheItemFromOrderLineInput {
3
+ /** tempOrder.products 中的一行 */
4
+ product: OrderProduct;
5
+ /** 与该行 product_uid 关联的 tempOrder.bookings 项 */
6
+ booking: Record<string, any>;
7
+ /** 商品 catalog / 详情,用于 capacity、duration、product_resource 等模板字段 */
8
+ sourceProduct?: Record<string, any> | null;
9
+ }
10
+ /**
11
+ * 从已加车的 order line + booking 反查 editService 所需的 cacheItem。
12
+ *
13
+ * 与 `buildCacheItemFromCartDetail` / `buildCacheItemFromDetail` 正向拼装互逆(在 getProductExtend 之前调用)。
14
+ * 调用方须传入与该行关联的 booking(通常 bookings[].product_uid === product.metadata.unique_identification_number)。
15
+ */
16
+ export declare function buildCacheItemFromOrderLine(input: BuildCacheItemFromOrderLineInput): Record<string, any>;