@pisell/pisellos 0.0.547 → 0.0.549

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.
@@ -0,0 +1,115 @@
1
+ import { ProductData } from '../Product/types';
2
+ /**
3
+ * 商品 holder 配置
4
+ */
5
+ export interface IHolderConfig {
6
+ required?: number;
7
+ resource_id: number;
8
+ status?: string;
9
+ [key: string]: any;
10
+ }
11
+ /**
12
+ * 表单记录
13
+ */
14
+ export interface IFormRecord {
15
+ form_id: number;
16
+ form_record_id: number;
17
+ main_field: string;
18
+ customer_cover?: string;
19
+ created_at?: string;
20
+ customer_id?: number;
21
+ [key: string]: any;
22
+ }
23
+ /**
24
+ * 表单配置/定义
25
+ */
26
+ export interface IFormInfo {
27
+ form_id: number;
28
+ name: string;
29
+ fields?: Record<string, any>[];
30
+ [key: string]: any;
31
+ }
32
+ /**
33
+ * 单个 form_id 下的数据结构
34
+ */
35
+ export interface IFormItemData {
36
+ records: IFormRecord[];
37
+ form: IFormInfo | Record<string, any>;
38
+ }
39
+ /**
40
+ * form_id 为 key 的 map 结构,如 948: { records: [], form: {} }
41
+ */
42
+ export type HolderFormMap = Record<string, IFormItemData>;
43
+ /**
44
+ * Holder 模块 reactive store,仅 holderMap 会触发 changed 事件
45
+ */
46
+ export interface HolderState {
47
+ holderMap: HolderFormMap;
48
+ }
49
+ export interface IFetchFormInfoParams {
50
+ url?: string;
51
+ query: {
52
+ form_id: string | number;
53
+ };
54
+ useCache?: boolean;
55
+ }
56
+ export interface IFetchFormRecordsParams {
57
+ url?: string;
58
+ query: {
59
+ customer_id?: number;
60
+ form_id: string | number;
61
+ shop_id: string | number;
62
+ num?: number;
63
+ skip?: number;
64
+ [key: string]: any;
65
+ };
66
+ useCache?: boolean;
67
+ }
68
+ export interface IAddFormRecordParams {
69
+ url?: string;
70
+ body: {
71
+ form_id: number | string;
72
+ shop_id: number | string;
73
+ customer_id?: number;
74
+ [key: string]: any;
75
+ };
76
+ }
77
+ /**
78
+ * UI 层自行调用添加接口后,将返回记录写入 holderMap
79
+ */
80
+ export interface IAppendFormRecordParams {
81
+ /** 接口返回的 data,或完整响应 { data: {...} } */
82
+ record: IFormRecord | Record<string, any>;
83
+ /** 可选,未传则从 record.form_id 读取 */
84
+ form_id?: number | string;
85
+ }
86
+ export interface IEnsureFormDataParams {
87
+ form_id: number | string;
88
+ shop_id: number | string;
89
+ customer_id?: number;
90
+ useCache?: boolean;
91
+ forceRefresh?: boolean;
92
+ formInfoUrl?: string;
93
+ recordsUrl?: string;
94
+ skip?: number;
95
+ num?: number;
96
+ }
97
+ export interface IEnsureFormByProductParams {
98
+ product: ProductData | Record<string, any>;
99
+ customer_id?: number;
100
+ shop_id?: number | string;
101
+ useCache?: boolean;
102
+ }
103
+ export interface HolderModuleAPI {
104
+ getHolderFormMap: () => HolderFormMap;
105
+ getHolderFormData: (formId: number | string) => IFormItemData | undefined;
106
+ setFormData: (formId: number | string, data: Partial<IFormItemData>) => void;
107
+ fetchFormInfo: (params: IFetchFormInfoParams) => Promise<IFormInfo | IFormInfo[]>;
108
+ fetchRecords: (params: IFetchFormRecordsParams) => Promise<IFormRecord[]>;
109
+ ensureFormData: (params: IEnsureFormDataParams) => Promise<IFormItemData>;
110
+ ensureFormByProduct: (params: IEnsureFormByProductParams) => Promise<IFormItemData | null>;
111
+ addFormRecord: (params: IAddFormRecordParams) => Promise<IFormRecord>;
112
+ appendFormRecord: (params: IAppendFormRecordParams) => IFormRecord;
113
+ removeFormRecord: (formId: number | string, formRecordId: number) => void;
114
+ clearFormData: (formId?: number | string) => void;
115
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { ProductData } from '../Product/types';
2
+ import { IHolderConfig } from './types';
3
+ export declare function getProductHolderConfig(product?: ProductData | Record<string, any> | null): IHolderConfig | null;
4
+ export declare function getFormIdFromHolderConfig(config: IHolderConfig): string;
5
+ export declare function normalizeFormId(formId: number | string): string;
6
+ export declare function createEmptyFormItemData(): {
7
+ records: any[];
8
+ form: Record<string, any>;
9
+ };
@@ -0,0 +1,20 @@
1
+ export function getProductHolderConfig(product) {
2
+ var _product$holder_confi, _product$origin;
3
+ if (!product) return null;
4
+ var config = (_product$holder_confi = product === null || product === void 0 ? void 0 : product.holder_config) !== null && _product$holder_confi !== void 0 ? _product$holder_confi : product === null || product === void 0 || (_product$origin = product.origin) === null || _product$origin === void 0 ? void 0 : _product$origin.holder_config;
5
+ if (config !== null && config !== void 0 && config.status && (config === null || config === void 0 ? void 0 : config.status) !== 'enable') return null;
6
+ if (!(config !== null && config !== void 0 && config.resource_id)) return null;
7
+ return config;
8
+ }
9
+ export function getFormIdFromHolderConfig(config) {
10
+ return String(config === null || config === void 0 ? void 0 : config.resource_id);
11
+ }
12
+ export function normalizeFormId(formId) {
13
+ return String(formId);
14
+ }
15
+ export function createEmptyFormItemData() {
16
+ return {
17
+ records: [],
18
+ form: {}
19
+ };
20
+ }
@@ -210,6 +210,13 @@ export interface ProductData {
210
210
  option_group_count: number;
211
211
  /** 服务时长 */
212
212
  service_times?: any;
213
+ /** holder 表单配置 */
214
+ holder_config?: {
215
+ required?: number;
216
+ resource_id?: number;
217
+ status?: string;
218
+ [key: string]: any;
219
+ };
213
220
  }
214
221
  /**
215
222
  * 商品媒体信息接口
@@ -16,3 +16,4 @@ export * from './Schedule';
16
16
  export * from './Quotation';
17
17
  export * from './ScanOrderLogger';
18
18
  export * from './OpenData';
19
+ export * from './Holder';
@@ -15,4 +15,5 @@ export * from "./SalesSummary";
15
15
  export * from "./Schedule";
16
16
  export * from "./Quotation";
17
17
  export * from "./ScanOrderLogger";
18
- export * from "./OpenData";
18
+ export * from "./OpenData";
19
+ export * from "./Holder";
@@ -10,6 +10,7 @@ import { ITime } from '../../modules/Date/types';
10
10
  import dayjs from 'dayjs';
11
11
  import { LoadScheduleAvailableDateParams } from '../../modules/Schedule/types';
12
12
  import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
13
+ import { IAppendFormRecordParams } from '../../modules/Holder/types';
13
14
  export declare class BookingByStepImpl extends BaseModule implements Module {
14
15
  protected defaultName: string;
15
16
  protected defaultVersion: string;
@@ -126,6 +127,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
126
127
  * @param params
127
128
  */
128
129
  fetchHolderAccountsAsync(params: IFetchHolderAccountsParams): Promise<void>;
130
+ /**
131
+ * 获取 holder 表单 map
132
+ */
133
+ getHolderFormMap(): import("../../modules").HolderFormMap;
134
+ /**
135
+ * 添加表单记录
136
+ */
137
+ appendFormRecord(params: IAppendFormRecordParams): import("../../modules").IFormRecord;
129
138
  setDateRange(dateRange: ITime[]): Promise<void>;
130
139
  clearDateRange(): void;
131
140
  getDateRange(): Promise<ITime[]>;
@@ -311,7 +320,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
320
  date: string;
312
321
  status: string;
313
322
  week: string;
314
- weekNum: 0 | 1 | 4 | 2 | 3 | 5 | 6;
323
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
324
  }[]>;
