@conecli/cone-render 0.10.1-shop-beta.14 → 0.10.1-shop-beta.16

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
  isDynamic,
3
2
  isLanguageForEn,
4
3
  isJdApp,
5
4
  showSuccessToast,
6
5
  showFailToast,
7
6
  isPc,
8
7
  draInterfaceCustomReport,
9
8
  isAndroidDevice,
10
9
  draBusinessCustomReport,
11
10
  cookiesStr: '',
12
11
  requestHeaderContentType: {
13
12
  jsonHeader: {
14
13
  'content-type': 'application/json;charset=utf-8',
15
14
  },
16
15
  formDataHeader: {
17
16
  'content-type': 'application/x-www-form-urlencoded',
18
17
  },
19
18
  },
20
19
  requestBaseParam: {
21
20
  data: null,
22
21
  header: {
23
22
  'content-type': 'application/json;charset=utf-8',
24
23
  },
25
24
  },
26
25
  timeOut: 7000,
27
26
  apiClientParams: {
28
27
  appid: 'wx_mini_app',
29
28
  clientVersion: '11.0.0',
30
29
  client: 'wh5',
31
30
  area: '1_72_2799_0',
32
31
  uuid: '-1',
33
32
  loginType: '11',
34
33
  },
35
34
  public addressFetchInfo: {
36
35
  reqState: boolean;
37
36
  promiseInstance: null | Promise<any>;
38
37
  };
39
38
  public getPromotionConfig: {
40
39
  projectId: null | string | number;
41
40
  pageId: null | string | number;
42
41
  };
43
42
  public resInfo: ServiceInterFace.HttpRequestInfo;
44
43
  public api: ServiceInterFace.HttpApi;
45
44
  public isPageDomain: boolean;
46
45
  public verifyColorList: string[];
47
46
  constructor(opt) {
48
47
  this._init();
49
48
  this.addressFetchInfo = {
50
49
  reqState: false,
51
50
  promiseInstance: null,
52
51
  };
53
52
  this.getPromotionConfig = {
54
53
  projectId: null,
55
54
  pageId: null,
56
55
  };
57
56
  this._userAreaUpdateListen();
58
57
  this.resInfo = this._getResConfig(opt);
59
58
  this.api = api;
60
59
  this.isPageDomain = false;
61
60
  this.verifyColorList = [];
62
61
  }
63
62
 
64
63
  _init(): void {
65
64
  !isDynamic &&
66
65
  httpInterceptors.forEach((item) => {
67
66
  Taro.addInterceptor((chain) => item(chain));
68
67
  });
69
68
  }
70
69
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
71
70
  return Object.assign({}, DefaultConfig, opt);
72
71
  }
73
72
 
74
73
  _userAreaUpdateListen() {
75
74
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
76
75
  this.updateApiClientParamsResInfo(areaInfo);
77
76
  });
78
77
  }
79
78
  updateApiClientParamsResInfo(opt = {}) {
80
79
  const { area, realTimeArea, ...others } = opt;
81
80
  this.resInfo.apiClientParams = {
82
81
  ...this.resInfo.apiClientParams,
83
82
  ...others,
84
83
  };
85
84
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
86
85
  realTimeArea &&
87
86
  realTimeArea !== '' &&
88
87
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
89
88
  }
90
89
 
91
90
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
92
91
  if (functionId === 'receiveShopCoupon') {
93
92
  clientParams = Object.assign(
94
93
  {},
95
94
  {
96
95
  loginType: '1',
97
96
  loginWQBiz: WXAPP_BIZ_KEY,
98
97
  },
99
98
  clientParams,
100
99
  );
101
100
  }
102
101
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
103
102
  const getReqData = {
104
103
  functionId: functionId,
105
104
  body: JSON.stringify(bodyParams),
106
105
  t: Date.now(),
107
106
  ...apiClientParams,
108
107
  };
109
108
  return http
110
109
  .request({
111
110
  url: this.api.apiFunc,
112
111
  data: getReqData,
113
112
  isColorVerify: false,
114
113
  })
