@pisell/pisellos 0.0.504 → 0.0.506

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.
@@ -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";
@@ -87,11 +87,11 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
87
87
  key: "serializeError",
88
88
  value: function serializeError(error) {
89
89
  if (error instanceof Error) {
90
- return {
90
+ return JSON.stringify({
91
91
  name: error.name,
92
92
  message: error.message,
93
93
  stack: error.stack
94
- };
94
+ });
95
95
  }
96
96
  return {
97
97
  message: String(error)
@@ -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,8 +760,21 @@ 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;
764
+
765
+ // single 预约独占整张桌台,capacity 取 form_record.capacity;其他情况(multiple / capacity / undefined)占 1 个容量位
766
+ var resolveResourceCapacity = function resolveResourceCapacity() {
767
+ if (resourceSelectType === 'single') {
768
+ var _resourceState$table_;
769
+ var raw = resourceState === null || resourceState === void 0 || (_resourceState$table_ = resourceState.table_form_record) === null || _resourceState$table_ === void 0 ? void 0 : _resourceState$table_.capacity;
770
+ var num = Number(raw);
771
+ if (Number.isFinite(num) && num > 0) return num;
772
+ return 1;
773
+ }
774
+ return 1;
775
+ };
762
776
  return function (payload, _ref) {
763
- var _tempOrder$resource_i, _ref2, _pickOriginal, _resourceState$table_, _resourceState$relati;
777
+ var _tempOrder$resource_i, _ref2, _pickOriginal, _resourceState$table_2, _resourceState$relati;
764
778
  var bookingUuid = _ref.bookingUuid,
765
779
  tempOrder = _ref.tempOrder;
766
780
  var resourceId = (_tempOrder$resource_i = tempOrder.resource_id) !== null && _tempOrder$resource_i !== void 0 ? _tempOrder$resource_i : resourceState === null || resourceState === void 0 ? void 0 : resourceState.relationId;
@@ -771,7 +785,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
771
785
  }
772
786
  return undefined;
773
787
  };
774
- var mainField = (_ref2 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_ = resourceState.table_form_record) === null || _resourceState$table_ === void 0 ? void 0 : _resourceState$table_.name)) !== null && _ref2 !== void 0 ? _ref2 : '';
788
+ var mainField = (_ref2 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_2 = resourceState.table_form_record) === null || _resourceState$table_2 === void 0 ? void 0 : _resourceState$table_2.name)) !== null && _ref2 !== void 0 ? _ref2 : '';
775
789
  var resourceEntry = resourceState && resourceId ? {
776
790
  relation_type: 'form',
777
791
  like_status: 'common',
@@ -779,13 +793,23 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
779
793
  main_field: mainField,
780
794
  form_id: resourceState.tableFormId,
781
795
  relation_id: (_resourceState$relati = resourceState.relationId) !== null && _resourceState$relati !== void 0 ? _resourceState$relati : resourceId,
782
- capacity: 1,
796
+ capacity: resolveResourceCapacity(),
783
797
  metadata: {}
784
798
  } : undefined;
785
799
  var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
800
+ var bookingCapacityValue = resolveResourceCapacity();
786
801
  var nextBookings = (payload.bookings || []).map(function (booking, idx) {
787
802
  return _objectSpread(_objectSpread(_objectSpread({}, booking), {}, {
788
- appointment_status: 'started'
803
+ appointment_status: 'started',
804
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, booking.metadata || {}), resourceSelectType ? {
805
+ resource_select_type: resourceSelectType
806
+ } : {}), resourceSelectType ? {
807
+ capacity: [{
808
+ id: 0,
809
+ value: bookingCapacityValue,
810
+ name: ''
811
+ }]
812
+ } : {})
789
813
  }, idx === 0 && resourceEntry ? {
790
814
  resources: [resourceEntry]
791
815
  } : {}), idx === 0 && ruleProductUid ? {
@@ -1738,22 +1762,24 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1738
1762
  }()
1739
1763
  }, {
1740
1764
  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);
