@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
@@ -21,7 +21,9 @@ export declare class AccountModule extends BaseModule implements Module, Account
21
21
  isLoggedIn(): boolean;
22
22
  resetPassword(email: string): Promise<void>;
23
23
  updatePassword(oldPassword: string, newPassword: string): Promise<void>;
24
- getLoginStatus(): Promise<boolean>;
25
- getAccount(): Promise<Account | null>;
24
+ getLoginStatus(): boolean;
25
+ getAccount(): Account | null;
26
26
  setAccountInfo(account: Account): void;
27
+ setActive(active: boolean): void;
28
+ isActive(): boolean;
27
29
  }
@@ -32,7 +32,8 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
32
32
  _defineProperty(_assertThisInitialized(_this), "isGuest", false);
33
33
  _defineProperty(_assertThisInitialized(_this), "store", {
34
34
  currentAccount: null,
35
- isLoggedIn: false
35
+ isLoggedIn: false,
36
+ active: false
36
37
  });
37
38
  return _this;
38
39
  }
@@ -45,7 +46,8 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
45
46
  case 0:
46
47
  this.core = core;
47
48
  this.store = options === null || options === void 0 ? void 0 : options.store;
48
- case 2:
49
+ this.store.isLoggedIn = false;
50
+ case 3:
49
51
  case "end":
50
52
  return _context.stop();
51
53
  }
@@ -216,46 +218,31 @@ export var AccountModule = /*#__PURE__*/function (_BaseModule) {
216
218
  }()
217
219
  }, {
218
220
  key: "getLoginStatus",
219
- value: function () {
220
- var _getLoginStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
221
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
222
- while (1) switch (_context8.prev = _context8.next) {
223
- case 0:
224
- return _context8.abrupt("return", this.store.isLoggedIn);
225
- case 1:
226
- case "end":
227
- return _context8.stop();
228
- }
229
- }, _callee8, this);
230
- }));
231
- function getLoginStatus() {
232
- return _getLoginStatus.apply(this, arguments);
233
- }
234
- return getLoginStatus;
235
- }()
221
+ value: function getLoginStatus() {
222
+ return this.store.isLoggedIn;
223
+ }
236
224
  }, {
237
225
  key: "getAccount",
238
- value: function () {
239
- var _getAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
240
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
241
- while (1) switch (_context9.prev = _context9.next) {
242
- case 0:
243
- return _context9.abrupt("return", this.store.currentAccount);
244
- case 1:
245
- case "end":
246
- return _context9.stop();
247
- }
248
- }, _callee9, this);
249
- }));
250
- function getAccount() {
251
- return _getAccount.apply(this, arguments);
252
- }
253
- return getAccount;
254
- }()
226
+ value: function getAccount() {
227
+ return this.store.currentAccount;
228
+ }
255
229
  }, {
256
230
  key: "setAccountInfo",
257
231
  value: function setAccountInfo(account) {
258
232
  this.store.currentAccount = account;
233
+ if (account.isGuest) {
234
+ this.isGuest = true;
235
+ }
236
+ }
237
+ }, {
238
+ key: "setActive",
239
+ value: function setActive(active) {
240
+ this.store.active = active;
241
+ }
242
+ }, {
243
+ key: "isActive",
244
+ value: function isActive() {
245
+ return this.store.active;
259
246
  }
260
247
  }]);
261
248
  return AccountModule;