115
114
  .then((res: ServiceInterFace.RequestPromiseRes) => {
116
115
  const { statusCode, data, status, msg } = res;
117
116
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
118
117
  ok: true,
119
118
  };
120
119
  if ((statusCode === 200 || status === '0') && data) {
121
120
  changeRes = this.dealResponseFormatRes(data, getReqData);
122
121
  return changeRes;
123
122
  } else {
124
123
  draInterfaceCustomReport({
125
124
  ...getReqData,
126
125
  ...res,
127
126
  source: 'remote',
128
127
  });
129
128
  changeRes = {
130
129
  ...data,
131
130
  statusCode,
132
131
  status,
133
132
  msg,
134
133
  ok: false,
135
134
  };
136
135
  return changeRes;
137
136
  }
138
137
  })
139
138
  .catch((res) => {
140
139
  const propertyNames = Object.getOwnPropertyNames(res);
141
140
  const resObject = {};
142
141
  propertyNames.forEach((propertyName) => {
143
142
  resObject[propertyName] = res[propertyName];
144
143
  });
145
144
  draInterfaceCustomReport({
146
145
  ...getReqData,
147
146
  ...resObject,
148
147
  source: 'remote',
149
148
  });
150
149
  return {
151
150
  ...resObject,
152
151
  ok: false,
153
152
  } as ServiceInterFace.RequestResponseFormatRes;
154
153
  });
155
154
  }
156
155
 
157
156
  dealResponseFormatRes(data, reqData) {
158
157
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
159
158
  ok: true,
160
159
  };
161
160
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
162
161
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
163
162
  ? Number(data.subCode)
164
163
  : -1;
165
164
  if (
166
165
  data.success === true ||
167
166
  data.isSuccess ||
168
167
  resCode === 0 ||
169
168
  resCode === 200 ||
170
169
  subCode === 0
171
170
  ) {
172
171
  changeRes = {
173
172
  result: Object.prototype.hasOwnProperty.call(data, 'result')
174
173
  ? data.result
175
174
  : Object.prototype.hasOwnProperty.call(data, 'data')
176
175
  ? data.data
177
176
  : data,
178
177
  code: data.code ?? 200,
179
178
  ok: true,
180
179
  source: data,
181
180
  };
182
181
  return changeRes;
183
182
  } else {
184
183
  changeRes = {
185
184
  ...data,
186
185
  ok: false,
187
186
  };
188
187
  if (reqData && resCode !== 3) {
189
188
  draInterfaceCustomReport({
190
189
  ...reqData,
191
190
  ...data,
192
191
  source: 'remote',
193
192
  });
194
193
  }
195
194
  return changeRes;
196
195
  }
197
196
  }
198
197
 
199
198
  async receiveCoupon(param = {}, clientParams) {
200
199
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
201
200
  return await this.gatewayReq(
202
201
  'receiveShopCoupon',
203
202
  {
204
203
  operation: '3',
205
204
  ...param,
206
205
  },
207
206
  { ...clientParams },
208
207
  );
209
208
  }
210
209
 
211
210
  getCustomerCenterDispatch(params = {}) {
212
211
  return this.gatewayReq('customerCenterDispatch', params, {
213
212
  clientVersion: '9.2.0',
214
213
  client: 'H5',
215
214
  uuid: 88888,
216
215
  appid: 'shopmember_m_jd_com',
217
216
  });
218
217
  }
219
218
 
220
219
  batchAddCart(...args) {
221
220
  let skuIds, num, showToast, giftCard;
222
221
  if (['number', 'string'].includes(typeof args[0])) {
223
222
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
224
223
  } else if (typeof args[0] === 'object' && args[0] !== null) {
225
224
  const params = args[0];
226
225
  skuIds = params.skuIds;
227
226
  num = params.num || 1;
228
227
  showToast = params.showToast !== undefined ? params.showToast : true;
229
228
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
230
229
  } else {
231
230
  console.error('batchAddCart() Invalid arguments!', args);
232
231
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
233
232
  showFailToast({
234
233
  title: msg,
235
234
  });
236
235
  return Promise.resolve({
237
236
  ok: false,
238
237
  msg,
239
238
  });
240
239
  }
241
240
  const successMsg = giftCard
242
241
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
243
242
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
244
243
  const failMsg = giftCard
245
244
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
246
245
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
247
246
  if (skuIds) {
248
247
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
249
248
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
250
249
  if (res?.ok) {
251
250
  if (showToast && !res?.isOpenApp)
252
251
  showSuccessToast({
253
252
  title: successMsg,
254
253
  });
255
254
  } else {
256
255
  showToast &&
257
256
  showFailToast({
258
257
  title: res?.errMsg || failMsg,
259
258
  });
260
259
  }
261
260
  return Promise.resolve(res);
262
261
  })
