@pisell/pisellos 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/core/index.d.ts +1 -0
  2. package/dist/core/index.js +7 -1
  3. package/dist/effects/index.d.ts +1 -1
  4. package/dist/effects/index.js +4 -5
  5. package/dist/modules/Account/index.d.ts +7 -1
  6. package/dist/modules/Account/index.js +67 -17
  7. package/dist/modules/Account/types.d.ts +2 -1
  8. package/dist/modules/AccountList/index.d.ts +18 -0
  9. package/dist/modules/AccountList/index.js +264 -0
  10. package/dist/modules/AccountList/types.d.ts +37 -0
  11. package/dist/modules/AccountList/types.js +17 -0
  12. package/dist/modules/BaseModule.js +1 -0
  13. package/dist/modules/Cart/index.d.ts +3 -1
  14. package/dist/modules/Cart/index.js +53 -12
  15. package/dist/modules/Cart/types.d.ts +3 -3
  16. package/dist/modules/Date/types.d.ts +2 -1
  17. package/dist/modules/Date/types.js +1 -0
  18. package/dist/modules/ProductList/index.d.ts +1 -1
  19. package/dist/modules/ProductList/index.js +20 -12
  20. package/dist/modules/Resource/index.d.ts +7 -5
  21. package/dist/modules/Resource/index.js +17 -20
  22. package/dist/modules/Resource/utils.d.ts +23 -0
  23. package/dist/modules/Resource/utils.js +28 -0
  24. package/dist/modules/Step/index.d.ts +19 -0
  25. package/dist/modules/Step/index.js +107 -0
  26. package/dist/modules/Step/tyeps.d.ts +18 -0
  27. package/dist/modules/Step/tyeps.js +1 -0
  28. package/dist/plugins/request.d.ts +1 -1
  29. package/dist/solution/BookingByStep/index.d.ts +29 -1
  30. package/dist/solution/BookingByStep/index.js +363 -12
  31. package/dist/solution/BookingByStep/types.d.ts +6 -2
  32. package/dist/solution/BookingByStep/types.js +29 -0
  33. package/dist/solution/BookingByStep/utils/resources.d.ts +61 -0
  34. package/dist/solution/BookingByStep/utils/resources.js +380 -0
  35. package/dist/solution/BuyTickets/index.js +1 -1
  36. package/dist/store/createStore.js +1 -1
  37. package/dist/types/index.d.ts +2 -1
  38. package/lib/core/index.d.ts +1 -0
  39. package/lib/core/index.js +5 -1
  40. package/lib/effects/index.d.ts +1 -1
  41. package/lib/effects/index.js +1 -2
  42. package/lib/modules/Account/index.d.ts +7 -1
  43. package/lib/modules/Account/index.js +34 -18
  44. package/lib/modules/Account/types.d.ts +2 -1
  45. package/lib/modules/AccountList/index.d.ts +18 -0
  46. package/lib/modules/AccountList/index.js +126 -0
  47. package/lib/modules/AccountList/types.d.ts +37 -0
  48. package/lib/modules/AccountList/types.js +33 -0
  49. package/lib/modules/BaseModule.js +1 -0
  50. package/lib/modules/Cart/index.d.ts +3 -1
  51. package/lib/modules/Cart/index.js +13 -3
  52. package/lib/modules/Cart/types.d.ts +3 -3
  53. package/lib/modules/Date/types.d.ts +2 -1
  54. package/lib/modules/Date/types.js +1 -0
  55. package/lib/modules/ProductList/index.d.ts +1 -1
  56. package/lib/modules/ProductList/index.js +8 -7
  57. package/lib/modules/Resource/index.d.ts +7 -5
  58. package/lib/modules/Resource/index.js +16 -20
  59. package/lib/modules/Resource/utils.d.ts +23 -0
  60. package/lib/modules/Resource/utils.js +39 -0
  61. package/lib/modules/Step/index.d.ts +19 -0
  62. package/lib/modules/Step/index.js +76 -0
  63. package/lib/modules/Step/tyeps.d.ts +18 -0
  64. package/lib/modules/Step/tyeps.js +17 -0
  65. package/lib/plugins/request.d.ts +1 -1
  66. package/lib/solution/BookingByStep/index.d.ts +29 -1
  67. package/lib/solution/BookingByStep/index.js +99 -5
  68. package/lib/solution/BookingByStep/types.d.ts +6 -2
  69. package/lib/solution/BookingByStep/types.js +33 -2
  70. package/lib/solution/BookingByStep/utils/resources.d.ts +61 -0
  71. package/lib/solution/BookingByStep/utils/resources.js +215 -0
  72. package/lib/solution/BuyTickets/index.js +1 -1
  73. package/lib/store/createStore.js +1 -1
  74. package/lib/types/index.d.ts +2 -1
  75. package/package.json +9 -8
