@pisell/pisellos 3.0.35 → 3.0.36

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 (49) hide show
  1. package/dist/modules/Cart/index.js +20 -34
  2. package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
  3. package/dist/modules/Cart/utils/cartAccount.js +52 -0
  4. package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
  5. package/dist/modules/Cart/utils/cartDate.js +55 -0
  6. package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
  7. package/dist/modules/Cart/utils/cartDiscount.js +35 -0
  8. package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
  9. package/dist/modules/Cart/utils/cartNote.js +29 -0
  10. package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
  11. package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
  12. package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  13. package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
  14. package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
  15. package/dist/modules/Cart/utils/cartResource.js +102 -0
  16. package/dist/modules/Cart/utils/index.d.ts +34 -0
  17. package/dist/modules/Cart/utils/index.js +63 -0
  18. package/dist/modules/Order/index.js +10 -4
  19. package/dist/modules/Product/types.d.ts +4 -0
  20. package/dist/modules/Product/utils.d.ts +17 -0
  21. package/dist/modules/Product/utils.js +41 -0
  22. package/dist/solution/BookingByStep/index.d.ts +8 -1
  23. package/dist/solution/BookingByStep/index.js +182 -63
  24. package/lib/modules/Cart/index.js +16 -24
  25. package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
  26. package/lib/modules/Cart/utils/cartAccount.js +65 -0
  27. package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
  28. package/lib/modules/Cart/utils/cartDate.js +75 -0
  29. package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
  30. package/lib/modules/Cart/utils/cartDiscount.js +52 -0
  31. package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
  32. package/lib/modules/Cart/utils/cartNote.js +46 -0
  33. package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
  34. package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
  35. package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
  36. package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
  37. package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
  38. package/lib/modules/Cart/utils/cartResource.js +124 -0
  39. package/lib/modules/Cart/utils/index.d.ts +34 -0
  40. package/lib/modules/Cart/utils/index.js +91 -0
  41. package/lib/modules/Order/index.js +7 -3
  42. package/lib/modules/Product/types.d.ts +4 -0
  43. package/lib/modules/Product/utils.d.ts +17 -0
  44. package/lib/modules/Product/utils.js +46 -0
  45. package/lib/solution/BookingByStep/index.d.ts +8 -1
  46. package/lib/solution/BookingByStep/index.js +106 -40
  47. package/package.json +1 -1
  48. package/dist/modules/Cart/utils.d.ts +0 -257
  49. package/lib/modules/Cart/utils.d.ts +0 -257
