orderDetailActions.js
14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
'use strict';
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
import * as _ from 'lodash';
const {
SET_TIP_MESSAGE,
SET_ERROR,
SET_ORDER_CODE,
GET_ORDER_DETAIL_REQUEST,
GET_ORDER_DETAIL_FAILURE,
GET_ORDER_DETAIL_SUCCESS,
SET_BANK_SAFE_PAY_VIEW_STATUS,
SET_CHANGE_BANK_CARD_VIEW_STATUS,
SET_PAY_CARD,
SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
UPDATE_ORDER_INFO_AND_FORMATE_DATA,
SET_BANK_CARDS_LIST_AND_PAY_CARD,
UPDATE_REPAY_TERM_LIST,
UPDATE_PREPAY_SUCCESS_PARAM,
} = require('../../constants/actionTypes').default;
export function setOrderCode(orderCode){
return {
type: SET_ORDER_CODE,
payload: orderCode,
}
}
export function getOrderDetailRequest(){
return {
type: GET_ORDER_DETAIL_REQUEST,
}
}
export function getOrderDetailFailure(error){
return {
type: GET_ORDER_DETAIL_FAILURE,
payload: error,
}
}
export function getOrderDetailSuccess(json){
return {
type: GET_ORDER_DETAIL_SUCCESS,
payload: json,
}
}
export function getOrderDetail() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let orderCode = myOrderDetail.get('orderCode');
let queryOrderDetail = (uid) => {
return new InstallmentService(app.host).getInstallmentOrderDetail(uid, orderCode)
.then(json => {
//处理一下订单状态,处理逻辑是根据还款列表最后一条记录来作为整个订单的状态
if(json && json.package_list){
let package_list = json.package_list;
let last_package = package_list[package_list.length - 1];
let status = last_package.status;
json.status = status;
}
dispatch(getOrderDetailSuccess(json));
})
.catch(error => {
dispatch(setError(error));
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
queryOrderDetail(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
queryOrderDetail(uid);
})
.catch(error => {
});
});
};
}
export function setError(error) {
return {
type: SET_ERROR,
payload: error,
}
}
export function setTipMessage(message){
return {
type: SET_TIP_MESSAGE,
payload: message,
}
}
export function setBankCardslistAndPayCard(list){
return {
type: SET_BANK_CARDS_LIST_AND_PAY_CARD,
payload: list,
}
}
function processBankCardsInfo(list) {
if (list && list.length > 0) {
_.forEach(list, (data) => {
let cardNo = data.cardNo;
data.outBankNameNumb = data.bankName +'(' + cardNo.substring(cardNo.length - 4) +')';
data.outMobile = data.mobile.substring(data.mobile.length - 6);
});
return list;
}
return [];
}
export function getBankCards() {
return (dispatch, getState) => {
let {app} = getState();
let queryBankCards = (uid) => {
return new InstallmentService(app.host).getBankCards(uid)
.then(json => {
let bankCardsInfo = processBankCardsInfo(json);
dispatch(setBankCardslistAndPayCard(bankCardsInfo));
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
queryBankCards(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
queryBankCards(uid);
})
.catch(error => {
});
});
};
}
//计算金额和费用
function amtAndFeeCount(list) {
let formateData = {
currAmtCount: 0,
currFeeCount: 0
};
let checkAbleCount = 0;
let checkedCount = 0
if (list) {
_.forEach(list, (data) => {
if (data.isChecked) {
checkedCount++;
formateData.currAmtCount = formateData.currAmtCount + parseFloat(data.curr_amt);
formateData.currFeeCount += formateData.currFeeCount + parseFloat(data.curr_fee_amt);
}
if(data.status == 1 || data.status == 3){
checkAbleCount++;
}
});
if (checkedCount == checkAbleCount) {
formateData.isAllChecked = true;
}else{
formateData.isAllChecked = false;
}
if (formateData.currFeeCount > 0) {
formateData.isCurrFee = true;
} else {
formateData.isCurrFee = false;
}
return formateData;
}else {
return null;
}
}
// onPressRepaylistCell
export function onPressCheckboxCell(curIndex) {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {orderInfo} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
let formateData;
let tipMessage = '';
curIndex = parseInt(curIndex);
if (curIndex == 0) {
if (package_list[curIndex+1].isChecked) {
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}else if (curIndex == package_list.length - 1) {
if (!package_list[curIndex-1].isChecked && (package_list[curIndex-1].status == 1 || package_list[curIndex-1].status == 3)) {
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}else {
let preCell = package_list[curIndex - 1];
let nextCell = package_list[curIndex + 1];
//上一个应付款未选中或者下一个已选中
if(((preCell.status == 1 || preCell.status == 3) && !preCell.isChecked) || (nextCell && nextCell.isChecked)){
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}
};
}
export function onPressCheckboxAll() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {orderInfo,formateData} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
formateData = formateData.toJS();
formateData.isAllChecked = !formateData.isAllChecked;
_.forEach(package_list, (data) => {
data.isChecked = formateData.isAllChecked;
});
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
};
}
export function updatOrderInfoAndFormateData(object){
return {
type: UPDATE_ORDER_INFO_AND_FORMATE_DATA,
payload: object,
}
}
export function setBankSafePayViewStatus(status){
return {
type: SET_BANK_SAFE_PAY_VIEW_STATUS,
payload: status,
}
}
export function setChangeBankCardViewStatus(status){
return {
type: SET_CHANGE_BANK_CARD_VIEW_STATUS,
payload: status,
}
}
export function setShowConfirmPayViewStatus(status) {
return {
type: SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
payload: status,
}
}
// onPressPayNow
export function onPressPayNow() {
return (dispatch, getState) => {
dispatch(getBankCards());
dispatch(setBankSafePayViewStatus(true));
let {app, myOrderDetail} = getState();
let {orderInfo, formateData} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
let orderCode = orderInfo.get("order_code");
formateData = formateData.toJS();
let termsList = [];
_.forEach(package_list, (data) => {
if (data.isChecked) {
termsList.push({
index: data.sort_id,
orderCode: orderCode,
termNo: data.sort_id
});
}
});
dispatch(updateRepayTermList(termsList));
}
}
export function confirmChangeBankCard(cardInfo) {
return (dispatch, getState) => {
dispatch(setChangeBankCardViewStatus(false));
dispatch(setPayCard(cardInfo));
}
}
export function setPayCard(cardInfo){
return {
type: SET_PAY_CARD,
payload: cardInfo,
}
}
export function goAddNewBankCard(){
return (dispatch, getState) => {
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.instalmentMyCardAdd","params":{}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
}
export function bankSafePayNow() {
return (dispatch, getState) => {
let bankSafePayNowAction = (uid) => {
let {app, myOrderDetail} = getState();
let {formateData,repayTermList,payCard} = myOrderDetail;
formateData = formateData.toJS();
repayTermList = repayTermList.toJS();
payCard = payCard.toJS();
let params = {
uid,
repay_amount: formateData.currAmtCount,
repayTermList:JSON.stringify(repayTermList),
bankcard_IdNo: payCard.cardIdNo,
terminal_type: 'mobile',
user_ip: '',
terminal_info: '',
card_id: payCard.cardIdNo,
}
return new InstallmentService(app.host).getPrerePay(params)
.then(json => {
if (json && json.isRepaySuccess == 'Y') {
dispatch(updatePrepaySuccessParam(json));
} else {
let tipMessage = json.message || '暂未获取到数据';
dispatch(setTipMessage(tipMessage));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
bankSafePayNowAction(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
bankSafePayNowAction(uid);
})
.catch(error => {
});
});
};
}
export function updatePrepaySuccessParam(param) {
return {
type: UPDATE_PREPAY_SUCCESS_PARAM,
payload: param,
}
}
export function updateRepayTermList(list) {
return {
type: UPDATE_REPAY_TERM_LIST,
payload: list,
}
}
//
export function reSendConfirmPaySnsCode() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let resendSnsCode = (uid) => {
let {prePaySuccessParam} = myOrderDetail;
prePaySuccessParam = prePaySuccessParam.toJS();
let params = {
uid,
orderNo: prePaySuccessParam.crfRepayOrderNo,
prepayNo: prePaySuccessParam.repayOrderCode,
}
return new InstallmentService(app.host).reSendConfirmPaySnsCode(params)
.then(json => {
if (json && json.code && json.code !== 200) {
let tipMessage = json.message || '暂未获取到数据';
dispatch(setTipMessage(tipMessage));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
resendSnsCode(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
resendSnsCode(uid);
})
.catch(error => {
});
});
};
}
//
export function confirmPayAction(snsCode) {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {payCard,repayTermList,formateData,prePaySuccessParam} = myOrderDetail;
payCard = payCard.toJS();
repayTermList = repayTermList.toJS();
formateData = formateData.toJS();
prePaySuccessParam = prePaySuccessParam.toJS();
let params = prePaySuccessParam;
delete params.isRepaySuccess;
params.phoneNumber = payCard.mobile;
params.smsCode = snsCode;
params.repayTermList = JSON.stringify(repayTermList);
params.terminal_type = 'mobile';
return new InstallmentService(app.host).confirmRepay(params)
.then(json => {
if (json.isPaySuccess == 'Y') {
//刷新页面数据
dispatch(setShowConfirmPayViewStatus(false));
dispatch(setBankSafePayViewStatus(false));
dispatch(getOrderDetail());
}else {
dispatch(setTipMessage(json.message || '暂未获取到数据'));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
}