263
262
  .catch((e) => {
264
263
  console.log('调用加购方法异常=======>', e);
265
264
  return Promise.resolve({
266
265
  ok: false,
267
266
  msg: failMsg,
268
267
  });
269
268
  });
270
269
  } else {
271
270
  return Promise.resolve({
272
271
  ok: false,
273
272
  msg: failMsg,
274
273
  });
275
274
  }
276
275
  }
277
276
 
278
277
  async giftCardAddCart(skuList, num) {
279
278
  const loginType = isPc ? { loginType: 3 } : {};
280
279
  return this.gatewayReq(
281
280
  'giftCardAddCart',
282
281
  {
283
282
  skuList,
284
283
  num: Number(num),
285
284
  },
286
285
  { ...loginType },
287
286
  );
288
287
  }
289
288
 
290
289
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
291
290
  return new Promise((resolve) => {
292
291
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
293
292
  if (productIdsArr.length > 0) {
294
293
  if (giftCard) {
295
294
  this.giftCardAddCart(productIdsArr, addCardNum)
296
295
  .then((res) => {
297
296
  if (res?.code === '0' && res?.result?.value) {
298
297
  resolve({
299
298
  ok: true,
300
299
  });
301
300
  } else {
302
301
  resolve({
303
302
  ok: false,
304
303
  msg: '加购失败,请稍后重试',
305
304
  });
306
305
  }
307
306
  })
308
307
  .catch((e) => {
309
308
  console.error('礼品卡加车失败: ', e);
310
309
  resolve({
311
310
  ok: false,
312
311
  msg: '加购失败,请稍后重试',
313
312
  });
314
313
  });
315
314
  } else if (isJdApp && isDynamic) {
316
315
  const productsAddCartList = productIdsArr.map((skuItem) => {
317
316
  const extFlag = {};
318
317
  return isAndroidDevice
319
318
  ? {
320
319
  sku: skuItem,
321
320
  num: addCardNum,
322
321
  extFlag,
323
322
  }
324
323
  : {
325
324
  productCode: skuItem,
326
325
  buyCount: addCardNum,
327
326
  extFlag,
328
327
  };
329
328
  });
330
329
  const addCartRouterParams = {
331
330
  url: isAndroidDevice ? `router://JDCartModule/addCartUniformWithUrl?wareList=${JSON.stringify(productsAddCartList)}&businessName=storeModel` : 'router://JDCartModule/batchAddService',
332
331
  params: isAndroidDevice ? {
333
332
  wareList: productsAddCartList,
334
333
  } : {
335
334
  sourceType: 'h5',
336
335
  sourceValue: '店铺批量加购',
337
336
  businessName: 'storeModel',
338
337
  isNewMode: '1',
339
338
  NotPassWebview: '1',
340
339
  products: productsAddCartList,
341
340
  }
342
341
  }
343
342
  Taro.JDRouter.callRouter({
344
343
  ...addCartRouterParams,
345
344
  success: (res) => {
346
345
  console.log('taro 动态化店铺批量加购成功结果', res);
347
346
  const { errno, errMsg, data } = res || {};
348
347
  const isOk = isAndroidDevice ? errno === 0 : errno === 0 && data?.code === 0
349
348
  if (isOk) {
350
349
  resolve({
351
350
  ok: true,
352
351
  msg: '已加入购物车!',
353
352
  });
354
353
  } else {
355
354
  resolve({
356
355
  ok: false,
357
356
  msg: '批量加车失败,请稍后重试',
358
357
  errMsg: data?.message || errMsg || "",
359
358
  });
360
359
  const reportData = {
361
360
  type: 'batchAddCart',
362
361
  subType: 'addCartFailByTaroDynamicCallIosNative',
363
362
  errMsg: 'taro 动态化 调用原生加车失败',
364
363
  platform: global.info?.sysInfo?.platform,
365
364
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
366
365
  };
367
366
  draBusinessCustomReport(reportData);
368
367
  }
369
368
  },
370
369
  fail: (res) => {
371
370
  const data = {
372
371
  type: 'batchAddCart',
373
372
  subType: 'addCartFailByTaroDynamicCallIosNative',
374
373
  errMsg: 'taro 动态化 调用原生加车失败',
375
374
  platform: global.info?.sysInfo?.platform,
376
375
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
377
376
  };
378
377
  draBusinessCustomReport(data);
379
378
  },
380
379
  });
381
380
  }
382
381
  } else {
383
382
  resolve({
384
383
  ok: false,
385
384
  msg: '加购sku不能为空',
386
385
  });
387
386
  }
388
387
  });