@@ -23,6 +23,7 @@ export interface Account {
23
23
  export interface AccountState {
24
24
  currentAccount: Account | null;
25
25
  isLoggedIn: boolean;
26
+ active: boolean;
26
27
  }
27
28
  /**
28
29
  * 账户模块 API
@@ -15,4 +15,6 @@ export declare class AccountListModule extends BaseModule implements Module {
15
15
  getAccount(id: string): AccountModule | null;
16
16
  clearAccounts(): Promise<void>;
17
17
  getState(): AccountListState;
18
+ setActiveAccount(id: string | number): void;
19
+ getActiveAccount(): AccountModule | null;
18
20
  }
@@ -84,27 +84,32 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
84
84
  case 5:
85
85
  accountModule = new AccountModule("account_".concat(account.id));
86
86
  this.core.registerModule(accountModule);
87
+ accountModule.setAccountInfo(account);
87
88
  this.store.accounts = [].concat(_toConsumableArray(this.store.accounts), [accountModule]);
88
- _context2.next = 10;
89
+ _context2.next = 11;
89
90
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
90
- case 10:
91
- _context2.next = 17;
91
+ case 11:
92
+ if (this.store.accounts.length === 1) {
93
+ this.setActiveAccount(accountModule.getId());
94
+ }
95
+ _context2.next = 20;
92
96
  break;
93
- case 12:
94
- _context2.prev = 12;
97
+ case 14:
98
+ _context2.prev = 14;
95
99
  _context2.t0 = _context2["catch"](0);
100
+ console.error(_context2.t0);
96
101
  this.store.error = _context2.t0 instanceof Error ? _context2.t0.message : 'Failed to add account';
97
- _context2.next = 17;
102
+ _context2.next = 20;
98
103
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
99
- case 17:
100
- _context2.prev = 17;
101
- this.store.isLoading = false;
102
- return _context2.finish(17);
103
104
  case 20:
105
+ _context2.prev = 20;
106
+ this.store.isLoading = false;
107
+ return _context2.finish(20);
108
+ case 23:
104
109
  case "end":
105
110
  return _context2.stop();
106
111
  }
107
- }, _callee2, this, [[0, 12, 17, 20]]);
112
+ }, _callee2, this, [[0, 14, 20, 23]]);
108
113
  }));
109
114
  function addAccount(_x3) {
110
115
  return _addAccount.apply(this, arguments);
@@ -259,6 +264,24 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
259
264
  value: function getState() {
260
265
  return _objectSpread({}, this.store);
261
266
  }
267
+ }, {
268
+ key: "setActiveAccount",
269
+ value: function setActiveAccount(id) {
270
+ this.store.accounts.forEach(function (account) {
271
+ if (account.getId() === id) {
272
+ account.setActive(true);
273
+ } else {
274
+ account.setActive(false);
275
+ }
276
+ });
277
+ }
278
+ }, {
279
+ key: "getActiveAccount",
280
+ value: function getActiveAccount() {
281
+ return this.store.accounts.find(function (account) {
282
+ return account.isActive();
283
+ }) || null;
284
+ }
262
285
  }]);
263
286
  return AccountListModule;
264
287
  }(BaseModule);
@@ -1,7 +1,7 @@
1
- import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { CartItem, CartModuleAPI } from './types';
4
- export * from './types';
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { CartItem, CartModuleAPI, IAddItemParams, IUpdateItemParams } from "./types";
4
+ export * from "./types";
5
5
  /**
6
6
  * 购物车模块实现
7
7
  */
@@ -18,18 +18,24 @@ export declare class CartModule extends BaseModule implements Module {
18
18
  */
19
19
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
20
20
  /**
21
- * 模块销毁
21
+ * 添加商品到购物车
22
22
  */
23
- destroy(): Promise<void>;
23
+ addItem(params: IAddItemParams): Promise<void>;
24
24
  /**
25
- * 添加商品到购物车
25
+ * 更新购物车信息
26
+ */
27
+ updateItem(params: IUpdateItemParams): Promise<void>;
28
+ /**
29
+ * 批量设置购物车数据
26
30
  */
27
- addItem(item: CartItem): Promise<void>;
31
+ batchSetItems(items: CartItem[]): Promise<void>;
28
32
  getItemCount(): number;
29
33
  getTotalPrice(): number;
30
- getItems(): Promise<CartItem[]>;
31
- updateItem(id: string, item: CartItem): Promise<void>;
34
+ getItems(): CartItem[];
32
35
  removeItem(id: string): Promise<void>;
33
36
  storeTemp(key: string, value: any): Promise<void>;
34
- getTemp(key?: string): Promise<any>;
37
+ getTemp(key?: string): any;
38
+ clear(): void;
39
+ clearCartByAccount(account_id: string): void;
40
+ getCartByAccount(account_id: string | number): CartItem[];
35
41
  }
@@ -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 { CartHooks } from "./types";
26
+ import { createCartItemOrigin, formatAccountToCartItem, formatProductToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
26
27
  export * from "./types";
27
28
 
28
29
  /**
@@ -36,8 +37,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
36
37
  _classCallCheck(this, CartModule);
37
38
  _this = _super.call(this, name, version);
38
39
  // 提供给 baseModule 用的默认名称 和 默认版本
39
- _defineProperty(_assertThisInitialized(_this), "defaultName", 'cart');
40
- _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
40
+ _defineProperty(_assertThisInitialized(_this), "defaultName", "cart");
41
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
41
42
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
42
43
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
43
44
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
@@ -65,25 +66,26 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
65
66
  case 0:
66
67
  this.core = core;
67
68
  this.store = options.store;
69
+ this.store.list = [];
68
70
 
69
71
  // 获取依赖的插件
70
- this.request = core.getPlugin('request');
71
- this.window = core.getPlugin('window');
72
+ this.request = core.getPlugin("request");
73
+ this.window = core.getPlugin("window");
72
74
  if (this.request) {
73
- _context.next = 6;
75
+ _context.next = 7;
74
76
  break;
75
77
  }
76
- throw new Error('购物车模块需要 request 插件支持');
77
- case 6:
78
+ throw new Error("购物车模块需要 request 插件支持");
79
+ case 7:
78
80
  if (this.window) {
79
- _context.next = 8;
81
+ _context.next = 9;
80
82
  break;
81
83
  }
82
- throw new Error('购物车模块需要 window 插件支持');
83
- case 8:
84
+ throw new Error("购物车模块需要 window 插件支持");
85
+ case 9:
84
86
  this.store.temp = {};
85
- console.log('[CartModule] 初始化完成');
86
- case 10:
87
+ console.log("[CartModule] 初始化完成");
88
+ case 11:
87
89
  case "end":
88
90
  return _context.stop();
89
91
  }
@@ -95,139 +97,191 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
95
97
  return initialize;
96
98
  }()
97
99
  /**
98
- * 模块销毁
100
+ * 添加商品到购物车
99
101
  */
100
102
  )
101
103
  }, {
102
- key: "destroy",
104
+ key: "addItem",
103
105
  value: (function () {
104
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
106
+ var _addItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
107
+ var account, product, bundle, options, cartItem, items;
105
108
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
106
109
  while (1) switch (_context2.prev = _context2.next) {
107
110
  case 0:
108
- console.log('[CartModule] 已销毁');
109
- case 1:
111
+ account = params.account, product = params.product, bundle = params.bundle, options = params.options; // 生成一个唯一的 ID
112
+ cartItem = {
113
+ _id: getUniqueId(),
114
+ _origin: createCartItemOrigin(),
115
+ _productOrigin: product
116
+ };
117
+ if (product) {
118
+ cartItem = formatProductToCartItem({
119
+ cartItem: cartItem,
120
+ product: product,
121
+ bundle: bundle,
122
+ options: options
123
+ });
124
+ }
125
+ if (account) {
126
+ cartItem = formatAccountToCartItem({
127
+ cartItem: cartItem,
128
+ account: account
129
+ });
130
+ }
131
+
132
+ // 更新购物车数据
133
+ items = [].concat(_toConsumableArray(this.store.list), [cartItem]);
134
+ this.store.list = items;
135
+
136
+ // 触发事件
137
+ _context2.next = 8;
138
+ return this.core.effects.emit(CartHooks.OnAddItem, cartItem);
139
+ case 8:
140
+ _context2.next = 10;
141
+ return this.core.effects.emit("".concat(this.name, ":changed"), items);
142
+ case 10:
110
143
  case "end":
111
144
  return _context2.stop();
112
145
  }
113
- }, _callee2);
146
+ }, _callee2, this);
114
147
  }));
