TripleImage.js 16 KB
import React, {Component } from 'react'
import {View, StyleSheet, Text, Dimensions,TouchableOpacity} from 'react-native';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';

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 = false;//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 = false;//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 = false;//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)}} >
                        <YH_Image url={backgroundImage1} style={styles.imagetype4}/>
                        {linkType1=='1'?<View style={styles.maskContainer4}>
    						<Text style={styles.titleText4} numberOfLines={1}>{name1}</Text>
                            <View style={styles.saleView}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble1?'red':'white',}}>{price1}</Text>
                                {saleAble1?<Text style={styles.deleteSale}>{sale1}</Text>:null}
                            </View>
    					</View>:null}
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype4} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                        <YH_Image url={backgroundImage2} style={styles.imagetype4}/>
                        {linkType2=='1'?<View style={styles.maskContainer4}>
    						<Text style={styles.titleText4} numberOfLines={1}>{name2}</Text>
                            <View style={styles.saleView}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble2?'red':'white',}}>{price2}</Text>
                                {saleAble2?<Text style={styles.deleteSale}>{sale2}</Text>:null}
                            </View>
    					</View>:null}
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype4} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                        <YH_Image url={backgroundImage3} style={styles.imagetype4}/>
                        {linkType3=='1'?<View style={styles.maskContainer4}>
    						<Text style={styles.titleText4} numberOfLines={1}>{name3}</Text>
                            <View style={styles.saleView}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble3?'red':'white',}}>{price3}</Text>
                                {saleAble3?<Text style={styles.deleteSale}>{sale3}</Text>:null}
                            </View>
    					</View>:null}
                    </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)}} >
                        <YH_Image url={backgroundImage1} style={styles.imagetype3}/>
                        {linkType1=='1'?<View style={styles.maskContainer3}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble1?'red':'white',}}>{price1}</Text>
                                {saleAble1?<Text style={styles.deleteSale}>{sale1}</Text>:null}
                            </View>:null}
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype3} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                        <YH_Image url={backgroundImage2} style={styles.imagetype3}/>
                        {linkType2=='1'?<View style={styles.maskContainer3}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble2?'red':'white',}}>{price2}</Text>
                                {saleAble2?<Text style={styles.deleteSale}>{sale2}</Text>:null}
                            </View>:null}
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.imagetype3} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                        <YH_Image url={backgroundImage3} style={styles.imagetype3}/>
                        {linkType3=='1'?<View style={styles.maskContainer3}>
    						    <Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble3?'red':'white',}}>{price3}</Text>
                                {saleAble3?<Text style={styles.deleteSale}>{sale3}</Text>:null}
                            </View>:null}
                    </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)}} >
                          <YH_Image url={backgroundImage1} style={styles.image}/>
                          {linkType1=='1'?<View style={styles.maskContainer1}>
                             <Text style={styles.titleText} numberOfLines={2}>{name1}</Text>
                             <View style={{backgroundColor: 'transparent',flexDirection: 'row',marginRight: 10}}>
                                 <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble1?'red':'white'}}>{price1}</Text>
                                  {saleAble1?<Text style={styles.deleteSale3}>{sale1}</Text>:null}
                              </View>
                         </View>:null}
                      </TouchableOpacity>
                      <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                          <YH_Image url={backgroundImage2} style={styles.image}/>
                          {linkType2=='1'?<View style={styles.maskContainer1}>
                             <Text style={styles.titleText} numberOfLines={2}>{name2}</Text>
                             <View style={{backgroundColor: 'transparent',flexDirection: 'row',marginRight: 10}}>
                                 <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble2?'red':'white'}}>{price2}</Text>
                                  {saleAble2?<Text style={styles.deleteSale3}>{sale2}</Text>:null}
                              </View>
                         </View>:null}
                      </TouchableOpacity>
                  </View>
                  <TouchableOpacity style={styles.imageBig} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                      <YH_Image url={backgroundImage3} style={styles.imageBig}/>
                      {linkType3=='1'?<View style={styles.maskContainer2}>
                         <Text style={styles.titleText} numberOfLines={2}>{name3}</Text>
                         <View style={{backgroundColor: 'transparent',flexDirection: 'row'}}>
                             <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble3?'red':'white'}}>{price3}</Text>
                              {saleAble3?<Text style={styles.deleteSale3}>{sale3}</Text>:null}
                          </View>
                     </View>:null}
                  </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}>
                              <YH_Image url={backgroundImage1} style={styles.imageBig}/>
                              {linkType1=='1'?<View style={styles.maskContainer2}>
                                 <Text style={styles.titleText} numberOfLines={2}>{name1}</Text>
                                 <View style={{backgroundColor: 'transparent',flexDirection: 'row'}}>
                                     <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble1?'red':'white'}}>{price1}</Text>
                                      {saleAble1?<Text style={styles.deleteSale3}>{sale1}</Text>:null}
                                  </View>
                             </View>:null}
                        </View>
                    </TouchableOpacity>
                  <View style={styles.subContainer}>
                    <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2)}} >
                          <YH_Image url={backgroundImage2} style={styles.image}/>
                          {linkType2=='1'?<View style={styles.maskContainer1}>
                             <Text style={styles.titleText} numberOfLines={2}>{name2}</Text>
                             <View style={{backgroundColor: 'transparent',flexDirection: 'row',marginRight: 10}}>
                                 <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble2?'red':'white'}}>{price2}</Text>
                                  {saleAble2?<Text style={styles.deleteSale3}>{sale2}</Text>:null}
                              </View>
                         </View>:null}
                    </TouchableOpacity>
                    <TouchableOpacity style={styles.image} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType3,linkReource3)}} >
                      <YH_Image url={backgroundImage3} style={styles.image}/>
                      {linkType3=='1'?<View style={styles.maskContainer1}>
                         <Text style={styles.titleText} numberOfLines={2}>{name3}</Text>
                         <View style={{backgroundColor: 'transparent',flexDirection: 'row',marginRight: 10}}>
                             <Text style={{fontSize: 12,backgroundColor: 'transparent',color: saleAble3?'red':'white'}}>{price3}</Text>
                              {saleAble3?<Text style={styles.deleteSale3}>{sale3}</Text>:null}
                          </View>
                     </View>:null}
                    </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: {
        position: 'absolute',
        width: width/2,
        height: maskHeight,
        backgroundColor: 'rgba(0,0,0,0.3)',
        top: containerHeigth/2-maskHeight,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
    },
    maskContainer2: {
        position: 'absolute',
        width: width/2,
        height: maskHeight,
        backgroundColor: 'rgba(0,0,0,0.3)',
        top: containerHeigth-maskHeight,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-around',
    },
    maskContainer3:{
        position: 'absolute',
        width: width/3,
        height: 24,
        backgroundColor: 'rgba(0,0,0,0.3)',
        top: containerHeigth3-24,
        flexDirection: 'row',
        alignItems: 'center',
        flexDirection: 'row',
    },
    maskContainer4: {
        position: 'absolute',
        width: width/3,
        height: 40,
        backgroundColor: 'rgba(0,0,0,0.3)',
        top: 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: {
        color:'white',
        width : 80,
        fontSize: 11,
        textAlign :'left',
        backgroundColor: 'transparent',
        fontWeight: 'bold',
        marginLeft: 10,
    },
    price: {
        color:'white',
        width : 80,
        fontSize: 11,
        textAlign :'right',
    },
    price3: {
        width:width/3 ,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 11,
        textAlign :'left',
    },
    titleText4: {
        width:width/3 -10,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 11,
        textAlign :'left',
        marginTop: 4,
        fontWeight: 'bold',
    },
    price4: {
        width:width/3 ,
        height:maskHeight / 2,
        color: 'white',
        marginLeft: 10,
        fontSize: 11,
        textAlign : 'left',
        marginTop: 2,
    },
    deleteSale: {
        marginLeft: 2,
        marginTop: 4,
        fontSize: 11,
        backgroundColor: 'transparent',
        color: 'white',
        textDecorationLine: 'line-through',
    },

    deleteSale3: {
        marginLeft: 2,
        marginTop: 4,
        fontSize: 11,
        backgroundColor: 'transparent',
        color: 'white',
        textDecorationLine: 'line-through',
    },

    saleView:{
		flexDirection: 'row',
    },
});