cardAddActions.js
4.49 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
'use strict';
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
const {
SET_ERROR,
SHOW_BANK_INFO,
SHOW_RESULT_INFO,
RESET_CARD_ADD_INFO,
} = require('../../constants/actionTypes').default;
export function getBankInfo(cardNo) {
return (dispatch, getState) => {
let bankInfo = (uid) => {
let {app} = getState();
let info = {
bankCode: '',
bankName: '',
cardNO: '',
bankSupport: false,
showBankInfo: false,
};
return new InstallmentService(app.host).fentchBankInfo(cardNo,uid)
.then(json => {
if (json.businessSupport == '0' && json.bankCode && json.bankCode != '') {
info.bankCode = json.bankCode;
info.bankName = json.bankName;
info.cardNO = json.cardNO;
info.bankSupport = true;
info.showBankInfo = true;
}else {
info.bankCode = '';
info.bankName = '';
info.bankSupport = false;
info.showBankInfo = true;
}
dispatch(showBankInfo(info));
})
.catch(error => {
info.bankCode = '';
info.bankName = '';
info.bankSupport = false;
info.showBankInfo = true;
dispatch(showBankInfo(info));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
bankInfo(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
bankInfo(uid);
})
.catch(error => {
});
});
}
}
export function showBankInfo(info) {
return {
type: SHOW_BANK_INFO,
payload: info,
}
}
export function bindingCard(cardNo, mobile, bankName, bankCode) {
return (dispatch, getState) => {
let bindCards = (uid) => {
let {app} = getState();
let result = {
showResult: false,
result: '',
message: '',
description: '',
buttonText: '',
};
return new InstallmentService(app.host).bindingCards(uid, cardNo, mobile, bankName, bankCode)
.then(json => {
result.showResult = true;
result.result = 'success';
result.message = '恭喜您,新增还款银行卡成功!';
result.description = '';
result.buttonText = '确认';
dispatch(showResultInfo(result));
})
.catch(error => {
result.showResult = true;
result.result = 'fail';
result.message = '对不起,绑定银行卡失败!';
result.description = '失败的原因可能是:银行卡户名、银行卡、预留的手机号不一致';
result.buttonText = '重新绑定银行卡';
dispatch(showResultInfo(result));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
bindCards(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
bindCards(uid);
})
.catch(error => {
});
});
}
}
export function showResultInfo(result) {
return {
type: SHOW_RESULT_INFO,
payload: result,
}
}
export function backToMyCardList() {
return (dispatch, getState) => {
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.instalmentMyCard","params":{}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
}
export function backToMyCardAdd() {
return (dispatch, getState) => {
let reset = {
bankCode: '',
bankName: '',
cardNO: '',
bankSupport: false,
showBankInfo: false,
showResult: false,
result: '',
message: '',
description: '',
buttonText: '',
};
dispatch(resetStateInfo(reset));
}
}
export function resetStateInfo(state) {
return {
type: RESET_CARD_ADD_INFO,
payload: state,
}
}