@conecli/cone-render 0.10.1-shop3.92 → 0.10.1-shop3.93
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro';
|
|
2
1
|
APPID,
|
|
3
2
|
JshopxColorFunctionIdList,
|
|
4
3
|
PagesColorFunctionIdList,
|
|
5
4
|
PAGES_DOMAIN,
|
|
6
5
|
B2BColorFunctionIdList,
|
|
7
6
|
MobileVerifyColorList,
|
|
8
7
|
AppVerifyColorList,
|
|
9
8
|
JshopxVerifyColorList,
|
|
10
9
|
BMallVerifyColorList,
|
|
11
10
|
shopMemberColorFunctionIdList,
|
|
12
11
|
draBusinessCustomReport,
|
|
13
12
|
isJdApp,
|
|
14
13
|
isIosDevice,
|
|
15
14
|
isAndroidDevice,
|
|
16
15
|
showSuccessToast,
|
|
17
16
|
showFailToast,
|
|
18
17
|
isH5,
|
|
19
18
|
isWxMinAndWxapp,
|
|
20
19
|
isMin,
|
|
21
20
|
isPc,
|
|
22
21
|
draInterfaceCustomReport,
|
|
23
22
|
isHarmonyDevice,
|
|
24
23
|
callRouterIOS,
|
|
25
24
|
callRouterAndroid,
|
|
26
25
|
callRouterHarmony,
|
|
27
26
|
sendNativePageToShowCartFloatBtn,
|
|
28
27
|
cookiesStr: '',
|
|
29
28
|
requestHeaderContentType: {
|
|
30
29
|
jsonHeader: {
|
|
31
30
|
'content-type': 'application/json;charset=utf-8',
|
|
32
31
|
},
|
|
33
32
|
formDataHeader: {
|
|
34
33
|
'content-type': 'application/x-www-form-urlencoded',
|
|
35
34
|
},
|
|
36
35
|
},
|
|
37
36
|
requestBaseParam: {
|
|
38
37
|
data: null,
|
|
39
38
|
header: {
|
|
40
39
|
'content-type': 'application/json;charset=utf-8',
|
|
41
40
|
},
|
|
42
41
|
},
|
|
43
42
|
timeOut: 7000,
|
|
44
43
|
apiClientParams: {
|
|
45
44
|
clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
46
45
|
client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
|
|
47
46
|
area: '1_72_2799_0',
|
|
48
47
|
screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
|
|
49
48
|
window.screen?.height * devicePixelRatio,
|
|
50
49
|
)}`,
|
|
51
50
|
uuid: UUID,
|
|
52
51
|
},
|
|
53
52
|
public addressFetchInfo: {
|
|
54
53
|
reqState: boolean;
|
|
55
54
|
promiseInstance: null | Promise<any>;
|
|
56
55
|
};
|
|
57
56
|
public getPromotionConfig: {
|
|
58
57
|
projectId: null | string | number;
|
|
59
58
|
pageId: null | string | number;
|
|
60
59
|
};
|
|
61
60
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
62
61
|
public api: ServiceInterFace.HttpApi;
|
|
63
62
|
public isPageDomain: boolean;
|
|
64
63
|
public verifyColorList: string[];
|
|
65
64
|
private isShowJdShopCartFloatBtn: boolean;
|
|
66
65
|
constructor(opt) {
|
|
67
66
|
this._init();
|
|
68
67
|
this.addressFetchInfo = {
|
|
69
68
|
reqState: false,
|
|
70
69
|
promiseInstance: null,
|
|
71
70
|
};
|
|
72
71
|
this.getPromotionConfig = {
|
|
73
72
|
projectId: null,
|
|
74
73
|
pageId: null,
|
|
75
74
|
};
|
|
76
75
|
this._userAreaUpdateListen();
|
|
77
76
|
this.resInfo = this._getResConfig(opt);
|
|
78
77
|
this.api = api;
|
|
79
78
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
80
79
|
this.verifyColorList = [
|
|
81
80
|
...MobileVerifyColorList,
|
|
82
81
|
...AppVerifyColorList,
|
|
83
82
|
...JshopxVerifyColorList,
|
|
84
83
|
...BMallVerifyColorList,
|
|
85
84
|
];
|
|
86
85
|
this.isShowJdShopCartFloatBtn =
|
|
87
86
|
jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
|
|
88
87
|
}
|
|
89
88
|
_init(): void {
|
|
90
89
|
httpInterceptors.forEach((item) => {
|
|
91
90
|
Taro.addInterceptor((chain) => item(chain));
|
|
92
91
|
});
|
|
93
92
|
}
|
|
94
93
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
95
94
|
return Object.assign({}, DefaultConfig, opt);
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
_userAreaUpdateListen() {
|
|
99
98
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
100
99
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
101
100
|
console.log(
|
|
102
101
|
'cone-render收到原生端获取传来的四级地址信息',
|
|
103
102
|
areaInfo,
|
|
104
103
|
'更新后的接口底层信息',
|
|
105
104
|
this.resInfo.apiClientParams,
|
|
106
105
|
);
|
|
107
106
|
});
|
|
108
107
|
}
|
|
109
108
|
updateApiClientParamsResInfo(opt = {}) {
|
|
110
109
|
const { area, realTimeArea, ...others } = opt;
|
|
111
110
|
this.resInfo.apiClientParams = {
|
|
112
111
|
...this.resInfo.apiClientParams,
|
|
113
112
|
...others,
|
|
114
113
|
};
|
|
115
114
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
116
115
|
realTimeArea &&
|
|
117
116
|
realTimeArea !== '' &&
|
|
118
117
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
119
118
|
}
|
|
120
119
|
|
|
121
120
|
checkFunctionIdToReturnAppId(functionId) {
|
|
122
121
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
123
122
|
return APPID.JSHOPX_COLOR_APPID;
|
|
124
123
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
125
124
|
return APPID.PAGES_COLOR_APPID;
|
|
126
125
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
127
126
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
128
127
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
129
128
|
return APPID.B2B_COLOR_APPID;
|
|
130
129
|
} else if (isPc) {
|
|
131
130
|
return APPID.MALL_COLOR_APPID;
|
|
132
131
|
} else {
|
|
133
132
|
return APPID.SHOP_COLOR_APPID;
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
138
137
|
if (
|
|
139
138
|
functionId === 'receiveShopCoupon' &&
|
|
140
139
|
((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
141
140
|
isWxMinAndWxapp)
|
|
142
141
|
) {
|
|
143
142
|
clientParams = Object.assign(
|
|
144
143
|
{},
|
|
145
144
|
{
|
|
146
145
|
loginType: '1',
|
|
147
146
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
148
147
|
},
|
|
149
148
|
clientParams,
|
|
150
149
|
);
|
|
151
150
|
}
|
|
152
151
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
153
152
|
typeof apiClientParams.appid === 'undefined' &&
|
|
154
153
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
|
|
155
154
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
156
155
|
const getReqData = {
|
|
157
156
|
functionId: functionId,
|
|
158
157
|
body: JSON.stringify(bodyParams),
|
|
159
158
|
t: Date.now(),
|
|
160
159
|
...apiClientParams,
|
|
161
160
|
};
|
|
162
161
|
return http
|
|
163
162
|
.request({
|
|
164
163
|
url: this.api.apiFunc,
|
|
165
164
|
data: getReqData,
|
|
166
165
|
isColorVerify,
|
|
167
166
|
})
|
|
168
167
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
169
168
|
const { statusCode, data, status, msg } = res;
|
|
170
169
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
171
170
|
ok: true,
|
|
172
171
|
};
|
|
173
172
|
if ((statusCode === 200 || status === '0') && data) {
|
|
174
173
|
changeRes = this.dealResponseFormatRes(data);
|
|
175
174
|
return changeRes;
|
|
176
175
|
} else {
|
|
177
176
|
changeRes = {
|
|
178
177
|
...data,
|
|
179
178
|
statusCode,
|
|
180
179
|
status,
|
|
181
180
|
msg,
|
|
182
181
|
ok: false,
|
|
183
182
|
};
|
|
184
183
|
return changeRes;
|
|
185
184
|
}
|
|
186
185
|
})
|
|
187
186
|
.catch((res) => {
|
|
188
187
|
const propertyNames = Object.getOwnPropertyNames(res);
|
|
189
188
|
const resObject = {};
|
|
190
189
|
propertyNames.forEach((propertyName) => {
|
|
191
190
|
resObject[propertyName] = res[propertyName];
|
|
192
191
|
});
|
|
193
192
|
draInterfaceCustomReport({
|
|
194
193
|
eventName: 'apiStatusCode',
|
|
195
194
|
errorName:`shop_${functionId}_error`,
|
|
196
195
|
errorMessage:`接口返回statusCode为${res?.statusCode || res?.status}`,
|
|
197
196
|
url: this.api.apiFunc,
|
|
198
197
|
source: 'remote',
|
|
199
198
|
requestType: res?.requestType,
|
|
200
199
|
functionId: getReqData?.functionId,
|
|
201
200
|
appid: getReqData?.appid,
|
|
202
201
|
client: getReqData?.client,
|
|
203
202
|
clientVersion: getReqData?.clientVersion,
|
|
204
203
|
statusCode: res?.statusCode,
|
|
205
204
|
status: res?.status,
|
|
206
205
|
statusText: res?.statusText,
|
|
207
206
|
errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
|
|
208
207
|
originReqDataStr: JSON.stringify(getReqData),
|
|
209
208
|
});
|
|
210
209
|
return {
|
|
211
210
|
...resObject,
|
|
212
211
|
ok: false,
|
|
213
212
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
214
213
|
});
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
dealResponseFormatRes(data) {
|
|
218
217
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
219
218
|
ok: true,
|
|
220
219
|
};
|
|
221
220
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
|
|
222
221
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
223
222
|
? Number(data.subCode)
|
|
224
223
|
: -1;
|
|
225
224
|
if (
|
|
226
225
|
data.success === true ||
|
|
227
226
|
data.isSuccess ||
|
|
228
227
|
resCode === 0 ||
|
|
229
228
|
resCode === 200 ||
|
|
230
229
|
subCode === 0
|
|
231
230
|
) {
|
|
232
231
|
changeRes = {
|
|
233
232
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
234
233
|
? data.result
|
|
235
234
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
236
235
|
? data.data
|
|
237
236
|
: data,
|
|
238
237
|
code: data.code ?? 200,
|
|
239
238
|
ok: true,
|
|
240
239
|
source: data,
|
|
241
240
|
};
|
|
242
241
|
return changeRes;
|
|
243
242
|
} else {
|
|
244
243
|
changeRes = {
|
|
245
244
|
...data,
|
|
246
245
|
ok: false,
|
|
247
246
|
};
|
|
248
247
|
return changeRes;
|
|
249
248
|
}
|
|
250
249
|
}
|
|
251
250
|
|
|
252
251
|
async receiveCoupon(param = {}, clientParams) {
|
|
253
252
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
254
253
|
return await this.gatewayReq(
|
|
255
254
|
'receiveShopCoupon',
|
|
256
255
|
{
|
|
257
256
|
operation: '3',
|
|
258
257
|
...param,
|
|
259
258
|
},
|
|
260
259
|
{ ...loginType, ...clientParams },
|
|
261
260
|
);
|
|
262
261
|
}
|
|
263
262
|
|
|
264
263
|
getCustomerCenterDispatch(params = {}) {
|
|
265
264
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
266
265
|
clientVersion: '9.2.0',
|
|
267
266
|
client: 'H5',
|
|
268
267
|
uuid: 88888,
|
|
269
268
|
appid: 'shopmember_m_jd_com',
|
|
270
269
|
});
|
|
271
270
|
}
|
|
272
271
|
|
|
273
272
|
batchAddCart(...args) {
|
|
274
273
|
let skuIds, num, showToast, giftCard;
|
|
275
274
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
276
275
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
277
276
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
278
277
|
const params = args[0];
|
|
279
278
|
skuIds = params.skuIds;
|
|
280
279
|
num = params.num || 1;
|
|
281
280
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
282
281
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
283
282
|
} else {
|
|
284
283
|
try {
|
|
285
284
|
const data = {
|
|
286
285
|
eventName: 'business',
|
|
287
286
|
errorName: 'shop_batchAddCart_error',
|
|
288
287
|
errorMessage: '入参不合法',
|
|
289
288
|
extraData: JSON.stringify(args),
|
|
290
289
|
};
|
|
291
290
|
draBusinessCustomReport(data);
|
|
292
291
|
} catch (e) {
|
|
293
292
|
console.error('draBusinessCustomReport error:', e);
|
|
294
293
|
}
|
|
295
294
|
const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
|
|
296
295
|
showFailToast({
|
|
297
296
|
title: msg,
|
|
298
297
|
});
|
|
299
298
|
return Promise.resolve({
|
|
300
299
|
ok: false,
|
|
301
300
|
msg,
|
|
302
301
|
});
|
|
303
302
|
}
|
|
304
303
|
const successMsg = giftCard ? (global?.languageJsonData?.successAddShopList || '加入购物清单成功') : (global?.languageJsonData?.successAddCart || '加入购物车成功');
|
|
305
304
|
const failMsg = giftCard ? (global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试') : (global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试');
|
|
306
305
|
if (skuIds) {
|
|
307
306
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
308
307
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
309
308
|
if (res?.ok) {
|
|
310
309
|
showToast &&
|
|
311
310
|
!res?.isOpenApp &&
|
|
312
311
|
showSuccessToast({
|
|
313
312
|
title: successMsg,
|
|
314
313
|
});
|
|
315
314
|
this.isShowJdShopCartFloatBtn &&
|
|
316
315
|
sendNativePageToShowCartFloatBtn({
|
|
317
316
|
isShow: true,
|
|
318
317
|
});
|
|
319
318
|
} else {
|
|
320
319
|
showToast &&
|
|
321
320
|
showFailToast({
|
|
322
321
|
title: res?.errMsg || failMsg,
|
|
323
322
|
});
|
|
324
323
|
}
|
|
325
324
|
return Promise.resolve(res);
|
|
326
325
|
})
|
|
327
326
|
.catch((e) => {
|
|
328
327
|
console.log('调用加购方法异常=======>', e);
|
|
329
328
|
return Promise.resolve({
|
|
330
329
|
ok: false,
|
|
331
330
|
msg: failMsg,
|
|
332
331
|
});
|
|
333
332
|
});
|
|
334
333
|
} else {
|
|
335
334
|
try {
|
|
336
335
|
const data = {
|
|
337
336
|
eventName: 'business',
|
|
338
337
|
errorName: 'shop_batchAddCart_error',
|
|
339
338
|
errorMessage: '没有传入合法的skuIds',
|
|
340
339
|
};
|
|
341
340
|
draBusinessCustomReport(data);
|
|
342
341
|
} catch (e) {
|
|
343
342
|
console.error('draBusinessCustomReport error:', e);
|
|
344
343
|
}
|
|
345
344
|
return Promise.resolve({
|
|
346
345
|
ok: false,
|
|
347
346
|
msg: failMsg,
|
|
348
347
|
});
|
|
349
348
|
}
|
|
350
349
|
}
|
|
351
350
|
|
|
352
351
|
async giftCardAddCart(skuList, num) {
|
|
353
352
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
354
353
|
return this.gatewayReq(
|
|
355
354
|
'giftCardAddCart',
|
|
356
355
|
{
|
|
357
356
|
skuList,
|
|
358
357
|
num: Number(num),
|
|
359
358
|
},
|
|
360
359
|
{ ...loginType },
|
|
361
360
|
);
|
|
362
361
|
}
|
|
363
362
|
|
|
364
363
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
365
364
|
return new Promise((resolve) => {
|
|
366
365
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
367
366
|
if (productIdsArr.length > 0) {
|
|
368
367
|
if (giftCard) {
|
|
369
368
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
370
369
|
.then((res) => {
|
|
371
370
|
if (res?.code === '0' && res?.result?.value) {
|
|
372
371
|
resolve({
|
|
373
372
|
ok: true,
|
|
374
373
|
});
|
|
375
374
|
} else {
|
|
376
375
|
try {
|
|
377
376
|
const data = {
|
|
378
377
|
eventName: 'business',
|
|
379
378
|
errorName: 'shop_batchAddCart_error',
|
|
380
379
|
errorMessage: '礼品卡加车接口返回加车失败标识',
|
|
381
380
|
};
|
|
382
381
|
draBusinessCustomReport(data);
|
|
383
382
|
} catch (e) {
|
|
384
383
|
console.error('draBusinessCustomReport error:', e);
|
|
385
384
|
}
|
|
386
385
|
resolve({
|
|
387
386
|
ok: false,
|
|
388
387
|
msg: '加购失败,请稍后重试',
|
|
389
388
|
});
|
|
390
389
|
}
|
|
391
390
|
})
|
|
392
391
|
.catch((e) => {
|
|
393
392
|
console.error('礼品卡加车失败: ', e);
|
|
394
393
|
resolve({
|
|
395
394
|
ok: false,
|
|
396
395
|
msg: '加购失败,请稍后重试',
|
|
397
396
|
});
|
|
398
397
|
});
|
|
399
398
|
} else if (isJdApp && (!isHarmonyDevice || isHarmonyDevice && useNativeHarmonyAddCartJd)) {
|
|
400
399
|
const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
|
|
401
400
|
console.log(
|
|
402
401
|
'==========>',
|
|
403
402
|
'使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
|
|
404
403
|
nativeAddCartCallBack,
|
|
405
404
|
);
|
|
406
405
|
if (!window[nativeAddCartCallBack]) {
|
|
407
406
|
window[nativeAddCartCallBack] = (res) => {
|
|
408
407
|
const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
|
|
409
408
|
console.info(
|
|
410
409
|
'获取批量加车原始数据',
|
|
411
410
|
res,
|
|
412
411
|
'====转换后的json数据为===',
|
|
413
412
|
getMessageJsonData,
|
|
414
413
|
);
|
|
415
414
|
try {
|
|
416
415
|
if (isAndroidDevice) {
|
|
417
416
|
const isOk = getMessageJsonData?.status === '0';
|
|
418
417
|
isOk
|
|
419
418
|
? resolve({
|
|
420
419
|
ok: true,
|
|
421
420
|
msg: '已加入购物车!',
|
|
422
421
|
})
|
|
423
422
|
: resolve({
|
|
424
423
|
ok: false,
|
|
425
424
|
msg: '加购失败,请稍后重试',
|
|
426
425
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
427
426
|
});
|
|
428
427
|
if (!isOk) {
|
|
429
428
|
const data = {
|
|
430
429
|
eventName: 'business',
|
|
431
430
|
errorName: 'shop_batchAddCart_error',
|
|
432
431
|
errorMessage: 'H5调用Android原生加车失败',
|
|
433
432
|
};
|
|
434
433
|
draBusinessCustomReport(data);
|
|
435
434
|
}
|
|
436
435
|
} else if (isIosDevice) {
|
|
437
436
|
const isOk =
|
|
438
437
|
getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
|
|
439
438
|
isOk
|
|
440
439
|
? resolve({
|
|
441
440
|
ok: true,
|
|
442
441
|
msg: '已加入购物车!',
|
|
443
442
|
})
|
|
444
443
|
: resolve({
|
|
445
444
|
ok: false,
|
|
446
445
|
msg: '批量加车失败,请稍后重试',
|
|
447
446
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
448
447
|
});
|
|
449
448
|
if (!isOk) {
|
|
450
449
|
const data = {
|
|
451
450
|
eventName: 'business',
|
|
452
451
|
errorName: 'shop_batchAddCart_error',
|
|
453
452
|
errorMessage: 'H5调用IOS原生加车失败',
|
|
454
453
|
};
|
|
455
454
|
draBusinessCustomReport(data);
|
|
456
455
|
}
|
|
457
456
|
} else if (isHarmonyDevice) {
|
|
458
457
|
const isOk = getMessageJsonData?.data?.code === 0 && getMessageJsonData?.data?.response?.resultCode === 0;
|
|
459
458
|
isOk
|
|
460
459
|
? resolve({
|
|
461
460
|
ok: true,
|
|
462
461
|
msg: '已加入购物车!',
|
|
463
462
|
})
|
|
464
463
|
: resolve({
|
|
465
464
|
ok: false,
|
|
466
465
|
msg: '加购失败,请稍后重试',
|
|
467
466
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
468
467
|
});
|
|
469
468
|
if (!isOk) {
|
|
470
469
|
const data = {
|
|
471
470
|
eventName: 'business',
|
|
472
471
|
errorName: 'shop_batchAddCart_error',
|
|
473
472
|
errorMessage: 'H5调用Harmony原生加车失败',
|
|
474
473
|
};
|
|
475
474
|
draBusinessCustomReport(data);
|
|
476
475
|
}
|
|
477
476
|
} else {
|
|
478
477
|
resolve({
|
|
479
478
|
ok: false,
|
|
480
479
|
msg: '加购失败,请稍后重试',
|
|
481
480
|
});
|
|
482
481
|
const data = {
|
|
483
482
|
eventName: 'business',
|
|
484
483
|
errorName: 'shop_batchAddCart_error',
|
|
485
484
|
errorMessage: 'H5调用未知原生加车失败',
|
|
486
485
|
};
|
|
487
486
|
draBusinessCustomReport(data);
|
|
488
487
|
}
|
|
489
488
|
} catch (e) {
|
|
490
489
|
resolve({
|
|
491
490
|
ok: false,
|
|
492
491
|
msg: '加购失败,请稍后重试',
|
|
493
492
|
});
|
|
494
493
|
console.warn('批量加车转换数据异常', e);
|
|
495
494
|
const data = {
|
|
496
495
|
eventName: 'business',
|
|
497
496
|
errorName: 'shop_batchAddCart_error',
|
|
498
497
|
errorMessage: '批量加车转换数据异常',
|
|
499
498
|
};
|
|
500
499
|
draBusinessCustomReport(data);
|
|
501
500
|
}
|
|
502
501
|
window[nativeAddCartCallBack] = null;
|
|
503
502
|
};
|
|
504
503
|
}
|
|
505
504
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
506
505
|
const adInfos = getAdInfoBySkuId(skuItem);
|
|
507
506
|
const extFlag = adInfos ? { adInfos } : {};
|
|
508
507
|
let item = null;
|
|
509
508
|
if(isAndroidDevice){
|
|
510
509
|
item = {
|
|
511
510
|
sku: skuItem,
|
|
512
511
|
num: addCardNum,
|
|
513
512
|
extFlag,
|
|
514
513
|
}
|
|
515
514
|
}else if(isIosDevice){
|
|
516
515
|
item = {
|
|
517
516
|
productCode: skuItem,
|
|
518
517
|
buyCount: addCardNum,
|
|
519
518
|
extFlag,
|
|
520
519
|
}
|
|
521
520
|
}else if(isHarmonyDevice){
|
|
522
521
|
item = {
|
|
523
522
|
sourceType: 'native',
|
|
524
523
|
sourceValue: 'shop',
|
|
525
524
|
productCode: skuItem,
|
|
526
525
|
buyCount: addCardNum,
|
|
527
526
|
extFlag,
|
|
528
527
|
}
|
|
529
528
|
}
|
|
530
529
|
return item;
|
|
531
530
|
});
|
|
532
531
|
if (isAndroidDevice) {
|
|
533
532
|
const androidProductsStr = JSON.stringify(productsAddCartList);
|
|
534
533
|
callRouterAndroid({
|
|
535
534
|
routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
|
|
536
535
|
routerParam: {
|
|
537
536
|
wareList: productsAddCartList,
|
|
538
537
|
},
|
|
539
538
|
callBackName: nativeAddCartCallBack,
|
|
540
539
|
});
|
|
541
540
|
} else if (isIosDevice) {
|
|
542
541
|
if (isLowAppVer) {
|
|
543
542
|
const lowVersionAppList = productIdsArr.map((skuItem) => {
|
|
544
543
|
return {
|
|
545
544
|
sku: skuItem,
|
|
546
545
|
num: addCardNum,
|
|
547
546
|
};
|
|
548
547
|
});
|
|
549
548
|
const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
|
|
550
549
|
const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
|
|
551
550
|
jump.side.jdJumpToWeb(url, {});
|
|
552
551
|
resolve({
|
|
553
552
|
ok: true,
|
|
554
553
|
isOpenApp: true,
|
|
555
554
|
msg: '加购完成, 加购结果请点击购物车确认',
|
|
556
555
|
});
|
|
557
556
|
} else {
|
|
558
557
|
callRouterIOS({
|
|
559
558
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
560
559
|
routerParam: {
|
|
561
560
|
sourceType: 'h5',
|
|
562
561
|
sourceValue: '店铺批量加购',
|
|
563
562
|
businessName: 'storeModel',
|
|
564
563
|
isNewMode: '1',
|
|
565
564
|
NotPassWebview: '1',
|
|
566
565
|
products: productsAddCartList,
|
|
567
566
|
},
|
|
568
567
|
callBackName: nativeAddCartCallBack,
|
|
569
568
|
});
|
|
570
569
|
}
|
|
571
570
|
} else if (isHarmonyDevice) {
|
|
572
571
|
callRouterHarmony({
|
|
573
572
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
574
573
|
routerParam: {
|
|
575
574
|
sourceType: 'native',
|
|
576
575
|
sourceValue: 'shop',
|
|
577
576
|
products: productsAddCartList
|
|
578
577
|
},
|
|
579
578
|
callBackName: nativeAddCartCallBack,
|
|
580
579
|
})
|
|
581
580
|
}
|
|
582
581
|
} else if (isMin) {
|
|
583
582
|
console.log('==========>', '京购批量加车!');
|
|
584
583
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
585
584
|
return {
|
|
586
585
|
skuId: skuItem,
|
|
587
586
|
buyNum: addCardNum,
|
|
588
587
|
};
|
|
589
588
|
});
|
|
590
589
|
global.wxAppBizInstance
|
|
591
590
|
.addCart({ commArr: productsAddCartList })
|
|
592
591
|
.then((res) => {
|
|
593
592
|
console.log('dealCartSuccess: ', res);
|
|
594
593
|
resolve({
|
|
595
594
|
ok: true,
|
|
596
595
|
msg: '已加入购物车!',
|
|
597
596
|
data: res,
|
|
598
597
|
});
|
|
599
598
|
})
|
|
600
599
|
.catch((e) => {
|
|
601
600
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
602
601
|
resolve({
|
|
603
602
|
ok: false,
|
|
604
603
|
msg: '加购失败,请稍后重试',
|
|
605
604
|
});
|
|
606
605
|
const data = {
|
|
607
606
|
eventName: 'business',
|
|
608
607
|
errorName: 'shop_batchAddCart_error',
|
|
609
608
|
errorMessage: 'H5调用小程序加车失败',
|
|
610
609
|
};
|
|
611
610
|
draBusinessCustomReport(data);
|
|
612
611
|
});
|
|
613
612
|
} else {
|
|
614
613
|
console.log('==========>', '使用M站批量加车!');
|
|
615
614
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
616
615
|
}
|
|
617
616
|
} else {
|
|
618
617
|
resolve({
|
|
619
618
|
ok: false,
|
|
620
619
|
msg: '加购sku不能为空',
|
|
621
620
|
});
|
|
622
621
|
const data = {
|
|
623
622
|
eventName: 'business',
|
|
624
623
|
errorName: 'shop_batchAddCart_error',
|
|
625
624
|
errorMessage: '加购sku不能为空',
|
|
626
625
|
};
|
|
627
626
|
draBusinessCustomReport(data);
|
|
628
627
|
}
|
|
629
628
|
});
|
|
630
629
|
}
|
|
631
630
|
|
|
632
631
|
productAddToCart(skuIdsStr, num) {
|
|
633
632
|
return new Promise((resolve) => {
|
|
634
633
|
if (window.AddcartToolObj) {
|
|
635
634
|
window.AddcartToolObj.addCart({
|
|
636
635
|
skuId: skuIdsStr,
|
|
637
636
|
num,
|
|
638
637
|
source: 'sjdpyw',
|
|
639
638
|
actId: '1',
|
|
640
639
|
loginType: window?.isJingGouMiniViewState ? '11' : isPc ? '3': '2',
|
|
641
640
|
sucFun(res) {
|
|
642
641
|
console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
|
|
643
642
|
if (res.errId === '0' && res.cartJson) {
|
|
644
643
|
resolve({
|
|
645
644
|
ok: true,
|
|
646
645
|
msg: '已加入购物车!',
|
|
647
646
|
...res,
|
|
648
647
|
});
|
|
649
648
|
} else {
|
|
650
649
|
if (res.errId === '13') {
|
|
651
650
|
global.doLogin();
|
|
652
651
|
} else {
|
|
653
652
|
resolve({
|
|
654
653
|
ok: false,
|
|
655
654
|
msg: '加购失败,请稍后重试',
|
|
656
655
|
...res,
|
|
657
656
|
});
|
|
658
657
|
const data = {
|
|
659
658
|
eventName: 'business',
|
|
660
659
|
errorName: 'shop_batchAddCart_error',
|
|
661
660
|
errorMessage: 'H5调用M站加车失败',
|
|
662
661
|
};
|
|
663
662
|
draBusinessCustomReport(data);
|
|
664
663
|
}
|
|
665
664
|
}
|
|
666
665
|
},
|
|
667
666
|
failFun(err) {
|
|
668
667
|
console.log('fail', err);
|
|
669
668
|
resolve({
|
|
670
669
|
ok: false,
|
|
671
670
|
msg: '加购失败,请稍后重试',
|
|
672
671
|
...err,
|
|
673
672
|
});
|
|
674
673
|
const data = {
|
|
675
674
|
eventName: 'business',
|
|
676
675
|
errorName: 'shop_batchAddCart_error',
|
|
677
676
|
errorMessage: 'H5调用M站加车失败',
|
|
678
677
|
};
|
|
679
678
|
draBusinessCustomReport(data);
|
|
680
679
|
},
|
|
681
680
|
});
|
|
682
681
|
} else {
|
|
683
682
|
resolve({
|
|
684
683
|
ok: false,
|
|
685
684
|
msg: '购物车方法检查异常',
|
|
686
685
|
});
|
|
687
686
|
const data = {
|
|
688
687
|
eventName: 'business',
|
|
689
688
|
errorName: 'shop_batchAddCart_error',
|
|
690
689
|
errorMessage: 'H5调用M站加车检查依赖方法异常',
|
|
691
690
|
};
|
|
692
691
|
draBusinessCustomReport(data);
|
|
693
692
|
}
|
|
694
693
|
});
|
|
695
694
|
}
|
|
696
695
|
bMallGetUserInfo = () => {
|
|
697
696
|
return getBMallUserInfo();
|
|
698
697
|
};
|
|
699
698
|
async bMallAddCart(params = {}) {
|
|
700
699
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
701
700
|
client: 'H5',
|
|
702
701
|
clientVersion: '5.5.0',
|
|
703
702
|
});
|
|
704
703
|
}
|
|
705
704
|
async bMallChangeCart(params = {}) {
|
|
706
705
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
707
706
|
client: 'H5',
|
|
708
707
|
clientVersion: '5.5.0',
|
|
709
708
|
});
|
|
710
709
|
}
|
|
711
710
|
async bMallRemoveCart(params = {}) {
|
|
712
711
|
return await this.gatewayReq(
|
|
713
712
|
'bmall_cartRemove',
|
|
714
713
|
params,
|
|
715
714
|
{
|
|
716
715
|
client: 'H5',
|
|
717
716
|
clientVersion: '5.5.0',
|
|
718
717
|
},
|
|
719
718
|
);
|
|
720
719
|
}
|
|
721
720
|
async bMallGetOmittedProduct(params = {}) {
|
|
722
721
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
723
722
|
client: 'H5',
|
|
724
723
|
clientVersion: '5.5.0',
|
|
725
724
|
});
|
|
726
725
|
}
|
|
727
726
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
728
727
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
729
728
|
return await this.bMallAddCart(params);
|
|
730
729
|
}
|
|
731
730
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
732
731
|
const params = await getParams({ bMallTag });
|
|
733
732
|
delete params.operations;
|
|
734
733
|
return await this.bMallGetOmittedProduct(params);
|
|
735
734
|
}
|
|
736
735
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
737
736
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
738
737
|
return await this.bMallRemoveCart(params);
|
|
739
738
|
}
|
|
740
739
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
741
740
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
742
741
|
return await this.bMallChangeCart(params);
|
|
743
742
|
}
|
|
744
743
|
|
|
745
744
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
746
745
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
747
746
|
return window?.bMallCartData;
|
|
748
747
|
}
|
|
749
748
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
750
749
|
let items;
|
|
751
750
|
if (cartData.ok && cartData.result) {
|
|
752
751
|
items = cartData?.result?.items || {};
|
|
753
752
|
}
|
|
754
753
|
if (isH5) {
|
|
755
754
|
window.bMallCartData = items;
|
|
756
755
|
}
|
|
757
756
|
return items;
|
|
758
757
|
}
|
|
759
758
|
|
|
760
759
|
async bMallCartHandle(goodItem, num) {
|
|
761
760
|
try {
|
|
762
761
|
const {
|
|
763
762
|
skuUuid,
|
|
764
763
|
limitUpper,
|
|
765
764
|
limitLower,
|
|
766
765
|
} = goodItem;
|
|
767
766
|
let cartNum = Number(num);
|
|
768
767
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
769
768
|
cartNum = limitLower;
|
|
770
769
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
771
770
|
cartNum = limitUpper;
|
|
772
771
|
}
|
|
773
772
|
if (skuUuid && cartNum > 0) {
|
|
774
773
|
return this.bMallChangeCartService({
|
|
775
774
|
...goodItem,
|
|
776
775
|
skuUuid,
|
|
777
776
|
num: cartNum,
|
|
778
777
|
});
|
|
779
778
|
} else if (!skuUuid && cartNum > 0) {
|
|
780
779
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
781
780
|
} else if (skuUuid && !cartNum) {
|
|
782
781
|
return this.bMallRemoveCartService({
|
|
783
782
|
...goodItem,
|
|
784
783
|
skuUuid,
|
|
785
784
|
num: cartNum,
|
|
786
785
|
});
|
|
787
786
|
} else {
|
|
788
787
|
console.error('参数不全');
|
|
789
788
|
return false;
|
|
790
789
|
}
|
|
791
790
|
} catch (e) {
|
|
792
791
|
console.error(e);
|
|
793
792
|
}
|
|
794
793
|
}
|
|
794
|
+
import Taro from '@tarojs/taro';
|
|
795
795
|
APPID,
|
|
796
796
|
JshopxColorFunctionIdList,
|
|
797
797
|
PagesColorFunctionIdList,
|
|
798
798
|
PAGES_DOMAIN,
|
|
799
799
|
B2BColorFunctionIdList,
|
|
800
800
|
MobileVerifyColorList,
|
|
801
801
|
AppVerifyColorList,
|
|
802
802
|
JshopxVerifyColorList,
|
|
803
803
|
BMallVerifyColorList,
|
|
804
804
|
shopMemberColorFunctionIdList,
|
|
805
805
|
draBusinessCustomReport,
|
|
806
806
|
isJdApp,
|
|
807
807
|
isIosDevice,
|
|
808
808
|
isAndroidDevice,
|
|
809
809
|
showSuccessToast,
|
|
810
810
|
showFailToast,
|
|
811
811
|
isH5,
|
|
812
812
|
isWxMinAndWxapp,
|
|
813
813
|
isMin,
|
|
814
814
|
isPc,
|
|
815
815
|
draInterfaceCustomReport,
|
|
816
816
|
isHarmonyDevice,
|
|
817
817
|
isAscfApp,
|
|
818
818
|
callRouterIOS,
|
|
819
819
|
callRouterAndroid,
|
|
820
820
|
callRouterHarmony,
|
|
821
821
|
sendNativePageToShowCartFloatBtn,
|
|
822
822
|
cookiesStr: '',
|
|
823
823
|
requestHeaderContentType: {
|
|
824
824
|
jsonHeader: {
|
|
825
825
|
'content-type': 'application/json;charset=utf-8',
|
|
826
826
|
},
|
|
827
827
|
formDataHeader: {
|
|
828
828
|
'content-type': 'application/x-www-form-urlencoded',
|
|
829
829
|
},
|
|
830
830
|
},
|
|
831
831
|
requestBaseParam: {
|
|
832
832
|
data: null,
|
|
833
833
|
header: {
|
|
834
834
|
'content-type': 'application/json;charset=utf-8',
|
|
835
835
|
},
|
|
836
836
|
},
|
|
837
837
|
timeOut: 7000,
|
|
838
838
|
apiClientParams: {
|
|
839
839
|
clientVersion: isJdApp && jdAppVersionStr !== '' ? jdAppVersionStr : '11.0.0',
|
|
840
840
|
client: isJdApp ? (isIosDevice ? 'apple' : 'android') : isPc ? 'pc' : 'wh5',
|
|
841
841
|
area: '1_72_2799_0',
|
|
842
842
|
screen: `${Math.ceil(window.screen?.width * devicePixelRatio)}*${Math.ceil(
|
|
843
843
|
window.screen?.height * devicePixelRatio,
|
|
844
844
|
)}`,
|
|
845
845
|
uuid: UUID,
|
|
846
846
|
},
|
|
847
847
|
window.shopGlobalSwitch?.useNativeHarmonyAddCartJdAppVersion;
|
|
848
848
|
nativeHarmonyAddCartJdAppVersion && jdAppVersionCompare(nativeHarmonyAddCartJdAppVersion) >= 0;
|
|
849
849
|
public addressFetchInfo: {
|
|
850
850
|
reqState: boolean;
|
|
851
851
|
promiseInstance: null | Promise<any>;
|
|
852
852
|
};
|
|
853
853
|
public getPromotionConfig: {
|
|
854
854
|
projectId: null | string | number;
|
|
855
855
|
pageId: null | string | number;
|
|
856
856
|
};
|
|
857
857
|
public resInfo: ServiceInterFace.HttpRequestInfo;
|
|
858
858
|
public api: ServiceInterFace.HttpApi;
|
|
859
859
|
public isPageDomain: boolean;
|
|
860
860
|
public verifyColorList: string[];
|
|
861
861
|
private isShowJdShopCartFloatBtn: boolean;
|
|
862
862
|
constructor(opt) {
|
|
863
863
|
this._init();
|
|
864
864
|
this.addressFetchInfo = {
|
|
865
865
|
reqState: false,
|
|
866
866
|
promiseInstance: null,
|
|
867
867
|
};
|
|
868
868
|
this.getPromotionConfig = {
|
|
869
869
|
projectId: null,
|
|
870
870
|
pageId: null,
|
|
871
871
|
};
|
|
872
872
|
this._userAreaUpdateListen();
|
|
873
873
|
this.resInfo = this._getResConfig(opt);
|
|
874
874
|
this.api = api;
|
|
875
875
|
this.isPageDomain = isH5 ? window?.location?.hostname === PAGES_DOMAIN : false;
|
|
876
876
|
this.verifyColorList = [
|
|
877
877
|
...MobileVerifyColorList,
|
|
878
878
|
...AppVerifyColorList,
|
|
879
879
|
...JshopxVerifyColorList,
|
|
880
880
|
...BMallVerifyColorList,
|
|
881
881
|
];
|
|
882
882
|
this.isShowJdShopCartFloatBtn =
|
|
883
883
|
jdAppVersionCompare(isJdAndIosDevice ? '13.8.6' : '13.6.2') >= 0;
|
|
884
884
|
}
|
|
885
885
|
_init(): void {
|
|
886
886
|
httpInterceptors.forEach((item) => {
|
|
887
887
|
Taro.addInterceptor((chain) => item(chain));
|
|
888
888
|
});
|
|
889
889
|
}
|
|
890
890
|
_getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
|
|
891
891
|
return Object.assign({}, DefaultConfig, opt);
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
_userAreaUpdateListen() {
|
|
895
895
|
Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
|
|
896
896
|
this.updateApiClientParamsResInfo(areaInfo);
|
|
897
897
|
console.log(
|
|
898
898
|
'cone-render收到原生端获取传来的四级地址信息',
|
|
899
899
|
areaInfo,
|
|
900
900
|
'更新后的接口底层信息',
|
|
901
901
|
this.resInfo.apiClientParams,
|
|
902
902
|
);
|
|
903
903
|
});
|
|
904
904
|
}
|
|
905
905
|
updateApiClientParamsResInfo(opt = {}) {
|
|
906
906
|
const { area, realTimeArea, ...others } = opt;
|
|
907
907
|
this.resInfo.apiClientParams = {
|
|
908
908
|
...this.resInfo.apiClientParams,
|
|
909
909
|
...others,
|
|
910
910
|
};
|
|
911
911
|
area && area !== '' && (this.resInfo.apiClientParams.area = area);
|
|
912
912
|
realTimeArea &&
|
|
913
913
|
realTimeArea !== '' &&
|
|
914
914
|
(this.resInfo.apiClientParams.realTimeArea = realTimeArea);
|
|
915
915
|
}
|
|
916
916
|
|
|
917
917
|
checkFunctionIdToReturnAppId(functionId) {
|
|
918
918
|
if (JshopxColorFunctionIdList.includes(functionId)) {
|
|
919
919
|
return APPID.JSHOPX_COLOR_APPID;
|
|
920
920
|
} else if (this.isPageDomain && PagesColorFunctionIdList.includes(functionId)) {
|
|
921
921
|
return APPID.PAGES_COLOR_APPID;
|
|
922
922
|
} else if (shopMemberColorFunctionIdList.includes(functionId)) {
|
|
923
923
|
return APPID.SHOP_MEMBER_COLOR_APPID;
|
|
924
924
|
} else if (B2BColorFunctionIdList.includes(functionId)) {
|
|
925
925
|
return APPID.B2B_COLOR_APPID;
|
|
926
926
|
} else if (isPc) {
|
|
927
927
|
return APPID.MALL_COLOR_APPID;
|
|
928
928
|
} else {
|
|
929
929
|
return APPID.SHOP_COLOR_APPID;
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
|
|
933
933
|
gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
|
|
934
934
|
if (
|
|
935
935
|
functionId === 'receiveShopCoupon' &&
|
|
936
936
|
((isH5 && (window?.isJingGouMiniViewState || window?.isJingxiMiniViewState)) ||
|
|
937
937
|
isWxMinAndWxapp)
|
|
938
938
|
) {
|
|
939
939
|
clientParams = Object.assign(
|
|
940
940
|
{},
|
|
941
941
|
{
|
|
942
942
|
loginType: isAscfApp ? '2' : '1',
|
|
943
943
|
loginWQBiz: WXAPP_BIZ_KEY,
|
|
944
944
|
},
|
|
945
945
|
clientParams,
|
|
946
946
|
);
|
|
947
947
|
}
|
|
948
948
|
const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
|
|
949
949
|
typeof apiClientParams.appid === 'undefined' &&
|
|
950
950
|
(apiClientParams.appid = this.checkFunctionIdToReturnAppId(functionId));
|
|
951
951
|
const isColorVerify = this.verifyColorList.includes(functionId);
|
|
952
952
|
const getReqData = {
|
|
953
953
|
functionId: functionId,
|
|
954
954
|
body: JSON.stringify(bodyParams),
|
|
955
955
|
t: Date.now(),
|
|
956
956
|
...apiClientParams,
|
|
957
957
|
};
|
|
958
958
|
return http
|
|
959
959
|
.request({
|
|
960
960
|
url: this.api.apiFunc,
|
|
961
961
|
data: getReqData,
|
|
962
962
|
isColorVerify,
|
|
963
963
|
})
|
|
964
964
|
.then((res: ServiceInterFace.RequestPromiseRes) => {
|
|
965
965
|
const { statusCode, data, status, msg } = res;
|
|
966
966
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
967
967
|
ok: true,
|
|
968
968
|
};
|
|
969
969
|
if ((statusCode === 200 || status === '0') && data) {
|
|
970
970
|
changeRes = this.dealResponseFormatRes(data);
|
|
971
971
|
return changeRes;
|
|
972
972
|
} else {
|
|
973
973
|
changeRes = {
|
|
974
974
|
...data,
|
|
975
975
|
statusCode,
|
|
976
976
|
status,
|
|
977
977
|
msg,
|
|
978
978
|
ok: false,
|
|
979
979
|
};
|
|
980
980
|
return changeRes;
|
|
981
981
|
}
|
|
982
982
|
})
|
|
983
983
|
.catch((res) => {
|
|
984
984
|
const propertyNames = Object.getOwnPropertyNames(res);
|
|
985
985
|
const resObject = {};
|
|
986
986
|
propertyNames.forEach((propertyName) => {
|
|
987
987
|
resObject[propertyName] = res[propertyName];
|
|
988
988
|
});
|
|
989
989
|
draInterfaceCustomReport({
|
|
990
990
|
eventName: 'apiStatusCode',
|
|
991
991
|
errorName: `shop_${functionId}_error`,
|
|
992
992
|
errorMessage: `接口返回statusCode为${res?.statusCode || res?.status}`,
|
|
993
993
|
url: this.api.apiFunc,
|
|
994
994
|
source: 'remote',
|
|
995
995
|
requestType: res?.requestType,
|
|
996
996
|
functionId: getReqData?.functionId,
|
|
997
997
|
appid: getReqData?.appid,
|
|
998
998
|
client: getReqData?.client,
|
|
999
999
|
clientVersion: getReqData?.clientVersion,
|
|
1000
1000
|
statusCode: res?.statusCode,
|
|
1001
1001
|
status: res?.status,
|
|
1002
1002
|
statusText: res?.statusText,
|
|
1003
1003
|
errMsg: res?.errMsg || res?.msg || res?.message || res?.data?.echo,
|
|
1004
1004
|
originReqDataStr: JSON.stringify(getReqData),
|
|
1005
1005
|
});
|
|
1006
1006
|
return {
|
|
1007
1007
|
...resObject,
|
|
1008
1008
|
ok: false,
|
|
1009
1009
|
} as ServiceInterFace.RequestResponseFormatRes;
|
|
1010
1010
|
});
|
|
1011
1011
|
}
|
|
1012
1012
|
|
|
1013
1013
|
dealResponseFormatRes(data) {
|
|
1014
1014
|
let changeRes: ServiceInterFace.RequestResponseFormatRes = {
|
|
1015
1015
|
ok: true,
|
|
1016
1016
|
};
|
|
1017
1017
|
const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
|
|
1018
1018
|
const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
|
|
1019
1019
|
? Number(data.subCode)
|
|
1020
1020
|
: -1;
|
|
1021
1021
|
if (
|
|
1022
1022
|
data.success === true ||
|
|
1023
1023
|
data.isSuccess ||
|
|
1024
1024
|
resCode === 0 ||
|
|
1025
1025
|
resCode === 200 ||
|
|
1026
1026
|
subCode === 0
|
|
1027
1027
|
) {
|
|
1028
1028
|
changeRes = {
|
|
1029
1029
|
result: Object.prototype.hasOwnProperty.call(data, 'result')
|
|
1030
1030
|
? data.result
|
|
1031
1031
|
: Object.prototype.hasOwnProperty.call(data, 'data')
|
|
1032
1032
|
? data.data
|
|
1033
1033
|
: data,
|
|
1034
1034
|
code: data.code ?? 200,
|
|
1035
1035
|
ok: true,
|
|
1036
1036
|
source: data,
|
|
1037
1037
|
};
|
|
1038
1038
|
return changeRes;
|
|
1039
1039
|
} else {
|
|
1040
1040
|
changeRes = {
|
|
1041
1041
|
...data,
|
|
1042
1042
|
ok: false,
|
|
1043
1043
|
};
|
|
1044
1044
|
return changeRes;
|
|
1045
1045
|
}
|
|
1046
1046
|
}
|
|
1047
1047
|
|
|
1048
1048
|
async receiveCoupon(param = {}, clientParams) {
|
|
1049
1049
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
1050
1050
|
return await this.gatewayReq(
|
|
1051
1051
|
'receiveShopCoupon',
|
|
1052
1052
|
{
|
|
1053
1053
|
operation: '3',
|
|
1054
1054
|
...param,
|
|
1055
1055
|
},
|
|
1056
1056
|
{ ...loginType, ...clientParams },
|
|
1057
1057
|
);
|
|
1058
1058
|
}
|
|
1059
1059
|
|
|
1060
1060
|
getCustomerCenterDispatch(params = {}) {
|
|
1061
1061
|
return this.gatewayReq('customerCenterDispatch', params, {
|
|
1062
1062
|
clientVersion: '9.2.0',
|
|
1063
1063
|
client: 'H5',
|
|
1064
1064
|
uuid: 88888,
|
|
1065
1065
|
appid: 'shopmember_m_jd_com',
|
|
1066
1066
|
});
|
|
1067
1067
|
}
|
|
1068
1068
|
|
|
1069
1069
|
batchAddCart(...args) {
|
|
1070
1070
|
let skuIds, num, showToast, giftCard;
|
|
1071
1071
|
if (['number', 'string'].includes(typeof args[0])) {
|
|
1072
1072
|
[skuIds, num = 1, showToast = true, giftCard = false] = args;
|
|
1073
1073
|
} else if (typeof args[0] === 'object' && args[0] !== null) {
|
|
1074
1074
|
const params = args[0];
|
|
1075
1075
|
skuIds = params.skuIds;
|
|
1076
1076
|
num = params.num || 1;
|
|
1077
1077
|
showToast = params.showToast !== undefined ? params.showToast : true;
|
|
1078
1078
|
giftCard = params.giftCard !== undefined ? params.giftCard : false;
|
|
1079
1079
|
} else {
|
|
1080
1080
|
try {
|
|
1081
1081
|
const data = {
|
|
1082
1082
|
eventName: 'business',
|
|
1083
1083
|
errorName: 'shop_batchAddCart_error',
|
|
1084
1084
|
errorMessage: '入参不合法',
|
|
1085
1085
|
extraData: JSON.stringify(args),
|
|
1086
1086
|
};
|
|
1087
1087
|
draBusinessCustomReport(data);
|
|
1088
1088
|
} catch (e) {
|
|
1089
1089
|
console.error('draBusinessCustomReport error:', e);
|
|
1090
1090
|
}
|
|
1091
1091
|
const msg = global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
|
|
1092
1092
|
showFailToast({
|
|
1093
1093
|
title: msg,
|
|
1094
1094
|
});
|
|
1095
1095
|
return Promise.resolve({
|
|
1096
1096
|
ok: false,
|
|
1097
1097
|
msg,
|
|
1098
1098
|
});
|
|
1099
1099
|
}
|
|
1100
1100
|
const successMsg = giftCard
|
|
1101
1101
|
? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
|
|
1102
1102
|
: global?.languageJsonData?.successAddCart || '加入购物车成功';
|
|
1103
1103
|
const failMsg = giftCard
|
|
1104
1104
|
? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
|
|
1105
1105
|
: global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
|
|
1106
1106
|
if (skuIds) {
|
|
1107
1107
|
return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
|
|
1108
1108
|
.then((res: ServiceInterFace.SkuToCartDataRes) => {
|
|
1109
1109
|
if (res?.ok) {
|
|
1110
1110
|
showToast &&
|
|
1111
1111
|
!res?.isOpenApp &&
|
|
1112
1112
|
showSuccessToast({
|
|
1113
1113
|
title: successMsg,
|
|
1114
1114
|
});
|
|
1115
1115
|
this.isShowJdShopCartFloatBtn &&
|
|
1116
1116
|
sendNativePageToShowCartFloatBtn({
|
|
1117
1117
|
isShow: true,
|
|
1118
1118
|
});
|
|
1119
1119
|
} else {
|
|
1120
1120
|
showToast &&
|
|
1121
1121
|
showFailToast({
|
|
1122
1122
|
title: res?.errMsg || failMsg,
|
|
1123
1123
|
});
|
|
1124
1124
|
}
|
|
1125
1125
|
return Promise.resolve(res);
|
|
1126
1126
|
})
|
|
1127
1127
|
.catch((e) => {
|
|
1128
1128
|
console.log('调用加购方法异常=======>', e);
|
|
1129
1129
|
return Promise.resolve({
|
|
1130
1130
|
ok: false,
|
|
1131
1131
|
msg: failMsg,
|
|
1132
1132
|
});
|
|
1133
1133
|
});
|
|
1134
1134
|
} else {
|
|
1135
1135
|
try {
|
|
1136
1136
|
const data = {
|
|
1137
1137
|
eventName: 'business',
|
|
1138
1138
|
errorName: 'shop_batchAddCart_error',
|
|
1139
1139
|
errorMessage: '没有传入合法的skuIds',
|
|
1140
1140
|
};
|
|
1141
1141
|
draBusinessCustomReport(data);
|
|
1142
1142
|
} catch (e) {
|
|
1143
1143
|
console.error('draBusinessCustomReport error:', e);
|
|
1144
1144
|
}
|
|
1145
1145
|
return Promise.resolve({
|
|
1146
1146
|
ok: false,
|
|
1147
1147
|
msg: failMsg,
|
|
1148
1148
|
});
|
|
1149
1149
|
}
|
|
1150
1150
|
}
|
|
1151
1151
|
|
|
1152
1152
|
async giftCardAddCart(skuList, num) {
|
|
1153
1153
|
const loginType = isPc ? { loginType: 3 } : {};
|
|
1154
1154
|
return this.gatewayReq(
|
|
1155
1155
|
'giftCardAddCart',
|
|
1156
1156
|
{
|
|
1157
1157
|
skuList,
|
|
1158
1158
|
num: Number(num),
|
|
1159
1159
|
},
|
|
1160
1160
|
{ ...loginType },
|
|
1161
1161
|
);
|
|
1162
1162
|
}
|
|
1163
1163
|
|
|
1164
1164
|
_addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
|
|
1165
1165
|
return new Promise((resolve) => {
|
|
1166
1166
|
const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
|
|
1167
1167
|
if (productIdsArr.length > 0) {
|
|
1168
1168
|
if (giftCard) {
|
|
1169
1169
|
this.giftCardAddCart(productIdsArr, addCardNum)
|
|
1170
1170
|
.then((res) => {
|
|
1171
1171
|
if (res?.code === '0' && res?.result?.value) {
|
|
1172
1172
|
resolve({
|
|
1173
1173
|
ok: true,
|
|
1174
1174
|
});
|
|
1175
1175
|
} else {
|
|
1176
1176
|
try {
|
|
1177
1177
|
const data = {
|
|
1178
1178
|
eventName: 'business',
|
|
1179
1179
|
errorName: 'shop_batchAddCart_error',
|
|
1180
1180
|
errorMessage: '礼品卡加车接口返回加车失败标识',
|
|
1181
1181
|
};
|
|
1182
1182
|
draBusinessCustomReport(data);
|
|
1183
1183
|
} catch (e) {
|
|
1184
1184
|
console.error('draBusinessCustomReport error:', e);
|
|
1185
1185
|
}
|
|
1186
1186
|
resolve({
|
|
1187
1187
|
ok: false,
|
|
1188
1188
|
msg: '加购失败,请稍后重试',
|
|
1189
1189
|
});
|
|
1190
1190
|
}
|
|
1191
1191
|
})
|
|
1192
1192
|
.catch((e) => {
|
|
1193
1193
|
console.error('礼品卡加车失败: ', e);
|
|
1194
1194
|
resolve({
|
|
1195
1195
|
ok: false,
|
|
1196
1196
|
msg: '加购失败,请稍后重试',
|
|
1197
1197
|
});
|
|
1198
1198
|
});
|
|
1199
1199
|
} else if (
|
|
1200
1200
|
isJdApp &&
|
|
1201
1201
|
(!isHarmonyDevice || (isHarmonyDevice && useNativeHarmonyAddCartJd))
|
|
1202
1202
|
) {
|
|
1203
1203
|
const nativeAddCartCallBack = `nativeBatchAddCart${Date.now() + Number(productIdsArr[0]) + Number(addCardNum)}`;
|
|
1204
1204
|
console.log(
|
|
1205
1205
|
'==========>',
|
|
1206
1206
|
'使用原生批量加车, 回调方法保证唯一添加skuid和数量,nativeAddCartCallBack',
|
|
1207
1207
|
nativeAddCartCallBack,
|
|
1208
1208
|
);
|
|
1209
1209
|
if (!window[nativeAddCartCallBack]) {
|
|
1210
1210
|
window[nativeAddCartCallBack] = (res) => {
|
|
1211
1211
|
const getMessageJsonData = typeof res === 'string' ? JSON.parse(res) : res;
|
|
1212
1212
|
console.info(
|
|
1213
1213
|
'获取批量加车原始数据',
|
|
1214
1214
|
res,
|
|
1215
1215
|
'====转换后的json数据为===',
|
|
1216
1216
|
getMessageJsonData,
|
|
1217
1217
|
);
|
|
1218
1218
|
try {
|
|
1219
1219
|
if (isAndroidDevice) {
|
|
1220
1220
|
const isOk = getMessageJsonData?.status === '0';
|
|
1221
1221
|
isOk
|
|
1222
1222
|
? resolve({
|
|
1223
1223
|
ok: true,
|
|
1224
1224
|
msg: '已加入购物车!',
|
|
1225
1225
|
})
|
|
1226
1226
|
: resolve({
|
|
1227
1227
|
ok: false,
|
|
1228
1228
|
msg: '加购失败,请稍后重试',
|
|
1229
1229
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
1230
1230
|
});
|
|
1231
1231
|
if (!isOk) {
|
|
1232
1232
|
const data = {
|
|
1233
1233
|
eventName: 'business',
|
|
1234
1234
|
errorName: 'shop_batchAddCart_error',
|
|
1235
1235
|
errorMessage: 'H5调用Android原生加车失败',
|
|
1236
1236
|
};
|
|
1237
1237
|
draBusinessCustomReport(data);
|
|
1238
1238
|
}
|
|
1239
1239
|
} else if (isIosDevice) {
|
|
1240
1240
|
const isOk =
|
|
1241
1241
|
getMessageJsonData?.status === '0' && getMessageJsonData?.data?.code === 0;
|
|
1242
1242
|
isOk
|
|
1243
1243
|
? resolve({
|
|
1244
1244
|
ok: true,
|
|
1245
1245
|
msg: '已加入购物车!',
|
|
1246
1246
|
})
|
|
1247
1247
|
: resolve({
|
|
1248
1248
|
ok: false,
|
|
1249
1249
|
msg: '批量加车失败,请稍后重试',
|
|
1250
1250
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
1251
1251
|
});
|
|
1252
1252
|
if (!isOk) {
|
|
1253
1253
|
const data = {
|
|
1254
1254
|
eventName: 'business',
|
|
1255
1255
|
errorName: 'shop_batchAddCart_error',
|
|
1256
1256
|
errorMessage: 'H5调用IOS原生加车失败',
|
|
1257
1257
|
};
|
|
1258
1258
|
draBusinessCustomReport(data);
|
|
1259
1259
|
}
|
|
1260
1260
|
} else if (isHarmonyDevice) {
|
|
1261
1261
|
const isOk =
|
|
1262
1262
|
getMessageJsonData?.data?.code === 0 &&
|
|
1263
1263
|
getMessageJsonData?.data?.response?.resultCode === 0;
|
|
1264
1264
|
isOk
|
|
1265
1265
|
? resolve({
|
|
1266
1266
|
ok: true,
|
|
1267
1267
|
msg: '已加入购物车!',
|
|
1268
1268
|
})
|
|
1269
1269
|
: resolve({
|
|
1270
1270
|
ok: false,
|
|
1271
1271
|
msg: '加购失败,请稍后重试',
|
|
1272
1272
|
errMsg: getMessageJsonData?.data?.message ?? '',
|
|
1273
1273
|
});
|
|
1274
1274
|
if (!isOk) {
|
|
1275
1275
|
const data = {
|
|
1276
1276
|
eventName: 'business',
|
|
1277
1277
|
errorName: 'shop_batchAddCart_error',
|
|
1278
1278
|
errorMessage: 'H5调用Harmony原生加车失败',
|
|
1279
1279
|
};
|
|
1280
1280
|
draBusinessCustomReport(data);
|
|
1281
1281
|
}
|
|
1282
1282
|
} else {
|
|
1283
1283
|
resolve({
|
|
1284
1284
|
ok: false,
|
|
1285
1285
|
msg: '加购失败,请稍后重试',
|
|
1286
1286
|
});
|
|
1287
1287
|
const data = {
|
|
1288
1288
|
eventName: 'business',
|
|
1289
1289
|
errorName: 'shop_batchAddCart_error',
|
|
1290
1290
|
errorMessage: 'H5调用未知原生加车失败',
|
|
1291
1291
|
};
|
|
1292
1292
|
draBusinessCustomReport(data);
|
|
1293
1293
|
}
|
|
1294
1294
|
} catch (e) {
|
|
1295
1295
|
resolve({
|
|
1296
1296
|
ok: false,
|
|
1297
1297
|
msg: '加购失败,请稍后重试',
|
|
1298
1298
|
});
|
|
1299
1299
|
console.warn('批量加车转换数据异常', e);
|
|
1300
1300
|
const data = {
|
|
1301
1301
|
eventName: 'business',
|
|
1302
1302
|
errorName: 'shop_batchAddCart_error',
|
|
1303
1303
|
errorMessage: '批量加车转换数据异常',
|
|
1304
1304
|
};
|
|
1305
1305
|
draBusinessCustomReport(data);
|
|
1306
1306
|
}
|
|
1307
1307
|
window[nativeAddCartCallBack] = null;
|
|
1308
1308
|
};
|
|
1309
1309
|
}
|
|
1310
1310
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
1311
1311
|
const adInfos = getAdInfoBySkuId(skuItem);
|
|
1312
1312
|
const extFlag = adInfos ? { adInfos } : {};
|
|
1313
1313
|
let item = null;
|
|
1314
1314
|
if (isAndroidDevice) {
|
|
1315
1315
|
item = {
|
|
1316
1316
|
sku: skuItem,
|
|
1317
1317
|
num: addCardNum,
|
|
1318
1318
|
extFlag,
|
|
1319
1319
|
};
|
|
1320
1320
|
} else if (isIosDevice) {
|
|
1321
1321
|
item = {
|
|
1322
1322
|
productCode: skuItem,
|
|
1323
1323
|
buyCount: addCardNum,
|
|
1324
1324
|
extFlag,
|
|
1325
1325
|
};
|
|
1326
1326
|
} else if (isHarmonyDevice) {
|
|
1327
1327
|
item = {
|
|
1328
1328
|
sourceType: 'native',
|
|
1329
1329
|
sourceValue: 'shop',
|
|
1330
1330
|
productCode: skuItem,
|
|
1331
1331
|
buyCount: addCardNum,
|
|
1332
1332
|
extFlag,
|
|
1333
1333
|
};
|
|
1334
1334
|
}
|
|
1335
1335
|
return item;
|
|
1336
1336
|
});
|
|
1337
1337
|
if (isAndroidDevice) {
|
|
1338
1338
|
const androidProductsStr = JSON.stringify(productsAddCartList);
|
|
1339
1339
|
callRouterAndroid({
|
|
1340
1340
|
routerURL: `router://JDCartModule/addCartUniformWithUrl?wareList=${androidProductsStr}&businessName=storeModel`,
|
|
1341
1341
|
routerParam: {
|
|
1342
1342
|
wareList: productsAddCartList,
|
|
1343
1343
|
},
|
|
1344
1344
|
callBackName: nativeAddCartCallBack,
|
|
1345
1345
|
});
|
|
1346
1346
|
} else if (isIosDevice) {
|
|
1347
1347
|
if (isLowAppVer) {
|
|
1348
1348
|
const lowVersionAppList = productIdsArr.map((skuItem) => {
|
|
1349
1349
|
return {
|
|
1350
1350
|
sku: skuItem,
|
|
1351
1351
|
num: addCardNum,
|
|
1352
1352
|
};
|
|
1353
1353
|
});
|
|
1354
1354
|
const lowVersionAppListStr = JSON.stringify(lowVersionAppList);
|
|
1355
1355
|
const url = `openApp.jdMobile://virtual?params={"category":"jump","des":"updateCartNum","sourceValue":"店铺批量加购","sourceType":"h5","businessName":"storeModel","wareList":${lowVersionAppListStr}}`;
|
|
1356
1356
|
jump.side.jdJumpToWeb(url, {});
|
|
1357
1357
|
resolve({
|
|
1358
1358
|
ok: true,
|
|
1359
1359
|
isOpenApp: true,
|
|
1360
1360
|
msg: '加购完成, 加购结果请点击购物车确认',
|
|
1361
1361
|
});
|
|
1362
1362
|
} else {
|
|
1363
1363
|
callRouterIOS({
|
|
1364
1364
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
1365
1365
|
routerParam: {
|
|
1366
1366
|
sourceType: 'h5',
|
|
1367
1367
|
sourceValue: '店铺批量加购',
|
|
1368
1368
|
businessName: 'storeModel',
|
|
1369
1369
|
isNewMode: '1',
|
|
1370
1370
|
NotPassWebview: '1',
|
|
1371
1371
|
products: productsAddCartList,
|
|
1372
1372
|
},
|
|
1373
1373
|
callBackName: nativeAddCartCallBack,
|
|
1374
1374
|
});
|
|
1375
1375
|
}
|
|
1376
1376
|
} else if (isHarmonyDevice) {
|
|
1377
1377
|
callRouterHarmony({
|
|
1378
1378
|
routerURL: 'router://JDCartModule/batchAddService',
|
|
1379
1379
|
routerParam: {
|
|
1380
1380
|
sourceType: 'native',
|
|
1381
1381
|
sourceValue: 'shop',
|
|
1382
1382
|
products: productsAddCartList,
|
|
1383
1383
|
},
|
|
1384
1384
|
callBackName: nativeAddCartCallBack,
|
|
1385
1385
|
});
|
|
1386
1386
|
}
|
|
1387
1387
|
} else if (isMin) {
|
|
1388
1388
|
console.log('==========>', '京购批量加车!');
|
|
1389
1389
|
const productsAddCartList = productIdsArr.map((skuItem) => {
|
|
1390
1390
|
return {
|
|
1391
1391
|
skuId: skuItem,
|
|
1392
1392
|
buyNum: addCardNum,
|
|
1393
1393
|
};
|
|
1394
1394
|
});
|
|
1395
1395
|
global.wxAppBizInstance
|
|
1396
1396
|
.addCart({ commArr: productsAddCartList })
|
|
1397
1397
|
.then((res) => {
|
|
1398
1398
|
console.log('dealCartSuccess: ', res);
|
|
1399
1399
|
resolve({
|
|
1400
1400
|
ok: true,
|
|
1401
1401
|
msg: '已加入购物车!',
|
|
1402
1402
|
data: res,
|
|
1403
1403
|
});
|
|
1404
1404
|
})
|
|
1405
1405
|
.catch((e) => {
|
|
1406
1406
|
console.log('京购小程序批量加车失败dealCartFail: ', e);
|
|
1407
1407
|
resolve({
|
|
1408
1408
|
ok: false,
|
|
1409
1409
|
msg: '加购失败,请稍后重试',
|
|
1410
1410
|
});
|
|
1411
1411
|
const data = {
|
|
1412
1412
|
eventName: 'business',
|
|
1413
1413
|
errorName: 'shop_batchAddCart_error',
|
|
1414
1414
|
errorMessage: 'H5调用小程序加车失败',
|
|
1415
1415
|
};
|
|
1416
1416
|
draBusinessCustomReport(data);
|
|
1417
1417
|
});
|
|
1418
1418
|
} else {
|
|
1419
1419
|
console.log('==========>', '使用M站批量加车!');
|
|
1420
1420
|
return this.productAddToCart(skuIdsStr, addCardNum).then((res) => resolve(res));
|
|
1421
1421
|
}
|
|
1422
1422
|
} else {
|
|
1423
1423
|
resolve({
|
|
1424
1424
|
ok: false,
|
|
1425
1425
|
msg: '加购sku不能为空',
|
|
1426
1426
|
});
|
|
1427
1427
|
const data = {
|
|
1428
1428
|
eventName: 'business',
|
|
1429
1429
|
errorName: 'shop_batchAddCart_error',
|
|
1430
1430
|
errorMessage: '加购sku不能为空',
|
|
1431
1431
|
};
|
|
1432
1432
|
draBusinessCustomReport(data);
|
|
1433
1433
|
}
|
|
1434
1434
|
});
|
|
1435
1435
|
}
|
|
1436
1436
|
|
|
1437
1437
|
productAddToCart(skuIdsStr, num) {
|
|
1438
1438
|
return new Promise((resolve) => {
|
|
1439
1439
|
if (window.AddcartToolObj) {
|
|
1440
1440
|
window.AddcartToolObj.addCart({
|
|
1441
1441
|
skuId: skuIdsStr,
|
|
1442
1442
|
num,
|
|
1443
1443
|
source: 'sjdpyw',
|
|
1444
1444
|
actId: '1',
|
|
1445
1445
|
loginType: isAscfApp ? '2' : window?.isJingGouMiniViewState ? '11' : isPc ? '3' : '2',
|
|
1446
1446
|
sucFun(res) {
|
|
1447
1447
|
console.log('ok,接口请求成功,不一定指的加车成功,加车成功需要看返回码errId为0', res);
|
|
1448
1448
|
if (res.errId === '0' && res.cartJson) {
|
|
1449
1449
|
resolve({
|
|
1450
1450
|
ok: true,
|
|
1451
1451
|
msg: '已加入购物车!',
|
|
1452
1452
|
...res,
|
|
1453
1453
|
});
|
|
1454
1454
|
} else {
|
|
1455
1455
|
if (res.errId === '13') {
|
|
1456
1456
|
global.doLogin();
|
|
1457
1457
|
} else {
|
|
1458
1458
|
resolve({
|
|
1459
1459
|
ok: false,
|
|
1460
1460
|
msg: '加购失败,请稍后重试',
|
|
1461
1461
|
...res,
|
|
1462
1462
|
});
|
|
1463
1463
|
const data = {
|
|
1464
1464
|
eventName: 'business',
|
|
1465
1465
|
errorName: 'shop_batchAddCart_error',
|
|
1466
1466
|
errorMessage: 'H5调用M站加车失败',
|
|
1467
1467
|
};
|
|
1468
1468
|
draBusinessCustomReport(data);
|
|
1469
1469
|
}
|
|
1470
1470
|
}
|
|
1471
1471
|
},
|
|
1472
1472
|
failFun(err) {
|
|
1473
1473
|
console.log('fail', err);
|
|
1474
1474
|
resolve({
|
|
1475
1475
|
ok: false,
|
|
1476
1476
|
msg: '加购失败,请稍后重试',
|
|
1477
1477
|
...err,
|
|
1478
1478
|
});
|
|
1479
1479
|
const data = {
|
|
1480
1480
|
eventName: 'business',
|
|
1481
1481
|
errorName: 'shop_batchAddCart_error',
|
|
1482
1482
|
errorMessage: 'H5调用M站加车失败',
|
|
1483
1483
|
};
|
|
1484
1484
|
draBusinessCustomReport(data);
|
|
1485
1485
|
},
|
|
1486
1486
|
});
|
|
1487
1487
|
} else {
|
|
1488
1488
|
resolve({
|
|
1489
1489
|
ok: false,
|
|
1490
1490
|
msg: '购物车方法检查异常',
|
|
1491
1491
|
});
|
|
1492
1492
|
const data = {
|
|
1493
1493
|
eventName: 'business',
|
|
1494
1494
|
errorName: 'shop_batchAddCart_error',
|
|
1495
1495
|
errorMessage: 'H5调用M站加车检查依赖方法异常',
|
|
1496
1496
|
};
|
|
1497
1497
|
draBusinessCustomReport(data);
|
|
1498
1498
|
}
|
|
1499
1499
|
});
|
|
1500
1500
|
}
|
|
1501
1501
|
bMallGetUserInfo = () => {
|
|
1502
1502
|
return getBMallUserInfo();
|
|
1503
1503
|
};
|
|
1504
1504
|
async bMallAddCart(params = {}) {
|
|
1505
1505
|
return await this.gatewayReq('bmall_cartAdd', params, {
|
|
1506
1506
|
client: 'H5',
|
|
1507
1507
|
clientVersion: '5.5.0',
|
|
1508
1508
|
});
|
|
1509
1509
|
}
|
|
1510
1510
|
async bMallChangeCart(params = {}) {
|
|
1511
1511
|
return await this.gatewayReq('bmall_cartChange', params, {
|
|
1512
1512
|
client: 'H5',
|
|
1513
1513
|
clientVersion: '5.5.0',
|
|
1514
1514
|
});
|
|
1515
1515
|
}
|
|
1516
1516
|
async bMallRemoveCart(params = {}) {
|
|
1517
1517
|
return await this.gatewayReq(
|
|
1518
1518
|
'bmall_cartRemove',
|
|
1519
1519
|
params,
|
|
1520
1520
|
{
|
|
1521
1521
|
client: 'H5',
|
|
1522
1522
|
clientVersion: '5.5.0',
|
|
1523
1523
|
},
|
|
1524
1524
|
);
|
|
1525
1525
|
}
|
|
1526
1526
|
async bMallGetOmittedProduct(params = {}) {
|
|
1527
1527
|
return await this.gatewayReq('bmall_getOmittedProduct', params, {
|
|
1528
1528
|
client: 'H5',
|
|
1529
1529
|
clientVersion: '5.5.0',
|
|
1530
1530
|
});
|
|
1531
1531
|
}
|
|
1532
1532
|
async bMallAddCartService({ skuId, bMallTag, num, data = {} }) {
|
|
1533
1533
|
const params = await getParams({ ...data, skuId, bMallTag, num });
|
|
1534
1534
|
return await this.bMallAddCart(params);
|
|
1535
1535
|
}
|
|
1536
1536
|
async bMallGetSkuNumService(bMallTag = 1) {
|
|
1537
1537
|
const params = await getParams({ bMallTag });
|
|
1538
1538
|
delete params.operations;
|
|
1539
1539
|
return await this.bMallGetOmittedProduct(params);
|
|
1540
1540
|
}
|
|
1541
1541
|
async bMallRemoveCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1542
1542
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1543
1543
|
return await this.bMallRemoveCart(params);
|
|
1544
1544
|
}
|
|
1545
1545
|
async bMallChangeCartService({ skuId, bMallTag, num, skuUuid, data = {} }) {
|
|
1546
1546
|
let params = await getParams({ ...data, skuId, bMallTag, num, skuUuid });
|
|
1547
1547
|
return await this.bMallChangeCart(params);
|
|
1548
1548
|
}
|
|
1549
1549
|
|
|
1550
1550
|
async bMallGetSkuNumApi(needRequest = false, bMallTag = 1) {
|
|
1551
1551
|
if (!needRequest && isH5 && window?.bMallCartData) {
|
|
1552
1552
|
return window?.bMallCartData;
|
|
1553
1553
|
}
|
|
1554
1554
|
const cartData = await this.bMallGetSkuNumService(bMallTag);
|
|
1555
1555
|
let items;
|
|
1556
1556
|
if (cartData.ok && cartData.result) {
|
|
1557
1557
|
items = cartData?.result?.items || {};
|
|
1558
1558
|
}
|
|
1559
1559
|
if (isH5) {
|
|
1560
1560
|
window.bMallCartData = items;
|
|
1561
1561
|
}
|
|
1562
1562
|
return items;
|
|
1563
1563
|
}
|
|
1564
1564
|
|
|
1565
1565
|
async bMallCartHandle(goodItem, num) {
|
|
1566
1566
|
try {
|
|
1567
1567
|
const {
|
|
1568
1568
|
skuUuid,
|
|
1569
1569
|
limitUpper,
|
|
1570
1570
|
limitLower,
|
|
1571
1571
|
} = goodItem;
|
|
1572
1572
|
let cartNum = Number(num);
|
|
1573
1573
|
if (limitLower && cartNum && cartNum < limitLower) {
|
|
1574
1574
|
cartNum = limitLower;
|
|
1575
1575
|
} else if (limitUpper && cartNum && cartNum > limitUpper) {
|
|
1576
1576
|
cartNum = limitUpper;
|
|
1577
1577
|
}
|
|
1578
1578
|
if (skuUuid && cartNum > 0) {
|
|
1579
1579
|
return this.bMallChangeCartService({
|
|
1580
1580
|
...goodItem,
|
|
1581
1581
|
skuUuid,
|
|
1582
1582
|
num: cartNum,
|
|
1583
1583
|
});
|
|
1584
1584
|
} else if (!skuUuid && cartNum > 0) {
|
|
1585
1585
|
return this.bMallAddCartService({ ...goodItem, num: cartNum });
|
|
1586
1586
|
} else if (skuUuid && !cartNum) {
|
|
1587
1587
|
return this.bMallRemoveCartService({
|
|
1588
1588
|
...goodItem,
|
|
1589
1589
|
skuUuid,
|
|
1590
1590
|
num: cartNum,
|
|
1591
1591
|
});
|
|
1592
1592
|
} else {
|
|
1593
1593
|
console.error('参数不全');
|
|
1594
1594
|
return false;
|
|
1595
1595
|
}
|
|
1596
1596
|
} catch (e) {
|
|
1597
1597
|
console.error(e);
|
|
1598
1598
|
}
|
|
1599
1599
|
}
|