Authored by chenl

修复了限时特卖楼层的问题。review by luliang。

... ... @@ -3,6 +3,8 @@
import React, {Component} from 'react';
import ReactNative, {
View,
Image,
Text,
TouchableOpacity,
StyleSheet,
Dimensions,
... ... @@ -28,24 +30,66 @@ export default class Sale1T1L4R extends Component{
constructor(props) {
super(props);
this._caculateTimerState = this._caculateTimerState.bind(this);
this.state = {
remainTime : "",
remainHour : "00",
remainMinute : "00",
remainSecond : "00",
timeOut: true,
};
}
componentDidMount() {
this.timer = TimerMixin.setInterval(() => {
if(diffTime > 0){
diffTime = diffTime - 1;
this._caculateTimerState();
}
}, 1000);
}
componentWillUnmount() {
this.timer && TimerMixin.clearTimeout(this.timer);
this.timer && TimerMixin.clearInterval(this.timer);
}
_caculateTimerState() {
if(diffTime > 0){
let hour = parseInt(diffTime / (60 * 60), 10);
let minute = parseInt(diffTime % (60 * 60) / 60, 10);
let second = diffTime % 60;
this.setState({
remainHour: hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour),
remainMinute: minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute),
remainSecond: second < 0 ? '00' : (second < 10 ? ('0' + second) : second),
timeOut: false,
});
}
else{
this.setState({
remainHour: '00',
remainMinute: '00',
remainSecond: '00',
timeOut: true,
});
this.timer && TimerMixin.clearInterval(this.timer);
}
}
render(){
let data = this.props.data;
let banner = data.get("banner");
let banner = data.get("big_image");
let title = data.get("title");
let imglst = data.get("list");
//初始化时间,待测
//剩余时间
time = imglst.get(0).get("end_time");
diffTime = time - Date.parse(new Date()) / 1000;
let leftBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(0).get("src"), leftBigImageWidth, leftBigImageHeight, 2);
let rightTopBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(1).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
... ... @@ -53,8 +97,14 @@ export default class Sale1T1L4R extends Component{
let rightBottomBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(3).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
let rightBottomSmallImageUrl = SlicedImage.getSlicedUrl(imglst.get(4).get("src"), rightSmallImageWidth, rightSmallImageHeight, 2);
let containerHeight = 40 + leftBigImageHeight;
if(banner.toJS().length > 0){
containerHeight = containerHeight + bannerHeight;
}
return(
<View style={styles.container}>
<View style={[styles.container, {height: containerHeight}]}>
<HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')} onPressTitleMore={this.props.onPressTitleMore} />
<ImageSlider
... ... @@ -70,9 +120,18 @@ export default class Sale1T1L4R extends Component{
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(0).toJS())}>
<YH_Image style={styles.leftBigImage} url={leftBigImageUrl}/>
<Image style={styles.timerImage} source={require("../../images/ic_limit_times.png")}/>
<Text style={styles.timerText}>{remainTime}</Text>
<View style={styles.timerImageContainer}>
<Image style={styles.timerImage} source={require("../../images/home_sale_time.png")}/>
<Image source={require("../../images/home_sale_time_text.png")}/>
</View>
<View style={styles.timerTextContainer}>
<Text style={styles.timerText}>{this.state.remainHour}</Text>
<Text style={styles.timerTextSymbol}>:</Text>
<Text style={styles.timerText}>{this.state.remainMinute}</Text>
<Text style={styles.timerTextSymbol}>:</Text>
<Text style={styles.timerText}>{this.state.remainSecond}</Text>
</View>
</TouchableOpacity>
... ... @@ -102,6 +161,10 @@ export default class Sale1T1L4R extends Component{
};
let time = 0;
let diffTime = 0;
let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
... ... @@ -121,7 +184,6 @@ let styles = StyleSheet.create({
container: {
width: width,
height: 40 + bannerHeight + leftBigImageHeight,
backgroundColor: "#e5e5e5",
},
... ... @@ -143,15 +205,41 @@ let styles = StyleSheet.create({
height: leftBigImageHeight,
},
timerImage:{
timerImageContainer:{
width: leftBigImageWidth,
position: 'absolute',
top: 20,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timerText:{
timerImage:{
paddingRight: 10,
},
timerTextContainer:{
width: leftBigImageWidth,
position: 'absolute',
top: 50,
textAlign: 'center',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timerText:{
backgroundColor: '#ffffff',
padding: 1,
borderRadius: 2,
color: '#444444',
fontWeight: 'bold',
},
timerTextSymbol:{
paddingLeft: 4,
paddingRight: 4,
color: '#ffffff',
fontWeight: 'bold',
},
rightTopBigImageContainer: {
... ...
... ... @@ -36,6 +36,7 @@ import PopularSingleProduct from '../floor/PopularSingleProduct';
import ShopRecommend from '../floor/ShopRecommend';
import SixLinesFloor from '../floor/SixLinesFloor';
import LivePicture from '../floor/LivePicture';
import Sale1T1L4R from '../floor/Sale1T1L4R';
import SmallPic from '../floor/SmallPic';
import RecommendContentOne from '../floor/RecommendContentOne';
import RecommendContentTwo from '../floor/RecommendContentTwo';
... ... @@ -364,6 +365,15 @@ export default class Home extends Component {
/>
)
}
case 'sale-1t-1l-4r':{
return (
<Sale1T1L4R
data={rowData.get('data')}
onPressImageItem={this.props.onPressImageItem}
onPressTitleMore={this.props.onPressTitleMore}
/>
)
}
case 'vipUse':{
return (
<VipUserFloor
... ...