...
|
...
|
@@ -2,12 +2,18 @@ |
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import InstallmentService from '../../../services/InstallmentService';
|
|
|
import * as _ from 'lodash';
|
|
|
|
|
|
const {
|
|
|
|
|
|
SET_PLATFORM,
|
|
|
SET_QUERY_DAYS,
|
|
|
SET_REPAYMENT_LIST,
|
|
|
SET_FORMATE_DATA,
|
|
|
QUERY_REPAYMENT_LIST_REQUEST,
|
|
|
QUERY_REPAYMENT_LIST_FAILURE,
|
|
|
QUERY_REPAYMENT_LIST_SUCCESS,
|
|
|
UPDATE_REPAYMENT_LIST_AND_FORMATE_DATA,
|
|
|
SET_TIP_MESSAGE,
|
|
|
|
|
|
} = require('../../../constants/actionTypes').default;
|
|
|
|
...
|
...
|
@@ -18,21 +24,166 @@ export function setQueryDays(days){ |
|
|
}
|
|
|
}
|
|
|
|
|
|
// SET_REPAYMENT_LIST
|
|
|
export function setRepaymentList(list){
|
|
|
// QUERY_REPAYMENT_LIST_SUCCESS
|
|
|
export function queryRepaymentListRequest(){
|
|
|
return {
|
|
|
type: SET_REPAYMENT_LIST,
|
|
|
type: QUERY_REPAYMENT_LIST_REQUEST,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRepaymentListFailure(error){
|
|
|
return {
|
|
|
type: QUERY_REPAYMENT_LIST_FAILURE,
|
|
|
payload: error,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRepaymentListSuccess(list){
|
|
|
return {
|
|
|
type: QUERY_REPAYMENT_LIST_SUCCESS,
|
|
|
payload: list,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setFormateData(data){
|
|
|
return {
|
|
|
type: SET_FORMATE_DATA,
|
|
|
payload: data,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function setTipMessage(message){
|
|
|
return {
|
|
|
type: SET_TIP_MESSAGE,
|
|
|
payload: message,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updatRepaymentListAndFormateData(object){
|
|
|
return {
|
|
|
type: UPDATE_REPAYMENT_LIST_AND_FORMATE_DATA,
|
|
|
payload: object,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function processAmtList(list, queryDays) {
|
|
|
let overduecount = 0;
|
|
|
let formateData = {
|
|
|
currAmtCount: 0,
|
|
|
currFeeCount: 0
|
|
|
};
|
|
|
if (list) {
|
|
|
_.forEach(list, (data, key) => {
|
|
|
// 第一条选中
|
|
|
if (key == 0) {
|
|
|
data.isChecked = true;
|
|
|
}
|
|
|
// 组装分期的显示格式
|
|
|
if (data.terms == 1) {
|
|
|
data.stage = data.terms;
|
|
|
} else {
|
|
|
data.stage = data.currTerm + '/' + data.terms;
|
|
|
}
|
|
|
|
|
|
// 判断是否逾期
|
|
|
if (data.unExpireDays < 0) {
|
|
|
data.isOverdue = true;
|
|
|
overduecount++;
|
|
|
}
|
|
|
|
|
|
data.day = Math.abs(data.unExpireDays);
|
|
|
data.url = `/home/installment/order/${data.billNo}`;
|
|
|
data.key = key;
|
|
|
});
|
|
|
|
|
|
if (overduecount == 0) {
|
|
|
if (queryDays == 0) { // 待还总金额
|
|
|
list[0].isChecked = true;
|
|
|
formateData.currAmtCount = (+list[0].currAmt);
|
|
|
formateData.currFeeCount = (+list[0].currFee);
|
|
|
if (list.length == 1) {
|
|
|
formateData.isAllChecked = true;
|
|
|
}
|
|
|
} else if (queryDays == 7 || queryDays == 30) { // 近7日待还金额和本月待还金额
|
|
|
_.forEach(list, (data) => {
|
|
|
data.isChecked = true;
|
|
|
formateData.currAmtCount += (+data.currAmt);
|
|
|
formateData.currFeeCount += (+data.currFee);
|
|
|
});
|
|
|
formateData.isAllChecked = true;
|
|
|
}
|
|
|
} else { // 只要有逾期的记录,走这里
|
|
|
_.forEach(list, (data) => {
|
|
|
if (data.unExpireDays < 0) {
|
|
|
data.isChecked = true;
|
|
|
formateData.currAmtCount += (+data.currAmt);
|
|
|
formateData.currFeeCount += (+data.currFee);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (overduecount == list.length) {
|
|
|
formateData.isAllChecked = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 逾期未还款金额
|
|
|
if (queryDays == -1) {
|
|
|
formateData.isAllChecked = true;
|
|
|
}
|
|
|
|
|
|
if (formateData.currFeeCount > 0) {
|
|
|
formateData.isCurrFee = true;
|
|
|
} else {
|
|
|
formateData.isCurrFee = false;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
repaymentList: list,
|
|
|
formateData,};
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function amtAndFeeCount(list) {
|
|
|
let formateData = {
|
|
|
currAmtCount: 0,
|
|
|
currFeeCount: 0
|
|
|
};
|
|
|
let cellLength = list.length;
|
|
|
let count = 0
|
|
|
if (list) {
|
|
|
_.forEach(list, (data) => {
|
|
|
if (data.isChecked) {
|
|
|
count++;
|
|
|
formateData.currAmtCount += (+data.currAmt);
|
|
|
formateData.currFeeCount += (+data.currFee);
|
|
|
}
|
|
|
});
|
|
|
if (count == cellLength) {
|
|
|
formateData.isAllChecked = true;
|
|
|
}
|
|
|
if (formateData.currFeeCount > 0) {
|
|
|
formateData.isCurrFee = true;
|
|
|
} else {
|
|
|
formateData.isCurrFee = false;
|
|
|
}
|
|
|
return formateData;
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function getQueryAmtList(days) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, rePayList} = getState();
|
|
|
let {app, repayList} = getState();
|
|
|
dispatch(queryRepaymentListRequest());
|
|
|
return new InstallmentService(app.host).getQueryAmtList(days)
|
|
|
.then(json => {
|
|
|
if (json && json.length > 0) {
|
|
|
dispatch(setRepaymentList(json));
|
|
|
if (json && json.amtList.length > 0) {
|
|
|
let result = processAmtList(json.amtList, days);
|
|
|
dispatch(queryRepaymentListSuccess(result.repaymentList));
|
|
|
dispatch(setFormateData(result.formateData));
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
...
|
...
|
@@ -42,9 +193,103 @@ export function getQueryAmtList(days) { |
|
|
|
|
|
export function getoNewArrival() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, rePayList} = getState();
|
|
|
let {app, repayList} = getState();
|
|
|
let jumpUrl = `http://m.yohobuy.com/product/new/?openby:yohobuy={"action":"go.new","params":{"title":"新品到着"}}`;
|
|
|
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(jumpUrl);
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// onPressRepaylistCell
|
|
|
export function onPressRepaylistCellCheckbox(cellInfo) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, repayList} = getState();
|
|
|
let {repaymentList,queryDays} = repayList;
|
|
|
repaymentList = repaymentList.toJS();
|
|
|
let formateData;
|
|
|
let curIndex = cellInfo.key;
|
|
|
let tipMessage = '';
|
|
|
if (curIndex == 0) {
|
|
|
if (repaymentList[curIndex+1].isChecked) {
|
|
|
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
|
|
|
dispatch(setTipMessage(tipMessage));
|
|
|
}else {
|
|
|
repaymentList[curIndex].isChecked = !repaymentList[curIndex].isChecked;
|
|
|
formateData = amtAndFeeCount(repaymentList);
|
|
|
dispatch(updatRepaymentListAndFormateData({repaymentList,formateData}));
|
|
|
}
|
|
|
}else if (curIndex == repaymentList.length - 1) {
|
|
|
if (!repaymentList[curIndex-1].isChecked) {
|
|
|
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
|
|
|
dispatch(setTipMessage(tipMessage));
|
|
|
}else {
|
|
|
repaymentList[curIndex].isChecked = !repaymentList[curIndex].isChecked;
|
|
|
formateData = amtAndFeeCount(repaymentList);
|
|
|
dispatch(updatRepaymentListAndFormateData({repaymentList,formateData}));
|
|
|
}
|
|
|
}else {
|
|
|
if (!repaymentList[curIndex-1].isChecked || repaymentList[curIndex + 1].isChecked) {
|
|
|
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
|
|
|
dispatch(setTipMessage(tipMessage));
|
|
|
}else {
|
|
|
repaymentList[curIndex].isChecked = !repaymentList[curIndex].isChecked;
|
|
|
formateData = amtAndFeeCount(repaymentList);
|
|
|
dispatch(updatRepaymentListAndFormateData({repaymentList,formateData}));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function onPressCheckAll(cellInfo) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, repayList} = getState();
|
|
|
let {repaymentList,queryDays,formateData} = repayList;
|
|
|
repaymentList = repaymentList.toJS();
|
|
|
formateData = formateData.toJS();
|
|
|
formateData.isAllChecked = !formateData.isAllChecked;
|
|
|
_.forEach(repaymentList, (data) => {
|
|
|
data.isChecked = formateData.isAllChecked;
|
|
|
});
|
|
|
formateData = amtAndFeeCount(repaymentList);
|
|
|
dispatch(updatRepaymentListAndFormateData({repaymentList,formateData}));
|
|
|
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// onPressPayNow
|
|
|
export function onPressPayNow() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, repayList} = getState();
|
|
|
let {repaymentList,queryDays,formateData} = repayList;
|
|
|
formateData = formateData.toJS();
|
|
|
repaymentList = repaymentList.toJS();
|
|
|
let checkedCellList=[];
|
|
|
_.forEach(repaymentList, (data) => {
|
|
|
if (data.isChecked) {
|
|
|
checkedCellList.push({
|
|
|
index: data.key,
|
|
|
orderCode: data.billNo,
|
|
|
termNo: data.currTerm,
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
console.log('checkedCellList');
|
|
|
console.log(checkedCellList);
|
|
|
let url = {
|
|
|
action: "go.instalmentRepayment",
|
|
|
params:{
|
|
|
list: checkedCellList,
|
|
|
amount: formateData.currAmtCount,
|
|
|
},
|
|
|
};
|
|
|
url = JSON.stringify(url);
|
|
|
let jumpUrl = `http://m.yohobuy.com/home/installment/repay/total?openby:yohobuy=${url}`;
|
|
|
// let jumpUrl = `http://m.yohobuy.com/product/new/?openby:yohobuy={"action":"go.new","params":{"title":"新品到着"}}`;
|
|
|
|
|
|
console.log('jumpUrl');
|
|
|
console.log(jumpUrl);
|
|
|
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(jumpUrl);
|
|
|
};
|
|
|
} |
...
|
...
|
|