115
- function destroy() {
116
- return _destroy.apply(this, arguments);
148
+ function addItem(_x3) {
149
+ return _addItem.apply(this, arguments);
117
150
  }
118
- return destroy;
151
+ return addItem;
119
152
  }()
120
153
  /**
121
- * 添加商品到购物车
154
+ * 更新购物车信息
122
155
  */
123
156
  )
124
157
  }, {
125
- key: "addItem",
158
+ key: "updateItem",
126
159
  value: (function () {
127
- var _addItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
128
- var items;
160
+ var _updateItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
161
+ var _tempCartItem$_origin;
162
+ var _id, cartItem, account, product, resources, note, tempCartItem, items;
129
163
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
130
164
  while (1) switch (_context3.prev = _context3.next) {
131
165
  case 0:
132
- items = [].concat(_toConsumableArray(this.store.list), [item]);
166
+ _id = params._id, cartItem = params.cartItem, account = params.account, product = params.product, resources = params.resources, note = params.note;
167
+ tempCartItem = this.store.list.find(function (i) {
168
+ return i._id === _id;
169
+ });
170
+ if (tempCartItem) {
171
+ _context3.next = 5;
172
+ break;
173
+ }
174
+ console.warn("[CartModule] 更新购物车商品失败,商品不存在");
175
+ return _context3.abrupt("return");
176
+ case 5:
177
+ if (cartItem) {
178
+ tempCartItem = cartItem;
179
+ }
180
+ if (product) {
181
+ tempCartItem = formatProductToCartItem({
182
+ cartItem: tempCartItem,
183
+ product: product
184
+ });
185
+ }
186
+ if (account) {
187
+ tempCartItem = formatAccountToCartItem({
188
+ cartItem: tempCartItem,
189
+ account: account
190
+ });
191
+ }
192
+ if (resources) {
193
+ tempCartItem = formatResourceToCartItem({
194
+ cartItem: tempCartItem,
195
+ resources: resources
196
+ });
197
+ }
198
+ if (note && (_tempCartItem$_origin = tempCartItem._origin) !== null && _tempCartItem$_origin !== void 0 && _tempCartItem$_origin.product) {
199
+ tempCartItem.note = note;
200
+ tempCartItem._origin.product.note = note;
201
+ }
202
+
203
+ // 更新购物车数据
204
+ items = this.store.list.map(function (item) {
205
+ var _tempCartItem;
206
+ if (item._id === ((_tempCartItem = tempCartItem) === null || _tempCartItem === void 0 ? void 0 : _tempCartItem._id)) {
207
+ return tempCartItem;
208
+ }
209
+ return item;
210
+ });
133
211
  this.store.list = items;
134
- _context3.next = 4;
135
- return this.core.effects.emit(CartHooks.OnAddItem, item);
136
- case 4:
137
- _context3.next = 6;
138
- return this.core.effects.emit(CartHooks.OnCartChange, items);
139
- case 6:
212
+
213
+ // 触发事件
214
+ _context3.next = 14;
215
+ return this.core.effects.emit("".concat(this.name, ":changed"), items);
216
+ case 14:
140
217
  case "end":
141
218
  return _context3.stop();
142
219
  }
143
220
  }, _callee3, this);
144
221
  }));
