@pisell/pisellos 0.0.44 → 0.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/Account/index.d.ts +2 -6
- package/dist/modules/Account/index.js +21 -103
- package/dist/modules/Account/types.d.ts +12 -1
- package/dist/modules/AccountList/index.d.ts +20 -1
- package/dist/modules/AccountList/index.js +243 -75
- package/dist/modules/AccountList/types.d.ts +33 -1
- package/dist/modules/AccountList/types.js +8 -0
- package/dist/modules/AccountList/utils.d.ts +9 -0
- package/dist/modules/AccountList/utils.js +25 -0
- package/dist/modules/BaseModule.d.ts +2 -2
- package/dist/modules/BaseModule.js +1 -1
- package/dist/modules/Cart/index.d.ts +5 -5
- package/dist/modules/Cart/index.js +33 -19
- package/dist/modules/Cart/types.d.ts +21 -7
- package/dist/modules/Cart/utils.d.ts +29 -5
- package/dist/modules/Cart/utils.js +72 -26
- package/dist/modules/Date/index.d.ts +6 -6
- package/dist/modules/Date/index.js +41 -55
- package/dist/modules/Date/types.d.ts +22 -6
- package/dist/modules/Date/utils.d.ts +4 -3
- package/dist/modules/Date/utils.js +74 -23
- package/dist/modules/Discount/index.d.ts +4 -4
- package/dist/modules/Discount/index.js +11 -11
- package/dist/modules/Order/index.d.ts +10 -5
- package/dist/modules/Order/index.js +32 -16
- package/dist/modules/Order/types.d.ts +10 -3
- package/dist/modules/Product/index.d.ts +4 -1
- package/dist/modules/Product/index.js +22 -0
- package/dist/modules/Product/types.d.ts +7 -3
- package/dist/modules/ProductList/index.js +11 -5
- package/dist/modules/Resource/utils.js +1 -1
- package/dist/modules/Rules/index.d.ts +4 -4
- package/dist/modules/Rules/index.js +11 -11
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/index.d.ts +8 -3
- package/dist/modules/Schedule/index.js +45 -5
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +8 -8
- package/dist/modules/Schedule/utils.d.ts +9 -3
- package/dist/modules/Schedule/utils.js +77 -48
- package/dist/modules/Step/index.d.ts +14 -3
- package/dist/modules/Step/index.js +54 -2
- package/dist/modules/Summary/index.d.ts +5 -5
- package/dist/modules/Summary/index.js +7 -7
- package/dist/modules/Summary/types.d.ts +2 -2
- package/dist/modules/Summary/utils.d.ts +4 -4
- package/dist/modules/Summary/utils.js +3 -3
- package/dist/plugins/index.d.ts +3 -3
- package/dist/plugins/request.d.ts +3 -3
- package/dist/plugins/request.js +30 -30
- package/dist/plugins/shopStore.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +71 -16
- package/dist/solution/BookingByStep/index.js +643 -227
- package/dist/solution/BookingByStep/types.d.ts +2 -2
- package/dist/solution/BookingByStep/types.js +9 -9
- package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
- package/dist/solution/BookingByStep/utils/products.js +3 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +6 -5
- package/dist/solution/BookingByStep/utils/resources.js +37 -19
- package/dist/solution/ShopDiscount/index.d.ts +4 -4
- package/dist/solution/ShopDiscount/index.js +16 -16
- package/dist/solution/ShopDiscount/types.d.ts +2 -2
- package/dist/solution/ShopDiscount/utils.js +1 -1
- package/lib/core/index.js +7 -2
- package/lib/modules/Account/index.d.ts +2 -6
- package/lib/modules/Account/index.js +15 -30
- package/lib/modules/Account/types.d.ts +12 -1
- package/lib/modules/AccountList/index.d.ts +20 -1
- package/lib/modules/AccountList/index.js +122 -13
- package/lib/modules/AccountList/types.d.ts +33 -1
- package/lib/modules/AccountList/utils.d.ts +9 -0
- package/lib/modules/AccountList/utils.js +39 -0
- package/lib/modules/BaseModule.d.ts +2 -2
- package/lib/modules/BaseModule.js +14 -3
- package/lib/modules/Cart/index.d.ts +5 -5
- package/lib/modules/Cart/index.js +28 -6
- package/lib/modules/Cart/types.d.ts +21 -7
- package/lib/modules/Cart/utils.d.ts +29 -5
- package/lib/modules/Cart/utils.js +47 -3
- package/lib/modules/Date/index.d.ts +6 -6
- package/lib/modules/Date/index.js +6 -6
- package/lib/modules/Date/types.d.ts +22 -6
- package/lib/modules/Date/utils.d.ts +4 -3
- package/lib/modules/Date/utils.js +37 -6
- package/lib/modules/Discount/index.d.ts +4 -4
- package/lib/modules/Discount/index.js +9 -2
- package/lib/modules/Guests/index.js +4 -1
- package/lib/modules/Order/index.d.ts +10 -5
- package/lib/modules/Order/index.js +11 -1
- package/lib/modules/Order/types.d.ts +10 -3
- package/lib/modules/Payment/index.js +1 -6
- package/lib/modules/Product/index.d.ts +4 -1
- package/lib/modules/Product/index.js +16 -0
- package/lib/modules/Product/types.d.ts +7 -3
- package/lib/modules/ProductList/index.js +21 -7
- package/lib/modules/Resource/index.js +4 -1
- package/lib/modules/Resource/utils.js +7 -4
- package/lib/modules/Rules/index.d.ts +4 -4
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.d.ts +8 -3
- package/lib/modules/Schedule/index.js +33 -2
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +8 -8
- package/lib/modules/Schedule/utils.d.ts +9 -3
- package/lib/modules/Schedule/utils.js +32 -4
- package/lib/modules/Step/index.d.ts +14 -3
- package/lib/modules/Step/index.js +38 -1
- package/lib/modules/Summary/index.d.ts +5 -5
- package/lib/modules/Summary/types.d.ts +2 -2
- package/lib/modules/Summary/utils.d.ts +4 -4
- package/lib/plugins/index.d.ts +3 -3
- package/lib/plugins/request.d.ts +3 -3
- package/lib/plugins/request.js +48 -11
- package/lib/plugins/shopStore.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +71 -16
- package/lib/solution/BookingByStep/index.js +396 -48
- package/lib/solution/BookingByStep/types.d.ts +2 -2
- package/lib/solution/BookingByStep/types.js +36 -9
- package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/products.js +3 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +6 -5
- package/lib/solution/BookingByStep/utils/resources.js +128 -58
- package/lib/solution/BuyTickets/index.js +34 -20
- package/lib/solution/ShopDiscount/index.d.ts +4 -4
- package/lib/solution/ShopDiscount/index.js +10 -2
- package/lib/solution/ShopDiscount/types.d.ts +2 -2
- package/package.json +4 -2
|
@@ -39,6 +39,8 @@ var import_resources = require("./utils/resources");
|
|
|
39
39
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
40
|
var import_utils = require("../../modules/Resource/utils");
|
|
41
41
|
var import_lodash_es = require("lodash-es");
|
|
42
|
+
var import_utils2 = require("../../modules/Schedule/utils");
|
|
43
|
+
var import_utils3 = require("../../modules/Date/utils");
|
|
42
44
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
43
45
|
constructor() {
|
|
44
46
|
super(...arguments);
|
|
@@ -46,9 +48,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
46
48
|
this.defaultVersion = "1.0.0";
|
|
47
49
|
this.isSolution = true;
|
|
48
50
|
this.otherParams = {};
|
|
51
|
+
this.otherData = {};
|
|
49
52
|
}
|
|
53
|
+
// 提供给 UI 层的临时数据存储,会进缓存
|
|
50
54
|
async initialize(core, options) {
|
|
51
|
-
var _a, _b;
|
|
55
|
+
var _a, _b, _c, _d;
|
|
52
56
|
this.core = core;
|
|
53
57
|
this.store = options.store || {};
|
|
54
58
|
this.otherParams = options.otherParams || {};
|
|
@@ -66,9 +70,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
66
70
|
if (sessionData) {
|
|
67
71
|
const data = JSON.parse(sessionData);
|
|
68
72
|
targetCacheData = data[this.otherParams.cacheId];
|
|
73
|
+
this.otherData = ((_d = (_c = data[this.otherParams.cacheId]) == null ? void 0 : _c[this.name]) == null ? void 0 : _d["otherData"]) || {};
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
|
-
const moduleArr = [
|
|
76
|
+
const moduleArr = [
|
|
77
|
+
"accountList",
|
|
78
|
+
"cart",
|
|
79
|
+
"schedule",
|
|
80
|
+
"summary",
|
|
81
|
+
"step",
|
|
82
|
+
"products",
|
|
83
|
+
"date",
|
|
84
|
+
"order",
|
|
85
|
+
"payment"
|
|
86
|
+
];
|
|
72
87
|
moduleArr.forEach((step) => {
|
|
73
88
|
var _a2, _b2;
|
|
74
89
|
const targetModule = (0, import_types.createModule)(step, this.name);
|
|
@@ -116,6 +131,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
116
131
|
getStepList() {
|
|
117
132
|
return this.store.step.getStepList();
|
|
118
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* 添加step
|
|
136
|
+
*/
|
|
137
|
+
addStep(step, key) {
|
|
138
|
+
this.store.step.addStep(step, key);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 删除step
|
|
142
|
+
*/
|
|
143
|
+
removeStep(key) {
|
|
144
|
+
this.store.step.removeStep(key);
|
|
145
|
+
}
|
|
119
146
|
// 获取购物车里 temp.xxx的方法
|
|
120
147
|
// async getStoreCart(key?: string) {
|
|
121
148
|
// return this.store.cart.getTemp(key);
|
|
@@ -132,8 +159,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
132
159
|
{
|
|
133
160
|
open_quotation: 1,
|
|
134
161
|
open_bundle: 1,
|
|
135
|
-
extension_type: [
|
|
136
|
-
|
|
162
|
+
extension_type: [
|
|
163
|
+
"product_appointment",
|
|
164
|
+
"appointment_ticket",
|
|
165
|
+
"session_product",
|
|
166
|
+
"session_ticket"
|
|
167
|
+
],
|
|
168
|
+
with: ["category", "collection", "resourceRelation"],
|
|
137
169
|
status: "published",
|
|
138
170
|
num: 500,
|
|
139
171
|
skip: 1,
|
|
@@ -148,44 +180,100 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
148
180
|
this.store.products.addProduct(productsData.data.list);
|
|
149
181
|
return productsData.data.list;
|
|
150
182
|
}
|
|
151
|
-
loadProductByScheduleDate(date) {
|
|
152
|
-
const scheduleList = this.store.schedule.
|
|
183
|
+
async loadProductByScheduleDate(date) {
|
|
184
|
+
const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
|
|
153
185
|
const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
|
|
154
|
-
this.
|
|
186
|
+
this.store.cart.clear();
|
|
187
|
+
return await this.loadProducts({ schedule_ids: scheduleIds });
|
|
155
188
|
}
|
|
156
189
|
// 加载当前店铺下所有 schedule
|
|
157
190
|
async loadAllSchedule() {
|
|
191
|
+
var _a;
|
|
158
192
|
const scheduleList = await this.request.get(`/schedule`);
|
|
159
|
-
this.store.schedule.setScheduleList(scheduleList.data);
|
|
193
|
+
this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
|
|
160
194
|
}
|
|
161
195
|
// ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
|
|
162
|
-
async
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
196
|
+
async loadScheduleAvailableDate({
|
|
197
|
+
startDate,
|
|
198
|
+
endDate,
|
|
199
|
+
custom_page_id
|
|
200
|
+
}) {
|
|
201
|
+
var _a;
|
|
202
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)())) {
|
|
203
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
204
|
+
}
|
|
205
|
+
let dates = (0, import_utils3.generateMonthDates)(startDate, endDate);
|
|
206
|
+
dates = (0, import_utils3.disableAllDates)(dates);
|
|
207
|
+
if ((0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)())) {
|
|
208
|
+
return dates;
|
|
209
|
+
}
|
|
210
|
+
const res = await this.request.get(
|
|
211
|
+
`/schedule/product/availability`,
|
|
212
|
+
{
|
|
213
|
+
start_date: startDate,
|
|
214
|
+
end_date: endDate,
|
|
215
|
+
custom_page_id
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
this.store.schedule.setAvailabilityScheduleDateList(res.data.date_list);
|
|
219
|
+
if (!((_a = res.data.date_list) == null ? void 0 : _a.length) || (0, import_dayjs.default)(endDate).isBefore((0, import_dayjs.default)())) {
|
|
220
|
+
return dates;
|
|
221
|
+
}
|
|
222
|
+
res.data.date_list.forEach((n) => {
|
|
223
|
+
if (n.schedule_id && n.schedule_id.length) {
|
|
224
|
+
const index = dates.findIndex((m) => m.date === n.date);
|
|
225
|
+
if (index !== -1) {
|
|
226
|
+
dates[index].status = "available";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
167
229
|
});
|
|
168
|
-
|
|
230
|
+
dates = (0, import_utils3.disableDatesBeforeOneDay)(dates);
|
|
231
|
+
return dates;
|
|
169
232
|
}
|
|
170
233
|
async storeProduct(productData) {
|
|
171
234
|
const activeAccount = this.getActiveAccount();
|
|
172
|
-
if (!activeAccount) {
|
|
173
|
-
throw new Error("没有找到当前账户");
|
|
174
|
-
}
|
|
175
235
|
const { bundle, options, origin, product_variant_id } = productData || {};
|
|
176
236
|
const product = { ...origin, product_variant_id };
|
|
177
|
-
|
|
178
|
-
account: activeAccount,
|
|
237
|
+
const addCartItem = {
|
|
179
238
|
product,
|
|
180
239
|
bundle,
|
|
181
240
|
options
|
|
182
|
-
}
|
|
241
|
+
};
|
|
242
|
+
if (activeAccount) {
|
|
243
|
+
addCartItem.account = activeAccount;
|
|
244
|
+
}
|
|
245
|
+
this.store.cart.addItem(addCartItem);
|
|
246
|
+
}
|
|
247
|
+
// 添加单个账户或者 guest
|
|
248
|
+
async addAccount(account, extra) {
|
|
249
|
+
if ((extra == null ? void 0 : extra.type) === "holder") {
|
|
250
|
+
const accountModules = await this.store.accountList.addHolderAccounts(
|
|
251
|
+
[account],
|
|
252
|
+
extra.customerId
|
|
253
|
+
);
|
|
254
|
+
return accountModules[0].getAccount();
|
|
255
|
+
}
|
|
256
|
+
const newAccount = await this.store.accountList.addAccount(account);
|
|
257
|
+
return newAccount.getAccount();
|
|
183
258
|
}
|
|
184
259
|
// 添加账户或者 guest
|
|
185
|
-
async
|
|
186
|
-
|
|
187
|
-
this.store.accountList.
|
|
188
|
-
|
|
260
|
+
async addAccounts(accounts, extra) {
|
|
261
|
+
if ((extra == null ? void 0 : extra.type) === "holder") {
|
|
262
|
+
this.store.accountList.addHolderAccounts(
|
|
263
|
+
accounts,
|
|
264
|
+
extra.customerId
|
|
265
|
+
);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const res = [];
|
|
269
|
+
for (const account of accounts) {
|
|
270
|
+
const accountModule = await this.store.accountList.addAccount(account);
|
|
271
|
+
const accountData = accountModule.getAccount();
|
|
272
|
+
if (accountData) {
|
|
273
|
+
res.push(accountData);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return res;
|
|
189
277
|
}
|
|
190
278
|
// 获取所有账户
|
|
191
279
|
async getAccounts() {
|
|
@@ -207,6 +295,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
207
295
|
this.store.accountList.removeAccount(id);
|
|
208
296
|
this.clearCartByAccount(id);
|
|
209
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* 获取holder类型账户列表
|
|
300
|
+
* @param params
|
|
301
|
+
*/
|
|
302
|
+
async fetchHolderAccountsAsync(params) {
|
|
303
|
+
return this.store.accountList.fetchHolderAccounts(params);
|
|
304
|
+
}
|
|
210
305
|
// 设置日期范围,注入到日期模块中
|
|
211
306
|
async setDateRange(dateRange) {
|
|
212
307
|
this.store.date.setDateRange(dateRange);
|
|
@@ -224,23 +319,43 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
224
319
|
// 获取商品/服务的可用日期
|
|
225
320
|
async getAvailableDate(params = {}) {
|
|
226
321
|
var _a, _b, _c, _d;
|
|
227
|
-
|
|
228
|
-
|
|
322
|
+
let { products, startDate, endDate, type } = params;
|
|
323
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)()) && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)()) || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)()))) {
|
|
324
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
325
|
+
}
|
|
326
|
+
let tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
|
|
327
|
+
if (tempProducts.length) {
|
|
328
|
+
tempProducts.forEach((p) => {
|
|
329
|
+
if (p == null ? void 0 : p["schedule.ids"]) {
|
|
330
|
+
const scheduleData = this.getScheduleDataByIds(p["schedule.ids"]);
|
|
331
|
+
p["_schedule"] = scheduleData;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (this.store.currentProduct) {
|
|
336
|
+
tempProducts = [
|
|
337
|
+
{
|
|
338
|
+
...this.store.currentProduct.getData(),
|
|
339
|
+
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
340
|
+
}
|
|
341
|
+
];
|
|
342
|
+
}
|
|
229
343
|
const tempStartDate = startDate || ((_b = (_a = this.otherParams) == null ? void 0 : _a.dateRange) == null ? void 0 : _b[0]);
|
|
230
344
|
const tempEndDate = endDate || ((_d = (_c = this.otherParams) == null ? void 0 : _c.dateRange) == null ? void 0 : _d[1]);
|
|
231
345
|
if (!tempProducts.length) {
|
|
232
346
|
return [];
|
|
233
347
|
}
|
|
234
348
|
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
235
|
-
console.log("resourceIds", tempProducts);
|
|
236
349
|
this.otherParams.currentResourcesMap = resourcesMap;
|
|
237
|
-
const res = await this.store.date.
|
|
350
|
+
const res = await this.store.date.getResourceDates({
|
|
351
|
+
url: params.url,
|
|
238
352
|
query: {
|
|
239
353
|
start_date: tempStartDate,
|
|
240
354
|
end_date: tempEndDate,
|
|
241
355
|
resource_ids: resourceIds
|
|
242
356
|
},
|
|
243
|
-
rules
|
|
357
|
+
rules,
|
|
358
|
+
type
|
|
244
359
|
});
|
|
245
360
|
return res;
|
|
246
361
|
}
|
|
@@ -290,6 +405,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
290
405
|
const res = await this.request.post(`/pay/order/free-pay/${id}`);
|
|
291
406
|
return res;
|
|
292
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* 检查购物车提交订单前是否符合条件
|
|
410
|
+
* @param type 类型 "holder" | "account"
|
|
411
|
+
* @returns boolean
|
|
412
|
+
*/
|
|
413
|
+
checkBeforeSubmitOrder(type) {
|
|
414
|
+
return this.store.order.checkBeforeSubmitOrder({
|
|
415
|
+
type,
|
|
416
|
+
cartItems: this.store.cart.getItems()
|
|
417
|
+
});
|
|
418
|
+
}
|
|
293
419
|
// 购物车提交订单
|
|
294
420
|
async submitOrder() {
|
|
295
421
|
const cartItems = this.store.cart.getItems();
|
|
@@ -303,7 +429,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
303
429
|
return { ...newResourcesItem };
|
|
304
430
|
});
|
|
305
431
|
});
|
|
306
|
-
return this.store.order.
|
|
432
|
+
return this.store.order.submitOrder({ query: { cartItems: newCartItems } });
|
|
307
433
|
}
|
|
308
434
|
// 拉起支付模块
|
|
309
435
|
async pay() {
|
|
@@ -323,11 +449,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
323
449
|
}
|
|
324
450
|
// 更新购物车
|
|
325
451
|
updateCart(params) {
|
|
326
|
-
this.store.cart.updateItem(params);
|
|
327
452
|
const targetCartItem = this.store.cart.getItem(params._id);
|
|
328
453
|
if (!targetCartItem) {
|
|
329
454
|
throw new Error(`没有找到${params._id}购物车商品`);
|
|
330
455
|
}
|
|
456
|
+
if (params.resources) {
|
|
457
|
+
params.resources = params.resources.map((n) => {
|
|
458
|
+
n.capacity = targetCartItem.num || 1;
|
|
459
|
+
(0, import_resources.checkSubResourcesCapacity)(n);
|
|
460
|
+
return n;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
this.store.cart.updateItem(params);
|
|
331
464
|
const cartItems = this.store.cart.getItems();
|
|
332
465
|
cartItems.forEach((item) => {
|
|
333
466
|
var _a;
|
|
@@ -395,21 +528,72 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
395
528
|
getResourcesList() {
|
|
396
529
|
const dateRange = this.store.date.getDateRange();
|
|
397
530
|
const resources = [];
|
|
398
|
-
dateRange.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
531
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
532
|
+
dateRange.forEach((n) => {
|
|
533
|
+
if (n.resource)
|
|
534
|
+
resources.push(...n.resource);
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if (!resources.length) {
|
|
538
|
+
const dateList = this.store.date.getDateList();
|
|
539
|
+
dateList.forEach((n) => {
|
|
540
|
+
if (n.resource)
|
|
541
|
+
resources.push(...n.resource);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
402
544
|
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
403
545
|
const cartItems = this.store.cart.getItems();
|
|
404
546
|
const arr = [];
|
|
547
|
+
const capacityMap = {};
|
|
405
548
|
cartItems.forEach((cartItem) => {
|
|
406
549
|
var _a, _b, _c;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
550
|
+
let selectedResources = [];
|
|
551
|
+
if (cartItem.holder_id) {
|
|
552
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
553
|
+
cartItems,
|
|
554
|
+
cartItem.holder_id,
|
|
555
|
+
resourcesMap
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
559
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
560
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
561
|
+
});
|
|
411
562
|
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
412
|
-
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
563
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
564
|
+
resourcesMap,
|
|
565
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
566
|
+
selectedResources,
|
|
567
|
+
currentCapacity
|
|
568
|
+
);
|
|
569
|
+
if (cartItem._origin.start_time) {
|
|
570
|
+
const startTime = (0, import_dayjs.default)(
|
|
571
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
572
|
+
);
|
|
573
|
+
const endTime = (0, import_dayjs.default)(
|
|
574
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
575
|
+
);
|
|
576
|
+
productResources.forEach((n) => {
|
|
577
|
+
n.renderList = n.renderList.filter((m) => {
|
|
578
|
+
const recordCount = capacityMap[m.id] || 0;
|
|
579
|
+
const canUseTime = m.times.find((item) => {
|
|
580
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
581
|
+
timeSlice: {
|
|
582
|
+
start_time: startTime.format("HH:mm"),
|
|
583
|
+
end_time: endTime.format("HH:mm"),
|
|
584
|
+
start_at: startTime,
|
|
585
|
+
end_at: endTime
|
|
586
|
+
},
|
|
587
|
+
time: item,
|
|
588
|
+
resource: m,
|
|
589
|
+
currentCount: recordCount + (currentCapacity || 0)
|
|
590
|
+
});
|
|
591
|
+
return res.usable;
|
|
592
|
+
});
|
|
593
|
+
return canUseTime;
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
}
|
|
413
597
|
arr.push({
|
|
414
598
|
id: cartItem.id,
|
|
415
599
|
// 这里返回的是购物车 id ,后面提交的时候要用的,用这个 id 绑定资源和时间
|
|
@@ -440,10 +624,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
440
624
|
}
|
|
441
625
|
if (!targetCartItem.holder_id)
|
|
442
626
|
return;
|
|
443
|
-
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
444
|
-
|
|
627
|
+
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
628
|
+
cartItems,
|
|
629
|
+
targetCartItem.holder_id,
|
|
630
|
+
resourcesMap
|
|
631
|
+
);
|
|
632
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
633
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
634
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
635
|
+
});
|
|
445
636
|
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
446
|
-
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
637
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
638
|
+
resourcesMap,
|
|
639
|
+
((_c = (_b = targetCartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
640
|
+
selectedResources,
|
|
641
|
+
currentCapacity
|
|
642
|
+
);
|
|
447
643
|
if (productResources) {
|
|
448
644
|
return {
|
|
449
645
|
id: targetCartItem.id,
|
|
@@ -605,7 +801,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
605
801
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
606
802
|
cartItems.forEach((item, index) => {
|
|
607
803
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
608
|
-
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
804
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
805
|
+
capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
|
|
806
|
+
product_bundle: item._origin.product.product_bundle
|
|
807
|
+
});
|
|
609
808
|
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
610
809
|
if (timeSlots) {
|
|
611
810
|
if (index !== 0 && recordTimeSlots) {
|
|
@@ -656,11 +855,24 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
656
855
|
const allCartItems = this.store.cart.getItems();
|
|
657
856
|
if (!item.holder_id)
|
|
658
857
|
return;
|
|
659
|
-
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
660
|
-
|
|
661
|
-
|
|
858
|
+
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
859
|
+
allCartItems,
|
|
860
|
+
item.holder_id,
|
|
861
|
+
resourcesMap
|
|
862
|
+
);
|
|
863
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
864
|
+
resourcesMap,
|
|
865
|
+
((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
|
|
866
|
+
selectedResources,
|
|
867
|
+
currentCapacity
|
|
868
|
+
);
|
|
869
|
+
const targetRenderList = (_l = productResources.find(
|
|
870
|
+
(n) => n.code === resources_code
|
|
871
|
+
)) == null ? void 0 : _l.renderList;
|
|
662
872
|
if (targetRenderList && targetRenderList.length > 0) {
|
|
663
|
-
if ((_m = item._origin.resources) == null ? void 0 : _m.some(
|
|
873
|
+
if ((_m = item._origin.resources) == null ? void 0 : _m.some(
|
|
874
|
+
(n) => n.form_id === targetRenderList[0].form_id
|
|
875
|
+
)) {
|
|
664
876
|
return;
|
|
665
877
|
}
|
|
666
878
|
const targetResource = targetRenderList[0];
|
|
@@ -761,11 +973,147 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
761
973
|
}
|
|
762
974
|
clearCacheByModule(module2) {
|
|
763
975
|
}
|
|
976
|
+
getScheduleDataByIds(scheduleIds) {
|
|
977
|
+
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
978
|
+
const targetSchedulesData = targetSchedules.map((item) => {
|
|
979
|
+
return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
|
|
980
|
+
});
|
|
981
|
+
const newSchedule = {};
|
|
982
|
+
targetSchedulesData.forEach((item) => {
|
|
983
|
+
item.forEach((n) => {
|
|
984
|
+
if (!newSchedule[n.date]) {
|
|
985
|
+
newSchedule[n.date] = n;
|
|
986
|
+
} else {
|
|
987
|
+
if (!n.isExcluded) {
|
|
988
|
+
newSchedule[n.date].isExcluded = false;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
const newScheduleArr = Object.values(newSchedule);
|
|
994
|
+
return newScheduleArr;
|
|
995
|
+
}
|
|
996
|
+
// 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
|
|
764
997
|
async openProductDetail(productId) {
|
|
765
998
|
const targetProduct = await this.store.products.getProduct(productId);
|
|
766
999
|
if (targetProduct) {
|
|
1000
|
+
const targetProductData = targetProduct.getData();
|
|
767
1001
|
this.store.currentProduct = targetProduct;
|
|
1002
|
+
const newScheduleArr = this.getScheduleDataByIds(
|
|
1003
|
+
targetProductData["schedule.ids"]
|
|
1004
|
+
);
|
|
1005
|
+
targetProduct.setOtherParams("schedule", newScheduleArr);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
closeProductDetail() {
|
|
1009
|
+
var _a;
|
|
1010
|
+
(_a = this.store.currentProduct) == null ? void 0 : _a.setOtherParams("schedule", []);
|
|
1011
|
+
this.store.currentProduct = void 0;
|
|
1012
|
+
}
|
|
1013
|
+
getTimeslotBySchedule({
|
|
1014
|
+
date,
|
|
1015
|
+
scheduleIds,
|
|
1016
|
+
resources
|
|
1017
|
+
}) {
|
|
1018
|
+
var _a, _b, _c;
|
|
1019
|
+
const targetProduct = this.store.currentProduct;
|
|
1020
|
+
const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
|
|
1021
|
+
let targetSchedules = [];
|
|
1022
|
+
if (scheduleIds == null ? void 0 : scheduleIds.length) {
|
|
1023
|
+
targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
1024
|
+
} else {
|
|
1025
|
+
targetSchedules = this.store.schedule.getScheduleListByIds(
|
|
1026
|
+
targetProductData["schedule.ids"]
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
const resourcesDates = this.store.date.getDateList();
|
|
1030
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === date);
|
|
1031
|
+
const cartItems = this.store.cart.getItems();
|
|
1032
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
|
|
1033
|
+
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1034
|
+
cartItems,
|
|
1035
|
+
"",
|
|
1036
|
+
resourcesMap
|
|
1037
|
+
);
|
|
1038
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1039
|
+
resourcesMap,
|
|
1040
|
+
resources || ((_c = (_b = (_a = this.store.currentProduct) == null ? void 0 : _a.getData()) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
1041
|
+
selectedResources,
|
|
1042
|
+
1
|
|
1043
|
+
);
|
|
1044
|
+
const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
|
|
1045
|
+
targetSchedules,
|
|
1046
|
+
{},
|
|
1047
|
+
date
|
|
1048
|
+
);
|
|
1049
|
+
const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1050
|
+
console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
|
|
1051
|
+
const allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1052
|
+
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1053
|
+
let count = 0;
|
|
1054
|
+
allProductResources == null ? void 0 : allProductResources.forEach((m) => {
|
|
1055
|
+
m.times.forEach((childTiem) => {
|
|
1056
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1057
|
+
timeSlice: {
|
|
1058
|
+
start_time: item.start,
|
|
1059
|
+
end_time: item.end,
|
|
1060
|
+
start_at: (0, import_dayjs.default)(item.start),
|
|
1061
|
+
end_at: (0, import_dayjs.default)(item.end)
|
|
1062
|
+
},
|
|
1063
|
+
time: childTiem,
|
|
1064
|
+
resource: m,
|
|
1065
|
+
currentCount: 1
|
|
1066
|
+
});
|
|
1067
|
+
if (res.usable) {
|
|
1068
|
+
count += (res == null ? void 0 : res.remainingCapacity) || 0;
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
});
|
|
1072
|
+
const startDayJs = (0, import_dayjs.default)(item.start);
|
|
1073
|
+
const endDayJs = (0, import_dayjs.default)(item.end);
|
|
1074
|
+
return {
|
|
1075
|
+
start_time: startDayJs.format("HH:mm"),
|
|
1076
|
+
end_time: endDayJs.format("HH:mm"),
|
|
1077
|
+
start_at: startDayJs,
|
|
1078
|
+
end_at: endDayJs,
|
|
1079
|
+
count
|
|
1080
|
+
};
|
|
1081
|
+
});
|
|
1082
|
+
return formatScheduleTimeSlots;
|
|
1083
|
+
}
|
|
1084
|
+
addProductToCart({
|
|
1085
|
+
product,
|
|
1086
|
+
date,
|
|
1087
|
+
account
|
|
1088
|
+
}) {
|
|
1089
|
+
const { bundle, options, origin, product_variant_id } = product || {};
|
|
1090
|
+
const productData = { ...origin, product_variant_id };
|
|
1091
|
+
this.store.cart.addItem({
|
|
1092
|
+
product: productData,
|
|
1093
|
+
date,
|
|
1094
|
+
account,
|
|
1095
|
+
bundle,
|
|
1096
|
+
options
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
setOtherData(key, value) {
|
|
1100
|
+
this.otherData[key] = value;
|
|
1101
|
+
this.checkSaveCache({
|
|
1102
|
+
cacheId: this.cacheId,
|
|
1103
|
+
fatherModule: this.name,
|
|
1104
|
+
store: { otherData: this.otherData },
|
|
1105
|
+
cacheKey: ["otherData"]
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
getOtherData(key) {
|
|
1109
|
+
return this.otherData[key];
|
|
1110
|
+
}
|
|
1111
|
+
async getProductTypeById(id) {
|
|
1112
|
+
const product = await this.store.products.getProduct(id);
|
|
1113
|
+
if (product) {
|
|
1114
|
+
return product.getProductType();
|
|
768
1115
|
}
|
|
1116
|
+
return "normal";
|
|
769
1117
|
}
|
|
770
1118
|
};
|
|
771
1119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from
|
|
1
|
+
import { ProductList, CartModule, Product, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
|
|
2
2
|
export interface BookingByStepState {
|
|
3
3
|
cart: CartModule;
|
|
4
4
|
summary: SummaryModule;
|
|
@@ -11,7 +11,7 @@ export interface BookingByStepState {
|
|
|
11
11
|
accountList: AccountListModule;
|
|
12
12
|
order: OrderModule;
|
|
13
13
|
payment: PaymentModule;
|
|
14
|
-
currentProduct
|
|
14
|
+
currentProduct?: Product;
|
|
15
15
|
schedule: ScheduleModule;
|
|
16
16
|
}
|
|
17
17
|
export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
|
|
@@ -27,23 +27,50 @@ var import_modules = require("../../modules");
|
|
|
27
27
|
function createModule(moduleName, solutionName, name, version) {
|
|
28
28
|
switch (moduleName) {
|
|
29
29
|
case "cart":
|
|
30
|
-
return new import_modules.CartModule(
|
|
30
|
+
return new import_modules.CartModule(
|
|
31
|
+
`${solutionName}_${name || moduleName}`,
|
|
32
|
+
version
|
|
33
|
+
);
|
|
31
34
|
case "summary":
|
|
32
|
-
return new import_modules.SummaryModule(
|
|
35
|
+
return new import_modules.SummaryModule(
|
|
36
|
+
`${solutionName}_${name || moduleName}`,
|
|
37
|
+
version
|
|
38
|
+
);
|
|
33
39
|
case "step":
|
|
34
|
-
return new import_modules.StepModule(
|
|
40
|
+
return new import_modules.StepModule(
|
|
41
|
+
`${solutionName}_${name || moduleName}`,
|
|
42
|
+
version
|
|
43
|
+
);
|
|
35
44
|
case "products":
|
|
36
|
-
return new import_modules.ProductList(
|
|
45
|
+
return new import_modules.ProductList(
|
|
46
|
+
`${solutionName}_${name || moduleName}`,
|
|
47
|
+
version
|
|
48
|
+
);
|
|
37
49
|
case "date":
|
|
38
|
-
return new import_modules.DateModule(
|
|
50
|
+
return new import_modules.DateModule(
|
|
51
|
+
`${solutionName}_${name || moduleName}`,
|
|
52
|
+
version
|
|
53
|
+
);
|
|
39
54
|
case "accountList":
|
|
40
|
-
return new import_modules.AccountListModule(
|
|
55
|
+
return new import_modules.AccountListModule(
|
|
56
|
+
`${solutionName}_${name || moduleName}`,
|
|
57
|
+
version
|
|
58
|
+
);
|
|
41
59
|
case "order":
|
|
42
|
-
return new import_modules.OrderModule(
|
|
60
|
+
return new import_modules.OrderModule(
|
|
61
|
+
`${solutionName}_${name || moduleName}`,
|
|
62
|
+
version
|
|
63
|
+
);
|
|
43
64
|
case "payment":
|
|
44
|
-
return new import_modules.PaymentModule(
|
|
65
|
+
return new import_modules.PaymentModule(
|
|
66
|
+
`${solutionName}_${name || moduleName}`,
|
|
67
|
+
version
|
|
68
|
+
);
|
|
45
69
|
case "schedule":
|
|
46
|
-
return new import_modules.ScheduleModule(
|
|
70
|
+
return new import_modules.ScheduleModule(
|
|
71
|
+
`${solutionName}_${name || moduleName}`,
|
|
72
|
+
version
|
|
73
|
+
);
|
|
47
74
|
default:
|
|
48
75
|
throw new Error(`Unknown module type: ${moduleName}`);
|
|
49
76
|
}
|