1765
+ value: function normalizeResourceState(detail, resourceSelectType, hasOrderId) {
1766
+ var _detail$form_record, _this$otherParams8, _detail$resource_capa, _detail$resource_capa2;
1767
+ var currentOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.order_id);
1768
+ var lastOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.last_order_id);
1769
+ var relationId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_record_id);
1770
+ var tableFormId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.form_id);
1771
+ 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
1772
  // 是否允许加餐
1751
1773
  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
1774
  // 开启同桌验证 - 本期没有这个配置,默认关掉
1753
1775
  var deskmateValid = false;
1754
- var isExclusive = tableMaxNumber > 0 ? tableMaxNumber <= 1 : false;
1755
- var isFull = tableMaxNumber > 0 ? orderCount >= tableMaxNumber : false;
1756
- var isBlock = tableMaxNumber === -1;
1776
+ var isExclusive = resourceSelectType === 'single';
1777
+ var isFull = computeResourceIsFull({
1778
+ resourceSelectType: resourceSelectType,
1779
+ lastOrderId: lastOrderId,
1780
+ 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 : [],
1781
+ capacity: formRecord === null || formRecord === void 0 ? void 0 : formRecord.capacity
1782
+ });
1757
1783
  var availabilityInfo = {
1758
1784
  mode: 'idle',
1759
1785
  deskmate_valid: deskmateValid
@@ -1782,33 +1808,19 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1782
1808
  }
1783
1809
  } else if (lastOrderId) {
1784
1810
  // 如果有其他人点的单
1785
- // TODO: 是否独占?如果非独占,其他人点的单应该不影响我下单
1786
- availabilityInfo = allowSnack ? {
1787
- mode: deskmateValid ? 'additional_order_with_code' : 'additional_order',
1788
- order_id: lastOrderId,
1789
- relation_id: relationId,
1790
- table_form_id: tableFormId,
1791
- deskmate_valid: deskmateValid
1792
- } : {
1793
- mode: 'resource_busy',
1794
- order_id: lastOrderId,
1795
- relation_id: relationId,
1796
- table_form_id: tableFormId,
1797
- deskmate_valid: deskmateValid
1798
- };
1799
- }
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
- };
1811
+ // multiple 预约且容量仍有剩余时,其他人的单不影响当前用户下单,保持 idle 走正常下单流程
1812
+ var canFallthroughToIdle = resourceSelectType === 'multiple' && !isFull;
1813
+ if (!canFallthroughToIdle) {
1814
+ availabilityInfo = {
1815
+ mode: 'resource_busy',
1816
+ order_id: '0',
1817
+ relation_id: relationId,
1818
+ table_form_id: tableFormId,
1819
+ deskmate_valid: deskmateValid
1820
+ };
1821
+ }
1808
1822
  }
