@pisell/pisellos 0.0.504 → 0.0.505

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.
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 4 | 3 | 2 | 5 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -1,6 +1,6 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderTableConfigApiData } from './types';
3
+ import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity } from './types';
4
4
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
5
5
  import type { StrategyConfig } from '../../model/strategy/type';
6
6
  export * from './types';
@@ -43,7 +43,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
43
43
  refresh(): Promise<void>;
44
44
  getStatus(): import("./types").ScanOrderStatus;
45
45
  getEntryContext(): import("./types").ScanOrderEntryContext | null;
46
- getConfig(): ScanOrderTableConfigApiData;
46
+ getConfig(): Record<string, any>;
47
47
  getItemRuleQuantityLimits(): QuantityLimitResult[];
48
48
  getCartValidationPassed(): boolean | null;
49
49
  getCartValidation(): {
@@ -85,7 +85,8 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
85
85
  private refreshCartValidationPassed;
86
86
  setItemRuleRuntimeConfig(config?: ScanOrderItemRuleRuntimeConfig): Promise<void>;
87
87
  private normalizeResourceState;
88
- private fetchTableConfigByResourceId;
88
+ private resolveResourceSelectType;
89
+ private fetchResourceOccupyDetailByResourceId;
89
90
  checkResourceAvailable(resourceId: string, hasOrderId: boolean): Promise<ScanOrderAvailabilityInfo>;
90
91
  getAdditionalOrderInfo(): Promise<{
91
92
  orderId: string;
@@ -99,6 +100,14 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
99
100
  setOtherParams(params: Record<string, any>, { cover }?: {
100
101
  cover?: boolean;
101
102
  }): Promise<void>;
103
+ private static readonly UI_STATE_KEY_PREFIX;
104
+ private getUIStateBucketKey;
105
+ private readUIStateBucket;
106
+ private writeUIStateBucket;
107
+ setUIState(key: string, value: any): void;
108
+ getUIState<T = any>(key: string): T | undefined;
109
+ deleteUIState(key: string): void;
110
+ clearUIState(): void;
102
111
  setEntryPaxNumber(number: number): Promise<void>;
103
112
  getEntryPaxNumber(): number | null;
104
113
  getFulfillmentModes(): {
@@ -26,7 +26,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
26
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); }
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { ScanOrderHooks } from "./types";
29
- import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, collectLinkProductIdsFromReservationRules, createEmptySummary, getProductIdentityIndex, getSafeProductNum, hasCustomCapacityProduct, pickFirstCustomCapacityPaxBounds, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, pickFirstDurationMinutesFromProducts, toNonNegativeInt, toNonNegativeNumber, toPriceString, toBoolean, toPositiveString } from "./utils";
29
+ import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, collectLinkProductIdsFromReservationRules, computeResourceIsFull, createEmptySummary, getProductIdentityIndex, getSafeProductNum, hasCustomCapacityProduct, pickFirstCustomCapacityPaxBounds, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, pickFirstDurationMinutesFromProducts, toNonNegativeInt, toPriceString, toBoolean, toPositiveString } from "./utils";
30
30
  import { createModule } from "../BookingByStep/types";
31
31
  import { ProductList } from "../../modules/ProductList";
32
32
  import { ScheduleModule } from "../../modules/Schedule";
@@ -752,6 +752,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
752
752
  return getSummary;
753
753
  }() // ScanOrder 提交 payload enhancer:
754
754
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
755
+ // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
755
756
  // - 给第一条 booking 补 resources 与 product_uid(仅当存在 resource / rule product)
756
757
  // - 追加一条 is_rule=true 的 rule product,与 booking 互相关联
