TripleImage.js 12.7 KB
import React, {Component } from 'react'
import { Image ,View, StyleSheet, Text, Dimensions,TouchableOpacity} from 'react-native';
import Immutable, {Map} from 'immutable';

export default class RedPersonPicThree extends Component{
  constructor(props) {
    super(props);
  }

  shouldComponentUpdate(nextProps){
      if (Immutable.is(nextProps.resource, this.props.resource)) {
          return false;
      } else {
          return true;
      }
  }

  render() {

    let {resource} = this.props;
    if (!resource) {
      return null;
    }

    let list = resource.get('module_data').get('data').toJS();
    let properties = resource.get('module_data').get('properties').toJS();
    let isModuleMargin = properties.isModuleMargin;
    let displayType = properties.displayType;

    let data1 = list?list[0]:null;
    let backgroundImage1 = data1?data1.pic:'';
    let linkType1 = data1.linkType;
    let product1 = data1.product;
    let salePrice1 = product1?parseFloat(product1.sales_price):0;
    let originPrice1 = product1?parseFloat(product1.market_price):0;
    let name1 = product1?product1.product_name:'';
    let price1 = '¥' + salePrice1.toFixed(2);
    let sale1 = '¥' + originPrice1.toFixed(2);
    let saleAble1 = salePrice1>0?true:false;
    let linkReource1 = data1.resource;

    let data2 = list?list[1]:null;
    let backgroundImage2 = data2.pic;
    let linkType2 = data2.linkType;
    let product2 = data2.product;
    let salePrice2 = product2?parseFloat(product2.sales_price):0;
    let originPrice2 = product2?parseFloat(product2.market_price):0;
    let name2 = product2?product2.product_name:'';
    let price2 = '¥' + salePrice2.toFixed(2);
    let sale2 = '¥' + originPrice2.toFixed(2);
    let saleAble2 = salePrice2>0?true:false;
    let linkReource2 = data2.resource;

    let data3 = list?list[2]:null;
    let backgroundImage3 = data3.pic;
    let linkType3 = data3.linkType;
    let product3 = data3.product;
    let salePrice3 = product3?parseFloat(product3.sales_price):0;
    let originPrice3= product3?parseFloat(product3.market_price):0;
    let name3 = product3?product3.product_name:'';
    let price3 = '¥' + salePrice3.toFixed(2);
    let sale3 = '¥' + originPrice3.toFixed(2);
    let saleAble3 = salePrice3>0?true:false;
    let linkReource3 = data3.resource;

    switch (displayType) {
        case '1':
            return (
                <View style={{flexDirection: 'row',width:width,height: isModuleMargin=='1'?containerHeigth4+nullHeigth:containerHeigth4,backgroundColor: 'white'}}>
                    <TouchableOpacity style={styles.imagetype4} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType1,linkReource1)}} >
                        <Image source={{uri: backgroundImage1}} style={styles.imagetype4}>
                            {saleAble1?<View style={styles.maskContainer4}>
                              <Text numberOfLines={1} style={styles.titleText4}>{name1}</Text>
                              <Text style={styles.price4}>{price1}</Text>
                            </View>:null}
                        </Image>
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype4} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                        <Image source={{uri: backgroundImage2}} style={styles.imagetype4}>
                            {saleAble2?<View style={styles.maskContainer4}>
                             <Text numberOfLines={1} style={styles.titleText4}>{name2}</Text>
                             <Text style={styles.price4}>{price2}</Text>
                         </View>:null}
                        </Image>
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype4} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                        <Image source={{uri: backgroundImage3}} style={styles.imagetype4}>
                            {saleAble3?<View style={styles.maskContainer4}>
                              <Text numberOfLines={1} style={styles.titleText4}>{name3}</Text>
                              <Text style={styles.price4}>{price3}</Text>
                            </View>:null}
                        </Image>
                    </TouchableOpacity>
                </View>
            )
            break;
        case '2':
            return (
                <View style={{flexDirection: 'row',width:width,height: isModuleMargin=='1'?containerHeigth3+nullHeigth:containerHeigth3,backgroundColor: 'white'}}>
                    <TouchableOpacity style={styles.imagetype3} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType1,linkReource1)}} >
                        <Image source={{uri: backgroundImage1}} style={styles.imagetype3}>
                            {saleAble1?<View style={styles.maskContainer3}>
                              <Text style={styles.price3}>{price1}</Text>
                            </View>:null}
                        </Image>
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype3} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                        <Image source={{uri: backgroundImage2}} style={styles.imagetype3}>
                            {saleAble2?<View style={styles.maskContainer3}>
            					<Text style={styles.price3}>{price2}</Text>
            				</View>:null}
                        </Image>
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype3} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                        <Image source={{uri: backgroundImage3}} style={styles.imagetype3}>
                            {saleAble3?<View style={styles.maskContainer3}>
                              <Text style={styles.price3}>{price3}</Text>
                            </View>:null}
                        </Image>
                    </TouchableOpacity>
                </View>
            )
            break;
        case '3':
            return (
              <View style={{flexDirection: 'row',width:width,height: isModuleMargin=='1'?containerHeigth+nullHeigth:containerHeigth,backgroundColor: 'white'}}>
                  <View style={styles.subContainer}>
                    <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType1,linkReource1)}} >
                          <Image source={{uri: backgroundImage1}} style={styles.image}>
                              {saleAble1?<View style={styles.maskContainer1}>
                                  <Text numberOfLines={2} style={styles.titleText}>{name1}</Text>
                                  <Text style={styles.price}>{price1}</Text>
                              </View>:null}
                          </Image>
                      </TouchableOpacity>
                      <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                          <Image source={{uri: backgroundImage2}} style={styles.image}>
                              {saleAble2?<View style={styles.maskContainer1}>
                                  <Text numberOfLines={2} style={styles.titleText}>{name2}</Text>
                                  <Text style={styles.price}>{price2}</Text>
                              </View>:null}
                          </Image>
                      </TouchableOpacity>
                  </View>
                  <TouchableOpacity style={styles.imageBig} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                      <Image source={{uri: backgroundImage3}} style={styles.imageBig}>
                          {saleAble3?<View style={styles.maskContainer2}>
                              <Text numberOfLines={2} style={styles.titleText}>{name3}</Text>
                              <Text style={styles.price}>{price3}</Text>
                          </View>:null}
                      </Image>
                  </TouchableOpacity>
              </View>
            )
            break;
        case '4':
            return (
                <View style={{flexDirection: 'row',width:width,height: isModuleMargin=='1'?containerHeigth+nullHeigth:containerHeigth,backgroundColor: 'white'}}>
                    <TouchableOpacity onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType1,linkReource1)}} >
                        <View style={styles.subContainer}>
                              <Image source={{uri: backgroundImage1}} style={styles.imageBig}>
                                  {saleAble1?<View style={styles.maskContainer2}>
                                    <Text numberOfLines={2} style={styles.titleText}>{name1}</Text>
                                    <Text style={styles.price}>{price1}</Text>
                                  </View>:null}
                              </Image>
                        </View>
                    </TouchableOpacity>
                  <View style={styles.subContainer}>
                    <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                          <Image source={{uri: backgroundImage2}} style={styles.image}>
                                {saleAble2?<View style={styles.maskContainer1}>
                                    <Text numberOfLines={2} style={styles.titleText}>{name2}</Text>
                                    <Text style={styles.price}>{price2}</Text>
                                </View>:null}
                          </Image>
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                      <Image source={{uri: backgroundImage3}} style={styles.image}>
                         {saleAble3?<View style={styles.maskContainer1}>
                            <Text numberOfLines={2} style={styles.titleText}>{name3}</Text>
                            <Text style={styles.price}>{price3}</Text>
                          </View>:null}
                      </Image>
                    </TouchableOpacity>
                  </View>
                </View>
            )
            break;
      default:
        return null;
    }
  }
}