316
325
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
326
  private getScheduleDataByIds;
@@ -118,7 +118,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
118
118
  this.otherData = ((_data$this$otherParam = data[this.otherParams.cacheId]) === null || _data$this$otherParam === void 0 || (_data$this$otherParam = _data$this$otherParam[this.name]) === null || _data$this$otherParam === void 0 ? void 0 : _data$this$otherParam['otherData']) || {};
119
119
  }
120
120
  }
121
- moduleArr = ['accountList', 'cart', 'schedule', 'summary', 'step', 'products', 'date', 'order'];
121
+ moduleArr = ['accountList', 'holder', 'cart', 'schedule', 'summary', 'step', 'products', 'date', 'order'];
122
122
  moduleArr.forEach(function (step) {
123
123
  var targetModule = createModule(step, _this2.name);
124
124
  if (targetModule) {
@@ -644,8 +644,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
644
644
  return _fetchHolderAccountsAsync.apply(this, arguments);
645
645
  }
646
646
  return fetchHolderAccountsAsync;
647
- }() // 设置日期范围,注入到日期模块中
647
+ }()
648
+ /**
649
+ * 获取 holder 表单 map
650
+ */
648
651
  )
652
+ }, {
653
+ key: "getHolderFormMap",
654
+ value: function getHolderFormMap() {
655
+ return this.store.holder.getHolderFormMap();
656
+ }
657
+
658
+ /**
659
+ * 添加表单记录
660
+ */
661
+ }, {
662
+ key: "appendFormRecord",
663
+ value: function appendFormRecord(params) {
664
+ return this.store.holder.appendFormRecord(params);
665
+ }
666
+
667
+ // 设置日期范围,注入到日期模块中
649
668
  }, {
650
669
  key: "setDateRange",
651
670
  value: function () {
@@ -1193,6 +1212,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1193
1212
  account = activeAccount;
1194
1213
  }
1195
1214
  }
