Authored by chenl

增加Sale1t1l4r楼层,review by luliang。

  1 +'use strict';
  2 +
  3 +import React, {Component} from 'react';
  4 +import ReactNative, {
  5 + View,
  6 + TouchableOpacity,
  7 + StyleSheet,
  8 + Dimensions,
  9 +} from 'react-native';
  10 +import Immutable, {Map} from 'immutable';
  11 +import TimerMixin from 'react-timer-mixin';
  12 +
  13 +
  14 +import SlicedImage from '../../../common/components/SlicedImage';
  15 +import YH_Image from '../../../common/components/YH_Image';
  16 +
  17 +import HeadTitleCell from '../cell/HeadTitleCell';
  18 +import ImageSlider from '../cell/ImageSlider';
  19 +
  20 +
  21 +/**
  22 + * 首页 sale 楼层,
  23 + * 这个楼层是标题、banner、左带倒计时大图,右四小图
  24 + **/
  25 +export default class Sale1T1L4R extends Component{
  26 +
  27 +
  28 + constructor(props) {
  29 + super(props);
  30 +
  31 + this.state = {
  32 + remainTime : "",
  33 + };
  34 + }
  35 +
  36 + componentWillUnmount() {
  37 + this.timer && TimerMixin.clearTimeout(this.timer);
  38 + }
  39 +
  40 +
  41 + render(){
  42 +
  43 + let data = this.props.data;
  44 + let banner = data.get("banner");
  45 + let title = data.get("title");
  46 + let imglst = data.get("list");
  47 +
  48 + //初始化时间,待测
  49 +
  50 + let leftBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(0).get("src"), leftBigImageWidth, leftBigImageHeight, 2);
  51 + let rightTopBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(1).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
  52 + let rightTopSmallImageUrl = SlicedImage.getSlicedUrl(imglst.get(2).get("src"), rightSmallImageWidth, rightSmallImageHeight, 2);
  53 + let rightBottomBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(3).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
  54 + let rightBottomSmallImageUrl = SlicedImage.getSlicedUrl(imglst.get(4).get("src"), rightSmallImageWidth, rightSmallImageHeight, 2);
  55 +
  56 + return(
  57 + <View style={styles.container}>
  58 + <HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')} />
  59 +
  60 + <ImageSlider
  61 + resource={banner}
  62 + sliderWidth={width}
  63 + sliderHeight={bannerHeight}
  64 + onPressSlideItem={this.props.onPressSlideItem}
  65 + />
  66 +
  67 + <View style={styles.imageContainer}>
  68 +
  69 + <TouchableOpacity style={styles.leftBigImageContainer} activeOpacity={1}
  70 + onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(0).toJS())}>
  71 + <YH_Image style={styles.leftBigImage} url={leftBigImageUrl}/>
  72 +
  73 + <Image style={styles.timerImage} source={require("../../images/ic_limit_times.png")}/>
  74 +
  75 + <Text style={styles.timerText}>{remainTime}</Text>
  76 +
  77 + </TouchableOpacity>
  78 +
  79 + <TouchableOpacity style={styles.rightTopBigImageContainer} activeOpacity={1}
  80 + onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(1).toJS())}>
  81 + <YH_Image style={styles.rightTopBigImage} url={rightTopBigImageUrl}/>
  82 + </TouchableOpacity>
  83 +
  84 + <TouchableOpacity style={styles.rightTopSmallImageContainer} activeOpacity={1}
  85 + onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(2).toJS())}>
  86 + <YH_Image style={styles.rightTopSmallImage} url={rightTopSmallImageUrl}/>
  87 + </TouchableOpacity>
  88 +
  89 + <TouchableOpacity style={styles.rightBottomBigImageContainer} activeOpacity={1}
  90 + onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(3).toJS())}>
  91 + <YH_Image style={styles.rightBottomBigImage} url={rightBottomBigImageUrl}/>
  92 + </TouchableOpacity>
  93 +
  94 + <TouchableOpacity style={styles.rightBottomSmallImageContainer} activeOpacity={1}
  95 + onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(4).toJS())}>
  96 + <YH_Image style={styles.rightBottomSmallImage} url={rightBottomSmallImageUrl}/>
  97 + </TouchableOpacity>
  98 + </View>
  99 + </View>
  100 + );
  101 + }
  102 +
  103 +};
  104 +
  105 +let {width} = Dimensions.get('window');
  106 +const DEVICE_WIDTH_RATIO = width / 320;
  107 +
  108 +let bannerHeight = Math.floor(width / 3);
  109 +
  110 +let leftBigImageWidth = width * 310 / 740;
  111 +let leftBigImageHeight = leftBigImageWidth * 422 / 310;
  112 +
  113 +let rightBigImageWidth = width * 330 / 740;
  114 +let rightBigImageHeight = rightBigImageWidth * 210 / 330;
  115 +
  116 +let rightSmallImageWidth = width * 100 / 740;
  117 +let rightSmallImageHeight = rightSmallImageWidth * 210 / 100;
  118 +
  119 +
  120 +let styles = StyleSheet.create({
  121 +
  122 + container: {
  123 + width: width,
  124 + backgroundColor: "#e5e5e5",
  125 + },
  126 +
  127 + imageContainer: {
  128 + width: width,
  129 + height: 422 * DEVICE_WIDTH_RATIO,
  130 + },
  131 +
  132 + leftBigImageContainer: {
  133 + position: 'absolute',
  134 + top: 0,
  135 + left: 0,
  136 + width: leftBigImageWidth,
  137 + height: leftBigImageHeight,
  138 + },
  139 +
  140 + leftBigImage: {
  141 + width: leftBigImageWidth,
  142 + height: leftBigImageHeight,
  143 + },
  144 +
  145 + timerImage:{
  146 + position: 'absolute',
  147 + top: 20,
  148 + },
  149 +
  150 + timerText:{
  151 + position: 'absolute',
  152 + top: 50,
  153 + textAlign: 'center',
  154 + },
  155 +
  156 + rightTopBigImageContainer: {
  157 + position: 'absolute',
  158 + top: 0,
  159 + left: leftBigImageWidth,
  160 + width: rightBigImageWidth,
  161 + height: rightBigImageHeight,
  162 + },
  163 +
  164 + rightTopBigImage: {
  165 + width: rightBigImageWidth,
  166 + height: rightBigImageHeight,
  167 + },
  168 +
  169 + rightTopSmallImageContainer: {
  170 + position: 'absolute',
  171 + top: 0,
  172 + left: leftBigImageWidth,
  173 + width: rightSmallImageWidth,
  174 + height: rightSmallImageHeight,
  175 + },
  176 +
  177 + rightTopSmallImage: {
  178 + width: rightSmallImageWidth,
  179 + height: rightSmallImageHeight,
  180 + },
  181 +
  182 + rightBottomBigImageContainer: {
  183 + position: 'absolute',
  184 + top: rightBigImageHeight,
  185 + left: leftBigImageWidth,
  186 + width: rightBigImageWidth,
  187 + height: rightBigImageHeight,
  188 + marginTop: 2,
  189 + },
  190 +
  191 + rightBottomBigImage: {
  192 + width: rightBigImageWidth,
  193 + height: rightBigImageHeight,
  194 + },
  195 +
  196 + rightBottomSmallImageContainer: {
  197 + position: 'absolute',
  198 + top: rightBigImageHeight,
  199 + left: leftBigImageWidth + rightBigImageWidth,
  200 + width: rightSmallImageWidth,
  201 + height: rightSmallImageHeight,
  202 + marginTop: 2,
  203 + },
  204 +
  205 + rightBottomBigImage: {
  206 + width: rightSmallImageWidth,
  207 + height: rightSmallImageHeight,
  208 + },
  209 +
  210 +
  211 +
  212 +
  213 +});
  214 +