1809
1823
  return _objectSpread(_objectSpread({}, availabilityInfo), {}, {
1810
- tableMaxNumber: tableMaxNumber,
1811
- orderCount: orderCount,
1812
1824
  currentOrderId: currentOrderId,
1813
1825
  lastOrderId: lastOrderId,
1814
1826
  relationId: relationId,
@@ -1817,50 +1829,76 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1817
1829
  deskmateValid: deskmateValid,
1818
1830
  isExclusive: isExclusive,
1819
1831
  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
1832
+ resourceSelectType: resourceSelectType,
1833
+ raw: detail,
1834
+ table_form_record: formRecord
1835
+ });
1836
+ }
1837
+
1838
+ // 从首个预约规则商品的 product_resource.resources 中,按 form_id 匹配返回 type
1839
+ }, {
1840
+ key: "resolveResourceSelectType",
1841
+ value: function resolveResourceSelectType(formId) {
1842
+ var _firstProduct$product;
1843
+ var firstProduct = this.enabledReservationRuleProducts[0];
1844
+ var resources = (firstProduct === null || firstProduct === void 0 || (_firstProduct$product = firstProduct.product_resource) === null || _firstProduct$product === void 0 ? void 0 : _firstProduct$product.resources) || [];
1845
+ var numericFormId = Number(formId);
1846
+ if (!Number.isFinite(numericFormId) || numericFormId <= 0) return undefined;
1847
+ var matched = resources.find(function (r) {
1848
+ return Number(r === null || r === void 0 ? void 0 : r.id) === numericFormId;
1823
1849
  });
1850
+ return matched === null || matched === void 0 ? void 0 : matched.type;
1824
1851
  }
1825
1852
  }, {
1826
- key: "fetchTableConfigByResourceId",
1853
+ key: "fetchResourceOccupyDetailByResourceId",
1827
1854
  value: function () {
1828
- var _fetchTableConfigByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(resourceId) {
1829
- var tableResourceId, response;
1855
+ var _fetchResourceOccupyDetailByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(resourceId) {
1856
+ var _this$otherParams9, _this$otherParams9$ge, _response$data$occupy, _response$data;
1857
+ var formRecordId, shopId, response;
1830
1858
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1831
1859
  while (1) switch (_context27.prev = _context27.next) {
1832
1860
  case 0:
1833
- tableResourceId = Number(resourceId);
1834
- if (!(!Number.isFinite(tableResourceId) || tableResourceId <= 0)) {
1861
+ formRecordId = Number(resourceId);
1862
+ if (!(!Number.isFinite(formRecordId) || formRecordId <= 0)) {
1835
1863
  _context27.next = 3;
1836
1864
  break;
1837
1865
  }
1838
1866
  throw new Error("[ScanOrder] \u975E\u6CD5\u684C\u53F0 resourceId: ".concat(resourceId));
1839
1867
  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
1868
+ 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');
1869
+ if (shopId) {
1870
+ _context27.next = 6;
1871
+ break;
1872
+ }
1873
+ throw new Error('[ScanOrder] 无法获取 shop_id');
1874
+ case 6:
1875
+ _context27.next = 8;
1876
+ return this.request.get('/order/resource/occupy-detail', {
1877
+ shop_id: shopId,
1878
+ 'form_record_ids[]': formRecordId,
1879
+ with_resource_capacity_info: 1,
1880
+ with_resource_order_info: 1,
1881
+ with_resource_form_info: 1
1844
1882
  });
1845
- case 5:
1883
+ case 8:
1846
1884
  response = _context27.sent;
1847
1885
  if (response !== null && response !== void 0 && response.status) {
1848
- _context27.next = 8;
1886
+ _context27.next = 11;
1849
1887
  break;
1850
1888
  }
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:
1889
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取资源占用详情失败');
1890
+ case 11:
1891
+ 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);
1892
+ case 12:
1855
1893
  case "end":
1856
1894
  return _context27.stop();
1857
1895
  }
1858
1896
  }, _callee27, this);
1859
1897
  }));
1860
- function fetchTableConfigByResourceId(_x9) {
1861
- return _fetchTableConfigByResourceId.apply(this, arguments);
1898
+ function fetchResourceOccupyDetailByResourceId(_x9) {
1899
+ return _fetchResourceOccupyDetailByResourceId.apply(this, arguments);
1862
1900
  }
1863
- return fetchTableConfigByResourceId;
1901
+ return fetchResourceOccupyDetailByResourceId;
1864
1902
  }() // 检测当前链接是否可用
1865
1903
  // 通过 resource_id + 店铺配置
1866
1904
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
@@ -1868,7 +1906,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1868
1906
  key: "checkResourceAvailable",
1869
1907
  value: function () {
1870
1908
  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;
1909
+ 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
1910
  return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1873
1911
  while (1) switch (_context28.prev = _context28.next) {
1874
1912
  case 0:
@@ -1877,7 +1915,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1877
1915
  });
1878
1916
  _context28.prev = 1;
1879
1917
  _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, {
1918
+ 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
1919
  scope: 'board',
1882
1920
  target: 'dine_in+scan_to_order',
1883
1921
  section_code: ['basic', 'fulfillment', 'reservation', 'sale', 'menu', 'availability', 'workflow']
@@ -1946,44 +1984,22 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1946
1984
  }
1947
1985
  return _context28.abrupt("return", makeShopClosed(closedMessage, closedBehaviorValue));
1948
1986
  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
- };
1987
+ // Step1: 先加载预约规则商品,拿到 enabledReservationRuleProducts 与容量附加信息
1988
+ // (resourceSelectType 需要基于这些商品 + 占用接口的 form_id 计算,故必须前置)
1965
1989
  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