@@ -0,0 +1,19 @@
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { IStep, IStepModuleAPI } from "./tyeps";
4
+ export declare class StepModule extends BaseModule implements Module, IStepModuleAPI {
5
+ protected defaultName: string;
6
+ protected defaultVersion: string;
7
+ private store;
8
+ constructor(name?: string, version?: string);
9
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
10
+ init(steps: IStep[]): void;
11
+ private setSteps;
12
+ private setCurrentStep;
13
+ getStepList(): IStep[];
14
+ getCurrentStep(): IStep;
15
+ getCurrentStepIndex(): number;
16
+ prevStep(): void;
17
+ nextStep(): void;
18
+ gotoStep(stepIndex: number): void;
19
+ }
@@ -0,0 +1,76 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Step/index.ts
20
+ var Step_exports = {};
21
+ __export(Step_exports, {
22
+ StepModule: () => StepModule
23
+ });
24
+ module.exports = __toCommonJS(Step_exports);
25
+ var import_BaseModule = require("../BaseModule");
26
+ var StepModule = class extends import_BaseModule.BaseModule {
27
+ constructor(name, version) {
28
+ super(name, version);
29
+ this.defaultName = "step";
30
+ this.defaultVersion = "1.0.0";
31
+ }
32
+ async initialize(core, options) {
33
+ this.core = core;
34
+ this.store = options.store;
35
+ }
36
+ init(steps) {
37
+ this.setSteps(steps);
38
+ this.setCurrentStep(0);
39
+ }
40
+ setSteps(stepList) {
41
+ this.store.stepList = stepList;
42
+ }
43
+ setCurrentStep(stepIndex) {
44
+ if (stepIndex < 0 || stepIndex >= this.store.stepList.length) {
45
+ return;
46
+ }
47
+ this.store.currentStepIndex = stepIndex;
48
+ this.store.currentStep = this.store.stepList[stepIndex];
49
+ }
50
+ getStepList() {
51
+ return this.store.stepList;
52
+ }
53
+ getCurrentStep() {
54
+ return this.store.currentStep;
55
+ }
56
+ getCurrentStepIndex() {
57
+ return this.store.currentStepIndex;
58
+ }
59
+ prevStep() {
60
+ if (this.store.currentStepIndex > 0) {
61
+ this.setCurrentStep(this.store.currentStepIndex - 1);
62
+ }
63
+ }
64
+ nextStep() {
65
+ if (this.store.currentStepIndex < this.store.stepList.length - 1) {
66
+ this.setCurrentStep(this.store.currentStepIndex + 1);
67
+ }
68
+ }
69
+ gotoStep(stepIndex) {
70
+ this.setCurrentStep(stepIndex);
71
+ }
72
+ };
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ StepModule
76
+ });
@@ -0,0 +1,18 @@
1
+ export interface IStepState {
2
+ stepList: IStep[];
3
+ currentStep: IStep;
4
+ currentStepIndex: number;
5
+ }
6
+ export interface IStep {
7
+ index: number;
8
+ key: string;
9
+ [key: string]: any;
10
+ }
11
+ export interface IStepModuleAPI {
12
+ getStepList: () => IStep[];
13
+ getCurrentStep: () => IStep;
14
+ getCurrentStepIndex: () => number;
15
+ nextStep: () => void;
16
+ prevStep: () => void;
17
+ gotoStep: (stepIndex: number) => void;
18
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/modules/Step/tyeps.ts
16
+ var tyeps_exports = {};
17
+ module.exports = __toCommonJS(tyeps_exports);
@@ -8,7 +8,7 @@ export interface RequestPlugin extends Plugin {
8
8
  * @param url 请求地址
9
9
  * @param options 请求选项
10
10
  */
11
- get: <T = any>(url: string, options?: RequestOptions) => Promise<T>;
11
+ get: <T = any>(url: string, data?: any, options?: RequestOptions) => Promise<T>;
12
12
  /**
13
13
  * 发起 POST 请求
14
14
  * @param url 请求地址
@@ -1,5 +1,8 @@
1
- import { Module, PisellCore } from '../../types';
1
+ import { Module, PisellCore } from "../../types";
2
2
  import { BaseModule } from "../../modules/BaseModule";
3
+ import { BookingByStepState } from "./types";
4
+ import { Account } from "../../modules/Account/types";
5
+ import { IStep } from "../../modules/Step/tyeps";
3
6
  export declare class BookingByStepImpl extends BaseModule implements Module {
4
7
  protected defaultName: string;
5
8
  protected defaultVersion: string;
@@ -9,4 +12,29 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
9
12
  private store;
10
13
  private otherParams;
11
14
  initialize(core: PisellCore, options: any): Promise<void>;
15
+ initStep(stepList: (keyof BookingByStepState)[]): void;
16
+ getCurrentStep(): {
17
+ index: number;
18
+ step: IStep;
19
+ };
20
+ next(): void;
21
+ getStoreCart(key?: string): Promise<any>;
22
+ loadProducts({ category_ids, product_ids }: {
23
+ category_ids?: number[];
24
+ product_ids?: number[];
25
+ }): Promise<void>;
26
+ storeProducts(productData: any[]): Promise<void>;
27
+ addAccount(accounts: Account[]): Promise<void>;
28
+ getAccounts(): Promise<import("../../modules/Account").AccountModule[]>;
29
+ setDateRange(dateRange: string[]): Promise<void>;
30
+ getRangeDate(): Promise<string>;
31
+ getAvailableDate(): Promise<void>;
32
+ getResourceTimeslot(): Promise<void>;
33
+ getProducts(): Promise<import("../../modules").ProductData[]>;
34
+ storeResources(resources: any[]): Promise<void>;
35
+ setLoginAccount(account: Account): Promise<void>;
36
+ generateCartData(): Promise<void>;
37
+ submitOrder(): Promise<void>;
38
+ pay(): Promise<void>;
39
+ getPayInfo(): Promise<void>;
12
40
  }
@@ -36,15 +36,109 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
36
36
  this.core = core;
37
37
  this.store = options.store || {};
38
38
  this.otherParams = options.otherParams || {};
39
- console.log("[BuyTickets] 初始化完成");
39
+ console.log("[BookingByStep] 初始化完成");
40
40
  this.request = core.getPlugin("request");
41
41
  this.window = core.getPlugin("window");
42
42
  if (!this.request) {
43
- throw new Error("tickets解决方案需要 request 插件支持");
43
+ throw new Error("bookingByStep解决方案需要 request 插件支持");
44
44
  }
45
- if (this.otherParams.prodctIds) {
46
- }
47
- await this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
45
+ const moduleArr = ["cart", "step", "products", "guests", "date", "accountList", "order", "payment"];
46
+ moduleArr.forEach((step) => {
47
+ const targetModule = (0, import_types.createModule)(step, this.name);
48
+ if (targetModule) {
49
+ this.store[step] = targetModule;
50
+ this.core.registerModule(targetModule);
51
+ } else {
52
+ throw new Error(`模块 ${step} 不存在`);
53
+ }
54
+ });
55
+ this.core.effects.emit(import_types.BookingByStepHooks.onInited, {});
56
+ }
57
+ // 初始化step
58
+ initStep(stepList) {
59
+ this.store.step.init(stepList);
60
+ }
61
+ getCurrentStep() {
62
+ return {
63
+ index: this.store.step.getCurrentStepIndex(),
64
+ step: this.store.step.getCurrentStep()
65
+ };
66
+ }
67
+ next() {
68
+ this.store.step.nextStep();
69
+ }
70
+ // 获取购物车里 temp.xxx的方法
71
+ async getStoreCart(key) {
72
+ return this.store.cart.getTemp(key);
73
+ }
74
+ // 加载商品,然后导到商品列表里去
75
+ async loadProducts({ category_ids, product_ids }) {
76
+ const productsData = await this.request.post(`${this.core.context.apiBasePath}/h5/product/query`, {
77
+ open_quotation: 1,
78
+ open_bundle: 1,
79
+ extension_type: ["product_appointment", "appointment_ticket"],
80
+ status: "published",
81
+ num: 500,
82
+ skip: 1,
83
+ category_ids,
84
+ ids: product_ids
85
+ });
86
+ this.store.products.addProduct(productsData.data.list);
87
+ }
88
+ // 往购物车里加一些商品/服务相关的选中数据
89
+ async storeProducts(productData) {
90
+ this.store.cart.storeTemp("products", productData);
91
+ }
92
+ // 添加账户或者 guest
93
+ async addAccount(accounts) {
94
+ accounts.forEach((account) => {
95
+ this.store.accountList.addAccount(account);
96
+ });
97
+ }
98
+ // 获取所有账户
99
+ async getAccounts() {
100
+ return this.store.accountList.getAccounts();
101
+ }
102
+ // 设置日期范围,注入到日期模块中
103
+ async setDateRange(dateRange) {
104
+ }
105
+ // 获取日期模块里选中的日期
106
+ async getRangeDate() {
107
+ return "2024-01-01";
108
+ }
109
+ // 获取商品/服务的可用日期
110
+ async getAvailableDate() {
111
+ const products = await this.getStoreCart("products");
112
+ console.log(products);
113
+ }
114
+ // 获取具体资源的可用时段
115
+ async getResourceTimeslot() {
116
+ }
117
+ // 获取可选择的商品、服务列表
118
+ async getProducts() {
119
+ return this.store.products.getProducts();
120
+ }
121
+ // 往购物车里加一些资源相关的选中数据
122
+ async storeResources(resources) {
123
+ this.store.cart.storeTemp("resources", resources);
124
+ }
125
+ // 如果用户登录
126
+ async setLoginAccount(account) {
127
+ const accounts = await this.getAccounts();
128
+ const mainAccount = accounts.find((n) => n.getLoginStatus());
129
+ mainAccount == null ? void 0 : mainAccount.setAccountInfo(account);
130
+ }
131
+ // 生成购物车的正规数据
132
+ async generateCartData() {
133
+ }
134
+ // 购物车提交订单
135
+ async submitOrder() {
136
+ }
137
+ // 拉起支付模块
138
+ async pay() {
139
+ }
140
+ // 获取支付信息
141
+ async getPayInfo() {
48
142
  }
49
143
  };
50
144
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,21 +1,25 @@
1
1
  import { ProductList, CartModule } from "../../modules";
2
2
  import { AccountModule } from "../../modules/Account";
3
+ import { AccountListModule } from "../../modules/AccountList";
3
4
  import { DateModule } from "../../modules/Date";
4
5
  import { GuestListModule } from "../../modules/Guests";
5
6
  import { OrderModule } from "../../modules/Order";
6
7
  import { PaymentModule } from "../../modules/Payment";
7
8
  import { ResourceListModule } from "../../modules/Resource";
9
+ import { StepModule } from "../../modules/Step";
8
10
  export interface BookingByStepState {
9
11
  cart: CartModule;
10
- currentStep: number;
12
+ step: StepModule;
11
13
  products: ProductList;
12
14
  guests: GuestListModule;
13
15
  date: DateModule;
14
- resources: ResourceListModule[];
16
+ resources?: ResourceListModule;
15
17
  account: AccountModule;
18
+ accountList: AccountListModule;
16
19
  order: OrderModule;
17
20
  payment: PaymentModule;
18
21
  }
22
+ export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
19
23
  export declare enum BookingByStepHooks {
20
24
  onInited = "bookingByStep:onInited",
21
25
  onDestroy = "bookingByStep:onDestroy",
@@ -19,9 +19,39 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/solution/BookingByStep/types.ts
20
20
  var types_exports = {};
21
21
  __export(types_exports, {
22
- BookingByStepHooks: () => BookingByStepHooks
22
+ BookingByStepHooks: () => BookingByStepHooks,
23
+ createModule: () => createModule
23
24
  });
24
25
  module.exports = __toCommonJS(types_exports);
26
+ var import_modules = require("../../modules");
27
+ var import_AccountList = require("../../modules/AccountList");
28
+ var import_Date = require("../../modules/Date");
29
+ var import_Guests = require("../../modules/Guests");
30
+ var import_Order = require("../../modules/Order");
31
+ var import_Payment = require("../../modules/Payment");
32
+ var import_Step = require("../../modules/Step");
33
+ function createModule(moduleName, solutionName, name, version) {
34
+ switch (moduleName) {
35
+ case "cart":
36
+ return new import_modules.CartModule(`${solutionName}_${name || moduleName}`, version);
37
+ case "step":
38
+ return new import_Step.StepModule(`${solutionName}_${name || moduleName}`, version);
39
+ case "products":
40
+ return new import_modules.ProductList(`${solutionName}_${name || moduleName}`, version);
41
+ case "guests":
42
+ return new import_Guests.GuestListModule(`${solutionName}_${name || moduleName}`, version);
43
+ case "date":
44
+ return new import_Date.DateModule(`${solutionName}_${name || moduleName}`, version);
45
+ case "accountList":
46
+ return new import_AccountList.AccountListModule(`${solutionName}_${name || moduleName}`, version);
47
+ case "order":
48
+ return new import_Order.OrderModule(`${solutionName}_${name || moduleName}`, version);
49
+ case "payment":
50
+ return new import_Payment.PaymentModule(`${solutionName}_${name || moduleName}`, version);
51
+ default:
52
+ throw new Error(`Unknown module type: ${moduleName}`);
53
+ }
54
+ }
25
55
  var BookingByStepHooks = /* @__PURE__ */ ((BookingByStepHooks2) => {
26
56
  BookingByStepHooks2["onInited"] = "bookingByStep:onInited";
27
57
  BookingByStepHooks2["onDestroy"] = "bookingByStep:onDestroy";
@@ -34,5 +64,6 @@ var BookingByStepHooks = /* @__PURE__ */ ((BookingByStepHooks2) => {
34
64
  })(BookingByStepHooks || {});
35
65
  // Annotate the CommonJS export names for ESM import in node:
36
66
  0 && (module.exports = {
37
- BookingByStepHooks
67
+ BookingByStepHooks,
68
+ createModule
38
69
  });
@@ -0,0 +1,61 @@
1
+ import { Dayjs } from 'dayjs';
2
+ /**
3
+ * 1. 获取资源列表
4
+ * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
5
+ * 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
6
+ *
7
+ */
8
+ type DateType = Dayjs | string;
9
+ interface TimeSliceItem {
10
+ start: DateType;
11
+ end: DateType;
12
+ start_at: DateType;
13
+ end_at: DateType;
14
+ [key: string]: any;
15
+ }
16
+ interface ResourceItem {
17
+ [key: string]: any;
18
+ }
19
+ interface BookingItem {
20
+ [key: string]: any;
21
+ }
22
+ interface ProductItem {
23
+ [key: string]: any;
24
+ }
25
+ /**
26
+ * @title: 获取商品下绑定的资源列表
27
+ * @description:
28
+ * @param {any} resourcesMap
29
+ * @param {any} product
30
+ * @return {*}
31
+ * @Author: zhiwei.Wang
32
+ */
33
+ export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, product: ProductItem) => any;
34
+ export declare const getSumCapacity: () => number;
35
+ /**
36
+ * @title: 获取资源列表
37
+ * @description:
38
+ * @return {*}
39
+ * @Author: zhiwei.Wang
40
+ * @Date: 2024-01-09 13:38
41
+ */
42
+ export declare const formatResources: ({ booking, resources }: {
43
+ booking: BookingItem;
44
+ resources: ResourceItem[];
45
+ }) => {
46
+ list: ResourceItem[];
47
+ maps: any;
48
+ };
49
+ /**
50
+ * @title: 获取资源的时间切片列表
51
+ * @description:
52
+ * @return {*}
53
+ * @Author: zhiwei.Wang
54
+ */
55
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate }: {
56
+ resource: ResourceItem;
57
+ duration: number;
58
+ split: number;
59
+ currentDate: DateType;
60
+ }) => TimeSliceItem[];
61
+ export {};
@@ -0,0 +1,215 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BookingByStep/utils/resources.ts
30
+ var resources_exports = {};
31
+ __export(resources_exports, {
32
+ formatResources: () => formatResources,
33
+ getResourcesByProduct: () => getResourcesByProduct,
34
+ getSumCapacity: () => getSumCapacity,
35
+ getTimeSlicesByResource: () => getTimeSlicesByResource
36
+ });
37
+ module.exports = __toCommonJS(resources_exports);
38
+ var import_dayjs = __toESM(require("dayjs"));
39
+ var getUseableEventCount = (eventList, current) => {
40
+ return (eventList || []).reduce((pre, event) => {
41
+ return pre - event.pax;
42
+ }, current || 0);
43
+ };
44
+ var isConflict = (event, current) => {
45
+ const eventStart = (0, import_dayjs.default)(event.start_at);
46
+ const eventEnd = (0, import_dayjs.default)(event.end_at);
47
+ const currentStart = (0, import_dayjs.default)(current.start_at);
48
+ const _isBefore = currentStart.isBefore(eventEnd);
49
+ let _isAfter = true;
50
+ if (current.end_at) {
51
+ const currentEnd = (0, import_dayjs.default)(current.end_at);
52
+ _isAfter = currentEnd.isAfter(eventStart);
53
+ }
54
+ return _isBefore && _isAfter;
55
+ };
56
+ var checkAfterToDay = (date, today = (0, import_dayjs.default)()) => {
57
+ return (0, import_dayjs.default)(date).isAfter((0, import_dayjs.default)(today));
58
+ };
59
+ var formatResource = (resourceItem, booking) => {
60
+ let _resourceItem = { ...resourceItem };
61
+ _resourceItem.timeSlices = getTimeSlicesByResource({
62
+ resource: _resourceItem,
63
+ duration: booking.duration,
64
+ split: 10,
65
+ currentDate: (0, import_dayjs.default)().format("YYYY-MM-DD")
66
+ });
67
+ _resourceItem.labelText = _resourceItem.main_field;
68
+ return _resourceItem;
69
+ };
70
+ var checkCapacity = ({ event_list, timeSlice, resource, currentCount = 1 }) => {
71
+ let conflict = (event_list || []).filter((d) => {
72
+ return isConflict({ start_at: d.start_at, end_at: d.end_at }, { start_at: timeSlice.start_at, end_at: timeSlice.end_at });
73
+ });
74
+ if (resource.resourceType === "single") {
75
+ if (conflict.length === 0) {
76
+ return true;
77
+ } else {
78
+ return false;
79
+ }
80
+ } else {
81
+ let conflictCount = getUseableEventCount(conflict, resource.capacity);
82
+ if (currentCount <= conflictCount) {
83
+ return true;
84
+ } else {
85
+ return false;
86
+ }
87
+ }
88
+ };
89
+ var getIsUsableByTimeItem = ({ timeSlice, time, resource, currentCount = 1 }) => {
90
+ let status = {
91
+ afterToDay: false,
92
+ capacity: false,
93
+ usable: false
94
+ };
95
+ let earliest = (0, import_dayjs.default)();
96
+ if (!checkAfterToDay(timeSlice.start_at, earliest)) {
97
+ return status;
98
+ }
99
+ status.afterToDay = true;
100
+ if (!checkCapacity({ event_list: time == null ? void 0 : time.event_list, timeSlice, resource, currentCount })) {
101
+ return status;
102
+ }
103
+ status.capacity = true;
104
+ status.usable = true;
105
+ return status;
106
+ };
107
+ var getResourcesByProduct = (resourcesMap, product) => {
108
+ var _a;
109
+ let _resources = (((_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) || []).filter((d) => d.status == 1);
110
+ for (let item of _resources) {
111
+ const form_id = item.id;
112
+ item.optional_resource = (item.optional_resource || []).filter(
113
+ (d) => item.default_resource.indexOf(d) == -1
114
+ );
115
+ let optional_resource = item.optional_resource.map(
116
+ (d) => (
117
+ // 合并数据, 将资源配置项添加到每一条内
118
+ resourcesMap[d] ? Object.assign({}, resourcesMap[d], {
119
+ form_id,
120
+ resourceType: item.type
121
+ }) : null
122
+ )
123
+ ).filter((d) => d);
124
+ let default_resource = item.default_resource.map((d) => {
125
+ let item2 = resourcesMap[d];
126
+ if (item2) {
127
+ item2.is_default = 1;
128
+ return Object.assign({}, item2, {
129
+ form_id,
130
+ resourceType: item2.type
131
+ });
132
+ } else {
133
+ return null;
134
+ }
135
+ }).filter((d) => d);
136
+ item.renderList = optional_resource.concat(default_resource);
137
+ item.form_id = form_id;
138
+ }
139
+ console.log("_resources", _resources);
140
+ return _resources;
141
+ };
142
+ var getSumCapacity = () => {
143
+ return 1;
144
+ };
145
+ var formatResources = ({ booking, resources }) => {
146
+ try {
147
+ let _list = [...resources];
148
+ let maps = {};
149
+ for (let item of _list) {
150
+ let renderListMaps = {};
151
+ item.renderList = item.renderList.map((d) => {
152
+ let res = formatResource(d, booking);
153
+ renderListMaps[res.id] = res;
154
+ return res;
155
+ }).sort((a, b) => b.usable ? 1 : -1);
156
+ maps[item.form_id] = {
157
+ ...item,
158
+ renderListMaps
159
+ };
160
+ }
161
+ return { list: _list, maps };
162
+ } catch (err) {
163
+ console.log("formatResourcesErr", err);
164
+ }
165
+ return {
166
+ list: [],
167
+ maps: {}
168
+ };
169
+ };
170
+ var getTimeSlicesByResource = ({
171
+ resource,
172
+ duration,
173
+ split = 10,
174
+ currentDate = (0, import_dayjs.default)()
175
+ }) => {
176
+ const { times } = resource;
177
+ const timeSlices = [];
178
+ times.forEach((time) => {
179
+ const today = (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD");
180
+ const startTime = (0, import_dayjs.default)(`${today} ${time.start_time}`);
181
+ const endTime = (0, import_dayjs.default)(`${today} ${time.end_time}`);
182
+ let currentStart = startTime;
183
+ while (true) {
184
+ const currentEnd = currentStart.add(duration, "minute");
185
+ if (currentEnd.isAfter(endTime)) {
186
+ break;
187
+ }
188
+ const timeSlice = {
189
+ start: currentStart.format("HH:mm"),
190
+ end: currentEnd.format("HH:mm"),
191
+ start_at: currentStart,
192
+ end_at: currentEnd
193
+ };
194
+ timeSlices.push({
195
+ ...timeSlice,
196
+ // 这里需要补充这个时间段内是否可预约
197
+ _status: getIsUsableByTimeItem({
198
+ timeSlice,
199
+ time,
200
+ resource,
201
+ currentCount: getSumCapacity()
202
+ })
203
+ });
204
+ currentStart = currentStart.add(split, "minute");
205
+ }
206
+ });
207
+ return timeSlices;
208
+ };
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ formatResources,
212
+ getResourcesByProduct,
213
+ getSumCapacity,
214
+ getTimeSlicesByResource
215
+ });
@@ -54,7 +54,7 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
54
54
  // 通过 ids 获取产品,在当前解决方案下,获取到的就是主商品
55
55
  async loadProductsByIds(ids) {
56
56
  const productsData = await this.request.post(
57
- `${this.core.context.apiBasePath}/shop/product/query`,
57
+ "/product/query",
58
58
  {
59
59
  ids,
60
60
  open_quotation: 1,
@@ -30,7 +30,7 @@ function createStore(initialState, moduleName, onChange) {
30
30
  },
31
31
  set(target, prop, value, receiver) {
32
32
  const result = Reflect.set(target, prop, value, receiver);
33
- onChange == null ? void 0 : onChange(`${moduleName}.${String(prop)}`, value);
33
+ onChange == null ? void 0 : onChange(`${String(prop)}`, value);
34
34
  return result;
35
35
  },
36
36
  deleteProperty(target, prop) {