145
- function addItem(_x3) {
146
- return _addItem.apply(this, arguments);
222
+ function updateItem(_x4) {
223
+ return _updateItem.apply(this, arguments);
147
224
  }
148
- return addItem;
149
- }())
150
- }, {
151
- key: "getItemCount",
152
- value: function getItemCount() {
153
- return this.store.list.length;
154
- }
155
- }, {
156
- key: "getTotalPrice",
157
- value: function getTotalPrice() {
158
- return this.store.list.reduce(function (total, item) {
159
- return total + item.price * item.quantity;
160
- }, 0);
161
- }
225
+ return updateItem;
226
+ }()
227
+ /**
228
+ * 批量设置购物车数据
229
+ */
230
+ )
162
231
  }, {
163
- key: "getItems",
164
- value: function () {
165
- var _getItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
232
+ key: "batchSetItems",
233
+ value: (function () {
234
+ var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(items) {
166
235
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
167
236
  while (1) switch (_context4.prev = _context4.next) {
168
237
  case 0:
169
- return _context4.abrupt("return", this.store.list);
238
+ this.store.list = items || [];
170
239
  case 1:
171
240
  case "end":
172
241
  return _context4.stop();
173
242
  }
174
243
  }, _callee4, this);
175
244
  }));
176
- function getItems() {
177
- return _getItems.apply(this, arguments);
245
+ function batchSetItems(_x5) {
246
+ return _batchSetItems.apply(this, arguments);
178
247
  }
179
- return getItems;
180
- }()
248
+ return batchSetItems;
249
+ }())
181
250
  }, {
182
- key: "updateItem",
183
- value: function () {
184
- var _updateItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id, item) {
185
- var items, itemIndex;
186
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
187
- while (1) switch (_context5.prev = _context5.next) {
188
- case 0:
189
- items = this.store.list;
190
- itemIndex = items.findIndex(function (i) {
191
- return i.id === id;
192
- });
193
- if (!(itemIndex !== -1)) {
194
- _context5.next = 7;
195
- break;
196
- }
197
- items[itemIndex] = item;
198
- this.store.list = items;
199
- _context5.next = 7;
200
- return this.core.effects.emit(CartHooks.OnCartUpdateItem, items);
201
- case 7:
202
- case "end":
203
- return _context5.stop();
204
- }
205
- }, _callee5, this);
206
- }));
207
- function updateItem(_x4, _x5) {
208
- return _updateItem.apply(this, arguments);
209
- }
210
- return updateItem;
211
- }()
251
+ key: "getItemCount",
252
+ value: function getItemCount() {
253
+ return this.store.list.length;
254
+ }
255
+ }, {
256
+ key: "getTotalPrice",
257
+ value: function getTotalPrice() {
258
+ // return this.store.list.reduce((total: number, item: CartItem) => total + item.price * item.quantity, 0);
259
+ return 0;
260
+ }
261
+ }, {
262
+ key: "getItems",
263
+ value: function getItems() {
264
+ return this.store.list;
265
+ }
212
266
  }, {
213
267
  key: "removeItem",
214
268
  value: function () {
215
- var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
269
+ var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
216
270
  var items;
217
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
218
- while (1) switch (_context6.prev = _context6.next) {
271
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
272
+ while (1) switch (_context5.prev = _context5.next) {
219
273
  case 0:
220
274
  items = this.store.list.filter(function (i) {
221
- return i.id !== id;
275
+ return i._id !== id;
222
276
  });
223
277
  this.store.list = items;
224
- _context6.next = 4;
278
+ _context5.next = 4;
225
279
  return this.core.effects.emit(CartHooks.OnCartRemove, items);
226
280
  case 4:
227
281
  case "end":
228
- return _context6.stop();
282
+ return _context5.stop();
229
283
  }
230
- }, _callee6, this);
284
+ }, _callee5, this);
231
285
  }));