1990
  reservationLinkIds = collectLinkProductIdsFromReservationRules(dineInConfig['fulfillment.enabled_resource_rules']);
1970
1991
  if (!(reservationLinkIds.length === 0)) {
1971
- _context28.next = 42;
1992
+ _context28.next = 32;
1972
1993
  break;
1973
1994
  }
1974
1995
  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;
1996
+ _context28.next = 43;
1981
1997
  break;
1982
- case 42:
1998
+ case 32:
1983
1999
  tempOrder.metadata = _objectSpread({}, tempOrder.metadata || {});
1984
2000
  delete tempOrder.metadata.table_occupancy_duration;
1985
2001
  reservationProductList = new ProductList("".concat(this.name, "_reservationEnabledRules"), this.defaultVersion);
1986
- _context28.next = 47;
2002
+ _context28.next = 37;
1987
2003
  return reservationProductList.initialize(this.core, {
1988
2004
  store: {
1989
2005
  list: [],
@@ -1995,17 +2011,17 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1995
2011
  cacheId: this.cacheId
1996
2012
  })
1997
2013
  });
1998
- case 47:
2014
+ case 37:
1999
2015
  scheduleDate = dayjs().format('YYYY-MM-DD');
2000
2016
  scheduleDatetime = dayjs().format('YYYY-MM-DD HH:mm:ss');
2001
- _context28.next = 51;
2017
+ _context28.next = 41;
2002
2018
  return reservationProductList.loadProducts({
2003
2019
  product_ids: reservationLinkIds,
2004
2020
  schedule_date: scheduleDate,
2005
2021
  schedule_datetime: scheduleDatetime,
2006
2022
  cacheId: this.cacheId
2007
2023
  });
2008
- case 51:
2024
+ case 41:
2009
2025
  loaded = _context28.sent;
2010
2026
  if (Array.isArray(loaded)) {
2011
2027
  this.enabledReservationRuleProducts = loaded;
@@ -2014,35 +2030,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2014
2030
  tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
2015
2031
  }
2016
2032
  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
- }
2033
+ pendingRequestEntryPax = 1;
2025
2034
  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;
2035
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.min) !== undefined) pendingRequestPaxMin = paxBounds.min;
2036
+ if ((paxBounds === null || paxBounds === void 0 ? void 0 : paxBounds.max) !== undefined) pendingRequestPaxMax = paxBounds.max;
2038
2037
  }
2039
2038
  } else {
2040
2039
  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
2040
  void this.addScanOrderLog({
2047
2041
  level: 'error',
2048
2042
  title: '[ScanOrder] enabled_reservation_rules product query failed',
@@ -2052,28 +2046,67 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2052
2046
  }
2053
2047
  });
2054
2048
  }