@@ -0,0 +1,102 @@
1
+ import dayjs from 'dayjs';
2
+ /**
3
+ * 格式化资源到购物车
4
+ * @param resource 资源
5
+ * @returns 格式化后的资源
6
+ */
7
+ export var formatResourceToCartItem = function formatResourceToCartItem(params) {
8
+ var cartItem = params.cartItem,
9
+ resources = params.resources;
10
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
11
+ var firstResource = resources[0];
12
+ cartItem.resource_id = firstResource === null || firstResource === void 0 ? void 0 : firstResource.id;
13
+ cartItem.relation_form_name = firstResource === null || firstResource === void 0 ? void 0 : firstResource.main_field;
14
+ if (firstResource.startTime && firstResource.endTime) {
15
+ cartItem.start_date = dayjs(firstResource.startTime).format('YYYY-MM-DD');
16
+ cartItem.start_time = dayjs(firstResource.startTime).format('HH:mm');
17
+ cartItem.end_date = dayjs(firstResource.endTime).format('YYYY-MM-DD');
18
+ cartItem.end_time = dayjs(firstResource.endTime).format('HH:mm');
19
+ }
20
+ } else {
21
+ cartItem.resource_id = undefined;
22
+ cartItem.relation_form_name = undefined;
23
+ cartItem.start_date = undefined;
24
+ cartItem.start_time = undefined;
25
+ cartItem.end_date = undefined;
26
+ cartItem.end_time = undefined;
27
+ }
28
+ var oringin = formatResourceToCartItemOrigin(params);
29
+ cartItem._origin = oringin;
30
+ cartItem._resourceOrigin = resources;
31
+ return cartItem;
32
+ };
33
+ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOrigin(params) {
34
+ var cartItem = params.cartItem,
35
+ resources = params.resources;
36
+ var origin = cartItem._origin;
37
+ if (resources && resources !== null && resources !== void 0 && resources.length) {
38
+ origin.resources = [];
39
+ // 接口只需要部分字段,需要处理
40
+ var checkResourcesFormat = function checkResourcesFormat(resources, arr) {
41
+ resources.forEach(function (resource) {
42
+ var _resource$children;
43
+ var childArr = [];
44
+ if (resource !== null && resource !== void 0 && (_resource$children = resource.children) !== null && _resource$children !== void 0 && _resource$children.length) {
45
+ checkResourcesFormat(resource.children, childArr);
46
+ }
47
+ var obj = {
48
+ relation_type: 'form',
49
+ like_status: 'common',
50
+ id: resource.id,
51
+ main_field: resource.main_field,
52
+ resourceType: resource.resourceType,
53
+ form_id: resource.form_id,
54
+ relation_id: resource.id,
55
+ capacity: (resource === null || resource === void 0 ? void 0 : resource.capacity) || 0,
56
+ metadata: (resource === null || resource === void 0 ? void 0 : resource.metadata) || {} // 后端可以在这里挂一个前端用于计算的数据
57
+ };
58
+ if (childArr.length) {
59
+ obj.children = childArr;
60
+ }
61
+ arr.push(obj);
62
+ });
63
+ };
64
+ checkResourcesFormat(resources, origin.resources);
65
+ var _resources$ = resources[0],
66
+ startTime = _resources$.startTime,
67
+ endTime = _resources$.endTime;
68
+ if (startTime && endTime) {
69
+ origin.select_date = dayjs(startTime).format('YYYY-MM-DD');
70
+ origin.start_date = dayjs(startTime).format('YYYY-MM-DD');
71
+ origin.start_time = dayjs(startTime).format('HH:mm');
72
+ origin.end_date = dayjs(endTime).format('YYYY-MM-DD');
73
+ origin.end_time = dayjs(endTime).format('HH:mm');
74
+ }
75
+ } else if ((resources === null || resources === void 0 ? void 0 : resources.length) === 0) {
76
+ origin.resources = [];
77
+ origin.select_date = null;
78
+ origin.start_date = null;
79
+ origin.start_time = null;
80
+ origin.end_date = null;
81
+ origin.end_time = null;
82
+ }
83
+ return origin;
84
+ };
85
+
86
+ /**
87
+ * 从购物车中删除资源相关信息
88
+ * @param cartItem 购物车
89
+ * @returns 删除后的购物车
90
+ */
91
+ export var deleteResourceFromCartItem = function deleteResourceFromCartItem(cartItem) {
92
+ // 删除UI层的数据
93
+ cartItem.resource_id = undefined;
94
+ cartItem.relation_form_name = undefined;
95
+
96
+ // 删除资源原始数据
97
+ delete cartItem._resourceOrigin;
98
+
99
+ // 删除原始数据
100
+ cartItem._origin.resources = null;
101
+ return cartItem;
102
+ };
@@ -0,0 +1,34 @@
1
+ export * from './cartAccount';
2
+ export * from './cartDate';
3
+ export * from './cartDiscount';
4
+ export * from './cartNote';
5
+ export * from './cartProduct';
6
+ export * from './cartRelationForms';
7
+ export * from './cartResource';
8
+ /**
9
+ * 生成一个唯一的 ID
10
+ */
11
+ export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
12
+ /**
13
+ * 创建购物车原始数据
14
+ */
15
+ export declare const createCartItemOrigin: () => {
16
+ id: number;
17
+ number: number;
18
+ registration_type: string;
19
+ relation_products: never[];
20
+ is_all: boolean;
21
+ product: null;
22
+ sub_type: null;
23
+ duration: null;
24
+ like_status: string;
25
+ resources: null;
26
+ schedule_id: number;
27
+ start_date: null;
28
+ start_time: null;
29
+ select_date: null;
30
+ end_time: null;
31
+ end_date: null;
32
+ metadata: {};
33
+ holder: null;
34
+ };
@@ -0,0 +1,63 @@
1
+ export * from "./cartAccount";
2
+ export * from "./cartDate";
3
+ export * from "./cartDiscount";
4
+ export * from "./cartNote";
5
+ export * from "./cartProduct";
6
+ export * from "./cartRelationForms";
7
+ export * from "./cartResource";
8
+
9
+ /**
10
+ * 生成一个唯一的 ID
11
+ */
12
+ export var getUniqueId = function getUniqueId() {
13
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
14
+ var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
15
+ return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
16
+ };
17
+
18
+ /**
19
+ * 创建购物车原始数据
20
+ */
21
+ export var createCartItemOrigin = function createCartItemOrigin() {
22
+ return {
23
+ // 新增为0
24
+ id: 0,
25
+ // 数量 固定为1
26
+ number: 1,
27
+ // 客户端报名所有活动;
28
+ registration_type: 'all',
29
+ // 暂时不用
30
+ relation_products: [],
31
+ // 固定
32
+ is_all: false,
33
+ // 商品相关
34
+ product: null,
35
+ // 时长类型
36
+ sub_type: null,
37
+ // 时长
38
+ duration: null,
39
+ // 资源相关
40
+ // 资源状态 -固定
41
+ like_status: 'common',
42
+ // 资源类型 - 固定--谭景琳备注:马天宇说现在平行资源是不传这个的
43
+ // relation_type: "form",
44
+ // 所选资源
45
+ resources: null,
46
+ // 日程id - 固定
47
+ schedule_id: 0,
48
+ // 所选开始时间
49
+ start_date: null,
50
+ // 所选开始时间
51
+ start_time: null,
52
+ // 所选开始时间
53
+ select_date: null,
54
+ // 所选结束时间
55
+ end_time: null,
56
+ // 所选结束时间
57
+ end_date: null,
58
+ // 额外信息
59
+ metadata: {},
60
+ // holder相关
61
+ holder: null
62
+ };
63
+ };
@@ -23,6 +23,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
23
23
  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); }
