@conecli/cone-render 0.10.1-shop-beta.64 → 0.10.1-shop-beta.66

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