2055
- case 53:
2049
+ case 43:
2050
+ _context28.next = 45;
2051
+ return this.fetchResourceOccupyDetailByResourceId(resourceId);
2052
+ case 45:
2053
+ occupyDetail = _context28.sent;
2054
+ // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2055
+ // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2056
+ resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id)); // Step4: 用 occupyDetail + resourceSelectType 规整为 resourceState
2057
+ resourceState = this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId);
2058
+ this.store.resource = resourceState;
2059
+
2060
+ // Step5: 把预约规则商品阶段暂存的 requestEntryPax 等注入 store.resource
2061
+ if (pendingRequestEntryPax !== undefined) {
2062
+ this.store.resource.requestEntryPax = pendingRequestEntryPax;
2063
+ }
2064
+ if (pendingRequestPaxMin !== undefined) {
2065
+ this.store.resource.requestPaxMin = pendingRequestPaxMin;
2066
+ }
2067
+ if (pendingRequestPaxMax !== undefined) {
2068
+ this.store.resource.requestPaxMax = pendingRequestPaxMax;
2069
+ }
2070
+ availabilityInfo = _objectSpread(_objectSpread(_objectSpread({
2071
+ mode: resourceState.mode,
2072
+ order_id: resourceState.order_id,
2073
+ relation_id: resourceState.relationId,
2074
+ table_form_id: resourceState.tableFormId,
2075
+ deskmate_valid: resourceState.deskmate_valid,
2076
+ table_form_record: resourceState.table_form_record,
2077
+ policy: occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$form_re = occupyDetail.form_record) === null || _occupyDetail$form_re === void 0 ? void 0 : _occupyDetail$form_re.policy,
2078
+ 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
2079
+ }, this.store.resource.requestEntryPax !== undefined ? {
2080
+ requestEntryPax: this.store.resource.requestEntryPax
2081
+ } : {}), this.store.resource.requestPaxMin !== undefined ? {
2082
+ requestPaxMin: this.store.resource.requestPaxMin
2083
+ } : {}), this.store.resource.requestPaxMax !== undefined ? {
2084
+ requestPaxMax: this.store.resource.requestPaxMax
2085
+ } : {});
2086
+ tempOrder.relation_id = resourceId || ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.relation_id);
2087
+ tempOrder.table_form_id = resourceState.tableFormId;
2088
+ tempOrder.resource_id = resourceId;
2056
2089
  (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 || _this$store$order5.persistTempOrder();
2057
2090
 
2058
2091
  // 空闲状态下自动准备本地临时订单,供后续“购物车式”商品操作使用
2059
2092
  if (!(availabilityInfo.mode === 'idle')) {
2060
- _context28.next = 57;
2093
+ _context28.next = 60;
2061
2094
  break;
2062
2095
  }
2063
- _context28.next = 57;
2096
+ _context28.next = 60;
2064
2097
  return this.addNewOrder();
2065
- case 57:
2098
+ case 60:
2066
2099
  // 如果是加单模式,tempOrder 里 需要记录 lastOrderId,提交的时候走加单接口
2067
2100
  if (availabilityInfo.mode === 'additional_order' || availabilityInfo.mode === 'additional_order_with_code') {
2068
2101
  tempOrder.order_id = resourceState.lastOrderId;
2069
2102
  }
2070
2103
  if (!tempOrder.order_id) {
2071
- _context28.next = 66;
2104
+ _context28.next = 69;
2072
2105
  break;
2073
2106
  }
2074
- _context28.next = 61;
2107
+ _context28.next = 64;
2075
2108
  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:
2109
+ case 64:
2077
2110
  res = _context28.sent;
2078
2111
  // 找到下单的时候输入的 entryPaxNumber
2079
2112
  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 +2114,12 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2081
2114
  return (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.collect_pax;
2082
2115
  })) === null || _res$data === void 0 || (_res$data = _res$data.metadata) === null || _res$data === void 0 ? void 0 : _res$data.collect_pax;
2083
2116
  if (!entryPaxNumber) {
2084
- _context28.next = 66;
2117
+ _context28.next = 69;
2085
2118
  break;
2086
2119
  }
2087
- _context28.next = 66;
2120
+ _context28.next = 69;
2088
2121
  return this.setEntryPaxNumber(entryPaxNumber);
2089
- case 66:
2122
+ case 69:
2090
2123
  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
2124
  historicalItems = hasOrderId && Array.isArray(lastOrderInfo === null || lastOrderInfo === void 0 ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce(function (acc, p) {
2092
2125
  if (typeof (p === null || p === void 0 ? void 0 : p.product_id) !== 'number') return acc;
@@ -2098,13 +2131,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2098
2131
  } : {}));
2099
2132
  return acc;
2100
2133
  }, []) : []; // pax 由 setEntryPaxNumber 负责写入 itemRuleRuntimeConfig.pax
