MyOrderListCell.js 3.66 KB
'use strict';
import React from 'react';
import ReactNative, {
    View,
    Text,
    Image,
    StyleSheet,
    Dimensions,
    TouchableOpacity,
} from 'react-native';

import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';
import SlicedImage from '../../../common/components/SlicedImage';

export default class MyOrderListCell extends React.Component {
    constructor(props) {
        super(props);
    }

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

        if(!orderData)
            return null;

        let orderGoods = orderData.get("order_goods") ? orderData.get("order_goods").get(0) : null;
        let goodsImage = orderGoods ? orderGoods.get("goods_image") : "";
        goodsImage = goodsImage ? SlicedImage.getSlicedUrl(goodsImage, 45, 60, 2) : "";
        let productName = orderGoods ? orderGoods.get("product_name") : "";
        let productSkn = orderGoods ? orderGoods.get("product_skn") : "";

        let orderCode = orderData.get("order_code");
        let orderTime = orderData.get("create_time");
        let orderMoney = orderData.get("amount");
        let orderStateText = orderData.get("install_status");

        let status = orderData.get("status");
        let isOrderPaying = (status == 1 || status == 3);
        let colorStyle = isOrderPaying ? {color: '#444444'} : {color: '#b0b0b0'};

        return(
            <TouchableOpacity activeOpacity={1} onPress={() => this.props.onPressOrder && this.props.onPressOrder(orderCode)}>
                <View style={styles.container} >
                    <YH_Image style={styles.goodsImage} url={goodsImage}/>
                    <Text style={styles.productName} numberOfLines={1}>{productName}</Text>
                    <Text style={styles.productSkn} numberOfLines={1}>{productSkn}</Text>
                    <Text style={styles.orderTime} numberOfLines={1}>{orderTime}</Text>
                    <Text style={styles.orderMoney} numberOfLines={1}>{orderMoney}</Text>
                    <Text style={[styles.orderStateText, colorStyle]} numberOfLines={1}>{orderStateText}</Text>
                </View>
            </TouchableOpacity>
        );
    }



};




let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;

let styles = StyleSheet.create({
    container: {
        flex: 1,
        width: width,
        height: 80 * DEVICE_WIDTH_RATIO,
        borderBottomColor: '#e0e0e0',
        borderBottomWidth: 0.5,
    },
    goodsImage:{
        position: 'absolute',
        top: 10 * DEVICE_WIDTH_RATIO,
        left: 15 * DEVICE_WIDTH_RATIO,
        width: 45 * DEVICE_WIDTH_RATIO,
        height: 60 * DEVICE_WIDTH_RATIO,
    },

    productName:{
        position: 'absolute',
        top: 15 * DEVICE_WIDTH_RATIO,
        left: 70 * DEVICE_WIDTH_RATIO,
        color: "#444444",
        fontSize: 12 * DEVICE_WIDTH_RATIO,
        width: 185 * DEVICE_WIDTH_RATIO,
    },

    productSkn:{
        position: 'absolute',
        top: 30 * DEVICE_WIDTH_RATIO,
        left: 70 * DEVICE_WIDTH_RATIO,
        color: "#444444",
        fontSize: 12 * DEVICE_WIDTH_RATIO,
    },

    orderTime:{
        position: 'absolute',
        top: 50 * DEVICE_WIDTH_RATIO,
        left: 70 * DEVICE_WIDTH_RATIO,
        color: "#b0b0b0",
        fontSize: 12 * DEVICE_WIDTH_RATIO,
    },

    orderMoney:{
        position: 'absolute',
        top: 15 * DEVICE_WIDTH_RATIO,
        right: 15 * DEVICE_WIDTH_RATIO,
        color: "#444444",
        fontSize: 14 * DEVICE_WIDTH_RATIO,
    },

    orderStateText:{
        position: 'absolute',
        top: 45 * DEVICE_WIDTH_RATIO,
        right: 15 * DEVICE_WIDTH_RATIO,
        fontSize: 12 * DEVICE_WIDTH_RATIO,
    },

});