389
388
  }
390
389
 
391
390
  productAddToCart() {
392
391
  return Promise.resolve({
393
392
  ok: false,
394
393
  msg: 'productAddToCart暂不支持小程序',
395
394
  });
396
395
  }
396
+ import Taro from '@tarojs/taro';
397
397
  isDynamic,
398
398
  isLanguageForEn,
399
399
  isJdApp,
400
400
  showSuccessToast,
401
401
  showFailToast,
402
402
  isPc,
403
403
  draInterfaceCustomReport,
404
404
  isAndroidDevice,
405
405
  draBusinessCustomReport,
406
406
  cookiesStr: '',
407
407
  requestHeaderContentType: {
408
408
  jsonHeader: {
409
409
  'content-type': 'application/json;charset=utf-8',
410
410
  },
411
411
  formDataHeader: {
412
412
  'content-type': 'application/x-www-form-urlencoded',
413
413
  },
414
414
  },
415
415
  requestBaseParam: {
416
416
  data: null,
417
417
  header: {
418
418
  'content-type': 'application/json;charset=utf-8',
419
419
  },
420
420
  },
421
421
  timeOut: 7000,
422
422
  apiClientParams: {
423
423
  appid: 'wx_mini_app',
424
424
  clientVersion: '11.0.0',
425
425
  client: 'wh5',
426
426
  area: '1_72_2799_0',
427
427
  uuid: '-1',
428
428
  loginType: '11',
429
429
  },
430
430
  public addressFetchInfo: {
431
431
  reqState: boolean;
432
432
  promiseInstance: null | Promise<any>;
433
433
  };
434
434
  public getPromotionConfig: {
435
435
  projectId: null | string | number;
436
436
  pageId: null | string | number;
437
437
  };
438
438
  public resInfo: ServiceInterFace.HttpRequestInfo;
439
439
  public api: ServiceInterFace.HttpApi;
440
440
  public isPageDomain: boolean;
441
441
  public verifyColorList: string[];
442
442
  constructor(opt) {
443
443
  this._init();
444
444
  this.addressFetchInfo = {
445
445
  reqState: false,
446
446
  promiseInstance: null,
447
447
  };
448
448
  this.getPromotionConfig = {
449
449
  projectId: null,
450
450
  pageId: null,
451
451
  };
452
452
  this._userAreaUpdateListen();
453
453
  this.resInfo = this._getResConfig(opt);
454
454
  this.api = api;
455
455
  this.isPageDomain = false;
456
456
  this.verifyColorList = [];
457
457
  }
458
458
 
459
459
  _init(): void {
460
460
  !isDynamic &&
461
461
  httpInterceptors.forEach((item) => {
462
462
  Taro.addInterceptor((chain) => item(chain));
463
463
  });
464
464
  }
465
465
  _getResConfig(opt = {}): ServiceInterFace.HttpRequestInfo {
466
466
  return Object.assign({}, DefaultConfig, opt);
467
467
  }
468
468
 
469
469
  _userAreaUpdateListen() {
470
470
  Taro.eventCenter.on(TaroEventType.USER_AREA_UPDATE, (areaInfo) => {
471
471
  this.updateApiClientParamsResInfo(areaInfo);
472
472
  });
473
473
  }