232
286
  function removeItem(_x6) {
233
287
  return _removeItem.apply(this, arguments);
@@ -237,16 +291,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
237
291
  }, {
238
292
  key: "storeTemp",
239
293
  value: function () {
240
- var _storeTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(key, value) {
241
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
242
- while (1) switch (_context7.prev = _context7.next) {
294
+ var _storeTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(key, value) {
295
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
296
+ while (1) switch (_context6.prev = _context6.next) {
243
297
  case 0:
244
298
  this.store.temp[key] = value;
245
- case 1:
299
+ _context6.next = 3;
300
+ return this.core.effects.emit("".concat(this.name, ":changed"), this.store.temp);
301
+ case 3:
246
302
  case "end":
247
- return _context7.stop();
303
+ return _context6.stop();
248
304
  }
249
- }, _callee7, this);
305
+ }, _callee6, this);
250
306
  }));
251
307
  function storeTemp(_x7, _x8) {
252
308
  return _storeTemp.apply(this, arguments);
@@ -255,29 +311,31 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
255
311
  }()
256
312
  }, {
257
313
  key: "getTemp",
258
- value: function () {
259
- var _getTemp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(key) {
260
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
261
- while (1) switch (_context8.prev = _context8.next) {
262
- case 0:
263
- if (key) {
264
- _context8.next = 2;
265
- break;
266
- }
267
- return _context8.abrupt("return", this.store.temp);
268
- case 2:
269
- return _context8.abrupt("return", this.store.temp[key]);
270
- case 3:
271
- case "end":
272
- return _context8.stop();
273
- }
274
- }, _callee8, this);
275
- }));
276
- function getTemp(_x9) {
277
- return _getTemp.apply(this, arguments);
314
+ value: function getTemp(key) {
315
+ if (!key) {
316
+ return this.store.temp;
278
317
  }
279
- return getTemp;
280
- }()
318
+ return this.store.temp[key];
319
+ }
320
+ }, {
321
+ key: "clear",
322
+ value: function clear() {
323
+ this.store.list = [];
324
+ }
325
+ }, {
326
+ key: "clearCartByAccount",
327
+ value: function clearCartByAccount(account_id) {
328
+ this.store.list = this.store.list.filter(function (item) {
329
+ return item.holder_id !== account_id;
330
+ });
331
+ }
332
+ }, {
333
+ key: "getCartByAccount",
334
+ value: function getCartByAccount(account_id) {
335
+ return this.store.list.filter(function (item) {
336
+ return item.holder_id === account_id;
337
+ });
338
+ }
281
339
  }]);
282
340
  return CartModule;
283
341
  }(BaseModule);