@pisell/pisellos 0.0.10 → 0.0.11

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 (130) hide show
  1. package/dist/modules/Account/index.d.ts +4 -2
  2. package/dist/modules/Account/index.js +23 -36
  3. package/dist/modules/Account/types.d.ts +1 -0
  4. package/dist/modules/AccountList/index.d.ts +2 -0
  5. package/dist/modules/AccountList/index.js +34 -11
  6. package/dist/modules/Cart/index.d.ts +17 -11
  7. package/dist/modules/Cart/index.js +179 -121
  8. package/dist/modules/Cart/types.d.ts +98 -9
  9. package/dist/modules/Cart/types.js +8 -0
  10. package/dist/modules/Cart/utils.d.ts +114 -0
  11. package/dist/modules/Cart/utils.js +345 -0
  12. package/dist/modules/Date/index.d.ts +11 -12
  13. package/dist/modules/Date/index.js +104 -60
  14. package/dist/modules/Date/types.d.ts +51 -20
  15. package/dist/modules/Date/types.js +2 -5
  16. package/dist/modules/Date/utils.d.ts +35 -0
  17. package/dist/modules/Date/utils.js +211 -0
  18. package/dist/modules/Discount/index.d.ts +26 -0
  19. package/dist/modules/Discount/index.js +234 -0
  20. package/dist/modules/Discount/types.d.ts +66 -0
  21. package/dist/modules/Discount/types.js +5 -0
  22. package/dist/modules/Order/index.d.ts +16 -12
  23. package/dist/modules/Order/index.js +38 -166
  24. package/dist/modules/Order/types.d.ts +18 -41
  25. package/dist/modules/Order/types.js +0 -14
  26. package/dist/modules/Payment/index.d.ts +0 -2
  27. package/dist/modules/Payment/index.js +45 -76
  28. package/dist/modules/Payment/types.d.ts +0 -2
  29. package/dist/modules/Payment/types.js +2 -0
  30. package/dist/modules/Product/types.d.ts +48 -1
  31. package/dist/modules/ProductList/index.d.ts +1 -0
  32. package/dist/modules/ProductList/index.js +21 -1
  33. package/dist/modules/ProductList/types.d.ts +1 -0
  34. package/dist/modules/Resource/types.d.ts +6 -2
  35. package/dist/modules/Rules/index.d.ts +32 -0
  36. package/dist/modules/Rules/index.js +423 -0
  37. package/dist/modules/Rules/types.d.ts +46 -0
  38. package/dist/modules/Rules/types.js +5 -0
  39. package/dist/modules/Summary/index.d.ts +13 -0
  40. package/dist/modules/Summary/index.js +80 -0
  41. package/dist/modules/Summary/types.d.ts +13 -0
  42. package/dist/modules/Summary/types.js +1 -0
  43. package/dist/modules/Summary/utils.d.ts +19 -0
  44. package/dist/modules/Summary/utils.js +56 -0
  45. package/dist/plugins/index.d.ts +3 -2
  46. package/dist/plugins/index.js +2 -1
  47. package/dist/plugins/request.d.ts +4 -3
  48. package/dist/plugins/request.js +30 -30
  49. package/dist/plugins/shopStore.d.ts +4 -0
  50. package/dist/plugins/shopStore.js +1 -0
  51. package/dist/solution/BookingByStep/index.d.ts +73 -12
  52. package/dist/solution/BookingByStep/index.js +635 -99
  53. package/dist/solution/BookingByStep/types.d.ts +2 -0
  54. package/dist/solution/BookingByStep/types.js +11 -8
  55. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  56. package/dist/solution/BookingByStep/utils/products.js +47 -0
  57. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  58. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  59. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  60. package/dist/solution/ShopDiscount/index.js +546 -0
  61. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  62. package/dist/solution/ShopDiscount/types.js +10 -0
  63. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  64. package/dist/solution/ShopDiscount/utils.js +7 -0
  65. package/dist/solution/index.d.ts +1 -0
  66. package/dist/solution/index.js +2 -1
  67. package/lib/modules/Account/index.d.ts +4 -2
  68. package/lib/modules/Account/index.js +14 -3
  69. package/lib/modules/Account/types.d.ts +1 -0
  70. package/lib/modules/AccountList/index.d.ts +2 -0
  71. package/lib/modules/AccountList/index.js +17 -0
  72. package/lib/modules/Cart/index.d.ts +17 -11
  73. package/lib/modules/Cart/index.js +72 -21
  74. package/lib/modules/Cart/types.d.ts +98 -9
  75. package/lib/modules/Cart/utils.d.ts +114 -0
  76. package/lib/modules/Cart/utils.js +320 -0
  77. package/lib/modules/Date/index.d.ts +11 -12
  78. package/lib/modules/Date/index.js +50 -31
  79. package/lib/modules/Date/types.d.ts +51 -20
  80. package/lib/modules/Date/types.js +0 -4
  81. package/lib/modules/Date/utils.d.ts +35 -0
  82. package/lib/modules/Date/utils.js +167 -0
  83. package/lib/modules/Discount/index.d.ts +26 -0
  84. package/lib/modules/Discount/index.js +118 -0
  85. package/lib/modules/Discount/types.d.ts +66 -0
  86. package/lib/modules/Discount/types.js +33 -0
  87. package/lib/modules/Order/index.d.ts +16 -12
  88. package/lib/modules/Order/index.js +23 -51
  89. package/lib/modules/Order/types.d.ts +18 -41
  90. package/lib/modules/Payment/index.d.ts +0 -2
  91. package/lib/modules/Payment/index.js +6 -17
  92. package/lib/modules/Payment/types.d.ts +0 -2
  93. package/lib/modules/Product/types.d.ts +48 -1
  94. package/lib/modules/ProductList/index.d.ts +1 -0
  95. package/lib/modules/ProductList/index.js +4 -0
  96. package/lib/modules/ProductList/types.d.ts +1 -0
  97. package/lib/modules/Resource/types.d.ts +6 -2
  98. package/lib/modules/Rules/index.d.ts +32 -0
  99. package/lib/modules/Rules/index.js +283 -0
  100. package/lib/modules/Rules/types.d.ts +46 -0
  101. package/lib/modules/Rules/types.js +33 -0
  102. package/lib/modules/Summary/index.d.ts +13 -0
  103. package/lib/modules/Summary/index.js +49 -0
  104. package/lib/modules/Summary/types.d.ts +13 -0
  105. package/lib/modules/Summary/types.js +17 -0
  106. package/lib/modules/Summary/utils.d.ts +19 -0
  107. package/lib/modules/Summary/utils.js +79 -0
  108. package/lib/plugins/index.d.ts +3 -2
  109. package/lib/plugins/index.js +3 -1
  110. package/lib/plugins/request.d.ts +4 -3
  111. package/lib/plugins/request.js +4 -20
  112. package/lib/plugins/shopStore.d.ts +4 -0
  113. package/lib/plugins/shopStore.js +17 -0
  114. package/lib/solution/BookingByStep/index.d.ts +73 -12
  115. package/lib/solution/BookingByStep/index.js +451 -24
  116. package/lib/solution/BookingByStep/types.d.ts +2 -0
  117. package/lib/solution/BookingByStep/types.js +3 -0
  118. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  119. package/lib/solution/BookingByStep/utils/products.js +60 -0
  120. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  121. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  122. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  123. package/lib/solution/ShopDiscount/index.js +321 -0
  124. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  125. package/lib/solution/ShopDiscount/types.js +38 -0
  126. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  127. package/lib/solution/ShopDiscount/utils.js +32 -0
  128. package/lib/solution/index.d.ts +1 -0
  129. package/lib/solution/index.js +3 -1
  130. package/package.json +3 -3