757
758
  }, {
@@ -759,6 +760,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
759
760
  value: function buildSubmitPayloadEnhancer() {
760
761
  var ruleProduct = this.enabledReservationRuleProducts[0];
761
762
  var resourceState = this.store.resource;
763
+ var resourceSelectType = resourceState === null || resourceState === void 0 ? void 0 : resourceState.resourceSelectType;
762
764
  return function (payload, _ref) {
763
765
  var _tempOrder$resource_i, _ref2, _pickOriginal, _resourceState$table_, _resourceState$relati;
764
766
  var bookingUuid = _ref.bookingUuid,
@@ -785,7 +787,10 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
785
787
  var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
786
788
  var nextBookings = (payload.bookings || []).map(function (booking, idx) {
787
789
  return _objectSpread(_objectSpread(_objectSpread({}, booking), {}, {
788
- appointment_status: 'started'
790
+ appointment_status: 'started',
791
+ metadata: _objectSpread(_objectSpread({}, booking.metadata || {}), resourceSelectType ? {
792
+ resource_select_type: resourceSelectType
793
+ } : {})
789
794
  }, idx === 0 && resourceEntry ? {
790
795
  resources: [resourceEntry]
791
796
  } : {}), idx === 0 && ruleProductUid ? {
@@ -1738,22 +1743,24 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1738
1743
  }()
1739
1744
  }, {
1740
1745
  key: "normalizeResourceState",
1741
- value: function normalizeResourceState(config, hasOrderId) {
1742
- var _this$otherParams8, _config$table_form_re;
1743
- var orderNumberPrefix = Array.isArray(config === null || config === void 0 ? void 0 : config.order_number_prefix) ? (config === null || config === void 0 ? void 0 : config.order_number_prefix) || [] : [];
1744
- var tableMaxNumber = Number((config === null || config === void 0 ? void 0 : config.table_max_number) || 1);
1745
- var orderCount = toNonNegativeNumber(config === null || config === void 0 ? void 0 : config.order_count);
1746
- var currentOrderId = toPositiveString(config === null || config === void 0 ? void 0 : config.order_id);
1747
- var lastOrderId = toPositiveString(config === null || config === void 0 ? void 0 : config.last_order_id);
1748
- var relationId = toPositiveString(config === null || config === void 0 ? void 0 : config.relation_id);
1749
- var tableFormId = toPositiveString(config === null || config === void 0 ? void 0 : config.table_form_id);
1746
+ value: function normalizeResourceState(detail, resourceSelectType, hasOrderId) {
1747
+ var _detail$form_record, _this$otherParams8, _detail$resource_capa, _detail$resource_capa2;
1748
+ var currentOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.order_id);
1749
+ var lastOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.last_order_id);
1750
+ var relationId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_record_id);
1751
+ var tableFormId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_id);
1752
+ var formRecord = (_detail$form_record = detail === null || detail === void 0 ? void 0 : detail.form_record) !== null && _detail$form_record !== void 0 ? _detail$form_record : null;
1750
1753
  // 是否允许加餐
1751
1754
  var allowSnack = ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 || (_this$otherParams8 = _this$otherParams8.dineInConfig) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8['workflow.allow_add_items']) || false;
1752
1755
  // 开启同桌验证 - 本期没有这个配置,默认关掉
1753
1756
  var deskmateValid = false;
1754
- var isExclusive = tableMaxNumber > 0 ? tableMaxNumber <= 1 : false;
1755
- var isFull = tableMaxNumber > 0 ? orderCount >= tableMaxNumber : false;
1756
- var isBlock = tableMaxNumber === -1;
1757
+ var isExclusive = resourceSelectType === 'single';
1758
+ var isFull = computeResourceIsFull({
1759
+ resourceSelectType: resourceSelectType,
1760
+ lastOrderId: lastOrderId,
1761
+ capacityList: (_detail$resource_capa = detail === null || detail === void 0 || (_detail$resource_capa2 = detail.resource_capacity) === null || _detail$resource_capa2 === void 0 || (_detail$resource_capa2 = _detail$resource_capa2[0]) === null || _detail$resource_capa2 === void 0 ? void 0 : _detail$resource_capa2.capacity_list) !== null && _detail$resource_capa !== void 0 ? _detail$resource_capa : [],
1762
+ capacity: formRecord === null || formRecord === void 0 ? void 0 : formRecord.capacity
1763
+ });
1757
1764
  var availabilityInfo = {
1758
1765
  mode: 'idle',
1759
1766
  deskmate_valid: deskmateValid
@@ -1797,18 +1804,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1797
1804
  deskmate_valid: deskmateValid
1798
1805
  };
1799
1806
  }
1800
- if (isBlock) {
1801
- availabilityInfo = {
1802
- mode: 'resource_block',
1803
- order_id: lastOrderId,
1804
- relation_id: relationId,
1805
- table_form_id: tableFormId,
1806
- deskmate_valid: deskmateValid
1807
- };
1808
- }
1809
1807
  return _objectSpread(_objectSpread({}, availabilityInfo), {}, {
1810
- tableMaxNumber: tableMaxNumber,
1811
- orderCount: orderCount,
1812
1808
  currentOrderId: currentOrderId,
1813
1809
  lastOrderId: lastOrderId,
1814
1810
  relationId: relationId,
@@ -1817,50 +1813,76 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1817
1813
  deskmateValid: deskmateValid,
1818
1814
  isExclusive: isExclusive,
1819
1815
  isFull: isFull,
1820
- orderNumberPrefix: orderNumberPrefix,
1821
- raw: config,
1822
- table_form_record: (_config$table_form_re = config === null || config === void 0 ? void 0 : config.table_form_record) !== null && _config$table_form_re !== void 0 ? _config$table_form_re : null
1816
+ resourceSelectType: resourceSelectType,
1817
+ raw: detail,
1818
+ table_form_record: formRecord
1819
+ });
1820
+ }
1821
+
1822
+ // 从首个预约规则商品的 product_resource.resources 中,按 form_id 匹配返回 type
1823
+ }, {
1824
+ key: "resolveResourceSelectType",
1825
+ value: function resolveResourceSelectType(formId) {
1826
+ var _firstProduct$product;
1827
+ var firstProduct = this.enabledReservationRuleProducts[0];
1828
+ var resources = (firstProduct === null || firstProduct === void 0 || (_firstProduct$product = firstProduct.product_resource) === null || _firstProduct$product === void 0 ? void 0 : _firstProduct$product.resources) || [];
1829
+ var numericFormId = Number(formId);
1830
+ if (!Number.isFinite(numericFormId) || numericFormId <= 0) return undefined;
1831
+ var matched = resources.find(function (r) {
1832
+ return Number(r === null || r === void 0 ? void 0 : r.id) === numericFormId;
1823
1833
  });
1834
+ return matched === null || matched === void 0 ? void 0 : matched.type;
1824
1835
  }
1825
1836
  }, {
1826
- key: "fetchTableConfigByResourceId",
1837
+ key: "fetchResourceOccupyDetailByResourceId",
1827
1838
  value: function () {
1828
- var _fetchTableConfigByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(resourceId) {
1829
- var tableResourceId, response;
1839
+ var _fetchResourceOccupyDetailByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(resourceId) {
1840
+ var _this$otherParams9, _this$otherParams9$ge, _response$data$occupy, _response$data;
1841
+ var formRecordId, shopId, response;
1830
1842
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1831
1843
  while (1) switch (_context27.prev = _context27.next) {
1832
1844
  case 0:
1833
- tableResourceId = Number(resourceId);
1834
- if (!(!Number.isFinite(tableResourceId) || tableResourceId <= 0)) {
1845
+ formRecordId = Number(resourceId);
1846
+ if (!(!Number.isFinite(formRecordId) || formRecordId <= 0)) {
1835
1847
  _context27.next = 3;
1836
1848
  break;
1837
1849
  }
1838
1850
  throw new Error("[ScanOrder] \u975E\u6CD5\u684C\u53F0 resourceId: ".concat(resourceId));
1839
1851
  case 3:
1840
- _context27.next = 5;
1841
- return this.request.get('/order/dining/table/config', {
1842
- table_resource_id: tableResourceId,
1843
- with_table_form_info: 1
1852
+ shopId = (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 || (_this$otherParams9$ge = _this$otherParams9.getStateData) === null || _this$otherParams9$ge === void 0 ? void 0 : _this$otherParams9$ge.call(_this$otherParams9, 'shop_id');
1853
+ if (shopId) {
1854
+ _context27.next = 6;
1855
+ break;
1856
+ }
1857
+ throw new Error('[ScanOrder] 无法获取 shop_id');
1858
+ case 6:
1859
+ _context27.next = 8;
1860
+ return this.request.get('/order/resource/occupy-detail', {
1861
+ shop_id: shopId,
1862
+ 'form_record_ids[]': formRecordId,
1863
+ with_resource_capacity_info: 1,
1864
+ with_resource_order_info: 1,
1865
+ with_resource_form_info: 1
1844
1866
  });
1845
- case 5:
1867
+ case 8:
1846
1868
  response = _context27.sent;
1847
1869
  if (response !== null && response !== void 0 && response.status) {
1848
- _context27.next = 8;
1870
+ _context27.next = 11;
1849
1871
  break;
1850
1872
  }
1851
- throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取桌台配置失败');
1852
- case 8:
1853
- return _context27.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || null);
1854
- case 9:
1873
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取资源占用详情失败');
1874
+ case 11:
1875
+ return _context27.abrupt("return", (_response$data$occupy = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 || (_response$data = _response$data.occupy_details) === null || _response$data === void 0 ? void 0 : _response$data[0]) !== null && _response$data$occupy !== void 0 ? _response$data$occupy : null);
1876
+ case 12:
1855
1877
  case "end":
1856
1878
  return _context27.stop();
1857
1879
  }
1858
1880
  }, _callee27, this);
1859
1881
  }));
1860
- function fetchTableConfigByResourceId(_x9) {
1861
- return _fetchTableConfigByResourceId.apply(this, arguments);
1882
+ function fetchResourceOccupyDetailByResourceId(_x9) {
1883
+ return _fetchResourceOccupyDetailByResourceId.apply(this, arguments);
1862
1884
  }
1863
- return fetchTableConfigByResourceId;
1885
+ return fetchResourceOccupyDetailByResourceId;
1864
1886
  }() // 检测当前链接是否可用
1865
1887
  // 通过 resource_id + 店铺配置
1866
1888
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
@@ -1868,7 +1890,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1868
1890
  key: "checkResourceAvailable",
1869
1891
  value: function () {
1870
1892
  var _checkResourceAvailable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(resourceId, hasOrderId) {
1871
- var _this$otherParams9, _this$otherParams9$ge, _config$table_form_re2, _config$table_form_re3, _this$otherParams10, _this$store$order5, _this$store$order7, _this$store$order7$ge, _this$otherParams11, openData, dineInConfig, closedBehaviorValue, closedMessage, basicUnavailableMessage, pauseMessage, makeShopClosed, operatingHourIds, outsideOperatingHours, scheduleList, now, config, resourceState, availabilityInfo, tempOrder, reservationLinkIds, reservationProductList, scheduleDate, scheduleDatetime, loaded, occupancyMinutes, paxBounds, _this$store$order6, _res$data, res, entryPaxNumber, lastOrderInfo, historicalItems;
1893
+ var _this$otherParams10, _this$otherParams10$g, _occupyDetail$form_re, _occupyDetail$form_re2, _this$otherParams11, _this$store$order5, _this$store$order7, _this$store$order7$ge, _this$otherParams12, openData, dineInConfig, closedBehaviorValue, closedMessage, basicUnavailableMessage, pauseMessage, makeShopClosed, operatingHourIds, outsideOperatingHours, scheduleList, now, tempOrder, reservationLinkIds, pendingRequestEntryPax, pendingRequestPaxMin, pendingRequestPaxMax, reservationProductList, scheduleDate, scheduleDatetime, loaded, occupancyMinutes, paxBounds, occupyDetail, resourceSelectType, resourceState, availabilityInfo, _this$store$order6, _res$data, res, entryPaxNumber, lastOrderInfo, historicalItems;
1872
1894
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1873
1895
  while (1) switch (_context28.prev = _context28.next) {
1874
1896
  case 0:
@@ -1877,7 +1899,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1877
1899
  });
1878
1900
  _context28.prev = 1;
1879
1901
  _context28.next = 4;
1880
- return (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 || (_this$otherParams9$ge = _this$otherParams9.getOpenData) === null || _this$otherParams9$ge === void 0 ? void 0 : _this$otherParams9$ge.call(_this$otherParams9, {
1902
+ return (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 || (_this$otherParams10$g = _this$otherParams10.getOpenData) === null || _this$otherParams10$g === void 0 ? void 0 : _this$otherParams10$g.call(_this$otherParams10, {
1881
1903
  scope: 'board',
1882
1904
  target: 'dine_in+scan_to_order',
1883
1905
  section_code: ['basic', 'fulfillment', 'reservation', 'sale', 'menu', 'availability', 'workflow']
@@ -1946,44 +1968,22 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1946
1968
  }
1947
1969
  return _context28.abrupt("return", makeShopClosed(closedMessage, closedBehaviorValue));
1948
1970
  case 26:
1949
- _context28.next = 28;
1950
- return this.fetchTableConfigByResourceId(resourceId);
1951
- case 28:
1952
- config = _context28.sent;
1953
- resourceState = this.normalizeResourceState(config, hasOrderId);
1954
- this.store.resource = resourceState;
1955
- availabilityInfo = {
1956
- mode: resourceState.mode,
1957
- order_id: resourceState.order_id,
1958
- relation_id: resourceState.relationId,
1959
- table_form_id: resourceState.tableFormId,
1960
- deskmate_valid: resourceState.deskmate_valid,
1961
- table_form_record: resourceState.table_form_record,
1962
- policy: config === null || config === void 0 || (_config$table_form_re2 = config.table_form_record) === null || _config$table_form_re2 === void 0 ? void 0 : _config$table_form_re2.policy,
1963
- partyroom_booking: config === null || config === void 0 || (_config$table_form_re3 = config.table_form_record) === null || _config$table_form_re3 === void 0 ? void 0 : _config$table_form_re3.partyroom_booking
1964
- };
1971
+ // Step1: 先加载预约规则商品,拿到 enabledReservationRuleProducts 与容量附加信息
1972
+ // (resourceSelectType 需要基于这些商品 + 占用接口的 form_id 计算,故必须前置)
1965
1973
  tempOrder = this.ensureTempOrder();
1966
- tempOrder.relation_id = resourceId || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.relation_id);
1967
- tempOrder.table_form_id = resourceState.tableFormId;
1968
- tempOrder.resource_id = resourceId;
1969
1974
  reservationLinkIds = collectLinkProductIdsFromReservationRules(dineInConfig['fulfillment.enabled_resource_rules']);
1970
1975
  if (!(reservationLinkIds.length === 0)) {
1971
- _context28.next = 42;
1976
+ _context28.next = 32;
1972
1977
  break;
1973
1978
  }
1974
1979
  this.enabledReservationRuleProducts = [];
1975
- if (this.store.resource) {
1976
- delete this.store.resource.requestEntryPax;
1977
- delete this.store.resource.requestPaxMin;
1978
- delete this.store.resource.requestPaxMax;
1979
- }
1980
- _context28.next = 53;
1980
+ _context28.next = 43;
1981
1981
  break;
1982
- case 42:
1982
+ case 32:
1983
1983
  tempOrder.metadata = _objectSpread({}, tempOrder.metadata || {});
1984
1984
  delete tempOrder.metadata.table_occupancy_duration;
1985
1985
  reservationProductList = new ProductList("".concat(this.name, "_reservationEnabledRules"), this.defaultVersion);
1986
- _context28.next = 47;
1986
+ _context28.next = 37;
1987
1987
  return reservationProductList.initialize(this.core, {
1988
1988
  store: {
1989
1989
  list: [],
@@ -1995,17 +1995,17 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1995
1995
  cacheId: this.cacheId
1996
1996
  })
1997
1997
  });
1998
- case 47:
1998
+ case 37:
1999
1999
  scheduleDate = dayjs().format('YYYY-MM-DD');
2000
2000
  scheduleDatetime = dayjs().format('YYYY-MM-DD HH:mm:ss');
2001
- _context28.next = 51;
2001
+ _context28.next = 41;
2002
2002
  return reservationProductList.loadProducts({
2003
2003
  product_ids: reservationLinkIds,
2004
2004
  schedule_date: scheduleDate,
2005
2005
  schedule_datetime: scheduleDatetime,
2006
2006
  cacheId: this.cacheId
2007
2007
  });
2008
- case 51:
2008
+ case 41:
2009
2009
  loaded = _context28.sent;
2010
2010
  if (Array.isArray(loaded)) {
2011
2011
  this.enabledReservationRuleProducts = loaded;
@@ -2014,35 +2014,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2014
2014
  tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
2015
2015
  }
2016
2016
  if (hasCustomCapacityProduct(loaded)) {
2017
- availabilityInfo.requestEntryPax = 1;
2018
- if (this.store.resource) this.store.resource.requestEntryPax = 1;
2019
- delete availabilityInfo.requestPaxMin;
2020
- delete availabilityInfo.requestPaxMax;
2021
- if (this.store.resource) {
2022
- delete this.store.resource.requestPaxMin;
2023
- delete this.store.resource.requestPaxMax;
2024
- }
2017
+ pendingRequestEntryPax = 1;
2025
2018
  paxBounds = pickFirstCustomCapacityPaxBounds(loaded);
2026
- if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.min) !== undefined) {
2027
- availabilityInfo.requestPaxMin = paxBounds.min;
2028
- if (this.store.resource) this.store.resource.requestPaxMin = paxBounds.min;
2029
- }
2030
- if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.max) !== undefined) {
2031
- availabilityInfo.requestPaxMax = paxBounds.max;
2032
- if (this.store.resource) this.store.resource.requestPaxMax = paxBounds.max;
2033
- }
2034
- } else if (this.store.resource) {
2035
- delete this.store.resource.requestEntryPax;
2036
- delete this.store.resource.requestPaxMin;
2037
- delete this.store.resource.requestPaxMax;
2019
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.min) !== undefined) pendingRequestPaxMin = paxBounds.min;
2020
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.max) !== undefined) pendingRequestPaxMax = paxBounds.max;
2038
2021
  }
