repayDetailActions.js
4.81 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
'use strict';
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
import * as _ from 'lodash';
const {
SET_PLATFORM,
SET_REPAY_ORDER_NO,
SET_TIP_MESSAGE,
SET_ERROR,
QUERY_REPAY_RECORD_LIST_REQUEST,
QUERY_REPAY_RECORD_LIST_FAILURE,
QUERY_REPAY_RECORD_LIST_SUCCESS,
} = require('../../constants/actionTypes').default;
export function setRepayOrderNo(repayOrderNo){
return {
type: SET_REPAY_ORDER_NO,
payload: repayOrderNo,
}
}
export function setTipMessage(message){
return {
type: SET_TIP_MESSAGE,
payload: message,
}
}
export function setError(error) {
return {
type: SET_ERROR,
payload: error,
}
}
export function queryRepayRecordListRequest(){
return {
type: QUERY_REPAY_RECORD_LIST_REQUEST,
}
}
export function queryRepayRecordListFailure(error){
return {
type: QUERY_REPAY_RECORD_LIST_FAILURE,
payload: error,
}
}
export function queryRepayRecordListSuccess(object){
return {
type: QUERY_REPAY_RECORD_LIST_SUCCESS,
payload: object,
}
}
// 处理还款记录数据
const _processRepayList = (list) => {
if (list !== 'NULL') {
_.forEach(list.rePayList, (data) => {
if (data.status === 1) {
data.repayStatus = '已还清';
data.txt = '还款成功!';
data.isTwo = true;
data.isThree = true;
delete data.desc;
} else if (data.status === 2) {
data.repayStatus = '还款失败';
data.txt = '还款失败';
if (data.desc || data.desc !== '') {
data.txt += `,${data.desc}`;
}
data.isTwo = true;
data.isThree = true;
} else {
data.repayStatus = '还款中';
data.txt = '预计1-2分钟内还款成功,<br>请到还款记录查看还款结果';
delete data.desc;
}
data.url = `/home/installment/repay/detail?id=${data.prePayNo}`;
});
return list.rePayList;
} else {
return false;
}
};
//还款详情
export function getRepayList() {
return (dispatch, getState) => {
let {app, repayDetail} = getState();
let currentPage = 1;
let queryRepayList = (uid) => {
let {repayOrderNo} = repayDetail;
let params = {
uid,
rePayNo: repayOrderNo,
pageNo: currentPage,
};
dispatch(queryRepayRecordListRequest());
return new InstallmentService(app.host).getQueryRePayList(params)
.then(json => {
let detailInfoList = _processRepayList(json);
dispatch(queryRepayRecordListSuccess({detailInfoList,currentPage}));
})
.catch(error => {
dispatch(setError(error));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
queryRepayList(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
queryRepayList(uid);
})
.catch(error => {
});
});
};
}
//还款记录
export function getRepayRecordList() {
return (dispatch, getState) => {
let {app, repayDetail} = getState();
let {currentPage,repayList,pageTotal} = repayDetail;
currentPage++;
if (pageTotal > 0 && currentPage > pageTotal) {
return;
}
repayList = repayList.toJS();
let queryRepayRecordList = (uid) => {
let {repayOrderNo} = repayDetail;
let params = {
uid,
pageNo: currentPage,
};
return new InstallmentService(app.host).getQueryRePayList(params)
.then(json => {
let detailInfoList = _processRepayList(json);
let pageTotal = json.pageTotal;
if (detailInfoList && detailInfoList.length > 0) {
detailInfoList = [...repayList, ...detailInfoList];
dispatch(queryRepayRecordListSuccess({detailInfoList,currentPage,pageTotal}));
}
})
.catch(error => {
dispatch(setError(error));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
queryRepayRecordList(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
queryRepayRecordList(uid);
})
.catch(error => {
});
});
};
}
export function gotoRepayRecordDetail(recordInfo) {
return (dispatch, getState) => {
ReactNative.NativeModules.YH_InstallmentHelper.gotoRepayDetailPage(recordInfo.repayOrderCode,false);
};
}