@pisell/pisellos 3.0.93 → 3.0.95

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 (53) hide show
  1. package/dist/modules/Cart/utils/changePrice.js +16 -9
  2. package/dist/modules/Holder/index.d.ts +48 -0
  3. package/dist/modules/Holder/index.js +640 -0
  4. package/dist/modules/Holder/types.d.ts +123 -0
  5. package/dist/modules/Holder/types.js +1 -0
  6. package/dist/modules/Holder/utils.d.ts +13 -0
  7. package/dist/modules/Holder/utils.js +34 -0
  8. package/dist/modules/Order/index.d.ts +1 -0
  9. package/dist/modules/Order/index.js +18 -1
  10. package/dist/modules/Order/types.d.ts +2 -0
  11. package/dist/modules/Order/utils.d.ts +10 -0
  12. package/dist/modules/Order/utils.js +35 -3
  13. package/dist/modules/Product/index.d.ts +1 -1
  14. package/dist/modules/Product/types.d.ts +7 -0
  15. package/dist/modules/index.d.ts +1 -0
  16. package/dist/modules/index.js +2 -1
  17. package/dist/plugins/window.d.ts +1 -0
  18. package/dist/solution/BookingByStep/index.d.ts +16 -1
  19. package/dist/solution/BookingByStep/index.js +276 -204
  20. package/dist/solution/BookingByStep/types.d.ts +2 -1
  21. package/dist/solution/BookingByStep/types.js +3 -1
  22. package/dist/solution/ScanOrder/types.d.ts +1 -0
  23. package/dist/solution/VenueBooking/index.d.ts +19 -0
  24. package/dist/solution/VenueBooking/index.js +978 -748
  25. package/dist/solution/VenueBooking/types.d.ts +2 -0
  26. package/dist/types/index.d.ts +1 -0
  27. package/lib/modules/Cart/utils/changePrice.js +13 -9
  28. package/lib/modules/Holder/index.d.ts +48 -0
  29. package/lib/modules/Holder/index.js +402 -0
  30. package/lib/modules/Holder/types.d.ts +123 -0
  31. package/lib/modules/Holder/types.js +17 -0
  32. package/lib/modules/Holder/utils.d.ts +13 -0
  33. package/lib/modules/Holder/utils.js +71 -0
  34. package/lib/modules/Order/index.d.ts +1 -0
  35. package/lib/modules/Order/index.js +14 -0
  36. package/lib/modules/Order/types.d.ts +2 -0
  37. package/lib/modules/Order/utils.d.ts +10 -0
  38. package/lib/modules/Order/utils.js +36 -5
  39. package/lib/modules/Product/index.d.ts +1 -1
  40. package/lib/modules/Product/types.d.ts +7 -0
  41. package/lib/modules/index.d.ts +1 -0
  42. package/lib/modules/index.js +3 -1
  43. package/lib/plugins/window.d.ts +1 -0
  44. package/lib/solution/BookingByStep/index.d.ts +16 -1
  45. package/lib/solution/BookingByStep/index.js +39 -0
  46. package/lib/solution/BookingByStep/types.d.ts +2 -1
  47. package/lib/solution/BookingByStep/types.js +5 -0
  48. package/lib/solution/ScanOrder/types.d.ts +1 -0
  49. package/lib/solution/VenueBooking/index.d.ts +19 -0
  50. package/lib/solution/VenueBooking/index.js +134 -16
  51. package/lib/solution/VenueBooking/types.d.ts +2 -0
  52. package/lib/types/index.d.ts +1 -0
  53. package/package.json +1 -1
@@ -54,6 +54,8 @@ var import_utils3 = require("../../modules/Order/utils");
54
54
  var import_Order = require("../../modules/Order");
55
55
  var import_types4 = require("../RegisterAndLogin/types");
56
56
  var import_decimal = __toESM(require("decimal.js"));
57
+ var import_Holder = require("../../modules/Holder");
58
+ var import_utils4 = require("../../modules/Holder/utils");
57
59
  __reExport(VenueBooking_exports, require("./types"), module.exports);
58
60
  var OPEN_DATA_SECTION_CODES = [
59
61
  "basic",
@@ -253,6 +255,42 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
253
255
  }
254
256
  return null;
255
257
  }
