@pisell/pisellos 0.0.14 → 0.0.16

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 (51) hide show
  1. package/dist/modules/AccountList/index.d.ts +5 -1
  2. package/dist/modules/AccountList/index.js +82 -36
  3. package/dist/modules/AccountList/types.d.ts +1 -0
  4. package/dist/modules/BaseModule.d.ts +6 -0
  5. package/dist/modules/BaseModule.js +41 -0
  6. package/dist/modules/Cart/index.d.ts +10 -2
  7. package/dist/modules/Cart/index.js +71 -34
  8. package/dist/modules/Cart/types.d.ts +2 -2
  9. package/dist/modules/Cart/utils.d.ts +12 -0
  10. package/dist/modules/Cart/utils.js +49 -0
  11. package/dist/modules/Date/index.d.ts +5 -0
  12. package/dist/modules/Date/index.js +35 -2
  13. package/dist/modules/Discount/index.d.ts +4 -0
  14. package/dist/modules/Discount/index.js +32 -4
  15. package/dist/modules/Discount/types.d.ts +3 -0
  16. package/dist/modules/Rules/index.js +7 -4
  17. package/dist/modules/Step/index.d.ts +4 -0
  18. package/dist/modules/Step/index.js +29 -1
  19. package/dist/modules/Summary/index.d.ts +4 -0
  20. package/dist/modules/Summary/index.js +28 -2
  21. package/dist/modules/Summary/utils.js +4 -5
  22. package/dist/solution/BookingByStep/index.d.ts +23 -4
  23. package/dist/solution/BookingByStep/index.js +152 -31
  24. package/dist/solution/BookingByStep/types.js +0 -3
  25. package/dist/solution/ShopDiscount/index.js +24 -3
  26. package/lib/modules/AccountList/index.d.ts +5 -1
  27. package/lib/modules/AccountList/index.js +33 -1
  28. package/lib/modules/AccountList/types.d.ts +1 -0
  29. package/lib/modules/BaseModule.d.ts +6 -0
  30. package/lib/modules/BaseModule.js +37 -0
  31. package/lib/modules/Cart/index.d.ts +10 -2
  32. package/lib/modules/Cart/index.js +42 -14
  33. package/lib/modules/Cart/types.d.ts +2 -2
  34. package/lib/modules/Cart/utils.d.ts +12 -0
  35. package/lib/modules/Cart/utils.js +33 -0
  36. package/lib/modules/Date/index.d.ts +5 -0
  37. package/lib/modules/Date/index.js +21 -0
  38. package/lib/modules/Discount/index.d.ts +4 -0
  39. package/lib/modules/Discount/index.js +19 -0
  40. package/lib/modules/Discount/types.d.ts +3 -0
  41. package/lib/modules/Rules/index.js +9 -4
  42. package/lib/modules/Step/index.d.ts +4 -0
  43. package/lib/modules/Step/index.js +19 -0
  44. package/lib/modules/Summary/index.d.ts +4 -0
  45. package/lib/modules/Summary/index.js +17 -0
  46. package/lib/modules/Summary/utils.js +4 -5
  47. package/lib/solution/BookingByStep/index.d.ts +23 -4
  48. package/lib/solution/BookingByStep/index.js +82 -21
  49. package/lib/solution/BookingByStep/types.js +0 -3
  50. package/lib/solution/ShopDiscount/index.js +21 -3
  51. package/package.json +1 -1
@@ -29,24 +29,40 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
29
29
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
30
30
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
31
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
34
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
32
35
  return _this;
33
36
  }
34
37
  _createClass(DateModule, [{
35
38
  key: "initialize",
36
39
  value: function () {
37
40
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
41
+ var _options$otherParams, _options$otherParams2;
38
42
  return _regeneratorRuntime().wrap(function _callee$(_context) {
39
43
  while (1) switch (_context.prev = _context.next) {
40
44
  case 0:
41
45
  this.core = core;
42
46
  this.store = options.store;
43
47
  this.request = this.core.getPlugin("request");
48
+ if (options.initialState) {
49
+ this.store.dateRange = options.initialState.dateRange;
50
+ this.store.dateList = options.initialState.dateList;
51
+ }
44
52
  if (this.request) {
45
- _context.next = 5;
53
+ _context.next = 6;
46
54
  break;
47
55
  }
48
56
  throw new Error("DateModule 需要 request 插件支持");
49
- case 5:
57
+ case 6:
58
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
59
+ this.openCache = options.otherParams.openCache;
60
+ this.cacheId = options.otherParams.cacheId;
61
+ }
62
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
63
+ this.fatherModule = options.otherParams.fatherModule;
64
+ }
65
+ case 8:
50
66
  case "end":
51
67
  return _context.stop();
52
68
  }
@@ -177,6 +193,23 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
177
193
  }
178
194
  return getAvailableTimeList;
179
195
  }()
196
+ }, {
197
+ key: "clearDateRange",
198
+ value: function clearDateRange() {
199
+ this.store.dateRange = [];
200
+ }
201
+ }, {
202
+ key: "storeChange",
203
+ value: function storeChange() {
204
+ if (this.openCache) {
205
+ this.checkSaveCache({
206
+ cacheId: this.cacheId,
207
+ fatherModule: this.fatherModule,
208
+ store: this.store,
209
+ cacheKey: ['dateRange', 'dateList']
210
+ });
211
+ }
212
+ }
180
213
  }]);