let {width, height} = Dimensions.get('window');
let containerHeigth = Math.ceil((468/750)*width);
let containerHeigth3 = Math.ceil(width/3);
let containerHeigth4 = Math.ceil((333/750)*width);
let maskHeight = 30;
let nullHeigth = 10;

let styles = StyleSheet.create({
    subContainer:{
        width:width / 2,
        flexDirection: 'column',
    },
    maskContainer1: {
        width: width/2,
        height: maskHeight,
        backgroundColor: 'rgba(0,0,0,0.3)',
        marginTop: containerHeigth/2-maskHeight,
        flexDirection: 'row',
        alignItems: 'center',
    },
    maskContainer2: {
        width: width/2,
        height: maskHeight,
        backgroundColor: 'rgba(0,0,0,0.3)',
        marginTop: containerHeigth-maskHeight,
        flexDirection: 'row',
        alignItems: 'center',
    },
    maskContainer3:{
        width: width/3,
        height: 24,
        backgroundColor: 'rgba(0,0,0,0.3)',
        marginTop: containerHeigth3-24,
        flexDirection: 'row',
        alignItems: 'center',
    },
    maskContainer4: {
        width: width/3,
        height: 40,
        backgroundColor: 'rgba(0,0,0,0.3)',
        marginTop: containerHeigth4-40,
    },
    imagetype3: {
        width:width/3 ,
        height:containerHeigth3,
    },
    imagetype4:{
        width:width/3,
        height:containerHeigth4,
    },
    image:{
        width:width/2,
        height: containerHeigth / 2,
    },
    imageBig:{
        width:width/2,
        height: containerHeigth,
    },
    titleText: {
        marginLeft: 10,
        color:'white',
        width : 80,
        fontSize: 12,
        textAlign :'left',
    },
    price: {
        color:'white',
        width : 80,
        fontSize: 12,
        textAlign :'right',
    },
    price3: {
        width:width/3 ,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 12,
        textAlign :'left',
    },
    titleText4: {
        width:width/3 ,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 12,
        textAlign :'left',
        marginTop: 4,
    },
    price4: {
        width:width/3 ,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 12,
        textAlign :'left',
        marginTop: 2,
    },
});