24
24
  import { BaseModule } from "../BaseModule";
25
25
  import { generateDuration } from "./utils";
26
+ import { isNormalProduct } from "../Product/utils";
26
27
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
27
28
  _inherits(OrderModule, _BaseModule);
28
29
  var _super = _createSuper(OrderModule);
@@ -83,8 +84,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
83
84
  item._origin.duration = duration;
84
85
  item._origin.sub_type = durationType;
85
86
  }
86
- // 零售都视为普通商品
87
- if (order.type === 'virtual') {
87
+ // 购物车是否为普通商品
88
+ if (isNormalProduct(item._origin)) {
88
89
  var _order$relation_forms;
89
90
  order.relation_products.push(item._origin.product);
90
91
  var relationForms = item._origin.relation_forms || [];
@@ -98,8 +99,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
98
99
  }
99
100
  });
100
101
  if (order.type === 'appointment_booking') {
101
- var firstCartItem = params.cartItems[0];
102
- order.schedule_date = firstCartItem.start_date + ' ' + firstCartItem.start_time + ':00';
102
+ var _params$cartItems$fil;
103
+ var firstAppointmentCartItem = (_params$cartItems$fil = params.cartItems.filter(function (n) {
104
+ return !isNormalProduct(n._productOrigin);
105
+ })) === null || _params$cartItems$fil === void 0 ? void 0 : _params$cartItems$fil[0];
106
+ if (firstAppointmentCartItem) {
107
+ order.schedule_date = firstAppointmentCartItem.start_date + ' ' + firstAppointmentCartItem.start_time + ':00';
108
+ }
103
109
  }