181
214
  return DateModule;
182
215
  }(BaseModule);
@@ -7,6 +7,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
7
7
  private request;
8
8
  private window;
9
9
  private store;
10
+ private cacheId;
11
+ private openCache;
12
+ private fatherModule;
10
13
  constructor(name?: string, version?: string);
11
14
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
12
15
  setDiscountList(discountList: Discount[]): Promise<void>;
@@ -23,4 +26,5 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
23
26
  calcDiscountApplicableProductTotalPrice(discount: Discount): number;
24
27
  destroy(): Promise<void>;
25
28
  clear(): Promise<void>;
29
+ storeChange(): void;
26
30
  }
@@ -30,33 +30,49 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
30
30
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
31
31
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
32
32
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
35
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
33
36
  return _this;
34
37
  }
35
38
  _createClass(DiscountModule, [{
36
39
  key: "initialize",
37
40
  value: function () {
38
41
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
42
+ var _options$initialState, _options$otherParams, _options$otherParams2;
39
43
  return _regeneratorRuntime().wrap(function _callee$(_context) {
40
44
  while (1) switch (_context.prev = _context.next) {
41
45
  case 0:
42
46
  this.core = core;
43
47
  this.store = options === null || options === void 0 ? void 0 : options.store;
48
+ if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.discountList)) {
49
+ this.store.discountList = options === null || options === void 0 ? void 0 : options.initialState.discountList;
50
+ } else {
51
+ this.store.discountList = [];
52
+ }
53
+ if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
54
+ this.openCache = options.otherParams.openCache;
55
+ this.cacheId = options.otherParams.cacheId;
56
+ }
57
+ if (options !== null && options !== void 0 && (_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
58
+ this.fatherModule = options.otherParams.fatherModule;
59
+ }
44
60
 
45
61
  // 获取依赖的插件
46
62
  this.request = core.getPlugin("request");
47
63
  this.window = core.getPlugin("window");
48
64
  if (this.request) {
49
- _context.next = 6;
65
+ _context.next = 9;
50
66
  break;
51
67
  }
52
68
  throw new Error("discount模块需要 request 插件支持");
53
- case 6:
69
+ case 9:
54
70
  if (this.window) {
55
- _context.next = 8;
71
+ _context.next = 11;
56
72
  break;
57
73
  }
58
74
  throw new Error("discount模块需要 window 插件支持");
59
- case 8:
75
+ case 11:
60
76
  case "end":
61
77
  return _context.stop();
62
78
  }
@@ -229,6 +245,18 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
229
245
  }
230
246
  return clear;
231
247
  }()
248
+ }, {
249
+ key: "storeChange",
250
+ value: function storeChange() {
251
+ if (this.openCache) {
252
+ this.checkSaveCache({
253
+ cacheId: this.cacheId,
254
+ fatherModule: this.fatherModule,
255
+ store: this.store,
256
+ cacheKey: ['discountList']
257
+ });
258
+ }
259
+ }
232
260
  }]);
233
261
  return DiscountModule;
234
262
  }(BaseModule);