2039
2022
  } else {
2040
2023
  this.enabledReservationRuleProducts = [];
2041
- if (this.store.resource) {
2042
- delete this.store.resource.requestEntryPax;
2043
- delete this.store.resource.requestPaxMin;
2044
- delete this.store.resource.requestPaxMax;
2045
- }
2046
2024
  void this.addScanOrderLog({
2047
2025
  level: 'error',
2048
2026
  title: '[ScanOrder] enabled_reservation_rules product query failed',
@@ -2052,28 +2030,67 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2052
2030
  }
2053
2031
  });
2054
2032
  }
2055
- case 53:
2033
+ case 43:
2034
+ _context28.next = 45;
2035
+ return this.fetchResourceOccupyDetailByResourceId(resourceId);
2036
+ case 45:
2037
+ occupyDetail = _context28.sent;
2038
+ // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2039
+ // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2040
+ resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id)); // Step4: 用 occupyDetail + resourceSelectType 规整为 resourceState
2041
+ resourceState = this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId);
2042
+ this.store.resource = resourceState;
2043
+
2044
+ // Step5: 把预约规则商品阶段暂存的 requestEntryPax 等注入 store.resource
2045
+ if (pendingRequestEntryPax !== undefined) {
2046
+ this.store.resource.requestEntryPax = pendingRequestEntryPax;
2047
+ }
2048
+ if (pendingRequestPaxMin !== undefined) {
2049
+ this.store.resource.requestPaxMin = pendingRequestPaxMin;
2050
+ }
2051
+ if (pendingRequestPaxMax !== undefined) {
2052
+ this.store.resource.requestPaxMax = pendingRequestPaxMax;
2053
+ }
2054
+ availabilityInfo = _objectSpread(_objectSpread(_objectSpread({
2055
+ mode: resourceState.mode,
2056
+ order_id: resourceState.order_id,
2057
+ relation_id: resourceState.relationId,
2058
+ table_form_id: resourceState.tableFormId,
2059
+ deskmate_valid: resourceState.deskmate_valid,
2060
+ table_form_record: resourceState.table_form_record,
2061
+ policy: occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$form_re = occupyDetail.form_record) === null || _occupyDetail$form_re === void 0 ? void 0 : _occupyDetail$form_re.policy,
2062
+ partyroom_booking: occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$form_re2 = occupyDetail.form_record) === null || _occupyDetail$form_re2 === void 0 ? void 0 : _occupyDetail$form_re2.partyroom_booking
2063
+ }, this.store.resource.requestEntryPax !== undefined ? {
2064
+ requestEntryPax: this.store.resource.requestEntryPax
2065
+ } : {}), this.store.resource.requestPaxMin !== undefined ? {
2066
+ requestPaxMin: this.store.resource.requestPaxMin
2067
+ } : {}), this.store.resource.requestPaxMax !== undefined ? {
2068
+ requestPaxMax: this.store.resource.requestPaxMax
2069
+ } : {});
2070
+ tempOrder.relation_id = resourceId || ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.relation_id);
2071
+ tempOrder.table_form_id = resourceState.tableFormId;
2072
+ tempOrder.resource_id = resourceId;
2056
2073
  (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 || _this$store$order5.persistTempOrder();
2057
2074
 
2058
2075
  // 空闲状态下自动准备本地临时订单,供后续“购物车式”商品操作使用
2059
2076
  if (!(availabilityInfo.mode === 'idle')) {
2060
- _context28.next = 57;
2077
+ _context28.next = 60;
2061
2078
  break;
2062
2079
  }
2063
- _context28.next = 57;
2080
+ _context28.next = 60;
2064
2081
  return this.addNewOrder();
2065
- case 57:
2082
+ case 60:
2066
2083
  // 如果是加单模式,tempOrder 里 需要记录 lastOrderId,提交的时候走加单接口
2067
2084
  if (availabilityInfo.mode === 'additional_order' || availabilityInfo.mode === 'additional_order_with_code') {
2068
2085
  tempOrder.order_id = resourceState.lastOrderId;
2069
2086
  }
2070
2087
  if (!tempOrder.order_id) {
2071
- _context28.next = 66;
2088
+ _context28.next = 69;
2072
2089
  break;
2073
2090
  }
2074
- _context28.next = 61;
2091
+ _context28.next = 64;
2075
2092
  return (_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 ? void 0 : _this$store$order6.getOrderInfoByRemote(tempOrder.order_id);
2076
- case 61:
2093
+ case 64:
2077
2094
  res = _context28.sent;
2078
2095
  // 找到下单的时候输入的 entryPaxNumber
2079
2096
  entryPaxNumber = res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.bookings) === null || _res$data === void 0 || (_res$data = _res$data.find(function (p) {
@@ -2081,12 +2098,12 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2081
2098
  return (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.collect_pax;
2082
2099
  })) === null || _res$data === void 0 || (_res$data = _res$data.metadata) === null || _res$data === void 0 ? void 0 : _res$data.collect_pax;
2083
2100
  if (!entryPaxNumber) {
2084
- _context28.next = 66;
2101
+ _context28.next = 69;
2085
2102
  break;
2086
2103
  }
2087
- _context28.next = 66;
2104
+ _context28.next = 69;
2088
2105
  return this.setEntryPaxNumber(entryPaxNumber);
2089
- case 66:
2106
+ case 69:
2090
2107
  lastOrderInfo = (_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 || (_this$store$order7$ge = _this$store$order7.getLastOrderInfo) === null || _this$store$order7$ge === void 0 ? void 0 : _this$store$order7$ge.call(_this$store$order7);
2091
2108
  historicalItems = hasOrderId && Array.isArray(lastOrderInfo === null || lastOrderInfo === void 0 ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce(function (acc, p) {
2092
2109
  if (typeof (p === null || p === void 0 ? void 0 : p.product_id) !== 'number') return acc;
@@ -2098,13 +2115,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2098
2115
  } : {}));
2099
2116
  return acc;
2100
2117
  }, []) : []; // pax 由 setEntryPaxNumber 负责写入 itemRuleRuntimeConfig.pax
2101
- _context28.next = 70;
2118
+ _context28.next = 73;
2102
2119
  return this.setItemRuleRuntimeConfig({
2103
- serviceType: (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode,
2120
+ serviceType: (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.businessCode,
2104
2121
  submissionIndex: hasOrderId ? 1 : 0,
2105
2122
  historicalItems: historicalItems
2106
2123
  });
2107
- case 70:
2124
+ case 73:
2108
2125
  // operating_hours 超出营业时段 + closed_behavior=show_menu_disabled:
2109
2126
  // 允许浏览商品但 UI 层需拦截“下一步”,这里覆盖最终 mode 并回传错误提示
2110
2127
  if (outsideOperatingHours && closedBehaviorValue === 'show_menu_disabled') {
@@ -2121,24 +2138,23 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2121
2138
  persistedRelationId: tempOrder.relation_id,
2122
2139
  persistedResourceId: tempOrder.resource_id,
2123
2140
  deskmateValid: availabilityInfo.deskmate_valid,
2124
- orderCount: resourceState.orderCount,
2125
- tableMaxNumber: resourceState.tableMaxNumber,
2141
+ resourceSelectType: resourceState.resourceSelectType,
2126
2142
  isExclusive: resourceState.isExclusive,
2127
2143
  isFull: resourceState.isFull
2128
2144
  });
2129
2145
  return _context28.abrupt("return", availabilityInfo);
2130
- case 75:
2131
- _context28.prev = 75;
2146
+ case 78:
2147
+ _context28.prev = 78;
2132
2148
  _context28.t0 = _context28["catch"](1);
2133
2149
  this.logMethodError('checkResourceAvailable', _context28.t0, {
2134
2150
  resourceId: resourceId
2135
2151
  });
2136
2152
  throw _context28.t0;
2137
- case 79:
2153
+ case 82:
2138
2154
  case "end":
2139
2155
  return _context28.stop();
2140
2156
  }
2141
- }, _callee28, this, [[1, 75]]);
2157
+ }, _callee28, this, [[1, 78]]);
2142
2158
  }));
