@pisell/pisellos 2.0.44 → 2.0.46
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.
- package/dist/modules/Date/index.js +25 -12
- package/dist/modules/Date/types.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +23 -9
- package/lib/modules/Date/index.js +31 -26
- package/lib/modules/Date/types.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +7 -5
- package/package.json +1 -1
|
@@ -93,11 +93,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
93
93
|
key: "getResourceDates",
|
|
94
94
|
value: function () {
|
|
95
95
|
var _getResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
96
|
-
var _params$query;
|
|
97
|
-
var currentDateList, currentDateListMap, resourceIds, hasResource, dates;
|
|
96
|
+
var _params$query, currentDateList, currentDateListMap, resourceIds, hasResource, dates;
|
|
98
97
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
99
98
|
while (1) switch (_context2.prev = _context2.next) {
|
|
100
99
|
case 0:
|
|
100
|
+
if (!params.useCache) {
|
|
101
|
+
_context2.next = 7;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
101
104
|
// 发请求之前,做一道检测,看 dateList 里是否有对应日期,且对应日期里是否都有对应 resource_ids 的资源
|
|
102
105
|
currentDateList = this.getDateList() || [];
|
|
103
106
|
currentDateListMap = new Map(currentDateList.map(function (item) {
|
|
@@ -112,18 +115,18 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
112
115
|
});
|
|
113
116
|
});
|
|
114
117
|
if (!hasResource) {
|
|
115
|
-
_context2.next =
|
|
118
|
+
_context2.next = 7;
|
|
116
119
|
break;
|
|
117
120
|
}
|
|
118
121
|
return _context2.abrupt("return", currentDateList);
|
|
119
|
-
case
|
|
120
|
-
_context2.next =
|
|
122
|
+
case 7:
|
|
123
|
+
_context2.next = 9;
|
|
121
124
|
return this.getResourceAvailableTimeList(params);
|
|
122
|
-
case
|
|
125
|
+
case 9:
|
|
123
126
|
dates = _context2.sent;
|
|
124
127
|
this.setDateList(dates);
|
|
125
128
|
return _context2.abrupt("return", dates);
|
|
126
|
-
case
|
|
129
|
+
case 12:
|
|
127
130
|
case "end":
|
|
128
131
|
return _context2.stop();
|
|
129
132
|
}
|
|
@@ -151,7 +154,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
151
154
|
return n.date === item.date;
|
|
152
155
|
});
|
|
153
156
|
if (currentItemIndex !== -1) {
|
|
154
|
-
var _item$resource;
|
|
157
|
+
var _item$resource, _currentItem$resource3;
|
|
155
158
|
var currentItem = currentDateList[currentItemIndex];
|
|
156
159
|
// 看那一天的数据有没有相同的,把不同的资源合并进去即可
|
|
157
160
|
var newResource = (_item$resource = item.resource) === null || _item$resource === void 0 ? void 0 : _item$resource.filter(function (n) {
|
|
@@ -160,6 +163,16 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
160
163
|
return m.id === n.id;
|
|
161
164
|
}));
|
|
162
165
|
});
|
|
166
|
+
// 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
|
|
167
|
+
(_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
|
|
168
|
+
var _item$resource2;
|
|
169
|
+
var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.find(function (m) {
|
|
170
|
+
return m.id === n.id;
|
|
171
|
+
});
|
|
172
|
+
if (newResource) {
|
|
173
|
+
n.times = newResource.times;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
163
176
|
currentItem.resource = [].concat(_toConsumableArray(currentItem.resource || []), _toConsumableArray(newResource || []));
|
|
164
177
|
currentDateList[currentItemIndex] = currentItem;
|
|
165
178
|
} else {
|
|
@@ -172,11 +185,11 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
172
185
|
key: "fetchResourceDates",
|
|
173
186
|
value: function () {
|
|
174
187
|
var _fetchResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
175
|
-
var url, query, fetchUrl, _ref, start_date, end_date, resource_ids, res;
|
|
188
|
+
var url, query, _params$useCache, useCache, fetchUrl, _ref, start_date, end_date, resource_ids, res;
|
|
176
189
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
177
190
|
while (1) switch (_context3.prev = _context3.next) {
|
|
178
191
|
case 0:
|
|
179
|
-
url = params.url, query = params.query;
|
|
192
|
+
url = params.url, query = params.query, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache;
|
|
180
193
|
fetchUrl = url || '/schedule/resource/list';
|
|
181
194
|
_ref = query || {}, start_date = _ref.start_date, end_date = _ref.end_date, resource_ids = _ref.resource_ids;
|
|
182
195
|
_context3.prev = 3;
|
|
@@ -185,9 +198,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
185
198
|
start_date: start_date,
|
|
186
199
|
end_date: end_date,
|
|
187
200
|
resource_ids: resource_ids,
|
|
188
|
-
front_end_cache_id: this.cacheId
|
|
201
|
+
front_end_cache_id: useCache && this.cacheId
|
|
189
202
|
}, {
|
|
190
|
-
useCache:
|
|
203
|
+
useCache: useCache
|
|
191
204
|
});
|
|
192
205
|
case 6:
|
|
193
206
|
res = _context3.sent;
|
|
@@ -131,6 +131,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
131
131
|
getCart(): CartItem[];
|
|
132
132
|
getAvailableDate(params?: {
|
|
133
133
|
url?: string;
|
|
134
|
+
useCache?: boolean;
|
|
134
135
|
products?: ProductData[];
|
|
135
136
|
startDate?: string;
|
|
136
137
|
endDate?: string;
|
|
@@ -272,7 +272,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
272
272
|
value: (function () {
|
|
273
273
|
var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
|
|
274
274
|
var _schedule$product_ids;
|
|
275
|
-
var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
|
|
275
|
+
var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, newProductIds, schedule, otherProductsIds, allProductIds;
|
|
276
276
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
277
277
|
while (1) switch (_context3.prev = _context3.next) {
|
|
278
278
|
case 0:
|
|
@@ -289,27 +289,38 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
289
289
|
week: '',
|
|
290
290
|
weekNum: 0
|
|
291
291
|
}]);
|
|
292
|
+
newProductIds = []; // const scheduleIds = scheduleList
|
|
293
|
+
// .filter((n) => n.date === date)
|
|
294
|
+
// .flatMap((n) => n.schedule_id)
|
|
295
|
+
// .filter((n) => n !== null && n !== undefined);
|
|
296
|
+
// 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
|
|
297
|
+
// if (!product_ids?.length) {
|
|
298
|
+
// const schedule = scheduleList.find((n) => n.date === date);
|
|
299
|
+
// if (schedule && schedule.product_ids?.length) {
|
|
300
|
+
// product_ids = schedule.product_ids;
|
|
301
|
+
// }
|
|
302
|
+
// }
|
|
292
303
|
// V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
|
|
293
304
|
schedule = scheduleList.find(function (n) {
|
|
294
305
|
return n.date === date;
|
|
295
306
|
});
|
|
296
307
|
if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
|
|
297
|
-
|
|
308
|
+
newProductIds = schedule.product_ids;
|
|
298
309
|
}
|
|
299
310
|
// 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
|
|
300
311
|
otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
|
|
301
|
-
allProductIds = [].concat(_toConsumableArray(
|
|
312
|
+
allProductIds = [].concat(_toConsumableArray(newProductIds), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
|
|
302
313
|
return self.indexOf(n) === index;
|
|
303
314
|
});
|
|
304
|
-
_context3.next =
|
|
315
|
+
_context3.next = 10;
|
|
305
316
|
return this.loadProducts({
|
|
306
317
|
product_ids: allProductIds,
|
|
307
318
|
category_ids: category_ids,
|
|
308
319
|
schedule_date: date
|
|
309
320
|
});
|
|
310
|
-
case 9:
|
|
311
|
-
return _context3.abrupt("return", _context3.sent);
|
|
312
321
|
case 10:
|
|
322
|
+
return _context3.abrupt("return", _context3.sent);
|
|
323
|
+
case 11:
|
|
313
324
|
case "end":
|
|
314
325
|
return _context3.stop();
|
|
315
326
|
}
|
|
@@ -681,6 +692,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
681
692
|
startDate,
|
|
682
693
|
endDate,
|
|
683
694
|
type,
|
|
695
|
+
_params$useCache,
|
|
696
|
+
useCache,
|
|
684
697
|
tempProducts,
|
|
685
698
|
dateRange,
|
|
686
699
|
tempStartDate,
|
|
@@ -696,7 +709,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
696
709
|
case 0:
|
|
697
710
|
params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
|
|
698
711
|
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
699
|
-
products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
712
|
+
products = params.products, startDate = params.startDate, endDate = params.endDate, type = params.type, _params$useCache = params.useCache, useCache = _params$useCache === void 0 ? true : _params$useCache; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
700
713
|
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
701
714
|
startDate = dayjs().format('YYYY-MM-DD');
|
|
702
715
|
}
|
|
@@ -738,7 +751,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
738
751
|
resource_ids: resourceIds
|
|
739
752
|
},
|
|
740
753
|
rules: rules,
|
|
741
|
-
type: type
|
|
754
|
+
type: type,
|
|
755
|
+
useCache: useCache
|
|
742
756
|
});
|
|
743
757
|
case 15:
|
|
744
758
|
res = _context12.sent;
|
|
@@ -1292,7 +1306,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1292
1306
|
var originResource = allOriginResources.find(function (n) {
|
|
1293
1307
|
return n.id === targetRes.id;
|
|
1294
1308
|
});
|
|
1295
|
-
var canUse = checkResourceCanUseByCapacity(currentResourcesCapacityMap[m.id], currentCapacity, originResource === null || originResource === void 0 ? void 0 : originResource.capacity);
|
|
1309
|
+
var canUse = checkResourceCanUseByCapacity(currentResourcesCapacityMap[m.id] || 0, currentCapacity, originResource === null || originResource === void 0 ? void 0 : originResource.capacity);
|
|
1296
1310
|
if (canUse) currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
1297
1311
|
return !canUse;
|
|
1298
1312
|
}
|
|
@@ -70,18 +70,20 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
70
70
|
}
|
|
71
71
|
async getResourceDates(params) {
|
|
72
72
|
var _a;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
if (params.useCache) {
|
|
74
|
+
const currentDateList = this.getDateList() || [];
|
|
75
|
+
const currentDateListMap = new Map(
|
|
76
|
+
currentDateList.map((item) => [item.date, item])
|
|
77
|
+
);
|
|
78
|
+
const resourceIds = ((_a = params.query) == null ? void 0 : _a.resource_ids) || [];
|
|
79
|
+
const hasResource = resourceIds.every((id) => {
|
|
80
|
+
var _a2;
|
|
81
|
+
const currentItem = currentDateListMap.get(id.toString());
|
|
82
|
+
return (_a2 = currentItem == null ? void 0 : currentItem.resource) == null ? void 0 : _a2.some((n) => n.id === id);
|
|
83
|
+
});
|
|
84
|
+
if (hasResource) {
|
|
85
|
+
return currentDateList;
|
|
86
|
+
}
|
|
85
87
|
}
|
|
86
88
|
const dates = await this.getResourceAvailableTimeList(params);
|
|
87
89
|
this.setDateList(dates);
|
|
@@ -93,7 +95,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
93
95
|
setDateList(dateList) {
|
|
94
96
|
const currentDateList = (0, import_cloneDeep.default)(this.store.dateList) || [];
|
|
95
97
|
dateList.forEach((item) => {
|
|
96
|
-
var _a;
|
|
98
|
+
var _a, _b;
|
|
97
99
|
const currentItemIndex = currentDateList.findIndex(
|
|
98
100
|
(n) => n.date === item.date
|
|
99
101
|
);
|
|
@@ -105,6 +107,13 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
105
107
|
return !((_a2 = currentItem.resource) == null ? void 0 : _a2.some((m) => m.id === n.id));
|
|
106
108
|
}
|
|
107
109
|
);
|
|
110
|
+
(_b = currentItem.resource) == null ? void 0 : _b.forEach((n) => {
|
|
111
|
+
var _a2;
|
|
112
|
+
const newResource2 = (_a2 = item.resource) == null ? void 0 : _a2.find((m) => m.id === n.id);
|
|
113
|
+
if (newResource2) {
|
|
114
|
+
n.times = newResource2.times;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
108
117
|
currentItem.resource = [
|
|
109
118
|
...currentItem.resource || [],
|
|
110
119
|
...newResource || []
|
|
@@ -117,22 +126,18 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
117
126
|
this.store.dateList = currentDateList;
|
|
118
127
|
}
|
|
119
128
|
async fetchResourceDates(params) {
|
|
120
|
-
const { url, query } = params;
|
|
129
|
+
const { url, query, useCache = true } = params;
|
|
121
130
|
const fetchUrl = url || "/schedule/resource/list";
|
|
122
131
|
const { start_date, end_date, resource_ids } = query || {};
|
|
123
132
|
try {
|
|
124
|
-
const res = await this.request.get(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
useCache: true
|
|
134
|
-
}
|
|
135
|
-
);
|
|
133
|
+
const res = await this.request.get(fetchUrl, {
|
|
134
|
+
start_date,
|
|
135
|
+
end_date,
|
|
136
|
+
resource_ids,
|
|
137
|
+
front_end_cache_id: useCache && this.cacheId
|
|
138
|
+
}, {
|
|
139
|
+
useCache
|
|
140
|
+
});
|
|
136
141
|
return res;
|
|
137
142
|
} catch (error) {
|
|
138
143
|
console.error(error);
|
|
@@ -131,6 +131,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
131
131
|
getCart(): CartItem[];
|
|
132
132
|
getAvailableDate(params?: {
|
|
133
133
|
url?: string;
|
|
134
|
+
useCache?: boolean;
|
|
134
135
|
products?: ProductData[];
|
|
135
136
|
startDate?: string;
|
|
136
137
|
endDate?: string;
|
|
@@ -217,12 +217,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
217
217
|
{ date, status: "available", week: "", weekNum: 0 },
|
|
218
218
|
{ date, status: "available", week: "", weekNum: 0 }
|
|
219
219
|
]);
|
|
220
|
+
let newProductIds = [];
|
|
220
221
|
const schedule = scheduleList.find((n) => n.date === date);
|
|
221
222
|
if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
|
|
222
|
-
|
|
223
|
+
newProductIds = schedule.product_ids;
|
|
223
224
|
}
|
|
224
225
|
const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
|
|
225
|
-
const allProductIds = [...
|
|
226
|
+
const allProductIds = [...newProductIds, ...otherProductsIds].filter(
|
|
226
227
|
(n, index, self) => self.indexOf(n) === index
|
|
227
228
|
);
|
|
228
229
|
return await this.loadProducts({
|
|
@@ -388,7 +389,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
388
389
|
// 获取商品/服务的可用日期
|
|
389
390
|
async getAvailableDate(params = {}) {
|
|
390
391
|
var _a, _b, _c;
|
|
391
|
-
let { products, startDate, endDate, type } = params;
|
|
392
|
+
let { products, startDate, endDate, type, useCache = true } = params;
|
|
392
393
|
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
393
394
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
394
395
|
}
|
|
@@ -425,7 +426,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
425
426
|
resource_ids: resourceIds
|
|
426
427
|
},
|
|
427
428
|
rules,
|
|
428
|
-
type
|
|
429
|
+
type,
|
|
430
|
+
useCache
|
|
429
431
|
});
|
|
430
432
|
return res;
|
|
431
433
|
}
|
|
@@ -718,7 +720,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
718
720
|
(n) => n.id === targetRes.id
|
|
719
721
|
);
|
|
720
722
|
const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
|
|
721
|
-
currentResourcesCapacityMap[m.id],
|
|
723
|
+
currentResourcesCapacityMap[m.id] || 0,
|
|
722
724
|
currentCapacity,
|
|
723
725
|
originResource == null ? void 0 : originResource.capacity
|
|
724
726
|
);
|