@@ -47,6 +47,9 @@ export interface Discount {
47
47
  resource_id?: number;
48
48
  savedAmount?: number;
49
49
  isEditMode?: boolean;
50
+ discount?: {
51
+ resource_id: number;
52
+ };
50
53
  isManualSelect?: boolean;
51
54
  isDisabled?: boolean;
52
55
  isSelected?: boolean;
@@ -125,7 +125,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
125
125
  if (discount_list && discount_list.length > 0) {
126
126
  // 检查是否有使用新折扣的情况
127
127
  var usedNewDiscount = discount_list.some(function (discount) {
128
- return newDiscountIds.includes(discount.resource_id);
128
+ var _discount$discount;
129
+ return newDiscountIds.includes(discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id);
129
130
  });
130
131
  if (usedNewDiscount) {
131
132
  hasApplicableDiscount = true;
@@ -217,9 +218,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
217
218
  applicableProducts.push({
218
219
  amount: product.price,
219
220
  type: discount.tag,
220
- resource_id: discount.id,
221
- title: discount.format_title,
222
- original_amount: product.origin_total
221
+ discount: {
222
+ resource_id: discount.id,
223
+ title: discount.format_title,
224
+ original_amount: product.origin_total
225
+ }
223
226
  });
224
227
  discountApplicableProducts.set(discount.id, applicableProducts);
225
228
  }
@@ -5,6 +5,9 @@ export declare class StepModule extends BaseModule implements Module, IStepModul
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
7
  private store;
8
+ private cacheId;
9
+ private openCache;
10
+ private fatherModule;
8
11
  constructor(name?: string, version?: string);
9
12
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
10
13
  init(steps: IStep[]): void;
@@ -16,4 +19,5 @@ export declare class StepModule extends BaseModule implements Module, IStepModul
16
19
  prevStep(): void;
17
20
  nextStep(): void;
18
21
  gotoStep(stepIndex: number): void;
22
+ storeChange(): void;
19
23
  }
@@ -26,18 +26,34 @@ export var StepModule = /*#__PURE__*/function (_BaseModule) {
26
26
  _defineProperty(_assertThisInitialized(_this), "defaultName", "step");
27
27
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
28
28
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
29
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
30
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
31
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
29
32
  return _this;
30
33
  }
31
34
  _createClass(StepModule, [{
32
35
  key: "initialize",
33
36
  value: function () {
34
37
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
38
+ var _options$otherParams, _options$otherParams2;
35
39
  return _regeneratorRuntime().wrap(function _callee$(_context) {
36
40
  while (1) switch (_context.prev = _context.next) {
37
41
  case 0:
38
42
  this.core = core;
39
43
  this.store = options.store;
40
- case 2:
44
+ if (options.initialState) {
45
+ this.store.stepList = options.initialState.stepList;
46
+ this.store.currentStep = options.initialState.currentStep;
47
+ this.store.currentStepIndex = options.initialState.currentStepIndex;
48
+ }
49
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
50
+ this.openCache = options.otherParams.openCache;
51
+ this.cacheId = options.otherParams.cacheId;
52
+ }
53
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
54
+ this.fatherModule = options.otherParams.fatherModule;
55
+ }
56
+ case 5:
41
57
  case "end":
42
58
  return _context.stop();
43
59
  }
@@ -102,6 +118,18 @@ export var StepModule = /*#__PURE__*/function (_BaseModule) {
102
118
  value: function gotoStep(stepIndex) {
103
119
  this.setCurrentStep(stepIndex);
104
120
  }
121
+ }, {
122
+ key: "storeChange",
123
+ value: function storeChange() {
124
+ if (this.openCache) {
125
+ this.checkSaveCache({
126
+ cacheId: this.cacheId,
127
+ fatherModule: this.fatherModule,
128
+ store: this.store,
129
+ cacheKey: ['currentStepIndex', 'currentStep', 'stepList']
130
+ });
131
+ }
132
+ }
105
133
  }]);
106
134
  return StepModule;
107
135
  }(BaseModule);
@@ -7,7 +7,11 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
7
7
  protected defaultVersion: string;
8
8
  private shopStore;
9
9
  private store;
10
+ private cacheId;
11
+ private openCache;
12
+ private fatherModule;
10
13
  constructor(name?: string, version?: string);
11
14
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
15
  getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
16
+ storeChange(): void;
13
17
  }
@@ -28,24 +28,38 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
28
28
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
29
29
  _defineProperty(_assertThisInitialized(_this), "shopStore", void 0);
30
30
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
31
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
32
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
33
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
31
34
  return _this;
32
35
  }
33
36
  _createClass(SummaryModule, [{
34
37
  key: "initialize",
35
38
  value: function () {
36
39
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
40
+ var _options$otherParams, _options$otherParams2;
37
41
  return _regeneratorRuntime().wrap(function _callee$(_context) {
38
42
  while (1) switch (_context.prev = _context.next) {
39
43
  case 0:
40
44
  this.core = core;
41
45
  this.store = options.store;
42
46
  this.shopStore = this.core.getPlugin("shopStore");
47
+ if (options.initialState) {
48
+ this.store.summary = options.initialState.summary;
49
+ }
50
+ if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
51
+ this.openCache = options.otherParams.openCache;
52
+ this.cacheId = options.otherParams.cacheId;
53
+ }
54
+ if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
55
+ this.fatherModule = options.otherParams.fatherModule;
56
+ }
43
57
  if (this.shopStore) {
44
- _context.next = 5;
58
+ _context.next = 8;
45
59
  break;
46
60
  }
47
61
  throw new Error("SummaryModule 需要 shopStore 插件支持");
48
- case 5:
62
+ case 8:
49
63
  case "end":
50
64
  return _context.stop();
51
65
  }
@@ -80,6 +94,18 @@ export var SummaryModule = /*#__PURE__*/function (_BaseModule) {
80
94
  }
81
95
  return getSummary;
82
96
  }()
97
+ }, {
98
+ key: "storeChange",
99
+ value: function storeChange() {
100
+ if (this.openCache) {
101
+ this.checkSaveCache({
102
+ cacheId: this.cacheId,
103
+ fatherModule: this.fatherModule,
104
+ store: this.store,
105
+ cacheKey: ['summary']
106
+ });
107
+ }
108
+ }
83
109
  }]);