474
474
  updateApiClientParamsResInfo(opt = {}) {
475
475
  const { area, realTimeArea, ...others } = opt;
476
476
  this.resInfo.apiClientParams = {
477
477
  ...this.resInfo.apiClientParams,
478
478
  ...others,
479
479
  };
480
480
  area && area !== '' && (this.resInfo.apiClientParams.area = area);
481
481
  realTimeArea &&
482
482
  realTimeArea !== '' &&
483
483
  (this.resInfo.apiClientParams.realTimeArea = realTimeArea);
484
484
  }
485
485
 
486
486
  gatewayReq(functionId: string, bodyParams = {}, clientParams = {}): Promise<any> {
487
487
  if (functionId === 'receiveShopCoupon') {
488
488
  clientParams = Object.assign(
489
489
  {},
490
490
  {
491
491
  loginType: '1',
492
492
  loginWQBiz: WXAPP_BIZ_KEY,
493
493
  },
494
494
  clientParams,
495
495
  );
496
496
  }
497
497
  const apiClientParams = Object.assign({}, this.resInfo.apiClientParams, clientParams);
498
498
  const getReqData = {
499
499
  functionId: functionId,
500
500
  body: JSON.stringify(bodyParams),
501
501
  t: Date.now(),
502
502
  ...apiClientParams,
503
503
  };
504
504
  return http
505
505
  .request({
506
506
  url: this.api.apiFunc,
507
507
  data: getReqData,
508
508
  isColorVerify: false,
509
509
  })
510
510
  .then((res: ServiceInterFace.RequestPromiseRes) => {
511
511
  const { statusCode, data, status, msg } = res;
512
512
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
513
513
  ok: true,
514
514
  };
515
515
  if ((statusCode === 200 || status === '0') && data) {
516
516
  changeRes = this.dealResponseFormatRes(data, getReqData);
517
517
  return changeRes;
518
518
  } else {
519
519
  draInterfaceCustomReport({
520
520
  ...getReqData,
521
521
  ...res,
522
522
  source: 'remote',
523
523
  });
524
524
  changeRes = {
525
525
  ...data,
526
526
  statusCode,
527
527
  status,
528
528
  msg,
529
529
  ok: false,
530
530
  };
531
531
  return changeRes;
532
532
  }
533
533
  })
534
534
  .catch((res) => {
535
535
  const propertyNames = Object.getOwnPropertyNames(res);
536
536
  const resObject = {};
537
537
  propertyNames.forEach((propertyName) => {
538
538
  resObject[propertyName] = res[propertyName];
539
539
  });
540
540
  draInterfaceCustomReport({
541
541
  ...getReqData,
542
542
  ...resObject,
543
543
  source: 'remote',
544
544
  });
545
545
  return {
546
546
  ...resObject,
547
547
  ok: false,
548
548
  } as ServiceInterFace.RequestResponseFormatRes;
549
549
  });
550
550
  }
551
551
 
552
552
  dealResponseFormatRes(data, reqData) {
553
553
  let changeRes: ServiceInterFace.RequestResponseFormatRes = {
554
554
  ok: true,
555
555
  };
556
556
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code') ? Number(data.code) : -1;
557
557
  const subCode = Object.prototype.hasOwnProperty.call(data, 'subCode')
558
558
  ? Number(data.subCode)
559
559
  : -1;
560
560
  if (
561
561
  data.success === true ||
562
562
  data.isSuccess ||
563
563
  resCode === 0 ||
564
564
  resCode === 200 ||
565
565
  subCode === 0
566
566
  ) {
567
567
  changeRes = {
568
568
  result: Object.prototype.hasOwnProperty.call(data, 'result')
569
569
  ? data.result
570
570
  : Object.prototype.hasOwnProperty.call(data, 'data')
571
571
  ? data.data
572
572
  : data,
573
573
  code: data.code ?? 200,
574
574
  ok: true,
575
575
  source: data,
576
576
  };
577
577
  return changeRes;
578
578
  } else {
579
579
  changeRes = {
580
580
  ...data,
581
581
  ok: false,
582
582
  };
583
583
  if (reqData && resCode !== 3) {
584
584
  draInterfaceCustomReport({
585
585
  ...reqData,
586
586
  ...data,
587
587
  source: 'remote',
588
588
  });
589
589
  }
590
590
  return changeRes;
591
591
  }
592
592
  }