1215
+ try {
1216
+ var _account;
1217
+ this.store.holder.ensureFormByProduct({
1218
+ product: productData,
1219
+ customer_id: (_account = account) !== null && _account !== void 0 && _account.id ? Number(account.id) : 16121,
1220
+ shop_id: (productData === null || productData === void 0 ? void 0 : productData.shop_id) || '',
1221
+ useCache: true
1222
+ });
1223
+ } catch (error) {
1224
+ console.error('[BookingByStep] 加载 holder 表单失败', error);
1225
+ }
1196
1226
  var flag = this.store.cart.mergeCartItemByRowKey({
1197
1227
  rowKey: rowKey,
1198
1228
  quantity: quantity,
@@ -1,4 +1,4 @@
1
- import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule } from '../../modules';
1
+ import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule, HolderModule } from '../../modules';
2
2
  export interface BookingByStepState {
3
3
  cart: CartModule;
4
4
  summary: SummaryModule;
@@ -16,6 +16,7 @@ export interface BookingByStepState {
16
16
  schedule: ScheduleModule;
17
17
  salesSummary?: SalesSummaryModule;
18
18
  scanOrderLogger?: ScanOrderLoggerModule;
19
+ holder: HolderModule;
19
20
  }
20
21
  export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
21
22
  export declare enum BookingByStepHooks {
@@ -1,4 +1,4 @@
1
- import { ProductList, CartModule, AccountListModule, DateModule, OrderModule, PaymentModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule } from "../../modules";
1
+ import { ProductList, CartModule, AccountListModule, DateModule, OrderModule, PaymentModule, StepModule, SummaryModule, SalesSummaryModule, ScheduleModule, ScanOrderLoggerModule, HolderModule } from "../../modules";
2
2
  export function createModule(moduleName, solutionName, name, version) {
3
3
  switch (moduleName) {
4
4
  case 'cart':
@@ -23,6 +23,8 @@ export function createModule(moduleName, solutionName, name, version) {
23
23
  return new ScheduleModule("".concat(solutionName, "_").concat(name || moduleName), version);
24
24
  case 'scanOrderLogger':
25
25
  return new ScanOrderLoggerModule("".concat(solutionName, "_").concat(name || moduleName), version);
26
+ case 'holder':
27
+ return new HolderModule("".concat(solutionName, "_").concat(name || moduleName), version);
26
28
  default:
27
29
  throw new Error("Unknown module type: ".concat(moduleName));
28
30
  }
@@ -0,0 +1,42 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { IFormInfo, IFormRecord, IFormItemData, IFetchFormInfoParams, IFetchFormRecordsParams, IAddFormRecordParams, IAppendFormRecordParams, IEnsureFormDataParams, IEnsureFormByProductParams, HolderModuleAPI, HolderFormMap } from './types';
4
+ export * from './types';
5
+ export * from './utils';
6
+ export declare class HolderModule extends BaseModule implements Module, HolderModuleAPI {
7
+ protected defaultName: string;
8
+ protected defaultVersion: string;
9
+ private store;
10
+ private request;
11
+ private cacheId;
12
+ private openCache;
13
+ private fatherModule;
14
+ private isLoading;
15
+ private error;
16
+ /** 已加载过表单数据的 form_id 缓存标记 */
17
+ private loadedFormIds;
18
+ constructor(name?: string, version?: string);
19
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
20
+ /** 统一提交 formMap,仅此处触发 store changed */
21
+ private commitFormMap;
22
+ /** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
23
+ private notifyFormMapChanged;
24
+ getHolderFormMap(): HolderFormMap;
25
+ getHolderFormData(formId: number | string): IFormItemData | undefined;
26
+ setFormData(formId: number | string, data: Partial<IFormItemData>): void;
27
+ private ensureFormItem;
28
+ private hasFormData;
29
+ private patchFormMap;
30
+ fetchFormInfo(params: IFetchFormInfoParams): Promise<IFormInfo | IFormInfo[]>;
31
+ fetchRecords(params: IFetchFormRecordsParams): Promise<any>;
32
+ ensureFormData(params: IEnsureFormDataParams): Promise<IFormItemData>;
33
+ ensureFormByProduct(params: IEnsureFormByProductParams): Promise<IFormItemData | null>;
34
+ addFormRecord(params: IAddFormRecordParams): Promise<any>;
35
+ /**
36
+ * UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
37
+ */
38
+ appendFormRecord(params: IAppendFormRecordParams): IFormRecord;
39
+ removeFormRecord(formId: number | string, formRecordId: number): void;
40
+ clearFormData(formId?: number | string): void;
41
+ storeChange(path?: string): void;
42
+ }
@@ -0,0 +1,329 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/Holder/index.ts
21
+ var Holder_exports = {};
22
+ __export(Holder_exports, {
23
+ HolderModule: () => HolderModule
24
+ });
25
+ module.exports = __toCommonJS(Holder_exports);
26
+ var import_lodash_es = require("lodash-es");
27
+ var import_BaseModule = require("../BaseModule");
28
+ var import_utils = require("./utils");
29
+ __reExport(Holder_exports, require("./types"), module.exports);
30
+ __reExport(Holder_exports, require("./utils"), module.exports);
31
+ var HolderModule = class extends import_BaseModule.BaseModule {
32
+ constructor(name, version) {
33
+ super(name, version);
34
+ this.defaultName = "holder";
35
+ this.defaultVersion = "1.0.0";
36
+ this.openCache = false;
37
+ this.isLoading = false;
38
+ this.error = null;
39
+ /** 已加载过表单数据的 form_id 缓存标记 */
40
+ this.loadedFormIds = /* @__PURE__ */ new Set();
41
+ }
42
+ async initialize(core, options) {
43
+ var _a, _b, _c;
44
+ this.core = core;
45
+ this.store = options.store;
46
+ this.request = this.core.getPlugin("request");
47
+ if ((_a = options.initialState) == null ? void 0 : _a.holderMap) {
48
+ this.commitFormMap((0, import_lodash_es.cloneDeep)(options.initialState.holderMap));
49
+ Object.keys(this.store.holderMap).forEach((formId) => {
50
+ if (this.hasFormData(formId)) {
51
+ this.loadedFormIds.add(formId);
52
+ }
53
+ });
54
+ }
55
+ if (!this.store.holderMap || typeof this.store.holderMap !== "object") {
56
+ this.store.holderMap = {};
57
+ }
58
+ if ((_b = options.otherParams) == null ? void 0 : _b.cacheId) {
59
+ this.openCache = options.otherParams.openCache;
60
+ this.cacheId = options.otherParams.cacheId;
61
+ }
62
+ if ((_c = options.otherParams) == null ? void 0 : _c.fatherModule) {
63
+ this.fatherModule = options.otherParams.fatherModule;
64
+ }
65
+ }
66
+ /** 统一提交 formMap,仅此处触发 store changed */
67
+ commitFormMap(holderMap) {
68
+ this.store.holderMap = holderMap;
69
+ }
70
+ /** 通知 UI 刷新(数据未变但需要 re-read 的场景) */
71
+ notifyFormMapChanged() {
72
+ this.commitFormMap({ ...this.store.holderMap });
73
+ }
74
+ getHolderFormMap() {
75
+ return (0, import_lodash_es.cloneDeep)(this.store.holderMap);
76
+ }
77
+ getHolderFormData(formId) {
78
+ const formData = this.store.holderMap[(0, import_utils.normalizeFormId)(formId)];
79
+ return formData ? (0, import_lodash_es.cloneDeep)(formData) : void 0;
80
+ }
81
+ setFormData(formId, data) {
82
+ const key = (0, import_utils.normalizeFormId)(formId);
83
+ const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
84
+ this.commitFormMap({
85
+ ...this.store.holderMap,
86
+ [key]: {
87
+ records: data.records ?? current.records,
88
+ form: data.form ?? current.form
89
+ }
90
+ });
91
+ }
92
+ ensureFormItem(formId, holderMap = this.store.holderMap) {
93
+ const key = (0, import_utils.normalizeFormId)(formId);
94
+ if (!holderMap[key]) {
95
+ holderMap[key] = (0, import_utils.createEmptyFormItemData)();
96
+ }
97
+ return holderMap[key];
98
+ }
99
+ hasFormData(formId) {
100
+ const item = this.store.holderMap[formId];
101
+ return !!item && (Object.keys(item.form || {}).length > 0 || item.records.length > 0);
102
+ }
103
+ patchFormMap(holderMap, formId, patch) {
104
+ const current = this.ensureFormItem(formId, holderMap);
105
+ holderMap[formId] = {
106
+ records: patch.records ?? current.records,
107
+ form: patch.form ?? current.form
108
+ };
109
+ }
110
+ async fetchFormInfo(params) {
111
+ const { form_id } = params.query || {};
112
+ const url = params.url || `/form/${form_id}`;
113
+ const useCache = params.useCache !== false;
114
+ this.isLoading = true;
115
+ this.error = null;
116
+ try {
117
+ const res = await this.request.get(url, {}, { useCache });
118
+ const formData = res == null ? void 0 : res.data;
119
+ const formList = Array.isArray(formData == null ? void 0 : formData.list) ? formData.list : formData ? [formData] : [];
120
+ const nextFormMap = { ...this.store.holderMap };
121
+ formList.forEach((form) => {
122
+ const key = (0, import_utils.normalizeFormId)(form.form_id ?? form_id ?? form.id);
123
+ this.patchFormMap(nextFormMap, key, { form });
124
+ });
125
+ if (!formList.length && form_id !== void 0) {
126
+ const key = (0, import_utils.normalizeFormId)(form_id);
127
+ this.patchFormMap(nextFormMap, key, { form: formData || {} });
128
+ }
129
+ this.commitFormMap(nextFormMap);
130
+ return formList.length === 1 ? formList[0] : formList;
131
+ } catch (error) {
132
+ this.error = error instanceof Error ? error.message : String(error);
133
+ throw error;
134
+ } finally {
135
+ this.isLoading = false;
136
+ }
137
+ }
138
+ async fetchRecords(params) {
139
+ var _a;
140
+ const url = params.url || "/form/data/v1";
141
+ const { form_id, shop_id, num, skip, customer_id, ...rest } = params.query || {};
142
+ const formId = (0, import_utils.normalizeFormId)(form_id);
143
+ const useCache = params.useCache !== false;
144
+ this.isLoading = true;
145
+ this.error = null;
146
+ try {
147
+ const res = await this.request.get(
148
+ url,
149
+ {
150
+ customer_id,
151
+ form_id,
152
+ shop_id,
153
+ num: num || 100,
154
+ skip: skip || 1,
155
+ front_end_cache_id: useCache && this.cacheId,
156
+ ...rest
157
+ },
158
+ { useCache }
159
+ );
160
+ const records = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || [];
161
+ const nextFormMap = { ...this.store.holderMap };
162
+ this.patchFormMap(nextFormMap, formId, { records });
163
+ this.commitFormMap(nextFormMap);
164
+ return records;
165
+ } catch (error) {
166
+ this.error = error instanceof Error ? error.message : String(error);
167
+ throw error;
168
+ } finally {
169
+ this.isLoading = false;
170
+ }
171
+ }
172
+ async ensureFormData(params) {
173
+ const formId = (0, import_utils.normalizeFormId)(params.form_id);
174
+ const useCache = params.useCache !== false;
175
+ if (useCache && !params.forceRefresh && this.loadedFormIds.has(formId)) {
176
+ this.notifyFormMapChanged();
177
+ return this.ensureFormItem(formId);
178
+ }
179
+ const current = this.ensureFormItem(formId);
180
+ const tasks = [];
181
+ if (params.forceRefresh || !Object.keys(current.form || {}).length) {
182
+ tasks.push(
183
+ this.fetchFormInfo({
184
+ url: params.formInfoUrl,
185
+ query: {
186
+ form_id: params.form_id
187
+ },
188
+ useCache
189
+ })
190
+ );
191
+ }
192
+ if (params.forceRefresh || !current.records.length) {
193
+ tasks.push(
194
+ this.fetchRecords({
195
+ url: params.recordsUrl,
196
+ query: {
197
+ form_id: params.form_id,
198
+ shop_id: params.shop_id,
199
+ customer_id: params.customer_id
200
+ },
201
+ useCache
202
+ })
203
+ );
204
+ }
205
+ if (!tasks.length) {
206
+ this.notifyFormMapChanged();
207
+ } else {
208
+ await Promise.all(tasks);
209
+ }
210
+ this.loadedFormIds.add(formId);
211
+ return this.ensureFormItem(formId);
212
+ }
213
+ async ensureFormByProduct(params) {
214
+ const holderConfig = (0, import_utils.getProductHolderConfig)(params.product);
215
+ if (!holderConfig)
216
+ return null;
217
+ const formId = (0, import_utils.getFormIdFromHolderConfig)(holderConfig);
218
+ const shopId = params.shop_id ?? params.product.shop_id;
219
+ return this.ensureFormData({
220
+ form_id: formId,
221
+ shop_id: shopId,
222
+ customer_id: params.customer_id,
223
+ useCache: params.useCache,
224
+ skip: 1,
225
+ num: 100
226
+ });
227
+ }
228
+ async addFormRecord(params) {
229
+ const url = params.url || "/form/record";
230
+ const formId = (0, import_utils.normalizeFormId)(params.body.form_id);
231
+ this.isLoading = true;
232
+ this.error = null;
233
+ try {
234
+ await this.request.post(url, params.body);
235
+ const records = await this.fetchRecords({
236
+ query: {
237
+ form_id: params.body.form_id,
238
+ shop_id: params.body.shop_id,
239
+ customer_id: params.body.customer_id
240
+ },
241
+ useCache: false
242
+ });
243
+ this.loadedFormIds.add(formId);
244
+ return records[records.length - 1];
245
+ } catch (error) {
246
+ this.error = error instanceof Error ? error.message : String(error);
247
+ throw error;
248
+ } finally {
249
+ this.isLoading = false;
250
+ }
251
+ }
252
+ /**
253
+ * UI 层自行请求添加接口后,将返回记录合并到 holderMap 对应 form_id 的 records 中
254
+ */
255
+ appendFormRecord(params) {
256
+ let record = params.record;
257
+ if ((record == null ? void 0 : record.data) && record.form_record_id === void 0) {
258
+ record = record.data;
259
+ }
260
+ const normalizedRecord = (0, import_lodash_es.cloneDeep)(record);
261
+ const formId = (0, import_utils.normalizeFormId)(
262
+ params.form_id ?? normalizedRecord.form_id
263
+ );
264
+ if (!formId) {
265
+ throw new Error("[HolderModule] appendFormRecord: form_id is required");
266
+ }
267
+ if (!normalizedRecord.form_record_id) {
268
+ throw new Error(
269
+ "[HolderModule] appendFormRecord: form_record_id is required"
270
+ );
271
+ }
272
+ normalizedRecord.form_id = Number(formId) || normalizedRecord.form_id;
273
+ const nextFormMap = { ...this.store.holderMap };
274
+ const current = this.ensureFormItem(formId, nextFormMap);
275
+ const recordIndex = current.records.findIndex(
276
+ (item) => item.form_record_id === normalizedRecord.form_record_id
277
+ );
278
+ const records = recordIndex >= 0 ? current.records.map(
279
+ (item, index) => index === recordIndex ? { ...item, ...normalizedRecord } : item
280
+ ) : [...current.records, normalizedRecord];
281
+ this.patchFormMap(nextFormMap, formId, { records });
282
+ this.commitFormMap(nextFormMap);
283
+ this.loadedFormIds.add(formId);
284
+ return normalizedRecord;
285
+ }
286
+ removeFormRecord(formId, formRecordId) {
287
+ const key = (0, import_utils.normalizeFormId)(formId);
288
+ const current = this.store.holderMap[key] || (0, import_utils.createEmptyFormItemData)();
289
+ const nextFormMap = { ...this.store.holderMap };
290
+ this.patchFormMap(nextFormMap, key, {
291
+ records: current.records.filter(
292
+ (record) => record.form_record_id !== formRecordId
293
+ )
294
+ });
295
+ this.commitFormMap(nextFormMap);
296
+ }
297
+ clearFormData(formId) {
298
+ if (formId !== void 0) {
299
+ const key = (0, import_utils.normalizeFormId)(formId);
300
+ const nextFormMap = { ...this.store.holderMap };
301
+ delete nextFormMap[key];
302
+ this.loadedFormIds.delete(key);
303
+ this.commitFormMap(nextFormMap);
304
+ } else {
305
+ this.loadedFormIds.clear();
306
+ this.commitFormMap({});
307
+ }
308
+ }
309
+ storeChange(path) {
310
+ if (path !== "holderMap" && path !== void 0) {
311
+ return;
312
+ }
313
+ if (this.openCache) {
314
+ const store = (0, import_lodash_es.cloneDeep)(this.store);
315
+ this.checkSaveCache({
316
+ cacheId: this.cacheId,
317
+ fatherModule: this.fatherModule,
318
+ store,
319
+ cacheKey: ["holderMap"]
320
+ });
321
+ }
322
+ }
323
+ };
324
+ // Annotate the CommonJS export names for ESM import in node:
325
+ 0 && (module.exports = {
326
+ HolderModule,
327
+ ...require("./types"),
328
+ ...require("./utils")
329
+ });