@pisell/pisellos 2.0.27 → 2.0.29

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.
@@ -207,6 +207,12 @@ export var formatDiscountToCartItemOrigin = function formatDiscountToCartItemOri
207
207
  origin.product = {};
208
208
  }
209
209
  origin.product.discount_list = discounts;
210
+ } else {
211
+ // 如果折扣为空,则清空折扣列表
212
+ if (!origin.product) {
213
+ origin.product = {};
214
+ }
215
+ origin.product.discount_list = [];
210
216
  }
211
217
  return origin;
212
218
  };
@@ -14,5 +14,7 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
14
14
  getScheduleListByIds(ids: number[]): ScheduleItem[];
15
15
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
16
16
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
17
+ setOtherProductsIds(ids: number[]): void;
18
+ getOtherProductsIds(): number[];
17
19
  storeChange(): void;
18
20
  }
@@ -92,6 +92,16 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
92
92
  value: function getAvailabilityScheduleDateList() {
93
93
  return this.store.availabilityDateList;
94
94
  }
95
+ }, {
96
+ key: "setOtherProductsIds",
97
+ value: function setOtherProductsIds(ids) {
98
+ this.store.otherProductsIds = ids;
99
+ }
100
+ }, {
101
+ key: "getOtherProductsIds",
102
+ value: function getOtherProductsIds() {
103
+ return this.store.otherProductsIds;
104
+ }
95
105
  }, {
96
106
  key: "storeChange",
97
107
  value: function storeChange() {
@@ -2,6 +2,7 @@ import dayjs from 'dayjs';
2
2
  export interface ScheduleState {
3
3
  scheduleList: ScheduleItem[];
4
4
  availabilityDateList: ScheduleAvailabilityDateItem[];
5
+ otherProductsIds: number[];
5
6
  }
6
7
  export type ScheduleAvailabilityDateItem = {
7
8
  date: string;
@@ -42,12 +42,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
42
42
  * 更新step
43
43
  */
44
44
  updateStep(key: string, step: IStep): void;
45
- loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
45
+ loadProducts({ category_ids, product_ids, collection, }: {
46
46
  category_ids?: number[];
47
47
  product_ids?: number[];
48
48
  collection?: number | string[];
49
- schedule_ids?: number[];
50
- schedule_date?: string;
51
49
  }): Promise<any>;
52
50
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
53
51
  date: string;
@@ -200,6 +198,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
200
198
  start_at: dayjs.Dayjs;
201
199
  end_at: dayjs.Dayjs;
202
200
  count: number;
201
+ left: number;
203
202
  }[];
204
203
  addProductToCart({ product, date, account, }: {
205
204
  product: ProductData;
@@ -211,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
211
210
  }): void;
212
211
  setOtherData(key: string, value: any): void;
213
212
  getOtherData(key: string): any;
214
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
213
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
215
214
  /**
216
215
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
217
216
  *
@@ -1,10 +1,10 @@
1
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
9
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
10
10
  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; }
@@ -208,24 +208,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
208
208
  key: "loadProducts",
209
209
  value: function () {
210
210
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
211
- var _schedule_ids;
212
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$schedule_ids, schedule_ids, schedule_date, schedule_ids_data, userPlugin, customer_id, _userPlugin$get, productsData;
211
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, userPlugin, customer_id, _userPlugin$get, productsData;
213
212
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
214
213
  while (1) switch (_context2.prev = _context2.next) {
215
214
  case 0:
216
- _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$schedule_ids = _ref.schedule_ids, schedule_ids = _ref$schedule_ids === void 0 ? [] : _ref$schedule_ids, schedule_date = _ref.schedule_date;
217
- // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
218
- if (!((_schedule_ids = schedule_ids) !== null && _schedule_ids !== void 0 && _schedule_ids.length)) {
219
- schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map(function (n) {
220
- return n.id;
221
- });
222
- if (schedule_ids_data.length) {
223
- schedule_ids = schedule_ids_data;
224
- } else if (schedule_date) {
225
- // 后端说如果 schedule_ids 如果为空,需要给[0]
226
- schedule_ids = [0];
227
- }
228
- }
215
+ _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection;
216
+ // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
217
+ // if (!schedule_ids?.length) {
218
+ // const schedule_ids_data = this.store.schedule
219
+ // .getScheduleListByIds(schedule_ids)
220
+ // .map((n) => n.id);
221
+ // if (schedule_ids_data.length) {
222
+ // schedule_ids = schedule_ids_data;
223
+ // } else if (schedule_date) {
224
+ // // 后端说如果 schedule_ids 如果为空,需要给[0]
225
+ // schedule_ids = [0];
226
+ // }
227
+ // }
229
228
  userPlugin = this.core.getPlugin('user');
230
229
  customer_id = undefined;
231
230
  try {
@@ -234,7 +233,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
234
233
  console.error(error);
235
234
  }
236
235
  // 如果没传schedule_date,则从
237
- _context2.next = 7;
236
+ _context2.next = 6;
238
237
  return this.request.post("/product/query", {
239
238
  open_quotation: 1,
240
239
  open_bundle: 0,
@@ -247,17 +246,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
247
246
  category_ids: category_ids,
248
247
  ids: product_ids,
249
248
  collection: collection,
250
- front_end_cache_id: this.cacheId,
251
- client_schedule_ids: schedule_ids,
252
- schedule_date: schedule_date
249
+ front_end_cache_id: this.cacheId
250
+ // client_schedule_ids: schedule_ids,
251
+ // schedule_date,
253
252
  }, {
254
253
  useCache: true
255
254
  });
256
- case 7:
255
+ case 6:
257
256
  productsData = _context2.sent;
258
257
  this.store.products.addProduct(productsData.data.list);
259
258
  return _context2.abrupt("return", productsData.data.list);
260
- case 10:
259
+ case 9:
261
260
  case "end":
262
261
  return _context2.stop();
263
262
  }
@@ -273,11 +272,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
273
272
  value: function () {
274
273
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
275
274
  var _product_ids;
276
- var date, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds, _schedule$product_ids, schedule;
275
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, _schedule$product_ids, schedule, otherProductsIds, allProductIds;
277
276
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
278
277
  while (1) switch (_context3.prev = _context3.next) {
279
278
  case 0:
280
- date = _ref2.date, product_ids = _ref2.product_ids, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids;
279
+ date = _ref2.date, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids;
281
280
  scheduleList = this.store.schedule.getAvailabilityScheduleDateList(); // 缓存下这次选择的结果,如果是先选日期再选 duration 类商品,后面用得到
282
281
  this.setDateRange([{
283
282
  date: date,
@@ -290,13 +289,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
290
289
  week: '',
291
290
  weekNum: 0
292
291
  }]);
293
- scheduleIds = scheduleList.filter(function (n) {
294
- return n.date === date;
295
- }).flatMap(function (n) {
296
- return n.schedule_id;
297
- }).filter(function (n) {
298
- return n !== null && n !== undefined;
299
- }); // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
292
+ // const scheduleIds = scheduleList
293
+ // .filter((n) => n.date === date)
294
+ // .flatMap((n) => n.schedule_id)
295
+ // .filter((n) => n !== null && n !== undefined);
296
+
297
+ // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
300
298
  if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
301
299
  schedule = scheduleList.find(function (n) {
302
300
  return n.date === date;
@@ -305,16 +303,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
305
303
  product_ids = schedule.product_ids;
306
304
  }
307
305
  }
308
- _context3.next = 7;
306
+ // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
307
+ otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
308
+ allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
309
+ return self.indexOf(n) === index;
310
+ });
311
+ _context3.next = 8;
309
312
  return this.loadProducts({
310
- schedule_ids: scheduleIds,
311
- product_ids: product_ids,
312
- category_ids: category_ids,
313
- schedule_date: date
313
+ // schedule_ids: scheduleIds,
314
+ product_ids: allProductIds,
315
+ category_ids: category_ids
316
+ // schedule_date: date,
314
317
  });
315
- case 7:
316
- return _context3.abrupt("return", _context3.sent);
317
318
  case 8:
319
+ return _context3.abrupt("return", _context3.sent);
320
+ case 9:
318
321
  case "end":
319
322
  return _context3.stop();
320
323
  }
@@ -472,7 +475,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
472
475
  key: "loadScheduleAvailableDate",
473
476
  value: function () {
474
477
  var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
475
- var _res$data$date_list;
478
+ var _res$data$date_list, _res$data$other_produ, _res$data$other_produ2;
476
479
  var startDate, endDate, custom_page_id, channel, dates, res;
477
480
  return _regeneratorRuntime().wrap(function _callee6$(_context7) {
478
481
  while (1) switch (_context7.prev = _context7.next) {
@@ -493,7 +496,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
493
496
  return _context7.abrupt("return", dates);
494
497
  case 6:
495
498
  _context7.next = 8;
496
- return this.request.get("/schedule/product/availability", {
499
+ return this.request.get("/schedule/product/availability/v2", {
497
500
  start_date: startDate,
498
501
  end_date: endDate,
499
502
  custom_page_id: custom_page_id,
@@ -502,24 +505,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
502
505
  case 8:
503
506
  res = _context7.sent;
504
507
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
508
+ this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
505
509
  // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
506
- if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
507
- _context7.next = 12;
510
+ if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) && !((_res$data$other_produ = res.data.other_product_ids) !== null && _res$data$other_produ !== void 0 && _res$data$other_produ.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
511
+ _context7.next = 13;
508
512
  break;
509
513
  }
510
514
  return _context7.abrupt("return", dates);
511
- case 12:
512
- res.data.date_list.forEach(function (n) {
513
- var index = dates.findIndex(function (m) {
514
- return m.date === n.date;
515
+ case 13:
516
+ if ((_res$data$other_produ2 = res.data.other_product_ids) !== null && _res$data$other_produ2 !== void 0 && _res$data$other_produ2.length) {
517
+ // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
518
+ dates.forEach(function (n) {
519
+ n.status = 'available';
515
520
  });
516
- if (index !== -1) {
517
- dates[index].status = 'available';
518
- }
519
- });
521
+ } else {
522
+ res.data.date_list.forEach(function (n) {
523
+ var index = dates.findIndex(function (m) {
524
+ return m.date === n.date;
525
+ });
526
+ if (index !== -1) {
527
+ dates[index].status = 'available';
528
+ }
529
+ });
530
+ }
520
531
  dates = disableDatesBeforeOneDay(dates);
521
532
  return _context7.abrupt("return", dates);
522
- case 15:
533
+ case 16:
523
534
  case "end":
524
535
  return _context7.stop();
525
536
  }
@@ -1950,9 +1961,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1950
1961
  var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
1951
1962
  return n.code === resources_code;
1952
1963
  });
1953
- var resourceBookingType = (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) || 'single';
1954
1964
  // 只有 duration 类商品需要这个操作
1955
- if (index !== 0 && recordTimeSlots && resourceBookingType === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
1965
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
1956
1966
  var _item$_productOrigin$, _item$_productOrigin6, _ref9, _item$_productOrigin7, _item$_productOrigin$2, _item$_productOrigin8, _ref10, _item$_productOrigin9;
1957
1967
  var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
1958
1968
  var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
@@ -2375,6 +2385,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2375
2385
  // 用来计算资源的可使用情况,针对单个schedule 时间片
2376
2386
  var resourcesUseableMap = {};
2377
2387
  var count = 0;
2388
+ var bookingLeft = 0;
2378
2389
  // 遍历所有资源
2379
2390
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
2380
2391
  // 遍历所有资源的上工时间片
@@ -2416,8 +2427,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2416
2427
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2417
2428
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2418
2429
  return n === false;
2419
- }) && currentResourcesCount >= count) {
2420
- count = currentResourcesCount;
2430
+ })) {
2431
+ if (currentResourcesCount >= count) {
2432
+ count = currentResourcesCount;
2433
+ }
2434
+ if (!m.onlyComputed) {
2435
+ bookingLeft += 1;
2436
+ }
2421
2437
  }
2422
2438
  });
2423
2439
  var startDayJs = dayjs(item.start);
@@ -2427,7 +2443,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2427
2443
  end_time: endDayJs.format('HH:mm'),
2428
2444
  start_at: startDayJs,
2429
2445
  end_at: endDayJs,
2430
- count: count
2446
+ count: count,
2447
+ left: bookingLeft
2431
2448
  };
2432
2449
  });
2433
2450
  return formatScheduleTimeSlots;
@@ -204,6 +204,11 @@ var formatDiscountToCartItemOrigin = (params) => {
204
204
  origin.product = {};
205
205
  }
206
206
  origin.product.discount_list = discounts;
207
+ } else {
208
+ if (!origin.product) {
209
+ origin.product = {};
210
+ }
211
+ origin.product.discount_list = [];
207
212
  }
208
213
  return origin;
209
214
  };
@@ -14,5 +14,7 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
14
14
  getScheduleListByIds(ids: number[]): ScheduleItem[];
15
15
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
16
16
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
17
+ setOtherProductsIds(ids: number[]): void;
18
+ getOtherProductsIds(): number[];
17
19
  storeChange(): void;
18
20
  }
@@ -63,6 +63,12 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
63
63
  getAvailabilityScheduleDateList() {
64
64
  return this.store.availabilityDateList;
65
65
  }
66
+ setOtherProductsIds(ids) {
67
+ this.store.otherProductsIds = ids;
68
+ }
69
+ getOtherProductsIds() {
70
+ return this.store.otherProductsIds;
71
+ }
66
72
  storeChange() {
67
73
  if (this.openCache) {
68
74
  const store = (0, import_lodash_es.cloneDeep)(this.store);
@@ -2,6 +2,7 @@ import dayjs from 'dayjs';
2
2
  export interface ScheduleState {
3
3
  scheduleList: ScheduleItem[];
4
4
  availabilityDateList: ScheduleAvailabilityDateItem[];
5
+ otherProductsIds: number[];
5
6
  }
6
7
  export type ScheduleAvailabilityDateItem = {
7
8
  date: string;
@@ -42,12 +42,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
42
42
  * 更新step
43
43
  */
44
44
  updateStep(key: string, step: IStep): void;
45
- loadProducts({ category_ids, product_ids, collection, schedule_ids, schedule_date, }: {
45
+ loadProducts({ category_ids, product_ids, collection, }: {
46
46
  category_ids?: number[];
47
47
  product_ids?: number[];
48
48
  collection?: number | string[];
49
- schedule_ids?: number[];
50
- schedule_date?: string;
51
49
  }): Promise<any>;
52
50
  loadProductByScheduleDate({ date, product_ids, category_ids, }: {
53
51
  date: string;
@@ -200,6 +198,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
200
198
  start_at: dayjs.Dayjs;
201
199
  end_at: dayjs.Dayjs;
202
200
  count: number;
201
+ left: number;
203
202
  }[];
204
203
  addProductToCart({ product, date, account, }: {
205
204
  product: ProductData;
@@ -211,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
211
210
  }): void;
212
211
  setOtherData(key: string, value: any): void;
213
212
  getOtherData(key: string): any;
214
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
213
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
215
214
  /**
216
215
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
217
216
  *
@@ -162,19 +162,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
162
162
  async loadProducts({
163
163
  category_ids = [],
164
164
  product_ids = [],
165
- collection = [],
166
- schedule_ids = [],
167
- schedule_date
165
+ collection = []
166
+ // schedule_ids = [],
167
+ // schedule_date,
168
168
  }) {
169
169
  var _a;
170
- if (!(schedule_ids == null ? void 0 : schedule_ids.length)) {
171
- const schedule_ids_data = this.store.schedule.getScheduleListByIds(schedule_ids).map((n) => n.id);
172
- if (schedule_ids_data.length) {
173
- schedule_ids = schedule_ids_data;
174
- } else if (schedule_date) {
175
- schedule_ids = [0];
176
- }
177
- }
178
170
  let userPlugin = this.core.getPlugin("user");
179
171
  let customer_id = void 0;
180
172
  try {
@@ -202,9 +194,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
202
194
  category_ids,
203
195
  ids: product_ids,
204
196
  collection,
205
- front_end_cache_id: this.cacheId,
206
- client_schedule_ids: schedule_ids,
207
- schedule_date
197
+ front_end_cache_id: this.cacheId
198
+ // client_schedule_ids: schedule_ids,
199
+ // schedule_date,
208
200
  },
209
201
  { useCache: true }
210
202
  );
@@ -213,7 +205,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
213
205
  }
214
206
  async loadProductByScheduleDate({
215
207
  date,
216
- product_ids,
208
+ product_ids = [],
217
209
  category_ids = []
218
210
  }) {
219
211
  var _a;
@@ -222,18 +214,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
222
214
  { date, status: "available", week: "", weekNum: 0 },
223
215
  { date, status: "available", week: "", weekNum: 0 }
224
216
  ]);
225
- const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null && n !== void 0);
226
217
  if (!(product_ids == null ? void 0 : product_ids.length)) {
227
218
  const schedule = scheduleList.find((n) => n.date === date);
228
219
  if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
229
220
  product_ids = schedule.product_ids;
230
221
  }
231
222
  }
223
+ const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
224
+ const allProductIds = [...product_ids, ...otherProductsIds].filter(
225
+ (n, index, self) => self.indexOf(n) === index
226
+ );
232
227
  return await this.loadProducts({
233
- schedule_ids: scheduleIds,
234
- product_ids,
235
- category_ids,
236
- schedule_date: date
228
+ // schedule_ids: scheduleIds,
229
+ product_ids: allProductIds,
230
+ category_ids
231
+ // schedule_date: date,
237
232
  });
238
233
  }
239
234
  async updateQuotationPriceAndCart(date) {
@@ -305,7 +300,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
305
300
  custom_page_id,
306
301
  channel
307
302
  }) {
308
- var _a;
303
+ var _a, _b, _c;
309
304
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
310
305
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
311
306
  }
@@ -315,7 +310,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
315
310
  return dates;
316
311
  }
317
312
  const res = await this.request.get(
318
- `/schedule/product/availability`,
313
+ `/schedule/product/availability/v2`,
319
314
  {
320
315
  start_date: startDate,
321
316
  end_date: endDate,
@@ -324,15 +319,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
324
319
  }
325
320
  );
326
321
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
327
- if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
322
+ this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
323
+ if (!((_a = res.data.date_list) == null ? void 0 : _a.length) && !((_b = res.data.other_product_ids) == null ? void 0 : _b.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
328
324
  return dates;
329
325
  }
330
- res.data.date_list.forEach((n) => {
331
- const index = dates.findIndex((m) => m.date === n.date);
332
- if (index !== -1) {
333
- dates[index].status = "available";
334
- }
335
- });
326
+ if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
327
+ dates.forEach((n) => {
328
+ n.status = "available";
329
+ });
330
+ } else {
331
+ res.data.date_list.forEach((n) => {
332
+ const index = dates.findIndex((m) => m.date === n.date);
333
+ if (index !== -1) {
334
+ dates[index].status = "available";
335
+ }
336
+ });
337
+ }
336
338
  dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
337
339
  return dates;
338
340
  }
@@ -1272,8 +1274,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1272
1274
  const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1273
1275
  (n) => n.code === resources_code
1274
1276
  );
1275
- const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
1276
- if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1277
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1277
1278
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1278
1279
  ((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
1279
1280
  ((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
@@ -1664,6 +1665,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1664
1665
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1665
1666
  const resourcesUseableMap = {};
1666
1667
  let count = 0;
1668
+ let bookingLeft = 0;
1667
1669
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1668
1670
  let currentResourcesCount = 0;
1669
1671
  const currentResourcesTimeSlotCanUsedArr = [];
@@ -1695,10 +1697,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1695
1697
  }
1696
1698
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1697
1699
  });
1698
- if (!currentResourcesTimeSlotCanUsedArr.some(
1699
- (n) => n === false
1700
- ) && currentResourcesCount >= count) {
1701
- count = currentResourcesCount;
1700
+ if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false)) {
1701
+ if (currentResourcesCount >= count) {
1702
+ count = currentResourcesCount;
1703
+ }
1704
+ if (!m.onlyComputed) {
1705
+ bookingLeft += 1;
1706
+ }
1702
1707
  }
1703
1708
  });
1704
1709
  const startDayJs = (0, import_dayjs.default)(item.start);
@@ -1708,7 +1713,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1708
1713
  end_time: endDayJs.format("HH:mm"),
1709
1714
  start_at: startDayJs,
1710
1715
  end_at: endDayJs,
1711
- count
1716
+ count,
1717
+ left: bookingLeft
1712
1718
  };
1713
1719
  });
1714
1720
  return formatScheduleTimeSlots;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.27",
4
+ "version": "2.0.29",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",