installmentActions.js
9.53 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
'use strict';
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
const {
SET_PLATFORM,
INSTALLMENT_PRODUCT_REQUEST,
INSTALLMENT_PRODUCT_SUCCESS,
INSTALLMENT_PRODUCT_FAILURE,
GET_INSTALLMENT_STATUS_REQUEST,
GET_INSTALLMENT_STATUS_SUCCESS,
GET_INSTALLMENT_STATUS_FAILURE,
UPDATE_SHOW_BANK_ALERT_STATUS,
UPDATE_AGREE_PROTOCOL_STATUS,
UPDATE_SNS_CHECK_CODE_ENABLE_STATUS,
UPDATE_CELL_LIST,
UPDATE_NEXT_BTN_ENABLE_STATUS,
UPDATE_NEXT_BTN_TEXT,
UPDATE_SNS_CHECK_CODE_TEXT,
} = require('../../constants/actionTypes').default;
const codeContent = {
openN: '0876085ff46bed27f1a1eb6ee8b68987',
openY: 'c233ad4ca91fef45ed7d0b26d9953e61',
advertisement: 'f3fe0793a7d59479542a14b15359c47d'
};
var Timer = function() {
this.counter = 0;
this.countdownTimer = null;
};
export function productListForInstallmentRequest(){
return {
type: INSTALLMENT_PRODUCT_REQUEST,
}
}
export function productListForInstallmentSuccess(json){
return {
type: INSTALLMENT_PRODUCT_SUCCESS,
payload:json,
}
}
export function productListForInstallmentFailure(){
return {
type: INSTALLMENT_PRODUCT_FAILURE,
}
}
export function featchInstallmentStatusRequest() {
return {
type: GET_INSTALLMENT_STATUS_REQUEST,
}
}
export function featchInstallmentStatusSuccess(status) {
return {
type: GET_INSTALLMENT_STATUS_SUCCESS,
payload: status
}
}
export function featchInstallmentStatusFailure(error) {
return {
type: GET_INSTALLMENT_STATUS_FAILURE,
payload: error
}
}
export function updateShowBankAlertStatus(status) {
return {
type: UPDATE_SHOW_BANK_ALERT_STATUS,
payload: status
}
}
export function updateAgreeProtocolStatus(status) {
return {
type: UPDATE_AGREE_PROTOCOL_STATUS,
payload: status
}
}
export function updateSnsCheckCodeEnableStatus(status) {
return {
type: UPDATE_SNS_CHECK_CODE_ENABLE_STATUS,
payload: status
}
}
export function updateCellList(cellList) {
return {
type: UPDATE_CELL_LIST,
payload: cellList
}
}
export function updateNextBtnEnableStatus(status) {
return {
type: UPDATE_NEXT_BTN_ENABLE_STATUS,
payload: status
}
}
export function updateNextBtnText(text) {
return {
type: UPDATE_NEXT_BTN_TEXT,
payload: text
}
}
export function updateSnsCheckCodeText(text) {
return {
type: UPDATE_SNS_CHECK_CODE_TEXT,
payload: text
}
}
export function productListForInstallment() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {isFetching,open,installmentStatus} = installment;
if(isFetching){
return
}
dispatch(productListForInstallmentRequest());
return new InstallmentService(app.host).fetchInstallmentProductList()
.then(json => {
let payload = json;//product_list
if (payload.page > 1) {
let oldList = open.fetchInstallmentProductList.list.toJS();
let list = [...oldList, ...payload.list];
payload.product_list = list;
}
dispatch(productListForInstallmentSuccess(payload));
})
.catch(error => {
dispatch(productListForInstallmentFailure());
});
}
}
export function onPressOpenInstallment() {
return (dispatch, getState) => {
ReactNative.NativeModules.YH_InstallmentHelper.goToOpenInstallment();
}
}
export function onPressMoreProducts() {
return (dispatch, getState) => {
//跳转原生筛选
let getToInstallFilter = (uid) => {
let url = `://m.yohobuy.com/home/installment/index?uid=${uid}?openby:yohobuy={"action":"go.instalmentlist","params":{"title":"分期专享"}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
getToInstallFilter(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
getToInstallFilter(uid);
})
.catch(error => {
});
});
}
}
export function getInstallmentStatus() {
return (dispatch, getState) => {
let installmentStatus = (uid) => {
let {app, installment} = getState();
dispatch(featchInstallmentStatusRequest());
return new InstallmentService(app.host).getStauts(uid)
.then(json => {
let status = 0;
if (json.status) {
status = json.status;
}
dispatch(productListForInstallment());
})
.catch(error => {
dispatch(featchInstallmentStatusFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
installmentStatus(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
installmentStatus(uid);
})
.catch(error => {
});
});
}
}
export function onPressProtocol() {
return (dispatch, getState) => {
//跳转原生静态页面
let url = `://m.yohobuy.com/home/installment/agreement?openby:yohobuy={"action":"go.h5","params":{"url":"http://m.yohobuy.com/home/installment/agreement"}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
};
}
export function onPressOpenNext() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {nextBtnEnable} = installment.openPageInfo;
if (!nextBtnEnable) {
return;
}
};
}
export function onPressCheckbox() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {agreeProtocol} = installment.openPageInfo;
agreeProtocol = !agreeProtocol;
dispatch(updateAgreeProtocolStatus(agreeProtocol));
};
}
export function onPressCardNoQuestion() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {showBankAlert} = installment.openPageInfo;
showBankAlert = !showBankAlert;
dispatch(updateShowBankAlertStatus(showBankAlert));
};
}
export function updateOpenPageCellInfo(cellInfo) {
return (dispatch, getState) => {
let {app, installment} = getState();
let {cellList,snsCheckCodeEnable} = installment.openPageInfo;
cellList = cellList.toJS();
let newCellList = cellList;
let cardNoValid = false;
let mobileValid = false;
let nextBtnEnable = true;
newCellList.map((item, i) => {
if (item.inputKey == 'cardNo' && item.text.length >=13) {
cardNoValid = true;
} else if (item.inputKey == 'mobile' && item.text.length ==11) {
mobileValid = true;
}
if (item.inputKey == cellInfo.inputKey) {
item.text = cellInfo.text;
}
if (item.text == '') {
nextBtnEnable = false;
}
cellList[i] = item;
});
if (cardNoValid && mobileValid) {
snsCheckCodeEnable = true;
}else {
snsCheckCodeEnable = false;
}
dispatch(updateCellList(cellList));
dispatch(updateSnsCheckCodeEnableStatus(snsCheckCodeEnable));
dispatch(updateNextBtnEnableStatus(nextBtnEnable));
};
}
/**
* 倒计时
*
* @param start 启动回调
* @param tick 进度回调
* @param complete 完成回调
*/
Timer.prototype.startCountdown = function(start, tick, complete) {
var self = this;
if (this.counter > 0 || this.countdownTimer) {
return;
} else {
this.counter = 59;
}
// 启动回调
if (start) {
start.call(this);
}
if (tick) {
tick.call(this, this.counter);
}
this.complete = complete;
// 开始计时器
this.countdownTimer = setInterval(function() {
self.counter--;
if (self.counter <= 0) {
if (complete) {
clearInterval(self.countdownTimer);
// 重置计时器
self.counter = 0;
self.countdownTimer = null;
complete.call(self);
}
}
// 完成回调
if (tick && self.counter > 0) {
tick.call(self, self.counter);
}
}, 1000);
return this;
};
export function onPressCheckCode() {
return (dispatch, getState) => {
let {app, installment} = getState();
let {cellList,snsCheckCodeEnable,snsCheckCodeText} = installment.openPageInfo;
if (snsCheckCodeEnable && snsCheckCodeText == '获取验证码') {
return new InstallmentService(app.host).sendVerifyCode('17705176933')
.then(json => {
console.log('json');
console.log(json);
let status = 0;
let snsText = '';
new Timer().startCountdown(function() {
}, function(counter) {
// 进度回调
snsText = counter + 's';
dispatch(updateSnsCheckCodeText(snsText));
}, function() {
// 倒计时结束后再次显示 "获取验证码"
snsText = '获取验证码';
dispatch(updateSnsCheckCodeText(snsText));
});
dispatch(updateSnsCheckCodeText(snsText));
})
.catch(error => {
});
}
};
}