84
110
  return SummaryModule;
85
111
  }(BaseModule);
@@ -24,9 +24,8 @@ export var calculateSubtotal = function calculateSubtotal(items) {
24
24
  return "0.00";
25
25
  }
26
26
  var subtotal = items.reduce(function (sum, item) {
27
- var price = new Decimal(item.price || 0);
28
- var quantity = new Decimal(item.num || 1);
29
- return sum.plus(price.times(quantity));
27
+ var cartItemTotalPrice = new Decimal(item.total || 0);
28
+ return sum.plus(cartItemTotalPrice);
30
29
  }, new Decimal(0));
31
30
  return subtotal.toFixed(2);
32
31
  };
@@ -47,9 +46,9 @@ export var calculateTaxFee = function calculateTaxFee(shopInfo, items) {
47
46
  is_price_include_tax = _ref.is_price_include_tax,
48
47
  tax_rate = _ref.tax_rate;
49
48
  var totalTaxFee = items.reduce(function (sum, item) {
50
- var price = new Decimal(item.price || 0);
49
+ var cartItemTotalPrice = new Decimal(item.total || 0);
51
50
  var taxRate = new Decimal(tax_rate || 0).div(100);
52
- var productTaxRate = price.times(taxRate).times((item === null || item === void 0 ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
51
+ var productTaxRate = cartItemTotalPrice.times(taxRate).times((item === null || item === void 0 ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
53
52
  return sum.plus(productTaxRate);
54
53
  }, new Decimal(0));
55
54
  return totalTaxFee;
@@ -1,7 +1,7 @@
1
1
  import { Module, PisellCore } from "../../types";
2
2
  import { BaseModule } from "../../modules/BaseModule";
3
3
  import { BookingByStepState } from "./types";
4
- import { IUpdateItemParams, ProductData } from "../../modules";
4
+ import { CartItem, IUpdateItemParams, ProductData } from "../../modules";
5
5
  import { Account } from "../../modules/Account/types";
6
6
  import { IStep } from "../../modules/Step/tyeps";
7
7
  import { TimeSliceItem } from "./utils/resources";
@@ -38,8 +38,9 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
38
38
  getActiveAccount(): Account | null;
39
39
  removeAccount(id: string): void;
40
40
  setDateRange(dateRange: ITime[]): Promise<void>;
41
- getRangeDate(): Promise<string>;
42
- getCart(): Promise<import("../../modules").CartItem[]>;
41
+ clearDateRange(): void;
42
+ getDateRange(): Promise<ITime[]>;
43
+ getCart(): Promise<CartItem[]>;
43
44
  getAvailableDate(params?: {
44
45
  products?: ProductData[];
45
46
  startDate?: string;
@@ -66,11 +67,27 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
66
67
  }): Promise<void>;
67
68
  getOtherParams(): Promise<Record<string, any>>;
68
69
  updateCart(params: IUpdateItemParams): void;
69
- deleteCart(product_id: string): void;
70
+ deleteCart(cartItemId: string): void;
70
71
  clearCart(): void;
71
72
  clearCartByAccount(account_id: string): void;
73
+ /**
74
+ * 批量更新购物车
75
+ */
76
+ batchUpdateCart(paramsList: IUpdateItemParams[]): void;
77
+ /**
78
+ * 从购物车中按类别删除信息
79
+ */
80
+ deleteCartItemInfo(types: "resource" | "time"): void;
72
81
  destory(): void;
73
82
  getResourcesList(): any[];
83
+ getResourcesListByCartItem(id: string | number): {
84
+ id: number | undefined;
85
+ _id: string;
86
+ product: ProductData | undefined;
87
+ resources: import("./utils/resources").ResourceItem[];
88
+ holder_id: string | number | undefined;
89
+ holder_name: string | undefined;
90
+ } | undefined;
74
91
  getResourceTimeSlot({ product, resources, currentResourceId, }: {
75
92
  product: ProductData;
76
93
  resources: any[];
@@ -103,4 +120,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
103
120
  };
104
121
  getTimeSlotByAllResources(resources_code: string): any[];
105
122
  submitTimeSlot(timeSlots: TimeSliceItem): void;
123
+ clearCache(): void;
124
+ clearCacheByModule(module: string): void;
106
125
  }