@pisell/pisellos 0.0.110 → 0.0.112

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.
@@ -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;
@@ -200,6 +200,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
200
200
  start_at: dayjs.Dayjs;
201
201
  end_at: dayjs.Dayjs;
202
202
  count: number;
203
+ left: number;
203
204
  }[];
204
205
  addProductToCart({ product, date, account, }: {
205
206
  product: ProductData;
@@ -211,7 +212,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
211
212
  }): void;
212
213
  setOtherData(key: string, value: any): void;
213
214
  getOtherData(key: string): any;
214
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
215
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
215
216
  /**
216
217
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
217
218
  *
@@ -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; }
@@ -271,11 +271,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
271
271
  key: "loadProductByScheduleDate",
272
272
  value: function () {
273
273
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
274
- var date, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds;
274
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, scheduleIds, otherProductsIds, allProductIds;
275
275
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
276
276
  while (1) switch (_context3.prev = _context3.next) {
277
277
  case 0:
278
- date = _ref2.date, product_ids = _ref2.product_ids, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids;
278
+ 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;
279
279
  scheduleList = this.store.schedule.getAvailabilityScheduleDateList(); // 缓存下这次选择的结果,如果是先选日期再选 duration 类商品,后面用得到
280
280
  this.setDateRange([{
281
281
  date: date,
@@ -292,17 +292,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
292
292
  return n.date === date;
293
293
  }).flatMap(function (n) {
294
294
  return n.schedule_id;
295
+ }).filter(function (n) {
296
+ return n !== null;
297
+ }); // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
298
+ otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
299
+ allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
300
+ return self.indexOf(n) === index;
295
301
  });
296
- _context3.next = 6;
302
+ _context3.next = 8;
297
303
  return this.loadProducts({
298
304
  schedule_ids: scheduleIds,
299
- product_ids: product_ids,
305
+ product_ids: allProductIds,
300
306
  category_ids: category_ids,
301
307
  schedule_date: date
302
308
  });
303
- case 6:
309
+ case 8:
304
310
  return _context3.abrupt("return", _context3.sent);
305
- case 7:
311
+ case 9:
306
312
  case "end":
307
313
  return _context3.stop();
308
314
  }
@@ -460,7 +466,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
460
466
  key: "loadScheduleAvailableDate",
461
467
  value: function () {
462
468
  var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref3) {
463
- var _res$data$date_list;
469
+ var _res$data$date_list, _res$data$other_produ, _res$data$other_produ2;
464
470
  var startDate, endDate, custom_page_id, channel, dates, res;
465
471
  return _regeneratorRuntime().wrap(function _callee6$(_context7) {
466
472
  while (1) switch (_context7.prev = _context7.next) {
@@ -481,7 +487,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
481
487
  return _context7.abrupt("return", dates);
482
488
  case 6:
483
489
  _context7.next = 8;
484
- return this.request.get("/schedule/product/availability", {
490
+ return this.request.get("/schedule/product/availability/v2", {
485
491
  start_date: startDate,
486
492
  end_date: endDate,
487
493
  custom_page_id: custom_page_id,
@@ -490,24 +496,32 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
490
496
  case 8:
491
497
  res = _context7.sent;
492
498
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
499
+ this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
493
500
  // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
494
- 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'))) {
495
- _context7.next = 12;
501
+ 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'))) {
502
+ _context7.next = 13;
496
503
  break;
497
504
  }
498
505
  return _context7.abrupt("return", dates);
499
- case 12:
500
- res.data.date_list.forEach(function (n) {
501
- var index = dates.findIndex(function (m) {
502
- return m.date === n.date;
506
+ case 13:
507
+ if ((_res$data$other_produ2 = res.data.other_product_ids) !== null && _res$data$other_produ2 !== void 0 && _res$data$other_produ2.length) {
508
+ // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
509
+ dates.forEach(function (n) {
510
+ n.status = 'available';
503
511
  });
504
- if (index !== -1) {
505
- dates[index].status = 'available';
506
- }
507
- });
512
+ } else {
513
+ res.data.date_list.forEach(function (n) {
514
+ var index = dates.findIndex(function (m) {
515
+ return m.date === n.date;
516
+ });
517
+ if (index !== -1) {
518
+ dates[index].status = 'available';
519
+ }
520
+ });
521
+ }
508
522
  dates = disableDatesBeforeOneDay(dates);
509
523
  return _context7.abrupt("return", dates);
510
- case 15:
524
+ case 16:
511
525
  case "end":
512
526
  return _context7.stop();
513
527
  }
@@ -2351,6 +2365,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2351
2365
  // 用来计算资源的可使用情况,针对单个schedule 时间片
2352
2366
  var resourcesUseableMap = {};
2353
2367
  var count = 0;
2368
+ var bookingLeft = 0;
2354
2369
  // 遍历所有资源
2355
2370
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
2356
2371
  // 遍历所有资源的上工时间片
@@ -2392,8 +2407,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2392
2407
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2393
2408
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2394
2409
  return n === false;
2395
- }) && currentResourcesCount >= count) {
2396
- count = currentResourcesCount;
2410
+ })) {
2411
+ if (currentResourcesCount >= count) {
2412
+ count = currentResourcesCount;
2413
+ }
2414
+ bookingLeft += 1;
2397
2415
  }
2398
2416
  });
2399
2417
  var startDayJs = dayjs(item.start);
@@ -2403,7 +2421,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2403
2421
  end_time: endDayJs.format('HH:mm'),
2404
2422
  start_at: startDayJs,
2405
2423
  end_at: endDayJs,
2406
- count: count
2424
+ count: count,
2425
+ left: bookingLeft
2407
2426
  };
2408
2427
  });
2409
2428
  return formatScheduleTimeSlots;
@@ -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;
@@ -200,6 +200,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
200
200
  start_at: dayjs.Dayjs;
201
201
  end_at: dayjs.Dayjs;
202
202
  count: number;
203
+ left: number;
203
204
  }[];
204
205
  addProductToCart({ product, date, account, }: {
205
206
  product: ProductData;
@@ -211,7 +212,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
211
212
  }): void;
212
213
  setOtherData(key: string, value: any): void;
213
214
  getOtherData(key: string): any;
214
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
215
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
215
216
  /**
216
217
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
217
218
  *
@@ -212,7 +212,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
212
212
  }
213
213
  async loadProductByScheduleDate({
214
214
  date,
215
- product_ids,
215
+ product_ids = [],
216
216
  category_ids = []
217
217
  }) {
218
218
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
@@ -220,10 +220,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
220
220
  { date, status: "available", week: "", weekNum: 0 },
221
221
  { date, status: "available", week: "", weekNum: 0 }
222
222
  ]);
223
- const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
223
+ const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null);
224
+ const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
225
+ const allProductIds = [...product_ids, ...otherProductsIds].filter((n, index, self) => self.indexOf(n) === index);
224
226
  return await this.loadProducts({
225
227
  schedule_ids: scheduleIds,
226
- product_ids,
228
+ product_ids: allProductIds,
227
229
  category_ids,
228
230
  schedule_date: date
229
231
  });
@@ -297,7 +299,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
297
299
  custom_page_id,
298
300
  channel
299
301
  }) {
300
- var _a;
302
+ var _a, _b, _c;
301
303
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day")) {
302
304
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
303
305
  }
@@ -307,7 +309,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
307
309
  return dates;
308
310
  }
309
311
  const res = await this.request.get(
310
- `/schedule/product/availability`,
312
+ `/schedule/product/availability/v2`,
311
313
  {
312
314
  start_date: startDate,
313
315
  end_date: endDate,
@@ -316,15 +318,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
316
318
  }
317
319
  );
318
320
  this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
319
- if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)(), "day")) {
321
+ this.store.schedule.setOtherProductsIds(res.data.other_product_ids || []);
322
+ 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")) {
320
323
  return dates;
321
324
  }
322
- res.data.date_list.forEach((n) => {
323
- const index = dates.findIndex((m) => m.date === n.date);
324
- if (index !== -1) {
325
- dates[index].status = "available";
326
- }
327
- });
325
+ if ((_c = res.data.other_product_ids) == null ? void 0 : _c.length) {
326
+ dates.forEach((n) => {
327
+ n.status = "available";
328
+ });
329
+ } else {
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
+ });
336
+ }
328
337
  dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
329
338
  return dates;
330
339
  }
@@ -1644,6 +1653,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1644
1653
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1645
1654
  const resourcesUseableMap = {};
1646
1655
  let count = 0;
1656
+ let bookingLeft = 0;
1647
1657
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1648
1658
  let currentResourcesCount = 0;
1649
1659
  const currentResourcesTimeSlotCanUsedArr = [];
@@ -1675,10 +1685,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1675
1685
  }
1676
1686
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1677
1687
  });
1678
- if (!currentResourcesTimeSlotCanUsedArr.some(
1679
- (n) => n === false
1680
- ) && currentResourcesCount >= count) {
1681
- count = currentResourcesCount;
1688
+ if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false)) {
1689
+ if (currentResourcesCount >= count) {
1690
+ count = currentResourcesCount;
1691
+ }
1692
+ bookingLeft += 1;
1682
1693
  }
1683
1694
  });
1684
1695
  const startDayJs = (0, import_dayjs.default)(item.start);
@@ -1688,7 +1699,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1688
1699
  end_time: endDayJs.format("HH:mm"),
1689
1700
  start_at: startDayJs,
1690
1701
  end_at: endDayJs,
1691
- count
1702
+ count,
1703
+ left: bookingLeft
1692
1704
  };
1693
1705
  });
1694
1706
  return formatScheduleTimeSlots;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.110",
4
+ "version": "0.0.112",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",