@pisell/pisellos 0.0.98 → 0.0.99

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.
@@ -7,9 +7,16 @@ export declare class ProductList extends BaseModule implements Module {
7
7
  protected defaultName: string;
8
8
  protected defaultVersion: string;
9
9
  private store;
10
+ private request;
10
11
  constructor(name?: string, version?: string);
11
12
  initialize(core: PisellCore, options: any): Promise<void>;
12
13
  storeChange(path?: string, value?: any): Promise<void>;
14
+ loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
15
+ ids?: number[];
16
+ customer_id?: number;
17
+ schedule_date?: string;
18
+ channel?: string;
19
+ }): Promise<any>;
13
20
  getProducts(): Promise<ProductData[]>;
14
21
  getProduct(id: number): Promise<Product | undefined>;
15
22
  addProduct(products: ProductData[]): Promise<void>;
@@ -30,6 +30,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
30
30
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'productList');
31
31
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
32
32
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
33
34
  return _this;
34
35
  }
35
36
  _createClass(ProductList, [{
@@ -51,7 +52,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
51
52
  this.store.productMap = new Map();
52
53
  this.store.selectProducts = [];
53
54
  }
54
- case 3:
55
+ this.request = core.getPlugin('request');
56
+ case 4:
55
57
  case "end":
56
58
  return _context.stop();
57
59
  }
@@ -95,22 +97,54 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
95
97
  return storeChange;
96
98
  }()
97
99
  }, {
98
- key: "getProducts",
100
+ key: "loadProductsPrice",
99
101
  value: function () {
100
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
102
+ var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
103
+ var _ref$ids, ids, customer_id, schedule_date, channel, productsData;
101
104
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
102
105
  while (1) switch (_context3.prev = _context3.next) {
103
106
  case 0:
104
- _context3.next = 2;
105
- return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
106
- case 2:
107
- return _context3.abrupt("return", cloneDeep(this.store.list));
107
+ _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date, channel = _ref.channel;
108
+ _context3.next = 3;
109
+ return this.request.post("/product/query/price", {
110
+ ids: ids,
111
+ customer_id: customer_id,
112
+ schedule_date: schedule_date,
113
+ channel: channel
114
+ }, {
115
+ useCache: true
116
+ });
108
117
  case 3:
118
+ productsData = _context3.sent;
119
+ return _context3.abrupt("return", productsData.data);
120
+ case 5:
109
121
  case "end":
110
122
  return _context3.stop();
111
123
  }
112
124
  }, _callee3, this);
113
125
  }));
126
+ function loadProductsPrice(_x5) {
127
+ return _loadProductsPrice.apply(this, arguments);
128
+ }
129
+ return loadProductsPrice;
130
+ }()
131
+ }, {
132
+ key: "getProducts",
133
+ value: function () {
134
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
135
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
136
+ while (1) switch (_context4.prev = _context4.next) {
137
+ case 0:
138
+ _context4.next = 2;
139
+ return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
140
+ case 2:
141
+ return _context4.abrupt("return", cloneDeep(this.store.list));
142
+ case 3:
143
+ case "end":
144
+ return _context4.stop();
145
+ }
146
+ }, _callee4, this);
147
+ }));
114
148
  function getProducts() {
115
149
  return _getProducts.apply(this, arguments);
116
150
  }
@@ -119,29 +153,29 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
119
153
  }, {
120
154
  key: "getProduct",
121
155
  value: function () {
122
- var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(id) {
156
+ var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
123
157
  var product;
124
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
125
- while (1) switch (_context4.prev = _context4.next) {
158
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
159
+ while (1) switch (_context5.prev = _context5.next) {
126
160
  case 0:
127
- _context4.next = 2;
161
+ _context5.next = 2;
128
162
  return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
129
163
  case 2:
130
164
  product = this.store.productMap.get("".concat(id));
131
165
  if (!product) {
132
- _context4.next = 5;
166
+ _context5.next = 5;
133
167
  break;
134
168
  }
135
- return _context4.abrupt("return", product);
169
+ return _context5.abrupt("return", product);
136
170
  case 5:
137
- return _context4.abrupt("return", undefined);
171
+ return _context5.abrupt("return", undefined);
138
172
  case 6:
139
173
  case "end":
140
- return _context4.stop();
174
+ return _context5.stop();
141
175
  }
142
- }, _callee4, this);
176
+ }, _callee5, this);
143
177
  }));