2101
- _context28.next = 70;
2134
+ _context28.next = 73;
2102
2135
  return this.setItemRuleRuntimeConfig({
2103
- serviceType: (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode,
2136
+ serviceType: (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.businessCode,
2104
2137
  submissionIndex: hasOrderId ? 1 : 0,
2105
2138
  historicalItems: historicalItems
2106
2139
  });
2107
- case 70:
2140
+ case 73:
2108
2141
  // operating_hours 超出营业时段 + closed_behavior=show_menu_disabled:
2109
2142
  // 允许浏览商品但 UI 层需拦截“下一步”,这里覆盖最终 mode 并回传错误提示
2110
2143
  if (outsideOperatingHours && closedBehaviorValue === 'show_menu_disabled') {
@@ -2121,24 +2154,23 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2121
2154
  persistedRelationId: tempOrder.relation_id,
2122
2155
  persistedResourceId: tempOrder.resource_id,
2123
2156
  deskmateValid: availabilityInfo.deskmate_valid,
2124
- orderCount: resourceState.orderCount,
2125
- tableMaxNumber: resourceState.tableMaxNumber,
2157
+ resourceSelectType: resourceState.resourceSelectType,
2126
2158
  isExclusive: resourceState.isExclusive,
2127
2159
  isFull: resourceState.isFull
2128
2160
  });
2129
2161
  return _context28.abrupt("return", availabilityInfo);
2130
- case 75:
2131
- _context28.prev = 75;
2162
+ case 78:
2163
+ _context28.prev = 78;
2132
2164
  _context28.t0 = _context28["catch"](1);
2133
- this.logMethodError('checkResourceAvailable', _context28.t0, {
2165
+ this.logMethodError('checkResourceAvailable', _context28.t0.message, {
2134
2166
  resourceId: resourceId
2135
2167
  });
2136
2168
  throw _context28.t0;
2137
- case 79:
2169
+ case 82:
2138
2170
  case "end":
2139
2171
  return _context28.stop();
2140
2172
  }
2141
- }, _callee28, this, [[1, 75]]);
2173
+ }, _callee28, this, [[1, 78]]);
2142
2174
  }));
2143
2175
  function checkResourceAvailable(_x10, _x11) {
2144
2176
  return _checkResourceAvailable.apply(this, arguments);
@@ -2181,14 +2213,14 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2181
2213
  key: "getProductList",
2182
2214
  value: function () {
2183
2215
  var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2184
- var _this$otherParams12;
2216
+ var _this$otherParams13;
2185
2217
  var menu_list_ids, _this$store$products, res, formattedRes;
2186
2218
  return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2187
2219
  while (1) switch (_context30.prev = _context30.next) {
2188
2220
  case 0:
2189
2221
  this.logMethodStart('getProductList');
2190
2222
  // 可以直接通过配置里的 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) {
2223
+ 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
2224
  return Number(n.value);
2193
2225
  })) || [];
2194
2226
  _context30.prev = 2;
@@ -2209,7 +2241,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2209
2241
  case 11:
2210
2242
  _context30.prev = 11;
2211
2243
  _context30.t0 = _context30["catch"](2);
2212
- this.logMethodError('getProductList', _context30.t0);
2244
+ this.logMethodError('getProductList', _context30.t0.message);
2213
2245
  throw _context30.t0;
2214
2246
  case 15:
2215
2247
  case "end":
@@ -2254,7 +2286,82 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2254
2286
  return _setOtherParams.apply(this, arguments);
2255
2287
  }
2256
2288
  return setOtherParams;