2143
2159
  function checkResourceAvailable(_x10, _x11) {
2144
2160
  return _checkResourceAvailable.apply(this, arguments);
@@ -2181,14 +2197,14 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2181
2197
  key: "getProductList",
2182
2198
  value: function () {
2183
2199
  var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2184
- var _this$otherParams12;
2200
+ var _this$otherParams13;
2185
2201
  var menu_list_ids, _this$store$products, res, formattedRes;
2186
2202
  return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2187
2203
  while (1) switch (_context30.prev = _context30.next) {
2188
2204
  case 0:
2189
2205
  this.logMethodStart('getProductList');
2190
2206
  // 可以直接通过配置里的 menu 读取
2191
- menu_list_ids = ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 || (_this$otherParams12 = _this$otherParams12.dineInConfig) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12['menu.associated_menus'].map(function (n) {
2207
+ menu_list_ids = ((_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 || (_this$otherParams13 = _this$otherParams13.dineInConfig) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13['menu.associated_menus'].map(function (n) {
2192
2208
  return Number(n.value);
2193
2209
  })) || [];
2194
2210
  _context30.prev = 2;
@@ -2254,7 +2270,82 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2254
2270
  return _setOtherParams.apply(this, arguments);
2255
2271
  }
2256
2272
  return setOtherParams;
2257
- }()
2273
+ }() // ─── UI 状态缓存(按 cacheId 分桶,sessionStorage) ───
2274
+ //
2275
+ // 用于物料层持久化 UI 层面的轻量状态(如当前步骤、gate 标记、登录回跳意图等)。
2276
+ // 桶键:pisell.scanOrder.uiState:<cacheId>;内部以 JSON object 形式存储多个字段。
2277
+ // 无 cacheId 时所有方法自动降级为 no-op,上层不用判空。
2278
+ }, {
2279
+ key: "getUIStateBucketKey",
2280
+ value: function getUIStateBucketKey() {
2281
+ if (!this.cacheId) return null;
2282
+ return "".concat(ScanOrderImpl.UI_STATE_KEY_PREFIX).concat(this.cacheId);
2283
+ }
2284
+ }, {
2285
+ key: "readUIStateBucket",
2286
+ value: function readUIStateBucket() {
2287
+ var _this$window;
2288
+ var key = this.getUIStateBucketKey();
2289
+ if (!key || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.sessionStorage)) return {};
2290
+ try {
2291
+ var raw = this.window.sessionStorage.getItem(key) || '{}';
2292
+ var parsed = JSON.parse(raw);
2293
+ return parsed && _typeof(parsed) === 'object' ? parsed : {};
2294
+ } catch (_unused) {
2295
+ return {};
2296
+ }
2297
+ }
2298
+ }, {
2299
+ key: "writeUIStateBucket",
2300
+ value: function writeUIStateBucket(bucket) {
2301
+ var _this$window2;
2302
+ var key = this.getUIStateBucketKey();
2303
+ if (!key || !((_this$window2 = this.window) !== null && _this$window2 !== void 0 && _this$window2.sessionStorage)) return;
2304
+ try {
2305
+ this.window.sessionStorage.setItem(key, JSON.stringify(bucket));
2306
+ } catch (error) {
2307
+ console.warn('[ScanOrder] writeUIStateBucket failed', error);
2308
+ }
2309
+ }
2310
+ }, {
2311
+ key: "setUIState",
2312
+ value: function setUIState(key, value) {
2313
+ if (!this.getUIStateBucketKey()) return;
2314
+ var bucket = this.readUIStateBucket();
2315
+ bucket[key] = value;
2316
+ this.writeUIStateBucket(bucket);
2317
+ }
2318
+ }, {
2319
+ key: "getUIState",
2320
+ value: function getUIState(key) {
2321
+ if (!this.getUIStateBucketKey()) return undefined;
2322
+ var bucket = this.readUIStateBucket();
2323
+ return bucket[key];
2324
+ }
2325
+ }, {
2326
+ key: "deleteUIState",
2327
+ value: function deleteUIState(key) {
2328
+ if (!this.getUIStateBucketKey()) return;
2329
+ var bucket = this.readUIStateBucket();
2330
+ if (key in bucket) {
2331
+ delete bucket[key];
2332
+ this.writeUIStateBucket(bucket);
2333
+ }
2334
+ }
2335
+
2336
+ // 整桶清空(用于扫新桌、提交成功、restoreOrder 等场景)
2337
+ }, {
2338
+ key: "clearUIState",
2339
+ value: function clearUIState() {
2340
+ var _this$window3;
2341
+ var key = this.getUIStateBucketKey();
2342
+ if (!key || !((_this$window3 = this.window) !== null && _this$window3 !== void 0 && _this$window3.sessionStorage)) return;
2343
+ try {
2344
+ this.window.sessionStorage.removeItem(key);
2345
+ } catch (error) {
2346
+ console.warn('[ScanOrder] clearUIState failed', error);
2347
+ }
2348
+ }
2258
2349
  }, {
2259
2350
  key: "setEntryPaxNumber",
2260
2351
  value: function () {
@@ -2309,9 +2400,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2309
2400
  }, {
2310
2401
  key: "getFulfillmentModes",
2311
2402
  value: function getFulfillmentModes() {
2312
- var _this$otherParams13;
2403
+ var _this$otherParams14;
2313
2404
  this.logMethodStart('getFulfillmentModes');
2314
- var dineInConfig = ((_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.dineInConfig) || {};
2405
+ var dineInConfig = ((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.dineInConfig) || {};
2315
2406
  var result = {
2316
2407
  enablePickup: Boolean(dineInConfig['fulfillment.enable_pickup']),
2317
2408
  enableTableService: Boolean(dineInConfig['fulfillment.enable_table_service'])
@@ -2325,9 +2416,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2325
2416
  }, {
2326
2417
  key: "checkManualPickupRef",
2327
2418
  value: function checkManualPickupRef() {
2328
- var _this$otherParams14;
2419
+ var _this$otherParams15;
2329
2420
  this.logMethodStart('checkManualPickupRef');
2330
- var dineInConfig = ((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.dineInConfig) || {};
2421
+ var dineInConfig = ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.dineInConfig) || {};
2331
2422
  var refMode = dineInConfig['fulfillment.fulfillment_ref_mode'];
2332
2423
  var manualInputType = dineInConfig['fulfillment.manual_input_type'];
2333
2424
  var enabled = refMode === 'manual_input';
@@ -2345,4 +2436,5 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2345
2436
  }
2346
2437
  }]);
2347
2438
  return ScanOrderImpl;
2348
- }(BaseModule);
2439
+ }(BaseModule);
2440
+ _defineProperty(ScanOrderImpl, "UI_STATE_KEY_PREFIX", 'pisell.scanOrder.uiState:');