144
- function getProduct(_x5) {
178
+ function getProduct(_x6) {
145
179
  return _getProduct.apply(this, arguments);
146
180
  }
147
181
  return getProduct;
@@ -149,10 +183,10 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
149
183
  }, {
150
184
  key: "addProduct",
151
185
  value: function () {
152
- var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products) {
186
+ var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(products) {
153
187
  var _this3 = this;
154
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
155
- while (1) switch (_context5.prev = _context5.next) {
188
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
189
+ while (1) switch (_context6.prev = _context6.next) {
156
190
  case 0:
157
191
  // 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
158
192
  // list 需要根据 id 去重
@@ -172,11 +206,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
172
206
  this.storeChange();
173
207
  case 3:
174
208
  case "end":
175
- return _context5.stop();
209
+ return _context6.stop();
176
210
  }
177
- }, _callee5, this);
211
+ }, _callee6, this);
178
212
  }));
179
- function addProduct(_x6) {
213
+ function addProduct(_x7) {
180
214
  return _addProduct.apply(this, arguments);
181
215
  }
182
216
  return addProduct;
@@ -184,18 +218,18 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
184
218
  }, {
185
219
  key: "selectProducts",
186
220
  value: function () {
187
- var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(products) {
188
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
189
- while (1) switch (_context6.prev = _context6.next) {
221
+ var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
222
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
223
+ while (1) switch (_context7.prev = _context7.next) {
190
224
  case 0:
191
225
  this.store.selectProducts = products;
192
226
  case 1:
193
227
  case "end":
194
- return _context6.stop();
228
+ return _context7.stop();
195
229
  }
196
- }, _callee6, this);
230
+ }, _callee7, this);
197
231
  }));