2257
- }()
2289
+ }() // ─── UI 状态缓存(按 cacheId 分桶,sessionStorage) ───
2290
+ //
2291
+ // 用于物料层持久化 UI 层面的轻量状态(如当前步骤、gate 标记、登录回跳意图等)。
2292
+ // 桶键:pisell.scanOrder.uiState:<cacheId>;内部以 JSON object 形式存储多个字段。
2293
+ // 无 cacheId 时所有方法自动降级为 no-op,上层不用判空。
2294
+ }, {
2295
+ key: "getUIStateBucketKey",
2296
+ value: function getUIStateBucketKey() {
2297
+ if (!this.cacheId) return null;
2298
+ return "".concat(ScanOrderImpl.UI_STATE_KEY_PREFIX).concat(this.cacheId);
2299
+ }
2300
+ }, {
2301
+ key: "readUIStateBucket",
2302
+ value: function readUIStateBucket() {
2303
+ var _this$window;
2304
+ var key = this.getUIStateBucketKey();
2305
+ if (!key || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.sessionStorage)) return {};
2306
+ try {
2307
+ var raw = this.window.sessionStorage.getItem(key) || '{}';
2308
+ var parsed = JSON.parse(raw);
2309
+ return parsed && _typeof(parsed) === 'object' ? parsed : {};
2310
+ } catch (_unused) {
2311
+ return {};
2312
+ }
2313
+ }
2314
+ }, {
2315
+ key: "writeUIStateBucket",
2316
+ value: function writeUIStateBucket(bucket) {
2317
+ var _this$window2;
2318
+ var key = this.getUIStateBucketKey();
2319
+ if (!key || !((_this$window2 = this.window) !== null && _this$window2 !== void 0 && _this$window2.sessionStorage)) return;
2320
+ try {
2321
+ this.window.sessionStorage.setItem(key, JSON.stringify(bucket));
2322
+ } catch (error) {
2323
+ console.warn('[ScanOrder] writeUIStateBucket failed', error);
2324
+ }
2325
+ }
2326
+ }, {
2327
+ key: "setUIState",
2328
+ value: function setUIState(key, value) {
2329
+ if (!this.getUIStateBucketKey()) return;
2330
+ var bucket = this.readUIStateBucket();
2331
+ bucket[key] = value;
2332
+ this.writeUIStateBucket(bucket);
2333
+ }
2334
+ }, {
2335
+ key: "getUIState",
2336
+ value: function getUIState(key) {
2337
+ if (!this.getUIStateBucketKey()) return undefined;
2338
+ var bucket = this.readUIStateBucket();
2339
+ return bucket[key];
2340
+ }
2341
+ }, {
2342
+ key: "deleteUIState",
2343
+ value: function deleteUIState(key) {
2344
+ if (!this.getUIStateBucketKey()) return;
2345
+ var bucket = this.readUIStateBucket();
2346
+ if (key in bucket) {
2347
+ delete bucket[key];
2348
+ this.writeUIStateBucket(bucket);
2349
+ }
2350
+ }
2351
+
2352
+ // 整桶清空(用于扫新桌、提交成功、restoreOrder 等场景)
2353
+ }, {
2354
+ key: "clearUIState",
2355
+ value: function clearUIState() {
2356
+ var _this$window3;
2357
+ var key = this.getUIStateBucketKey();
2358
+ if (!key || !((_this$window3 = this.window) !== null && _this$window3 !== void 0 && _this$window3.sessionStorage)) return;
2359
+ try {
2360
+ this.window.sessionStorage.removeItem(key);
2361
+ } catch (error) {
2362
+ console.warn('[ScanOrder] clearUIState failed', error);
2363
+ }
2364
+ }
2258
2365
  }, {
2259
2366
  key: "setEntryPaxNumber",
2260
2367
  value: function () {
@@ -2309,9 +2416,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2309
2416
  }, {
2310
2417
  key: "getFulfillmentModes",
2311
2418
  value: function getFulfillmentModes() {
2312
- var _this$otherParams13;
2419
+ var _this$otherParams14;
2313
2420
  this.logMethodStart('getFulfillmentModes');
2314
- var dineInConfig = ((_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.dineInConfig) || {};
2421
+ var dineInConfig = ((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.dineInConfig) || {};
2315
2422
  var result = {
2316
2423
  enablePickup: Boolean(dineInConfig['fulfillment.enable_pickup']),
2317
2424
  enableTableService: Boolean(dineInConfig['fulfillment.enable_table_service'])
@@ -2325,9 +2432,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2325
2432
  }, {
2326
2433
  key: "checkManualPickupRef",
2327
2434
  value: function checkManualPickupRef() {
2328
- var _this$otherParams14;
2435
+ var _this$otherParams15;
2329
2436
  this.logMethodStart('checkManualPickupRef');
2330
- var dineInConfig = ((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.dineInConfig) || {};
2437
+ var dineInConfig = ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.dineInConfig) || {};
2331
2438
  var refMode = dineInConfig['fulfillment.fulfillment_ref_mode'];
2332
2439
  var manualInputType = dineInConfig['fulfillment.manual_input_type'];
2333
2440
  var enabled = refMode === 'manual_input';
@@ -2345,4 +2452,5 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2345
2452
  }
2346
2453
  }]);
2347
2454
  return ScanOrderImpl;
2348
- }(BaseModule);
2455
+ }(BaseModule);
2456
+ _defineProperty(ScanOrderImpl, "UI_STATE_KEY_PREFIX", 'pisell.scanOrder.uiState:');