593
593
 
594
594
  async receiveCoupon(param = {}, clientParams) {
595
595
  console.warn('receiveCoupon 方法在微信京购小程序环境未经验证,请不要使用!');
596
596
  return await this.gatewayReq(
597
597
  'receiveShopCoupon',
598
598
  {
599
599
  operation: '3',
600
600
  ...param,
601
601
  },
602
602
  { ...clientParams },
603
603
  );
604
604
  }
605
605
 
606
606
  getCustomerCenterDispatch(params = {}) {
607
607
  return this.gatewayReq('customerCenterDispatch', params, {
608
608
  clientVersion: '9.2.0',
609
609
  client: 'H5',
610
610
  uuid: 88888,
611
611
  appid: 'shopmember_m_jd_com',
612
612
  });
613
613
  }
614
614
 
615
615
  batchAddCart(...args) {
616
616
  let skuIds, num, showToast, giftCard;
617
617
  if (['number', 'string'].includes(typeof args[0])) {
618
618
  [skuIds, num = 1, showToast = true, giftCard = false] = args;
619
619
  } else if (typeof args[0] === 'object' && args[0] !== null) {
620
620
  const params = args[0];
621
621
  skuIds = params.skuIds;
622
622
  num = params.num || 1;
623
623
  showToast = params.showToast !== undefined ? params.showToast : true;
624
624
  giftCard = params.giftCard !== undefined ? params.giftCard : false;
625
625
  } else {
626
626
  console.error('batchAddCart() Invalid arguments!', args);
627
627
  const msg = isLanguageForEn ? 'Please retry later' : '加入购物车失败,请稍后重试!';
628
628
  showFailToast({
629
629
  title: msg,
630
630
  });
631
631
  return Promise.resolve({
632
632
  ok: false,
633
633
  msg,
634
634
  });
635
635
  }
636
636
  const successMsg = giftCard
637
637
  ? global?.languageJsonData?.successAddShopList || '加入购物清单成功'
638
638
  : global?.languageJsonData?.successAddCart || '加入购物车成功';
639
639
  const failMsg = giftCard
640
640
  ? global?.languageJsonData?.failAddShopList || '加入购物清单失败,请稍后重试'
641
641
  : global?.languageJsonData?.failAddCart || '加入购物车失败,请稍后重试';
642
642
  if (skuIds) {
643
643
  return this._addShopGoodCart(`${skuIds}`, `${num}`, { giftCard })
644
644
  .then((res: ServiceInterFace.SkuToCartDataRes) => {
645
645
  if (res?.ok) {
646
646
  if (showToast && !res?.isOpenApp)
647
647
  showSuccessToast({
648
648
  title: successMsg,
649
649
  });
650
650
  } else {
651
651
  showToast &&
652
652
  showFailToast({
653
653
  title: res?.errMsg || failMsg,
654
654
  });
655
655
  }
656
656
  return Promise.resolve(res);
657
657
  })
658
658
  .catch((e) => {
659
659
  console.log('调用加购方法异常=======>', e);
660
660
  return Promise.resolve({
661
661
  ok: false,
662
662
  msg: failMsg,
663
663
  });
664
664
  });
665
665
  } else {
666
666
  return Promise.resolve({
667
667
  ok: false,
668
668
  msg: failMsg,
669
669
  });
670
670
  }
671
671
  }
672
672
 
673
673
  async giftCardAddCart(skuList, num) {
674
674
  const loginType = isPc ? { loginType: 3 } : {};
675
675
  return this.gatewayReq(
676
676
  'giftCardAddCart',
677
677
  {
678
678
  skuList,
679
679
  num: Number(num),
680
680
  },
681
681
  { ...loginType },
682
682
  );
683
683
  }
684
684
 
