Detail.js 9.81 KB
'use strict';

import React, {Component} from 'react';
import Immutable, {Map} from 'immutable';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import AddressCell from './AddressCell'
import OrderInfoCell from './OrderInfoCell'
import Footer from './Footer'
import PaymentInfoCell from './PaymentInfoCell'
import ExpressCell from './ExpressCell'
import ProductListCell from './ProductListCell'
import InvoiceCell from './InvoiceCell'
import OrderHistoryCell from './OrderHistoryCell'
import MultiPackageCell from './MultiPackageCell'
import YohoGiveCoinCell from './YohoGiveCoinCell'
import YohoReturnCoinCell from './YohoReturnCoinCell'
import Prompt from '../../../coupon/components/coupon/Prompt';
import DistributionInfoCell from './DistributionInfoCell'
import AntiFraudTip from './AntiFraudTip'

import ReactNative, {
    View,
    Text,
    Image,
    ListView,
    StyleSheet,
    Dimensions,
    TouchableOpacity,
    InteractionManager,
    Platform
} from 'react-native';

export default class Detail extends Component {

    constructor(props) {
        super(props);
        this.renderRow = this.renderRow.bind(this);
        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
            sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2)
        });
    }
    renderRow(rowData, sectionID, rowID, highlightRow) {
        switch (sectionID) {
            case 'tip':
                return(<AntiFraudTip onPressAntiFraudTip={this.props.onPressAntiFraudTip}/>)
                break;
            case 'address':
                return (<AddressCell channel={this.props.channel} data={rowData}/>);
                break;
            case 'orderInfo':
                return (<OrderInfoCell data={rowData} onPressCopy={this.props.onPressCopy}/>);
                break;
            case 'orderHistory':
                return (<OrderHistoryCell data={rowData}/>);
                break;
            case 'deliveryOffline':
                return (<DistributionInfoCell/>);
                break;
            case 'express':
                return (<ExpressCell data={rowData} onPressExpress={() => {
                    let {order_code, firstProductSKN, expressType} = this.props.resource;
                    let param = {
                        orderCode: order_code,
                        productSKN: firstProductSKN,
                        expressType: expressType
                    }
                    this.onPressExpress && this.onPressExpress(param);
                }}/>);
                break;
            case 'multiPackage':
                return (<MultiPackageCell data={rowData} pushMultiPackageWithPackages={() => {
                    let {detail} = this.props.resource;
                    let {data} = detail;
                    if (data) {
                        let packageList = data.get('package_list')
                            ? data.get('package_list').toJS()
                            : [];
                        this.props.pushMultiPackageWithPackages && this.props.pushMultiPackageWithPackages(packageList);
                    }
                }}/>);
                break;
            case 'productList':
                return (<ProductListCell data={rowData} onPressProduct={this.props.onPressProduct} _onPressDelayNotice={this.props._onPressDelayNotice}/>);
                break;
            case 'paymentInfo':
                return (<PaymentInfoCell data={rowData}/>);
                break;
            case 'yoho_give_coin':
                return (<YohoGiveCoinCell data={rowData}/>);
                break;
            case 'return_yoho_coin_num':
                return (<YohoReturnCoinCell data={rowData} onPressReturnOrderCode={this.props.onPressReturnOrderCode}/>);
                break;
            case 'invoice':
                return (<InvoiceCell data={rowData}/>);
                break;
        }
        return null;
    }

    render() {
        let {
            order_code,
            detail,
            expressType,
            expressName,
            acceptTime,
            accept_address
        } = this.props.resource;
        let {isFetching, data} = detail;

        let addressBlob = {
            'name': data && data.get('user_name'),
            'mobile': data && data.get('mobile'),
            'address': data && data.get('area') + data.get('address')
        }

        let expressBlob;

        if (expressType == 1 && data) { //OrderDetailExpressTypeOnDeliver
            expressBlob = [
                '物流公司:' + expressName,
                '快递单号:' + data.get('express_number')
            ];
        } else if (expressType == 0 && data) { //OrderDetailExpressTypeOnRecive
            expressBlob = [accept_address, acceptTime];
        }
        let is_delivery_offline = 'N';
        if (data) {
            is_delivery_offline = data.get('is_delivery_offline');
        }
        let showDeliveryOffline = is_delivery_offline && is_delivery_offline == 'Y';

        let orderInfoBlob = {
            orderCode: order_code,
            orderStatus: data && data.get('status_str'),
            orderTime: data && data.get('create_time'),
            payWay: data && data.get('payment_name'),
            offLineStore: data && data.get('offline_store'),
            expressExisted: expressBlob,
            showDeliveryOffline,
        }

        let paymentInfoBlob = {
            promotionAry: data && data.get('promotion_formulas'),
            total: data && data.get('payment_amount'),
            type: data && data.get('payment_type')
        }

        let isVirtualOrder = false;
        let isPresaleOrder = false;
        let isMultiPackage = false;
        let yoho_give_coin = 0;
        let packageTitle = '';
        let return_yoho_coin_num = 0;

        if (data) {
            isVirtualOrder = data.get('attribute') == '3';
            isPresaleOrder = data.get('attribute') == '9';
            isMultiPackage = data.get('is_multi_package') == 'Y';
            packageTitle = data.get('package_title');
            yoho_give_coin = data.get('yoho_give_coin');
            return_yoho_coin_num = data.get('return_yoho_coin_num');
        }

        let orderHistoryBlob = null;
        if (isPresaleOrder) {
            orderHistoryBlob = {
                orderCode: order_code,
                orderStatus: data && data.get('status_str'),
                tailPayPhone: data && data.get('tail_pay_notice_phone'),
                historyList: data.get('order_history')
            }
        }

        let productListBlob = {
            isVirtualOrder,
            isPresaleOrder,
            list: data && data.get('order_goods')
        }

        let invoiceBlob = null;
        if (data && data.get('invoice')) {
            invoiceBlob = data.get('invoice');
        }

        let dataSource = {
            'tip': data && this.props.showAntiFraud
                ? [1]
                : [],
            'address': data
                ? [addressBlob]
                : [],
            'orderInfo': data && !isPresaleOrder
                ? [orderInfoBlob]
                : [],
            'orderHistory': isPresaleOrder
                ? [orderHistoryBlob]
                : [],
            'deliveryOffline': showDeliveryOffline
                ?[1]
                :[],
            'express': expressBlob && !showDeliveryOffline
                ? [expressBlob]
                : [],
            'multiPackage': isMultiPackage && packageTitle.length
                ? [packageTitle]
                : [],
            'productList': data
                ? [productListBlob]
                : [],
            'paymentInfo': data
                ? [paymentInfoBlob]
                : [],
            'yoho_give_coin': yoho_give_coin
                ? [yoho_give_coin]
                : [],
            'return_yoho_coin_num': return_yoho_coin_num
                ? [return_yoho_coin_num]
                : [],
            'invoice': invoiceBlob
                ? [invoiceBlob]
                : []
        };

        let buttonArray = data
            ? data.get('links').toJS()
            : [];
        return (
            <View style={styles.container}>
                {!isFetching
                    ? <View style={styles.container}>
                            <ListView
                                contentContainerStyle={styles.contentContainer}
                                enableEmptySections={true}
                                showsVerticalScrollIndicator={false}
                                dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
                                renderRow={this.renderRow}
                                />
                                {buttonArray.length
                                ? <Footer
                                    buttonArray={buttonArray}
                                    data={data}
                                    onPressFooterAction={(type) => {
                                        let param = {
                                            type,
                                            data: data.toJS(),
                                        }
                                        this.props.onPressFooterAction && this.props.onPressFooterAction(param)
                                    }}
                                    refreshDetail={this.props.refreshDetail}/>
                                : null}
                        </View>
                    : <LoadingIndicator isVisible={isFetching}/>}
            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');

let styles = StyleSheet.create({
    container: {
        flex: 1,
        width: width,
        backgroundColor: '#f0f0f0'
    },
    contentContainer: {
        backgroundColor: 'white',
        flexWrap: 'wrap'
    },
    listContainer: {
        width: width / 2
    }
});