|
|
'use strict';
|
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import InstallmentService from '../../services/InstallmentService';
|
|
|
import InstallmentService from '../../../services/InstallmentService';
|
|
|
|
|
|
const {
|
|
|
|
...
|
...
|
@@ -15,17 +15,6 @@ 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_SNS_CHECK_CODE_TEXT,
|
|
|
UPDATE_TIP_MESSAGE,
|
|
|
NEXT_BTN_PROCESSING_REQUEST,
|
|
|
NEXT_BTN_PROCESSING_SUCCESS,
|
|
|
NEXT_BTN_PROCESSING_FAILURE,
|
|
|
|
|
|
SET_INSTALLMENT_STATUS_PAGE_ORIGINAL_INFO,
|
|
|
SET_INSTALLMENT_STATUS_PAGE_GOODS,
|
|
|
SET_STATUS_PAGE_ADVERTISEMENT,
|
...
|
...
|
@@ -38,18 +27,13 @@ SET_ALREADY_PAGE_AMT_INFO, |
|
|
SET_ALREADY_PAGE_OVERDUE_STATUS,
|
|
|
SET_ALREADY_PAGE_CREDIT_INFO,
|
|
|
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
} = 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,
|
...
|
...
|
@@ -90,71 +74,6 @@ export function featchInstallmentStatusFailure(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 updateSnsCheckCodeText(text) {
|
|
|
return {
|
|
|
type: UPDATE_SNS_CHECK_CODE_TEXT,
|
|
|
payload: text
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updateTipMessage(message) {
|
|
|
return {
|
|
|
type: UPDATE_TIP_MESSAGE,
|
|
|
payload: message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function nextBtnProcessingRequest() {
|
|
|
return {
|
|
|
type: NEXT_BTN_PROCESSING_REQUEST,
|
|
|
}
|
|
|
}
|
|
|
export function nextBtnProcessingFailure() {
|
|
|
return {
|
|
|
type: NEXT_BTN_PROCESSING_FAILURE
|
|
|
}
|
|
|
}
|
|
|
export function nextBtnProcessingSuccess() {
|
|
|
return {
|
|
|
type: NEXT_BTN_PROCESSING_SUCCESS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setInstallmentStatusPageOriginalInfo(params) {
|
|
|
return {
|
|
|
type: SET_INSTALLMENT_STATUS_PAGE_ORIGINAL_INFO,
|
...
|
...
|
@@ -225,6 +144,7 @@ export function setAlreadPageCreditInfo(creditInfo) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
export function productListForInstallment() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, installment} = getState();
|
...
|
...
|
@@ -325,293 +245,6 @@ export function getInstallmentStatus() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
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,cellList,nextProcessing} = installment.openPageInfo;
|
|
|
let activateParams = {};
|
|
|
let newCellList = cellList;
|
|
|
// if (!nextBtnEnable) {
|
|
|
// return;
|
|
|
// }
|
|
|
ReactNative.NativeModules.YH_InstallmentHelper.gotoInstallmentStatusView('2', '您的授信未通过,在有货更多的消费,增加信用度,会大大提升审核通过率奥。');
|
|
|
return;
|
|
|
cellList.map((item, i) => {
|
|
|
if (item.get('inputKey') != 'BankIcon') {
|
|
|
activateParams[item.get('inputKey')]= item.get('text');
|
|
|
}
|
|
|
});
|
|
|
let activateService = (uid) => {
|
|
|
dispatch(nextBtnProcessingRequest());
|
|
|
return new InstallmentService(app.host).checkVerifyCode(uid, activateParams.mobile, activateParams.snsCheckCode)
|
|
|
.then(json => {
|
|
|
if (json.result === '1') {
|
|
|
return new InstallmentService(app.host).activateService(activateParams)
|
|
|
}else {
|
|
|
newCellList.map((item, i) => {
|
|
|
if (item.inputKey == 'snsCheckCode') {
|
|
|
item.text = '';
|
|
|
}
|
|
|
cellList[i] = item;
|
|
|
});
|
|
|
dispatch(updateTipMessage(json.message))
|
|
|
dispatch(updateCellList(cellList));
|
|
|
dispatch(nextBtnProcessingFailure());
|
|
|
}
|
|
|
})
|
|
|
.then(json => {
|
|
|
dispatch(nextBtnProcessingSuccess());
|
|
|
console.log('2222222');
|
|
|
console.log(json);
|
|
|
let tipMessage = '';
|
|
|
if (json.status == '3') {
|
|
|
json.failReason = json.failReason || '姓名、身份证、银行卡不匹配';
|
|
|
}
|
|
|
ReactNative.NativeModules.YH_InstallmentHelper.gotoInstallmentStatusView(json.status, json.failReason);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
activateService(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
activateService(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
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 getBankInfo(cellInfo,cardNo) {
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
let bankInfo = (uid) => {
|
|
|
let {app, installment} = getState();
|
|
|
let {cellList,snsCheckCodeEnable} = installment.openPageInfo;
|
|
|
cellList = cellList.toJS();
|
|
|
let newCellList = cellList;
|
|
|
let nextBtnEnable = true;
|
|
|
return new InstallmentService(app.host).fentchBankInfo(cardNo,uid)
|
|
|
.then(json => {
|
|
|
let bankIconInfo = {
|
|
|
inputKey: 'BankIcon',
|
|
|
bankCode: '',
|
|
|
bankName: '',
|
|
|
bankText: '',
|
|
|
show: true,
|
|
|
};
|
|
|
if (json.bankCode) {
|
|
|
bankIconInfo.bankCode = json.bankCode;
|
|
|
bankIconInfo.bankName = json.bankName;
|
|
|
}
|
|
|
if (json.businessSupport === '1') {
|
|
|
bankIconInfo.bankCode = '';
|
|
|
bankIconInfo.bankName = '';
|
|
|
bankIconInfo.bankText = '暂不支持此银行卡';
|
|
|
}
|
|
|
|
|
|
newCellList.map((item, i) => {
|
|
|
if (item.inputKey == 'BankIcon') {
|
|
|
item = bankIconInfo;
|
|
|
}
|
|
|
cellList[i] = item;
|
|
|
});
|
|
|
dispatch(updateCellList(cellList));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
bankInfo(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
bankInfo(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
if (cellInfo.inputKey == "cardNo") {
|
|
|
let value = cellInfo.text;
|
|
|
console.log('value');
|
|
|
console.log(value);
|
|
|
let cardNo = value.replace(/\s/g, '');
|
|
|
let newCardNo = value.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ');
|
|
|
console.log('newCardNo');
|
|
|
console.log(newCardNo);
|
|
|
cellInfo.text = newCardNo;
|
|
|
if (cardNo && cardNo.length >= 16) {
|
|
|
cardNoValid = true;
|
|
|
dispatch(getBankInfo(cellInfo,value));
|
|
|
}else {
|
|
|
cardNoValid = false;
|
|
|
cellInfo.showBankIcon = false;
|
|
|
}
|
|
|
|
|
|
}else if (cellInfo.inputKey == "mobile" && cellInfo.text.length ==11) {
|
|
|
mobileValid = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
newCellList.map((item, i) => {
|
|
|
if (item.inputKey == 'cardNo' && item.text.length >=16 && cellInfo.inputKey != 'cardNo') {
|
|
|
cardNoValid = true;
|
|
|
} else if (item.inputKey == 'mobile' && item.text.length ==11 && cellInfo.inputKey != 'mobile') {
|
|
|
mobileValid = true;
|
|
|
}
|
|
|
if (item.inputKey == cellInfo.inputKey) {
|
|
|
item = cellInfo;
|
|
|
}
|
|
|
if (item.text == '') {
|
|
|
nextBtnEnable = false;
|
|
|
}
|
|
|
cellList[i] = item;
|
|
|
});
|
|
|
if (cardNoValid && mobileValid) {
|
|
|
snsCheckCodeEnable = true;
|
|
|
}else {
|
|
|
snsCheckCodeEnable = false;
|
|
|
}
|
|
|
console.log('cellInfo');
|
|
|
console.log(cellInfo);
|
|
|
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 => {
|
|
|
|
|
|
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 => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function setInstallmentStausPageParams(statusCode, failReason, uid) {
|
|
|
return (dispatch, getState) => {
|
...
|
...
|
@@ -810,3 +443,11 @@ export function onPressTabBtn() { |
|
|
ReactNative.NativeModules.YH_InstallmentHelper.helpAction();
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function gotoRepayListPageWithDays(days) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, installment} = getState();
|
|
|
ReactNative.NativeModules.YH_InstallmentHelper.gotoRepayListPage(days);
|
|
|
};
|
|
|
} |
...
|
...
|
|