685
685
  _addShopGoodCart(skuIdsStr, addCardNum = '1', { giftCard }) {
686
686
  return new Promise((resolve) => {
687
687
  const productIdsArr = skuIdsStr ? `${skuIdsStr}`.split(',') : [];
688
688
  if (productIdsArr.length > 0) {
689
689
  if (giftCard) {
690
690
  this.giftCardAddCart(productIdsArr, addCardNum)
691
691
  .then((res) => {
692
692
  if (res?.code === '0' && res?.result?.value) {
693
693
  resolve({
694
694
  ok: true,
695
695
  });
696
696
  } else {
697
697
  resolve({
698
698
  ok: false,
699
699
  msg: '加购失败,请稍后重试',
700
700
  });
701
701
  }
702
702
  })
703
703
  .catch((e) => {
704
704
  console.error('礼品卡加车失败: ', e);
705
705
  resolve({
706
706
  ok: false,
707
707
  msg: '加购失败,请稍后重试',
708
708
  });
709
709
  });
710
710
  } else if (isJdApp && isDynamic) {
711
711
  const productsAddCartList = productIdsArr.map((skuItem) => {
712
712
  const extFlag = {};
713
713
  return isAndroidDevice
714
714
  ? {
715
715
  sku: skuItem,
716
716
  num: addCardNum,
717
717
  extFlag,
718
718
  }
719
719
  : {
720
720
  productCode: skuItem,
721
721
  buyCount: addCardNum,
722
722
  extFlag,
723
723
  };
724
724
  });
725
725
  const addCartRouterParams = {
726
726
  url: isAndroidDevice ? `router://JDCartModule/addCartUniformWithUrl?wareList=${JSON.stringify(productsAddCartList)}&businessName=storeModel` : 'router://JDCartModule/batchAddService',
727
727
  params: isAndroidDevice ? {
728
728
  wareList: productsAddCartList,
729
729
  } : {
730
730
  sourceType: 'h5',
731
731
  sourceValue: '店铺批量加购',
732
732
  businessName: 'storeModel',
733
733
  isNewMode: '1',
734
734
  NotPassWebview: '1',
735
735
  products: productsAddCartList,
736
736
  }
737
737
  }
738
738
  Taro.JDRouter.callRouter({
739
739
  ...addCartRouterParams,
740
740
  success: (res) => {
741
741
  console.log('taro 动态化店铺批量加购成功结果', res);
742
742
  const { errno, errMsg, data } = res || {};
743
743
  const isOk = isAndroidDevice ? errno === 0 : errno === 0 && data?.code === 0
744
744
  if (isOk) {
745
745
  Taro.eventCenter.trigger(TaroEventType.UPDATE_CART,data?.response || data || res)
746
746
  resolve({
747
747
  ok: true,
748
748
  msg: '已加入购物车!',
749
749
  });
750
750
  } else {
751
751
  resolve({
752
752
  ok: false,
753
753
  msg: '批量加车失败,请稍后重试',
754
754
  errMsg: data?.message || errMsg || "",
755
755
  });
756
756
  const reportData = {
757
757
  type: 'batchAddCart',
758
758
  subType: 'addCartFailByTaroDynamicCallIosNative',
759
759
  errMsg: 'taro 动态化 调用原生加车失败',
760
760
  platform: global.info?.sysInfo?.platform,
761
761
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
762
762
  };
763
763
  draBusinessCustomReport(reportData);
764
764
  }
765
765
  },
766
766
  fail: (res) => {
767
767
  const data = {
768
768
  type: 'batchAddCart',
769
769
  subType: 'addCartFailByTaroDynamicCallIosNative',
770
770
  errMsg: 'taro 动态化 调用原生加车失败',
771
771
  platform: global.info?.sysInfo?.platform,
772
772
  originData: typeof res === 'object' ? JSON.stringify(res) : res,
773
773
  };
774
774
  draBusinessCustomReport(data);
775
775
  },
776
776
  });
777
777
  }
778
778
  } else {
779
779
  resolve({
780
780
  ok: false,
781
781
  msg: '加购sku不能为空',
782
782
  });
783
783
  }
784
784
  });
785
785
  }
786
786
 
787
787
  productAddToCart() {
788
788
  return Promise.resolve({
789
789
  ok: false,
790
790
  msg: 'productAddToCart暂不支持小程序',
791
791
  });
792
792
  }