ListFooter.js 3.82 KB
import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  View,
  Image,
  Dimensions,
} from 'react-native';

import Immutable,{List} from 'immutable';
import ActionView from './ActionView'

export default class ListFooter extends Component {
    constructor(props) {
        super(props);
        this.goodsCount = this.goodsCount.bind(this);
    }

    goodsCount(){
        let orderData = this.props.data;
        let goodsCount = orderData.get('goods_quantity',0);
        if (goodsCount > 0) {
            return goodsCount;
        }else {
            let orderGoodsList = orderData.get('order_goods',List()).toJS();
            let count = 0;
            for (var i = 0; i < orderGoodsList.length; i++) {
                let goods = orderGoodsList[i];
                count += goods.buy_number;
            }
            return count;
        }
    }

    render(){
        let orderData = this.props.data;

        let goodsCountString = '共' + this.goodsCount() + '件商品 '; //共n件商品
        let payInfoString = '实付';
        let orderAmout = orderData.get('amount',0);

        let orderPaymentStage = orderData.get('payment_stage');
        if (orderPaymentStage == '1') {
            payInfoString = '需支付定金';
            orderAmout = orderData.get('order_deposit_amount',0);
        }
        if (orderPaymentStage == '2') {
            payInfoString = '已支付定金';
            orderAmout = orderData.get('order_deposit_amount',0);
        }
        if (orderPaymentStage == '3') {
            payInfoString = '待支付尾款';
            orderAmout = orderData.get('order_tail_pay_amount',0);
        }
        let shipCost = orderData.get('shipping_cost',0);
        let shipCostString = '';
        if (shipCost > 0 && orderPaymentStage != '1' && orderPaymentStage != '2') {
            shipCostString = '(含运费¥' + shipCost + ')';
        }
        let buttonArray = orderData ? orderData.get('links').toJS() : [];
        return(
            <View style={styles.container}>

                <View style={styles.price}>
                    <Text style={styles.count} numberOfLines={1}>
                        {goodsCountString}
                        <Text style={styles.payInfo}>
                            {payInfoString}
                        </Text>
                        <Text style={styles.amount}>
                            {' ¥'+(orderAmout)}
                        </Text>
                        <Text style={styles.shippingCost}>
                            {shipCostString}
                        </Text>
                    </Text>
                </View>
                {buttonArray.length > 0?
                    <ActionView data={orderData} buttonLiks={buttonArray} orderAction={this.props.orderAction}/>
                    :null}
            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
    container: {
        flexDirection: 'column',
        alignItems: 'center',
        backgroundColor: 'white',
        justifyContent: 'flex-end',
    },
    price: {
        flexDirection: 'row',
        justifyContent: 'flex-end',
        alignItems: 'center',
        height: 46,
        width,
        borderColor:'#f0f0f0',
        borderTopWidth:1,
        borderBottomWidth:1,
    },
    count: {
        marginRight: 15,
        backgroundColor: 'transparent',
        maxWidth: width-30,
        color: '#444444',
        fontSize: 16,
        fontWeight: '100'
    },
    payInfo: {
        fontSize: 16,
        color:'#444444',
        fontWeight: '100'
    },
    amount: {
        fontSize: 16,
         color:'#d0021b',
         fontWeight:'normal'
    },
    shippingCost: {
        fontSize: 12,
        color: '#444444',
        fontWeight: '100',
    },
    line: {
        backgroundColor: '#e5e5e5',
        height: 1,
    }
});