258
+ resolveHolderCustomerId() {
259
+ var _a, _b;
260
+ const customer = JSON.parse(((_b = (_a = this.window) == null ? void 0 : _a.getLocalStorage) == null ? void 0 : _b.call(_a, "customer")) || "{}");
261
+ if (customer == null ? void 0 : customer.id)
262
+ return Number(customer.id);
263
+ return void 0;
264
+ }
265
+ /**
266
+ * 按商品 holder_config 预加载表单数据到 holderMap。
267
+ * appointment_booking 在加购时触发;venueBooking 在商品加载后预加载,避免 getHolderFormMap 为空。
268
+ */
269
+ async preloadHolderForms(products) {
270
+ var _a, _b, _c, _d;
271
+ if (!this.store.holder || !products.length)
272
+ return;
273
+ const seenFormIds = /* @__PURE__ */ new Set();
274
+ for (const item of products) {
275
+ const holderConfig = (0, import_utils4.getProductHolderConfig)((_a = item == null ? void 0 : item._origin) == null ? void 0 : _a.product);
276
+ if (!holderConfig)
277
+ continue;
278
+ const formId = (0, import_utils4.getFormIdFromHolderConfig)(holderConfig);
279
+ if (seenFormIds.has(formId))
280
+ continue;
281
+ seenFormIds.add(formId);
282
+ try {
283
+ await this.store.holder.ensureFormByProduct({
284
+ product: ((_b = item == null ? void 0 : item._origin) == null ? void 0 : _b.product) || {},
285
+ customer_id: this.resolveHolderCustomerId(),
286
+ shop_id: (_d = (_c = item == null ? void 0 : item._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.shop_id,
287
+ useCache: true
288
+ });
289
+ } catch (error) {
290
+ console.error("[VenueBooking] 预加载 holder 表单失败", { formId, error });
291
+ }
292
+ }
293
+ }
256
294
  clearLoginEffectListeners() {
257
295
  for (const dispose of this.loginEffectDisposers) {
258
296
  dispose();
@@ -299,6 +337,12 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
299
337
  this.customerLoginRefreshIdInFlight = params.customerId;
300
338
  const refreshTask = (async () => {
301
339
  var _a;
340
+ if (this.store.holder) {
341
+ await this.store.holder.refreshAllFormRecords({
342
+ customer_id: params.customerId,
343
+ useCache: false
344
+ });
345
+ }
302
346
  if (this.store.quotation) {
303
347
  await this.store.quotation.loadQuotations({
304
348
  channel: (_a = this.otherParams) == null ? void 0 : _a.channel
@@ -326,7 +370,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
326
370
  }
327
371
  }
328
372
  async initialize(core, options = {}) {
329
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
373
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
330
374
  this.logMethodStart("initialize");
331
375
  this.core = core;
332
376
  this.initializeOptions = options || {};
@@ -451,20 +495,42 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
451
495
  cacheId: (_g = this.otherParams) == null ? void 0 : _g.cacheId
452
496
  }
453
497
  });
498
+ let holderCacheState;
499
+ if ((_h = this.otherParams) == null ? void 0 : _h.cacheId) {
500
+ const sessionData = this.window.sessionStorage.getItem(this.name);
501
+ if (sessionData) {
502
+ try {
503
+ const data = JSON.parse(sessionData);
504
+ holderCacheState = (_i = data[this.otherParams.cacheId]) == null ? void 0 : _i[`${this.name}_holder`];
505
+ } catch {
506
+ }
507
+ }
508
+ }
509
+ const holderModule = new import_Holder.HolderModule(`${this.name}_holder`);
510
+ this.store.holder = holderModule;
511
+ this.core.registerModule(holderModule, {
512
+ initialState: holderCacheState,
513
+ otherParams: {
514
+ ...this.otherParams,
515
+ fatherModule: this.name,
516
+ openCache: !!((_j = this.otherParams) == null ? void 0 : _j.cacheId),
517
+ cacheId: (_k = this.otherParams) == null ? void 0 : _k.cacheId
518
+ }
519
+ });
454
520
  if (this.store.scanOrderLogger) {
455
521
  this.store.scanOrderLogger.setContext(this.getLoggerContext());
456
522
  }
457
523
  this.registerCustomerLoginListeners();
458
524
  console.log("[VenueBooking] 初始化开始");
459
525
  try {
460
- await ((_h = this.store.order) == null ? void 0 : _h.recalculateSummary({ createIfMissing: false }));
461
- (_i = this.store.order) == null ? void 0 : _i.persistTempOrder();
526
+ await ((_l = this.store.order) == null ? void 0 : _l.recalculateSummary({ createIfMissing: false }));
527
+ (_m = this.store.order) == null ? void 0 : _m.persistTempOrder();
462
528
  await this.loadRuntimeConfigs();
463
529
  if (this.store.schedule) {
464
530
  await this.store.schedule.loadAllSchedule();
465
531
  this.injectScheduleResolverToQuotation();
466
- (_k = this.store.quotation) == null ? void 0 : _k.loadQuotations({
467
- channel: (_j = this.otherParams) == null ? void 0 : _j.channel
532
+ (_o = this.store.quotation) == null ? void 0 : _o.loadQuotations({
533
+ channel: (_n = this.otherParams) == null ? void 0 : _n.channel
468
534
  });
469
535
  }
470
536
  await this.refreshItemRuleQuantityLimits();
@@ -551,7 +617,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
551
617
  return this.loadAllProductsInFlight;
552
618
  }
553
619
  async _doLoadAllProducts() {
554
- var _a, _b, _c;
620
+ var _a, _b, _c, _d, _e;
555
621
  this.logMethodStart("loadAllProducts");
556
622
  try {
557
623
  if (!this.store.venueProducts)
@@ -580,6 +646,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
580
646
  }
581
647
  this.store.addonProducts.addProduct(addonList);
582
648
  this.resourceProductMap = (0, import_resource.buildResourceProductMap)(venueList);
649
+ if (this.store.order) {
650
+ const products = ((_e = (_d = this.store.order) == null ? void 0 : _d.getOrderProducts) == null ? void 0 : _e.call(_d)) || [];
651
+ await this.preloadHolderForms(products);
652
+ }
583
653
  this.productsLoaded = true;
584
654
  this.logMethodSuccess("loadAllProducts", {
585
655
  total: list.length,
@@ -972,6 +1042,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
972
1042
  * 同一场地下不同商品互不干扰,各自单独 reconcile。
973
1043
  */
974
1044
  async reconcileOrderForResourceProduct(resourceId, productId, slots) {
1045
+ var _a, _b;
975
1046
  const mappings = this.resourceProductMap.get(resourceId);
976
1047
  if (!mappings || !mappings.length || !this.store.order)
977
1048
  return;
@@ -985,10 +1056,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
985
1056
  );
986
1057
  tempOrder.bookings = (tempOrder.bookings || []).filter(
987
1058
  (b) => {
988
- var _a, _b, _c, _d;
989
- if (!((_a = b.metadata) == null ? void 0 : _a.venue_booking))
1059
+ var _a2, _b2, _c, _d;
1060
+ if (!((_a2 = b.metadata) == null ? void 0 : _a2.venue_booking))
990
1061
  return true;
991
- if (String((_b = b.metadata) == null ? void 0 : _b.resource_id) !== String(resourceId))
1062
+ if (String((_b2 = b.metadata) == null ? void 0 : _b2.resource_id) !== String(resourceId))
992
1063
  return true;
993
1064
  const bookingProductId = ((_c = b.metadata) == null ? void 0 : _c.product_id) ?? ((_d = b == null ? void 0 : b.product) == null ? void 0 : _d.product_id);
994
1065
  if (bookingProductId == null)
@@ -1080,7 +1151,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1080
1151
  product_option_item: [],
1081
1152
  discount_list: [],
1082
1153
  custom_deposit_data: customDepositData,
1083
- metadata: {}
1154
+ metadata: {},
1155
+ holder_config: venueProduct == null ? void 0 : venueProduct.holder_config,
1156
+ bookingUuid,
1157
+ shop_id: (venueProduct == null ? void 0 : venueProduct.shop_id) || 0
1084
1158
  },
1085
1159
  sub_type: "minutes",
1086
1160
  duration,
@@ -1111,6 +1185,8 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1111
1185
  });
1112
1186
  tempOrder.bookings.push(booking);
1113
1187
  }
1188
+ const products = ((_b = (_a = this.store.order) == null ? void 0 : _a.getOrderProducts) == null ? void 0 : _b.call(_a)) || [];
1189
+ await this.preloadHolderForms(products);
1114
1190
  this.store.order.applyDiscount();
1115
1191
  await this.store.order.recalculateSummary({ createIfMissing: true });
1116
1192
  this.store.order.persistTempOrder();
@@ -1915,15 +1991,57 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1915
1991
  }
1916
1992
  }
1917
1993
  setBookingHolder(bookingUid, holder) {
1918
- var _a;
1919
- const order = this.getTempOrder();
1920
- const booking = (_a = order == null ? void 0 : order.bookings) == null ? void 0 : _a.find((b) => {
1921
- var _a2;
1922
- return ((_a2 = b.metadata) == null ? void 0 : _a2.unique_identification_number) === bookingUid;
1923
- });
1994
+ var _a, _b, _c, _d;
1995
+ if (!this.store.order)
1996
+ return;
1997
+ const tempOrder = this.store.order.ensureTempOrder();
1998
+ const booking = (_a = tempOrder.bookings) == null ? void 0 : _a.find(
1999
+ (b) => {
2000
+ var _a2;
2001
+ return ((_a2 = b.metadata) == null ? void 0 : _a2.unique_identification_number) === bookingUid;
2002
+ }
2003
+ );
1924
2004
  if (booking) {
1925
2005
  booking.holder = holder;
1926
2006
  }
2007
+ for (const product of tempOrder.products) {
2008
+ const productBookingUid = ((_b = product.metadata) == null ? void 0 : _b.booking_uid) ?? ((_d = (_c = product._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.bookingUuid);
2009
+ if (String(productBookingUid) !== String(bookingUid))
2010
+ continue;
2011
+ const origin = product._origin && typeof product._origin === "object" ? product._origin : {};
2012
+ origin.holder = holder;
2013
+ product._origin = origin;
2014
+ }
2015
+ this.store.order.notifyTempOrderChanged();
2016
+ }
2017
+ /**
2018
+ * 获取 holder 表单 map
2019
+ */
2020
+ getHolderFormMap() {
2021
+ if (!this.store.holder)
2022
+ throw new Error("[VenueBooking] holder 模块未初始化");
2023
+ return this.store.holder.getHolderFormMap();
2024
+ }
2025
+ /**
2026
+ * UI 层触发:按当前 holderMap 批量刷新所有表单的 records
2027
+ */
2028
+ async refreshAllHolderFormRecords(params) {
2029
+ if (!this.store.holder)
2030
+ throw new Error("[VenueBooking] holder 模块未初始化");
2031
+ const customer_id = (params == null ? void 0 : params.customer_id) ?? this.resolveHolderCustomerId();
2032
+ return this.store.holder.refreshAllFormRecords({
2033
+ ...params,
2034
+ customer_id,
2035
+ useCache: (params == null ? void 0 : params.useCache) ?? false
2036
+ });
2037
+ }
2038
+ /**
2039
+ * 添加表单记录
2040
+ */
2041
+ appendFormRecord(params) {
2042
+ if (!this.store.holder)
2043
+ throw new Error("[VenueBooking] holder 模块未初始化");
2044
+ return this.store.holder.appendFormRecord(params);
1927
2045
  }
1928
2046
  // ─── OpenData 可用性 ───
1929
2047
  async checkOpenDataAvailability() {
@@ -1,5 +1,6 @@
1
1
  import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, DateModule, ScheduleModule, QuotationModule, OpenDataModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
+ import { HolderModule } from '../../modules/Holder';
3
4
  export type { ScanOrderOrderProductIdentity, ScanOrderOrderProduct, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder, ScanOrderSubmitPayload, } from '../ScanOrder/types';
4
5
  export declare enum VenueBookingHooks {
5
6
  onInited = "venueBooking:onInited",
@@ -145,6 +146,7 @@ export interface VenueBookingState {
145
146
  passed: boolean | null;
146
147
  failures: QuantityCheckResult[];
147
148
  };
149
+ holder?: HolderModule;
148
150
  }
149
151
  export interface VenueBookingLoggerRuntimeConfig {
150
152
  provider?: ScanOrderLoggerProviderType;
@@ -6,6 +6,7 @@ export interface Plugin {
6
6
  version: string;
7
7
  initialize: () => Promise<void> | void;
8
8
  destroy?: () => Promise<void> | void;
9
+ getLocalStorage?: (key: string) => string | null;
9
10
  }
10
11
  export interface PluginOptions {
11
12
  dependencies?: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.93",
4
+ "version": "3.0.95",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",