198
- function selectProducts(_x7) {
232
+ function selectProducts(_x8) {
199
233
  return _selectProducts.apply(this, arguments);
200
234
  }
201
235
  return selectProducts;
@@ -186,10 +186,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
186
186
  private getScheduleDataByIds;
187
187
  openProductDetail(productId: number): Promise<void>;
188
188
  closeProductDetail(): void;
189
- getTimeslotBySchedule({ date, scheduleIds, resources, }: {
189
+ getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
190
190
  date: string;
191
191
  scheduleIds?: number[];
192
192
  resources?: ProductResourceItem[];
193
+ product?: ProductData;
193
194
  }): {
194
195
  start_time: string;
195
196
  end_time: string;
@@ -232,7 +232,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
232
232
  _context2.next = 7;
233
233
  return this.request.post("/product/query", {
234
234
  open_quotation: 1,
235
- open_bundle: 1,
235
+ open_bundle: 0,
236
236
  extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket'],
237
237
  with: ['category', 'collection', 'resourceRelation'],
238
238
  status: 'published',
@@ -313,64 +313,62 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
313
313
  key: "updateQuotationPriceAndCart",
314
314
  value: function () {
315
315
  var _updateQuotationPriceAndCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(date) {
316
- var _this$otherParams3,
317
- _this3 = this;
318
- var dateRange, scheduleList, scheduleIds, cartItems, _iterator, _step, _loop;
316
+ var _this3 = this;
317
+ var cartItems, userPlugin, customer_id, _userPlugin$get2, res, _iterator, _step, _loop;
319
318
  return _regeneratorRuntime().wrap(function _callee4$(_context5) {
320
319
  while (1) switch (_context5.prev = _context5.next) {
321
320
  case 0:
322
- dateRange = this.store.date.getDateRange();
323
- scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
324
- scheduleIds = [];
325
- if (dateRange && dateRange.length) {
326
- scheduleIds = scheduleList.filter(function (n) {
327
- return n.date === dateRange[0].date;
328
- }).flatMap(function (n) {
329
- return n.schedule_id;
330
- });
331
- } else {
332
- scheduleIds = scheduleList.filter(function (n) {
333
- return n.date === date;
334
- }).flatMap(function (n) {
335
- return n.schedule_id;
336
- });
337
- }
338
- _context5.next = 6;
339
- return this.loadProducts(_objectSpread(_objectSpread({}, (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.productModuleParams), {}, {
340
- scheduleIds: scheduleIds,
341
- schedule_date: date
342
- }));
343
- case 6:
344
321
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
345
322
  cartItems = this.store.cart.getItems();
346
323
  if (!cartItems.length) {
347
324
  _context5.next = 25;
348
325
  break;
349
326
  }
327
+ userPlugin = this.core.getPlugin('user');
328
+ customer_id = undefined;
329
+ try {
330
+ customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get2 = userPlugin.get()) === null || _userPlugin$get2 === void 0 ? void 0 : _userPlugin$get2.id;
331
+ } catch (error) {
332
+ console.error(error);
333
+ }
334
+ _context5.next = 7;
335
+ return this.store.products.loadProductsPrice({
336
+ ids: cartItems.map(function (n) {
337
+ return n.id;
338
+ }),
339
+ schedule_date: date,
340
+ customer_id: customer_id
341
+ });
342
+ case 7:
343
+ res = _context5.sent;
350
344
  _iterator = _createForOfIteratorHelper(cartItems);
351
345
  _context5.prev = 9;
352
346
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
353
347
  var _bundle;
354
- var item, targetProduct, productInfo, bundle;
348
+ var item, targetProduct, cartProduct, productInfo, bundle;
355
349
  return _regeneratorRuntime().wrap(function _loop$(_context4) {
356
350
  while (1) switch (_context4.prev = _context4.next) {
357
351
  case 0:
358
352
  item = _step.value;
359
- _context4.next = 3;
353
+ targetProduct = res.find(function (n) {
354
+ return n.id === item.id;
355
+ });
356
+ _context4.next = 4;
360
357
  return _this3.store.products.getProduct(item.id);
361
- case 3:
362
- targetProduct = _context4.sent;
363
- productInfo = cloneDeep(targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
358
+ case 4:
359
+ cartProduct = _context4.sent;
360
+ productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
364
361
  bundle = item._bundleOrigin;
362
+ productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
363
+ productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
365
364
  bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
366
- var _productInfo$bundle;
367
- // 尝试到新的 productInfo 里找对应的 bundleitem
368
- // 然后更新 bundle 的价格
369
- var targetBundle = productInfo === null || productInfo === void 0 || (_productInfo$bundle = productInfo.bundle) === null || _productInfo$bundle === void 0 ? void 0 : _productInfo$bundle.find(function (m) {
370
- return m.group_id === n.id;
365
+ var _targetProduct$bundle;
366
+ // 更新 bundle 的价格
367
+ var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
368
+ return m.id === n.group_id;
371
369
  });
372
370
  if (targetBundle) {
373
- var targetBundleItem = targetBundle.items.find(function (m) {
371
+ var targetBundleItem = targetBundle.bundle_item.find(function (m) {
374
372
  return m.id === n.id;
375
373
  });
376
374
  if (targetBundleItem) {
@@ -387,7 +385,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
387
385
  product: productInfo,
388
386
  bundle: bundle
389
387
  });
390
- case 8:
388
+ case 11:
391
389
  case "end":
392
390
  return _context4.stop();
393
391
  }
@@ -2277,9 +2275,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2277
2275
  var _this$store$currentPr2;
2278
2276
  var date = _ref12.date,
2279
2277
  scheduleIds = _ref12.scheduleIds,
2280
- resources = _ref12.resources;
2278
+ resources = _ref12.resources,
2279
+ product = _ref12.product;
2281
2280
  var targetProduct = this.store.currentProduct;
2282
- var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
2281
+ // 如果外面传递了product 优先用外面的
2282
+ var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
2283
2283
  var targetSchedules = [];
2284
2284
  // 如果外面传递了 scheduleIds,优先取入参
2285
2285
  if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
@@ -7,9 +7,16 @@ export declare class ProductList extends BaseModule implements Module {
7
7
  protected defaultName: string;
8
8
  protected defaultVersion: string;
9
9
  private store;
10
+ private request;
10
11
  constructor(name?: string, version?: string);
11
12
  initialize(core: PisellCore, options: any): Promise<void>;
12
13
  storeChange(path?: string, value?: any): Promise<void>;
14
+ loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
15
+ ids?: number[];
16
+ customer_id?: number;
17
+ schedule_date?: string;
18
+ channel?: string;
19
+ }): Promise<any>;
13
20
  getProducts(): Promise<ProductData[]>;
14
21
  getProduct(id: number): Promise<Product | undefined>;
15
22
  addProduct(products: ProductData[]): Promise<void>;
@@ -47,6 +47,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
47
47
  this.store.productMap = /* @__PURE__ */ new Map();
48
48
  this.store.selectProducts = [];
49
49
  }
50
+ this.request = core.getPlugin("request");
50
51
  }
51
52
  async storeChange(path, value) {
52
53
  var _a;
@@ -63,6 +64,24 @@ var ProductList = class extends import_BaseModule.BaseModule {
63
64
  }
64
65
  });
65
66
  }
67
+ async loadProductsPrice({
68
+ ids = [],
69
+ customer_id,
70
+ schedule_date,
71
+ channel
72
+ }) {
73
+ const productsData = await this.request.post(
74
+ `/product/query/price`,
75
+ {
76
+ ids,
77
+ customer_id,
78
+ schedule_date,
79
+ channel
80
+ },
81
+ { useCache: true }
82
+ );
83
+ return productsData.data;
84
+ }
66
85
  async getProducts() {
67
86
  await this.core.effects.emit(
68
87
  import_types.ProductListHooks.onGetProducts,
@@ -186,10 +186,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
186
186
  private getScheduleDataByIds;
187
187
  openProductDetail(productId: number): Promise<void>;
188
188
  closeProductDetail(): void;
189
- getTimeslotBySchedule({ date, scheduleIds, resources, }: {
189
+ getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
190
190
  date: string;
191
191
  scheduleIds?: number[];
192
192
  resources?: ProductResourceItem[];
193
+ product?: ProductData;
193
194
  }): {
194
195
  start_time: string;
195
196
  end_time: string;
@@ -181,7 +181,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
181
181
  `/product/query`,
182
182
  {
183
183
  open_quotation: 1,
184
- open_bundle: 1,
184
+ open_bundle: 0,
185
185
  extension_type: [
186
186
  "product_appointment",
187
187
  "appointment_ticket",
@@ -225,30 +225,32 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
225
225
  }
226
226
  async updateQuotationPriceAndCart(date) {
227
227
  var _a;
228
- const dateRange = this.store.date.getDateRange();
229
- const scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
230
- let scheduleIds = [];
231
- if (dateRange && dateRange.length) {
232
- scheduleIds = scheduleList.filter((n) => n.date === dateRange[0].date).flatMap((n) => n.schedule_id);
233
- } else {
234
- scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
235
- }
236
- await this.loadProducts({
237
- ...(_a = this.otherParams) == null ? void 0 : _a.productModuleParams,
238
- scheduleIds,
239
- schedule_date: date
240
- });
241
228
  const cartItems = this.store.cart.getItems();
242
229
  if (cartItems.length) {
230
+ let userPlugin = this.core.getPlugin("user");
231
+ let customer_id = void 0;
232
+ try {
233
+ customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
234
+ } catch (error) {
235
+ console.error(error);
236
+ }
237
+ const res = await this.store.products.loadProductsPrice({
238
+ ids: cartItems.map((n) => n.id),
239
+ schedule_date: date,
240
+ customer_id
241
+ });
243
242
  for (const item of cartItems) {
244
- const targetProduct = await this.store.products.getProduct(item.id);
245
- const productInfo = (0, import_lodash_es.cloneDeep)(targetProduct == null ? void 0 : targetProduct.getData());
243
+ const targetProduct = res.find((n) => n.id === item.id);
244
+ const cartProduct = await this.store.products.getProduct(item.id);
245
+ const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
246
246
  let bundle = item._bundleOrigin;
247
+ productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
248
+ productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
247
249
  bundle = bundle == null ? void 0 : bundle.map((n) => {
248
250
  var _a2;
249
- const targetBundle = (_a2 = productInfo == null ? void 0 : productInfo.bundle) == null ? void 0 : _a2.find((m) => m.group_id === n.id);
251
+ const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find((m) => m.id === n.group_id);
250
252
  if (targetBundle) {
251
- const targetBundleItem = targetBundle.items.find((m) => m.id === n.id);
253
+ const targetBundleItem = targetBundle.bundle_item.find((m) => m.id === n.id);
252
254
  if (targetBundleItem) {
253
255
  return {
254
256
  ...n,
@@ -1532,11 +1534,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1532
1534
  getTimeslotBySchedule({
1533
1535
  date,
1534
1536
  scheduleIds,
1535
- resources
1537
+ resources,
1538
+ product
1536
1539
  }) {
1537
1540
  var _a, _b, _c;
1538
1541
  const targetProduct = this.store.currentProduct;
1539
- const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
1542
+ const targetProductData = product || (targetProduct == null ? void 0 : targetProduct.getData());
1540
1543
  let targetSchedules = [];
1541
1544
  if (scheduleIds == null ? void 0 : scheduleIds.length) {
1542
1545
  targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.98",
4
+ "version": "0.0.99",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",