104
110
  order.is_deposit = is_deposit;
105
111
  }
@@ -2,6 +2,8 @@
2
2
  * 商品基本信息接口
3
3
  */
4
4
  export interface ProductData {
5
+ /** 商品数量 */
6
+ quantity?: number;
5
7
  /** 商品id */
6
8
  id: number;
7
9
  /** 商品所属账户id */
@@ -180,6 +182,8 @@ export interface ProductData {
180
182
  title: string;
181
183
  }>;
182
184
  };
185
+ /** 购物车行键,用于唯一标识购物车中的商品,用于相同 SKU商品合并 */
186
+ rowKey?: string;
183
187
  }
184
188
  /**
185
189
  * 商品媒体信息接口
@@ -0,0 +1,17 @@
1
+ import type { ProductData } from './types';
2
+ /**
3
+ * 传入单个商品信息,通过商品上是否有 duration 或者 schedule.ids 来判断是否是普通商品
4
+ *
5
+ * @export
6
+ * @param {ProductData} product
7
+ * @return {*} {boolean}
8
+ */
9
+ export declare function isNormalProduct(product: ProductData): boolean;
10
+ /**
11
+ * 传入多个商品信息,确定这些商品是否都是普通商品
12
+ *
13
+ * @export
14
+ * @param {ProductData[]} products
15
+ * @return {*} {boolean}
16
+ */
17
+ export declare function areAllNormalProducts(products: ProductData[]): boolean;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 传入单个商品信息,通过商品上是否有 duration 或者 schedule.ids 来判断是否是普通商品
3
+ *
4
+ * @export
5
+ * @param {ProductData} product
6
+ * @return {*} {boolean}
7
+ */
8
+ export function isNormalProduct(product) {
9
+ var _product$scheduleIds;
10
+ // 如果有 duration 配置,则不是普通商品
11
+ if (product.duration) {
12
+ return false;
13
+ }
14
+
15
+ // 如果有 schedule.ids 且长度大于0,则不是普通商品
16
+ if ((_product$scheduleIds = product['schedule.ids']) !== null && _product$scheduleIds !== void 0 && _product$scheduleIds.length) {
17
+ return false;
18
+ }
19
+
20
+ // 既没有 duration 也没有 schedule.ids,则是普通商品
21
+ return true;
22
+ }
23
+
24
+ /**
25
+ * 传入多个商品信息,确定这些商品是否都是普通商品
26
+ *
27
+ * @export
28
+ * @param {ProductData[]} products
29
+ * @return {*} {boolean}
30
+ */
31
+ export function areAllNormalProducts(products) {
32
+ // 如果数组为空,返回 true
33
+ if (!products.length) {
34
+ return false;
35
+ }
36
+
37
+ // 检查所有商品是否都是普通商品
38
+ return products.every(function (product) {
39
+ return isNormalProduct(product);
40
+ });
41
+ }
@@ -171,6 +171,9 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
171
171
  }[]>;
172
172
  capacity?: number;
173
173
  }): {
174
+ selectedResource?: undefined;
175
+ timeSlots?: undefined;
176
+ } | {
174
177
  selectedResource: any;
175
178
  timeSlots?: undefined;
176
179
  } | {
@@ -210,7 +213,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
210
213
  }): void;
211
214
  setOtherData(key: string, value: any): void;
212
215
  getOtherData(key: string): any;
213
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
216
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
214
217
  /**
215
218
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
216
219
  *
@@ -246,4 +249,8 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
246
249
  dateList: any;
247
250
  firstAvailableDate: any;
248
251
  }>;
252
+ isCartAllNormalProducts(): boolean;
253
+ isCartHasDurationProduct(): boolean;
254
+ isTargetNormalProduct(product: ProductData): boolean;
255
+ isTargetCartIdNormalProduct(id: string): boolean | undefined;
249
256
  }