Authored by chenl

增加了订单付款详情业务逻辑。review by 张丽霞。

... ... @@ -97,8 +97,8 @@ export default class ConfirmPay extends React.Component {
onChange={this._codeValueChange}
onFocus={this._codeInputOnFocus}
style={styles.textInput}
maxLength={4}
keyboardType='numeric'
underlineColorAndroid="transparent"
/>
</View>
<TouchableOpacity onPress={() => {this._reSendConfirmPaySnsCode()}} >
... ... @@ -198,6 +198,7 @@ let styles = StyleSheet.create({
height: 44 * DEVICE_WIDTH_RATIO,
fontSize: 12 * DEVICE_WIDTH_RATIO,
marginTop: 1 * DEVICE_WIDTH_RATIO,
padding: 0,
},
reSendSnsCode: {
width: 78 * DEVICE_WIDTH_RATIO,
... ...
... ... @@ -19,6 +19,8 @@ import SlicedImage from '../../../common/components/SlicedImage';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import BankSafePay from '../installment/BankSafePay';
import ConfirmPay from '../installment/ConfirmPay';
import Prompt from '../../../coupon/components/coupon/Prompt';
export default class MyOrderDetail extends React.Component {
constructor(props) {
... ... @@ -35,13 +37,15 @@ export default class MyOrderDetail extends React.Component {
return (
<MyOrderDetailPayListCell
data={rowData}
rowIndex={rowID}
onPressCheckboxCell={this.props.onPressCheckboxCell}
/>
);
}
render() {
let {isFetching, orderInfo, showBankSafePayView, showConfirmPayView, payCard, formateData} = this.props.myOrderDetail;
let {isFetching, orderInfo, showBankSafePayView, showConfirmPayView, payCard, formateData, tipMessage} = this.props.myOrderDetail;
if(!orderInfo)
return null;
... ... @@ -64,7 +68,7 @@ export default class MyOrderDetail extends React.Component {
//分期列表
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toArray() : [];
let checked = this.props.isChecked;
let checked = formateData.get("isAllChecked");
let checkboxIcon = require('../../image/uncheck_icon.png');
if (checked) {
checkboxIcon = require('../../image/check_icon.png');
... ... @@ -107,14 +111,15 @@ export default class MyOrderDetail extends React.Component {
/>
<View style={styles.splitLine}></View>
<View style={styles.bottomContainer}>
<View style={styles.checkboxContainer}>
<TouchableOpacity style={styles.checkboxContainer} activeOpacity={1} onPress={() => {
this.props.onPressCheckboxAll && this.props.onPressCheckboxAll()}}>
<Image style={styles.checkboxIcon} source={checkboxIcon}/>
</View>
</TouchableOpacity>
<View style={styles.payMoneyContainer}>
<Text style={styles.payTitle} numberOfLines={1}>待支付</Text>
<Text style={styles.payAmount} numberOfLines={1}>{"¥ 555"}</Text>
<Text style={styles.payAmount} numberOfLines={1}> ¥{formateData.get("currAmtCount")?formateData.get("currAmtCount"):'0.00'}</Text>
</View>
<Text style={styles.payDesc} numberOfLines={1}>{"含服务费¥5.00"}</Text>
<Text style={styles.payDesc} numberOfLines={1}>含服务费¥{formateData.get("currFeeCount")?formateData.get("currFeeCount"):'0.00'}</Text>
<TouchableOpacity style={styles.payButtonContainer} activeOpacity={1} onPress={() => {
this.props.onPressPayNow && this.props.onPressPayNow()}}>
... ... @@ -129,8 +134,8 @@ export default class MyOrderDetail extends React.Component {
{showBankSafePayView?
<BankSafePay
payCard={payCard}
formateData={formateData}
payCard={payCard.toJS()}
formateData={formateData.toJS()}
closeBankSafePay={this.props.closeBankSafePay}
bankSafePayNow={this.props.bankSafePayNow}
changeBankCard={this.props.changeBankCard}
... ... @@ -146,6 +151,12 @@ export default class MyOrderDetail extends React.Component {
/>
:null
}
{tipMessage !== '' ? <Prompt
text={tipMessage}
duration={800}
onPromptHidden={this.props.clearTipMessage}
/> : null}
</View>
... ...
... ... @@ -45,26 +45,27 @@ export default class MyOrderDetailPayListCell extends React.Component {
return(
<TouchableOpacity activeOpacity={1} onPress={() => this.props.onPressOrder && this.props.onPressOrder()}>
<View style={styles.container} >
<View style={styles.sortContainer}>
{
isPayable ? <Image style={styles.checkboxIcon} source={checkboxIcon}/>
: <Text style={styles.sortText} numberOfLines={1}>{sort}</Text>
}
</View>
<Text style={styles.totalAmount} numberOfLines={1}>{currentTotalAmount}</Text>
<View style={styles.amountDetailContainer}>
<Text style={styles.amountText}>{currentDate}</Text>
<Text style={styles.amountText}>{"本金:" + currentPAmount}</Text>
<Text style={styles.amountText}>{"服务费:" + currentFee}</Text>
{
isDelay ? <Text style={styles.amountText}>{"逾期服务费:" + currentDelayFee}</Text> : null
}
</View>
<Text style={[styles.desc,colorStyle]} numberOfLines={1}>{desc}</Text>
<View style={styles.container} >
<View style={styles.sortContainer}>
{
isPayable ?
<TouchableOpacity activeOpacity={1} onPress={() => this.props.onPressCheckboxCell && this.props.onPressCheckboxCell(this.props.rowIndex)}>
<Image style={styles.checkboxIcon} source={checkboxIcon}/>
</TouchableOpacity>
: <Text style={styles.sortText} numberOfLines={1}>{sort}</Text>
}
</View>
</TouchableOpacity>
<Text style={styles.totalAmount} numberOfLines={1}>{currentTotalAmount}</Text>
<View style={styles.amountDetailContainer}>
<Text style={styles.amountText}>{currentDate}</Text>
<Text style={styles.amountText}>{"本金:" + currentPAmount}</Text>
<Text style={styles.amountText}>{"服务费:" + currentFee}</Text>
{
isDelay ? <Text style={styles.amountText}>{"逾期服务费:" + currentDelayFee}</Text> : null
}
</View>
<Text style={[styles.desc,colorStyle]} numberOfLines={1}>{desc}</Text>
</View>
);
}
... ...
... ... @@ -90,4 +90,6 @@ export default keyMirror({
GET_ORDER_DETAIL_REQUEST: null,
GET_ORDER_DETAIL_FAILURE: null,
GET_ORDER_DETAIL_SUCCESS: null,
UPDATE_ORDER_INFO_AND_FORMATE_DATA: null,
});
... ...
... ... @@ -47,19 +47,30 @@ class InstallmentMyOrderDetailContainer extends Component {
constructor(props) {
super(props);
this._reloadPage = this._reloadPage.bind(this);
// this._onPressCheckAll = this._onPressCheckAll.bind(this);
this._onPressCheckboxCell = this._onPressCheckboxCell.bind(this);
this._onPressCheckboxAll = this._onPressCheckboxAll.bind(this);
this._onPressPayNow = this._onPressPayNow.bind(this);
this._closeBankSafePay = this._closeBankSafePay.bind(this);
this._bankSafePayNow = this._bankSafePayNow.bind(this);
this._cancelPayInConfirm = this._cancelPayInConfirm.bind(this);
this._reSendConfirmPaySnsCode = this._reSendConfirmPaySnsCode.bind(this);
this._confirmPayAction = this._confirmPayAction.bind(this);
this._clearTipMessage = this._clearTipMessage.bind(this);
}
_reloadPage() {
this.props.actions.getBankCards();
this.props.actions.getOrderDetail();
}
_onPressCheckboxCell(cellInfo) {
this.props.actions.onPressCheckboxCell(cellInfo);
}
_onPressCheckboxAll() {
this.props.actions.onPressCheckboxAll();
}
_onPressPayNow() {
this.props.actions.onPressPayNow();
}
... ... @@ -84,8 +95,13 @@ class InstallmentMyOrderDetailContainer extends Component {
this.props.actions.confirmPayAction(snsCode);
}
_clearTipMessage() {
this.props.actions.setTipMessage('');
}
componentDidMount() {
this.props.actions.getBankCards();
this.props.actions.getOrderDetail();
}
... ... @@ -104,14 +120,15 @@ class InstallmentMyOrderDetailContainer extends Component {
<MyOrderDetail
style={styles.container}
myOrderDetail={this.props.myOrderDetail}
// onPressRepaylistCellCheckbox={this._onPressRepaylistCellCheckbox}
// onPressCheckAll={this._onPressCheckAll}
onPressCheckboxCell={this._onPressCheckboxCell}
onPressCheckboxAll={this._onPressCheckboxAll}
onPressPayNow={this._onPressPayNow}
closeBankSafePay={this._closeBankSafePay}
bankSafePayNow={this._bankSafePayNow}
cancelPayInConfirm={this._cancelPayInConfirm}
reSendConfirmPaySnsCode={this._reSendConfirmPaySnsCode}
confirmPayAction={this._confirmPayAction}
clearTipMessage={this._clearTipMessage}
/>
);
... ...
... ... @@ -2,6 +2,8 @@
import ReactNative from 'react-native';
import InstallmentService from '../../services/InstallmentService';
import * as _ from 'lodash';
const {
... ... @@ -15,6 +17,11 @@ GET_ORDER_DETAIL_FAILURE,
GET_ORDER_DETAIL_SUCCESS,
SET_BANK_SAFE_PAY_VIEW_STATUS,
SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
UPDATE_ORDER_INFO_AND_FORMATE_DATA,
SET_BANK_CARDS_LIST_AND_PAY_CARD,
UPDATE_REPAY_TERM_LIST,
UPDATE_PREPAY_SUCCESS_PARAM,
} = require('../../constants/actionTypes').default;
... ... @@ -48,7 +55,7 @@ export function getOrderDetailSuccess(json){
export function getOrderDetail(orderCode) {
export function getOrderDetail() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
... ... @@ -96,6 +103,167 @@ export function setTipMessage(message){
}
}
export function setBankCardslistAndPayCard(list){
return {
type: SET_BANK_CARDS_LIST_AND_PAY_CARD,
payload: list,
}
}
function processBankCardsInfo(list) {
if (list && list.length > 0) {
_.forEach(list, (data) => {
let cardNo = data.cardNo;
data.outBankNameNumb = data.bankName +'(' + cardNo.substring(cardNo.length - 4) +')';
data.outMobile = data.mobile.substring(data.mobile.length - 6);
});
return list;
}
return [];
}
export function getBankCards() {
return (dispatch, getState) => {
let {app} = getState();
let queryBankCards = (uid) => {
return new InstallmentService(app.host).getBankCards(uid)
.then(json => {
let bankCardsInfo = processBankCardsInfo(json);
dispatch(setBankCardslistAndPayCard(bankCardsInfo));
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
queryBankCards(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
queryBankCards(uid);
})
.catch(error => {
});
});
};
}
//计算金额和费用
function amtAndFeeCount(list) {
let formateData = {
currAmtCount: 0,
currFeeCount: 0
};
let checkAbleCount = 0;
let checkedCount = 0
if (list) {
_.forEach(list, (data) => {
if (data.isChecked) {
checkedCount++;
formateData.currAmtCount = formateData.currAmtCount + parseFloat(data.curr_amt);
formateData.currFeeCount += formateData.currFeeCount + parseFloat(data.curr_fee_amt);
}
if(data.status == 1 || data.status == 3){
checkAbleCount++;
}
});
if (checkedCount == checkAbleCount) {
formateData.isAllChecked = true;
}else{
formateData.isAllChecked = false;
}
if (formateData.currFeeCount > 0) {
formateData.isCurrFee = true;
} else {
formateData.isCurrFee = false;
}
return formateData;
}else {
return null;
}
}
// onPressRepaylistCell
export function onPressCheckboxCell(curIndex) {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {orderInfo} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
let formateData;
let tipMessage = '';
curIndex = parseInt(curIndex);
if (curIndex == 0) {
if (package_list[curIndex+1].isChecked) {
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}else if (curIndex == package_list.length - 1) {
if (!package_list[curIndex-1].isChecked && (package_list[curIndex-1].status == 1 || package_list[curIndex-1].status == 3)) {
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}else {
let preCell = package_list[curIndex - 1];
let nextCell = package_list[curIndex + 1];
//上一个应付款未选中或者下一个已选中
if(((preCell.status == 1 || preCell.status == 3) && !preCell.isChecked) || (nextCell && nextCell.isChecked)){
tipMessage = '同一个分期订单不能跨期还款,请按时间顺序还款';
dispatch(setTipMessage(tipMessage));
}else {
package_list[curIndex].isChecked = !package_list[curIndex].isChecked;
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
}
}
};
}
export function onPressCheckboxAll() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {orderInfo,formateData} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
formateData = formateData.toJS();
formateData.isAllChecked = !formateData.isAllChecked;
_.forEach(package_list, (data) => {
data.isChecked = formateData.isAllChecked;
});
formateData = amtAndFeeCount(package_list);
dispatch(updatOrderInfoAndFormateData({package_list,formateData}));
};
}
export function updatOrderInfoAndFormateData(object){
return {
type: UPDATE_ORDER_INFO_AND_FORMATE_DATA,
payload: object,
}
}
export function setBankSafePayViewStatus(status){
... ... @@ -105,28 +273,177 @@ export function setBankSafePayViewStatus(status){
}
}
export function setShowConfirmPayViewStatus(status) {
return {
type: SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
payload: status,
}
}
// onPressPayNow
export function onPressPayNow() {
return (dispatch, getState) => {
// dispatch(getBankCards());
dispatch(getBankCards());
dispatch(setBankSafePayViewStatus(true));
// let {app, repayList} = getState();
// let {repaymentList,queryDays,formateData} = repayList;
// repaymentList = repaymentList.toJS();
// formateData = formateData.toJS();
// let termsList = [];
// _.forEach(repaymentList, (data) => {
// if (data.isChecked) {
// termsList.push({
// index: data.key,
// orderCode: data.billNo,
// termNo: data.currTerm
// });
// }
// });
// dispatch(updateRepayTermList(termsList));
let {app, myOrderDetail} = getState();
let {orderInfo, formateData} = myOrderDetail;
let package_list = orderInfo.get("package_list") ? orderInfo.get("package_list").toJS() : [];
let orderCode = orderInfo.get("order_code");
formateData = formateData.toJS();
let termsList = [];
_.forEach(package_list, (data) => {
if (data.isChecked) {
termsList.push({
index: data.sort_id,
orderCode: orderCode,
termNo: data.sort_id
});
}
});
dispatch(updateRepayTermList(termsList));
}
}
export function bankSafePayNow() {
return (dispatch, getState) => {
let bankSafePayNowAction = (uid) => {
let {app, myOrderDetail} = getState();
let {formateData,repayTermList,payCard} = myOrderDetail;
formateData = formateData.toJS();
repayTermList = repayTermList.toJS();
payCard = payCard.toJS();
let params = {
uid,
repay_amount: formateData.currAmtCount,
repayTermList:JSON.stringify(repayTermList),
bankcard_IdNo: payCard.cardIdNo,
terminal_type: 'mobile',
user_ip: '',
terminal_info: '',
card_id: payCard.cardIdNo,
}
return new InstallmentService(app.host).getPrerePay(params)
.then(json => {
if (json && json.isRepaySuccess == 'Y') {
dispatch(updatePrepaySuccessParam(json));
} else {
let tipMessage = json.message || '暂未获取到数据';
dispatch(setTipMessage(tipMessage));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
bankSafePayNowAction(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
bankSafePayNowAction(uid);
})
.catch(error => {
});
});
};
}
export function updatePrepaySuccessParam(param) {
return {
type: UPDATE_PREPAY_SUCCESS_PARAM,
payload: param,
}
}
export function updateRepayTermList(list) {
return {
type: UPDATE_REPAY_TERM_LIST,
payload: list,
}
}
//
export function reSendConfirmPaySnsCode() {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let resendSnsCode = (uid) => {
let {prePaySuccessParam} = myOrderDetail;
prePaySuccessParam = prePaySuccessParam.toJS();
let params = {
uid,
orderNo: prePaySuccessParam.crfRepayOrderNo,
prepayNo: prePaySuccessParam.repayOrderCode,
}
return new InstallmentService(app.host).reSendConfirmPaySnsCode(params)
.then(json => {
if (json && json.code && json.code !== 200) {
let tipMessage = json.message || '暂未获取到数据';
dispatch(setTipMessage(tipMessage));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
resendSnsCode(uid);
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
resendSnsCode(uid);
})
.catch(error => {
});
});
};
}
//
export function confirmPayAction(snsCode) {
return (dispatch, getState) => {
let {app, myOrderDetail} = getState();
let {payCard,repayTermList,formateData,prePaySuccessParam} = myOrderDetail;
payCard = payCard.toJS();
repayTermList = repayTermList.toJS();
formateData = formateData.toJS();
prePaySuccessParam = prePaySuccessParam.toJS();
let params = prePaySuccessParam;
delete params.isRepaySuccess;
params.phoneNumber = payCard.mobile;
params.smsCode = snsCode;
params.repayTermList = JSON.stringify(repayTermList);
params.terminal_type = 'mobile';
return new InstallmentService(app.host).confirmRepay(params)
.then(json => {
if (json.isPaySuccess == 'Y') {
//刷新页面数据
dispatch(setShowConfirmPayViewStatus(false));
dispatch(setBankSafePayViewStatus(false));
dispatch(getOrderDetail());
}else {
dispatch(setTipMessage(json.message || '暂未获取到数据'));
}
})
.catch(error => {
dispatch(setTipMessage(error.message || '暂未获取到数据'));
});
};
}
... ...
... ... @@ -11,9 +11,13 @@ let InitialState = Record({
orderInfo: Map(),
formateData: Map(),
bankCardsList: List(),
payCard: Map(),
showBankSafePayView: false,
showConfirmPayView: false,
repayTermList:List(),
prePaySuccessParam: Map(),
});
... ...
... ... @@ -14,6 +14,10 @@ const {
SET_BANK_SAFE_PAY_VIEW_STATUS,
SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
UPDATE_ORDER_INFO_AND_FORMATE_DATA,
SET_BANK_CARDS_LIST_AND_PAY_CARD,
UPDATE_REPAY_TERM_LIST,
UPDATE_PREPAY_SUCCESS_PARAM,
} = require('../../constants/actionTypes').default;
... ... @@ -42,7 +46,18 @@ export default function appReducer(state = initialState, action) {
case SET_BANK_SAFE_PAY_VIEW_STATUS:
return state.set('showBankSafePayView',action.payload);
case SET_SHOW_CONFIRM_PAY_VIEW_STATUS:
return state.set('showConfirmPayView', action.payload);
return state.set('showConfirmPayView', action.payload);
case UPDATE_ORDER_INFO_AND_FORMATE_DATA:
return state.setIn(['orderInfo', 'package_list'], Immutable.fromJS(action.payload.package_list))
.set('formateData', Immutable.fromJS(action.payload.formateData));
case SET_BANK_CARDS_LIST_AND_PAY_CARD:
return state.set('bankCardsList', Immutable.fromJS(action.payload))
.set('payCard', Immutable.fromJS(action.payload[0]));
case UPDATE_REPAY_TERM_LIST:
return state.set('repayTermList', Immutable.fromJS(action.payload));
case UPDATE_PREPAY_SUCCESS_PARAM:
return state.set('prePaySuccessParam',Immutable.fromJS(action.payload))
.set('showConfirmPayView', true);
}
return state;
... ...