@@ -1,4 +1,6 @@
1
- import { ProductData } from '../Product/types';
1
+ import { ProductData } from "../Product/types";
2
+ import { Account } from "../Account/types";
3
+ import { Resource } from "../Resource/types";
2
4
  export declare enum CartHooks {
3
5
  OnAddItem = "card:onAddItem",
4
6
  OnCartChange = "card:onCartChange",
@@ -9,16 +11,69 @@ export declare enum CartHooks {
9
11
  * 购物车商品接口
10
12
  */
11
13
  export interface CartItem {
12
- id: string;
13
- price: number;
14
- quantity: number;
15
- product: ProductData;
14
+ /** 购物车ID */
15
+ _id: string;
16
+ /** 商品ID */
17
+ id?: number;
18
+ /** 商品名称 */
19
+ name?: string;
20
+ /** 商品价格 */
21
+ price?: number | string;
22
+ /** 商品总价 */
23
+ total?: number | string;
24
+ /** 商品原价总价,排除原始价格为0的场景 */
25
+ origin_total?: number | string;
26
+ /** 商品数量 */
27
+ num?: number;
28
+ /** 商品图片 */
29
+ image?: string;
30
+ /** 商品时长 */
31
+ duration?: {
32
+ type: string;
33
+ value: number;
34
+ };
35
+ /** 是否显示备注 */
36
+ isShowNote?: boolean;
37
+ /** 备注 */
38
+ note?: string;
39
+ /** 点赞状态 */
40
+ like_status?: "like" | "common";
41
+ /** 用户名称 */
42
+ holder_title?: string;
43
+ /** 用户ID */
44
+ holder_id?: number | string;
45
+ /** 符号 */
46
+ symbol?: string;
47
+ /** 开始日期 */
48
+ start_date?: string;
49
+ /** 开始时间 */
50
+ start_time?: string;
51
+ /** 结束日期 */
52
+ end_date?: string;
53
+ /** 结束时间 */
54
+ end_time?: string;
55
+ /** 是否收取税费 */
56
+ is_charge_tax?: number;
57
+ /** 商品套餐信息 */
58
+ bundle?: any[];
59
+ /** 商品规格信息 */
60
+ options?: any[];
61
+ /** 是否为普通商品 */
62
+ isNormalProduct?: boolean;
63
+ /** 资源ID */
64
+ resource_id?: string | number;
65
+ /** 资源名称 */
66
+ relation_form_name?: string;
67
+ /** 原始数据 */
68
+ _origin: any;
69
+ /** 商品原始数据 */
70
+ _productOrigin: ProductData;
16
71
  }
17
72
  /**
18
73
  * 购物车状态接口
19
74
  */
20
75
  export interface CartState {
21
- list: any[];
76
+ list: CartItem[];
22
77
  total: number;
23
78
  temp: Record<string, any>;
24
79
  }
@@ -26,10 +81,44 @@ export interface CartState {
26
81
  * 购物车模块 API
27
82
  */
28
83
  export interface CartModuleAPI {
29
- addItem: (item: CartItem) => Promise<void>;
84
+ addItem: (item: IAddItemParams) => Promise<void>;
30
85
  getItemCount: () => number;
31
86
  getTotalPrice: () => number;
32
- getItems: () => Promise<CartItem[]>;
33
- updateItem: (id: string, item: CartItem) => Promise<void>;
87
+ getItems: () => CartItem[];
88
+ updateItem: (params: IUpdateItemParams) => Promise<void>;
34
89
  removeItem: (id: string) => Promise<void>;
35
90
  }
91
+ /**
92
+ * 添加商品到购物车参数
93
+ */
94
+ export interface IAddItemParams {
95
+ /** 账户 */
96
+ account: Account;
97
+ /** 商品 */
98
+ product: ProductData;
99
+ /** 数量 */
100
+ quantity?: number;
101
+ /** 商品套餐信息 */
102
+ bundle?: any[];
103
+ /** 商品规格信息 */
104
+ options?: any[];
105
+ }
106
+ /**
107
+ * 更新购物车信息参数
108
+ */
109
+ export interface IUpdateItemParams {
110
+ /** 购物车_id字段 */
111
+ _id?: string;
112
+ /** 购物车商品 */
113
+ cartItem?: CartItem;
114
+ /** 账户 */
115
+ account?: Account;
116
+ /** 商品 */
117
+ product?: ProductData;
118
+ /** 数量 */
119
+ quantity?: number;
120
+ /** 资源 */
121
+ resources?: Resource[];
122
+ /** 备注 */
123
+ note?: string;
124
+ }
@@ -16,4 +16,12 @@ export var CartHooks = /*#__PURE__*/function (CartHooks) {
16
16
 
17
17
  /**
18
18
  * 购物车模块 API
19
+ */
20
+
21
+ /**
22
+ * 添加商品到购物车参数
23
+ */
24
+
25
+ /**
26
+ * 更新购物车信息参数
19
27
  */
@@ -0,0 +1,114 @@
1
+ import { Account } from "../Account";
2
+ import { ProductData } from "../Product/types";
3
+ import { Resource } from "../Resource/types";
4
+ import { CartItem } from "./types";
5
+ /**
6
+ * 生成一个唯一的 ID
7
+ */
8
+ export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ /**
10
+ * 创建购物车原始数据
11
+ */
12
+ export declare const createCartItemOrigin: () => {
13
+ id: number;
14
+ number: number;
15
+ registration_type: string;
16
+ relation_products: never[];
17
+ is_all: boolean;
18
+ product: null;
19
+ sub_type: null;
20
+ duration: null;
21
+ like_status: string;
22
+ relation_type: string;
23
+ resources: null;
24
+ schedule_id: number;
25
+ start_date: null;
26
+ start_time: null;
27
+ select_date: null;
28
+ end_time: null;
29
+ end_date: null;
30
+ metadata: {};
31
+ };
32
+ /**
33
+ * 格式化商品到购物车
34
+ * @param product 商品
35
+ * @returns 格式化后的商品
36
+ */
37
+ export declare const formatProductToCartItem: (params: {
38
+ cartItem: CartItem;
39
+ product: ProductData;
40
+ bundle?: any;
41
+ options?: any;
42
+ }) => CartItem;
43
+ export declare const formatProductToCartItemOrigin: (params: {
44
+ cartItem: CartItem;
45
+ product: ProductData;
46
+ bundle?: any;
47
+ options?: any;
48
+ }) => any;
49
+ /**
50
+ * 格式化账户到购物车
51
+ * @param account 账户
52
+ * @returns 格式化后的账户
53
+ */
54
+ export declare const formatAccountToCartItem: (params: {
55
+ cartItem: CartItem;
56
+ account: Account;
57
+ }) => CartItem;
58
+ export declare const formatAccountToCartItemOrigin: (params: {
59
+ cartItem: CartItem;
60
+ account: Account;
61
+ }) => any;
62
+ /**
63
+ * 格式化资源到购物车
64
+ * @param resource 资源
65
+ * @returns 格式化后的资源
66
+ */
67
+ export declare const formatResourceToCartItem: (params: {
68
+ cartItem: CartItem;
69
+ resources: Resource[];
70
+ }) => CartItem;
71
+ export declare const formatResourceToCartItemOrigin: (params: {
72
+ cartItem: CartItem;
73
+ resources: Resource[];
74
+ }) => any;
75
+ /**
76
+ * 格式化套餐规格信息
77
+ * @param options 套餐规格信息
78
+ * @returns 格式化后的套餐规格信息
79
+ */
80
+ export declare const formatOptions: (options: any) => any;
81
+ export declare const formatOptionsToOrigin: (options: any) => any;
82
+ /**
83
+ * 格式化商品套餐信息
84
+ * @param bundle 商品套餐信息
85
+ * @returns 格式化后的商品套餐信息
86
+ */
87
+ export declare const formatBundle: (bundle: any) => any;
88
+ export declare const formatBundleToOrigin: (bundle: any) => any;
89
+ /**
90
+ * 判断是否是普通商品
91
+ * @param product 商品
92
+ * @returns 是否是普通商品
93
+ */
94
+ export declare const isNormalProduct: (product: any) => boolean;
95
+ /**
96
+ * 获取商品总价
97
+ * @param item 商品
98
+ * @returns 商品总价
99
+ */
100
+ export declare const getProductTotalPrice: (params: {
101
+ product: ProductData;
102
+ bundle?: any;
103
+ options?: any;
104
+ }) => number;
105
+ /**
106
+ * 获取商品原始总价
107
+ * @param item 商品
108
+ * @returns 商品原始总价
109
+ */
110
+ export declare const getProductOriginTotalPrice: (params: {
111
+ product: ProductData;
112
+ bundle?: any;
113
+ options?: any;
114
+ }) => number | undefined;
@@ -0,0 +1,345 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import dayjs from "dayjs";
8
+ /**
9
+ * 生成一个唯一的 ID
10
+ */
11
+ export var getUniqueId = function getUniqueId() {
12
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
13
+ var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
14
+ return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
15
+ };
16
+
17
+ /**
18
+ * 创建购物车原始数据
19
+ */
20
+ export var createCartItemOrigin = function createCartItemOrigin() {
21
+ return {
22
+ // 新增为0
23
+ id: 0,
24
+ // 数量 固定为1
25
+ number: 1,
26
+ // 客户端报名所有活动;
27
+ registration_type: "all",
28
+ // 暂时不用
29
+ relation_products: [],
30
+ // 固定
31
+ is_all: false,
32
+ // 商品相关
33
+ product: null,
34
+ // 时长类型
35
+ sub_type: null,
36
+ // 时长
37
+ duration: null,
38
+ // 资源相关
39
+ // 资源状态 -固定
40
+ like_status: "common",
41
+ // 资源类型 - 固定
42
+ relation_type: "form",
43
+ // 所选资源
44
+ resources: null,
45
+ // 日程id - 固定
46
+ schedule_id: 0,
47
+ // 所选开始时间
48
+ start_date: null,
49
+ // 所选开始时间
50
+ start_time: null,
51
+ // 所选开始时间
52
+ select_date: null,
53
+ // 所选结束时间
54
+ end_time: null,
55
+ // 所选结束时间
56
+ end_date: null,
57
+ // 额外信息
58
+ metadata: {}
59
+
60
+ // holder相关
61
+ // holder: null,
62
+ };
63
+ };
64
+
65
+ /**
66
+ * 格式化商品到购物车
67
+ * @param product 商品
68
+ * @returns 格式化后的商品
69
+ */
70
+ export var formatProductToCartItem = function formatProductToCartItem(params) {
71
+ var cartItem = params.cartItem,
72
+ product = params.product,
73
+ bundle = params.bundle,
74
+ options = params.options;
75
+ if (product) {
76
+ cartItem.id = product === null || product === void 0 ? void 0 : product.id;
77
+ cartItem.name = product === null || product === void 0 ? void 0 : product.title;
78
+ cartItem.price = product === null || product === void 0 ? void 0 : product.price;
79
+ cartItem.total = getProductTotalPrice({
80
+ product: product,
81
+ bundle: bundle,
82
+ options: options
83
+ });
84
+ cartItem.origin_total = getProductOriginTotalPrice({
85
+ product: product,
86
+ bundle: bundle,
87
+ options: options
88
+ });
89
+ cartItem.num = 1;
90
+ cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
91
+ cartItem.like_status = "common";
92
+ cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
93
+ cartItem.isNormalProduct = isNormalProduct(product);
94
+ cartItem.is_charge_tax = product === null || product === void 0 ? void 0 : product.is_charge_tax;
95
+ }
96
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
97
+ cartItem.bundle = formatBundle(bundle);
98
+ }
99
+ if (options !== null && options !== void 0 && options.length) {
100
+ cartItem.options = formatOptions(options);
101
+ }
102
+ var oringin = formatProductToCartItemOrigin(params);
103
+ cartItem._origin = oringin;
104
+ return cartItem;
105
+ };
106
+ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigin(params) {
107
+ var cartItem = params.cartItem,
108
+ product = params.product,
109
+ bundle = params.bundle,
110
+ options = params.options;
111
+ var origin = cartItem._origin;
112
+ if (product) {
113
+ var _origin$product, _origin$product2, _product$duration, _product$duration2;
114
+ origin.product = _objectSpread(_objectSpread({}, origin.product || {}), {}, {
115
+ num: 1,
116
+ product_id: product.id,
117
+ product_variant_id: (product === null || product === void 0 ? void 0 : product.product_variant_id) || 0,
118
+ product_bundle: ((_origin$product = origin.product) === null || _origin$product === void 0 ? void 0 : _origin$product.product_bundle) || [],
119
+ product_option_item: ((_origin$product2 = origin.product) === null || _origin$product2 === void 0 ? void 0 : _origin$product2.product_option_item) || []
120
+ });
121
+ // 时长类型
122
+ origin.sub_type = product === null || product === void 0 || (_product$duration = product.duration) === null || _product$duration === void 0 ? void 0 : _product$duration.type;
123
+ // 时长
124
+ origin.duration = product === null || product === void 0 || (_product$duration2 = product.duration) === null || _product$duration2 === void 0 ? void 0 : _product$duration2.value;
125
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
126
+ origin.product.product_bundle = formatBundleToOrigin(bundle);
127
+ }
128
+ if (options !== null && options !== void 0 && options.length) {
129
+ origin.product.product_option_item = formatOptionsToOrigin(options);
130
+ }
131
+ }
132
+ return origin;
133
+ };
134
+
135
+ /**
136
+ * 格式化账户到购物车
137
+ * @param account 账户
138
+ * @returns 格式化后的账户
139
+ */
140
+ export var formatAccountToCartItem = function formatAccountToCartItem(params) {
141
+ var cartItem = params.cartItem,
142
+ account = params.account;
143
+ if (account) {
144
+ cartItem.holder_id = account.id;
145
+ cartItem.holder_title = account.username;
146
+ }
147
+ var oringin = formatAccountToCartItemOrigin(params);
148
+ cartItem._origin = oringin;
149
+ return cartItem;
150
+ };
151
+ export var formatAccountToCartItemOrigin = function formatAccountToCartItemOrigin(params) {
152
+ var cartItem = params.cartItem,
153
+ account = params.account;
154
+ var origin = cartItem._origin;
155
+ if (account) {
156
+ origin.metadata.account = account;
157
+ }
158
+ return origin;
159
+ };
160
+
161
+ /**
162
+ * 格式化资源到购物车
163
+ * @param resource 资源
164
+ * @returns 格式化后的资源
165
+ */
166
+ export var formatResourceToCartItem = function formatResourceToCartItem(params) {
167
+ var cartItem = params.cartItem,
168
+ resources = params.resources;
169
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
170
+ var firstResource = resources[0];
171
+ cartItem.resource_id = firstResource === null || firstResource === void 0 ? void 0 : firstResource.id;
172
+ cartItem.relation_form_name = firstResource === null || firstResource === void 0 ? void 0 : firstResource.main_field;
173
+ if (firstResource.startTime && firstResource.endTime) {
174
+ cartItem.start_date = dayjs(firstResource.startTime).format("YYYY-MM-DD");
175
+ cartItem.start_time = dayjs(firstResource.startTime).format("HH:mm");
176
+ cartItem.end_date = dayjs(firstResource.endTime).format("YYYY-MM-DD");
177
+ cartItem.end_time = dayjs(firstResource.endTime).format("HH:mm");
178
+ }
179
+ }
180
+ var oringin = formatResourceToCartItemOrigin(params);
181
+ cartItem._origin = oringin;
182
+ return cartItem;
183
+ };
184
+ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOrigin(params) {
185
+ var cartItem = params.cartItem,
186
+ resources = params.resources;
187
+ var origin = cartItem._origin;
188
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
189
+ origin.resources = [];
190
+ // 接口只需要部分字段,需要处理
191
+ resources.forEach(function (resource) {
192
+ origin.resources.push({
193
+ relation_type: "form",
194
+ like_status: "common",
195
+ id: resource.id,
196
+ main_field: resource.main_field,
197
+ resourceType: resource.resourceType,
198
+ form_id: resource.form_id,
199
+ relation_id: resource.id,
200
+ capacity: (resource === null || resource === void 0 ? void 0 : resource.capacity) || 0
201
+ });
202
+ });
203
+ var _resources$ = resources[0],
204
+ startTime = _resources$.startTime,
205
+ endTime = _resources$.endTime;
206
+ if (startTime && endTime) {
207
+ origin.select_date = dayjs(startTime).format("YYYY-MM-DD");
208
+ origin.start_date = dayjs(startTime).format("YYYY-MM-DD");
209
+ origin.start_time = dayjs(startTime).format("HH:mm");
210
+ origin.end_date = dayjs(endTime).format("YYYY-MM-DD");
211
+ origin.end_time = dayjs(endTime).format("HH:mm");
212
+ }
213
+ }
214
+ return origin;
215
+ };
216
+
217
+ /**
218
+ * 格式化套餐规格信息
219
+ * @param options 套餐规格信息
220
+ * @returns 格式化后的套餐规格信息
221
+ */
222
+ export var formatOptions = function formatOptions(options) {
223
+ if (!(options !== null && options !== void 0 && options.length)) return [];
224
+ return options.map(function (item) {
225
+ return {
226
+ id: item === null || item === void 0 ? void 0 : item.id,
227
+ name: item === null || item === void 0 ? void 0 : item.name,
228
+ num: item === null || item === void 0 ? void 0 : item.num,
229
+ price: item === null || item === void 0 ? void 0 : item.price,
230
+ total: item === null || item === void 0 ? void 0 : item.price,
231
+ origin_total: item === null || item === void 0 ? void 0 : item.original_price
232
+ };
233
+ });
234
+ };
235
+ export var formatOptionsToOrigin = function formatOptionsToOrigin(options) {
236
+ if (!(options !== null && options !== void 0 && options.length)) {
237
+ return [];
238
+ }
239
+ return options.map(function (d) {
240
+ return {
241
+ num: d.num,
242
+ option_group_item_id: d.product_option_item_id,
243
+ option_group_id: d.option_group_id
244
+ };
245
+ });
246
+ };
247
+
248
+ /**
249
+ * 格式化商品套餐信息
250
+ * @param bundle 商品套餐信息
251
+ * @returns 格式化后的商品套餐信息
252
+ */
253
+ export var formatBundle = function formatBundle(bundle) {
254
+ if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
255
+ return bundle.map(function (item) {
256
+ return {
257
+ id: item === null || item === void 0 ? void 0 : item.id,
258
+ title: item === null || item === void 0 ? void 0 : item.title,
259
+ num: item === null || item === void 0 ? void 0 : item.num,
260
+ price: item === null || item === void 0 ? void 0 : item.price,
261
+ total: item === null || item === void 0 ? void 0 : item.price,
262
+ price_type: item === null || item === void 0 ? void 0 : item.price_type,
263
+ bundle_sum_price: item === null || item === void 0 ? void 0 : item.bundle_sum_price,
264
+ bundle_sum_type: item === null || item === void 0 ? void 0 : item.bundle_sum_type,
265
+ options: formatOptions(item === null || item === void 0 ? void 0 : item.option)
266
+ };
267
+ });
268
+ };
269
+ export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
270
+ if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
271
+ return bundle.map(function (d) {
272
+ return {
273
+ bundle_group_id: d.group_id,
274
+ bundle_id: d.id,
275
+ bundle_product_id: (d === null || d === void 0 ? void 0 : d._bundle_product_id) || (d === null || d === void 0 ? void 0 : d.product_id),
276
+ bundle_variant_id: d.bundle_variant_id,
277
+ num: d.num,
278
+ extension_id: d.extension_id,
279
+ extension_type: d.extension_type,
280
+ option: formatOptionsToOrigin(d.option)
281
+ };
282
+ });
283
+ };
284
+
285
+ /**
286
+ * 判断是否是普通商品
287
+ * @param product 商品
288
+ * @returns 是否是普通商品
289
+ */
290
+ export var isNormalProduct = function isNormalProduct(product) {
291
+ return (product === null || product === void 0 ? void 0 : product.extension_type) !== "product_appointment";
292
+ };
293
+
294
+ /**
295
+ * 获取商品总价
296
+ * @param item 商品
297
+ * @returns 商品总价
298
+ */
299
+ export var getProductTotalPrice = function getProductTotalPrice(params) {
300
+ var product = params.product,
301
+ bundle = params.bundle,
302
+ options = params.options;
303
+ var price = Number(product.price);
304
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
305
+ price = bundle.reduce(function (accumulator, currentValue) {
306
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
307
+ }, price);
308
+ }
309
+
310
+ // 单规格
311
+ if (options !== null && options !== void 0 && options.length) {
312
+ price = options.reduce(function (accumulator, currentValue) {
313
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
314
+ }, price);
315
+ }
316
+ return price;
317
+ };
318
+
319
+ /**
320
+ * 获取商品原始总价
321
+ * @param item 商品
322
+ * @returns 商品原始总价
323
+ */
324
+ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(params) {
325
+ var product = params.product,
326
+ bundle = params.bundle,
327
+ options = params.options;
328
+ var price = Number(product.original_price);
329
+ if (isNaN(price) || price === 0) {
330
+ return undefined;
331
+ }
332
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
333
+ price = bundle.reduce(function (accumulator, currentValue) {
334
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
335
+ }, price);
336
+ }
337
+
338
+ // 单规格
339
+ if (options !== null && options !== void 0 && options.length) {
340
+ price = options.reduce(function (accumulator, currentValue) {
341
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
342
+ }, price);
343
+ }
344
+ return price;
345
+ };
@@ -1,17 +1,16 @@
1
- import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { TimeSlot, DateModuleAPI } from './types';
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { DateModuleAPI, IGetAvailableTimeListParams, ITime } from "./types";
4
4
  export declare class DateModule extends BaseModule implements Module, DateModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
- private state;
7
+ private store;
8
+ private request;
8
9
  constructor(name?: string, version?: string);
9
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
10
- setDate(date: Date): Promise<void>;
11
- setTimeSlot(timeSlot: TimeSlot): Promise<void>;
12
- getSelectedDate(): Date | null;
13
- getSelectedTimeSlot(): TimeSlot | null;
14
- getAvailableTimeSlots(): TimeSlot[];
15
- isDateAvailable(date: Date): boolean;
16
- isTimeSlotAvailable(timeSlot: TimeSlot): boolean;
10
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
11
+ setDateRange(dateRange: ITime[]): void;
12
+ getDateRange(): ITime[];
13
+ getMonthDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
14
+ getDateList(): Promise<ITime[]>;
15
+ getAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
16
  }