|
|
'use strict';
|
|
|
|
|
|
import React, {Component} from 'react';
|
|
|
import ReactNative, {
|
|
|
View,
|
|
|
Text,
|
|
|
Image,
|
|
|
ListView,
|
|
|
StyleSheet,
|
|
|
Dimensions,
|
|
|
TouchableOpacity,
|
|
|
} from 'react-native';
|
|
|
|
|
|
import Banner from '../../../common/components/Banner';
|
|
|
import SlicedImage from '../../../common/components/SlicedImage';
|
|
|
import AutoSizeImage from './AutoSizeImage';
|
|
|
import LoadingIndicator from '../../../common/components/LoadingIndicator';
|
|
|
import Prompt from './Prompt';
|
|
|
|
|
|
export default class CouponCenter extends Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_renderRow(rowData: object, sectionID: number, rowID: number) {
|
|
|
let data = rowData.get('data');
|
|
|
switch (rowData.get('templateName')) {
|
|
|
case 'carousel_banner':
|
|
|
case 'focus':
|
|
|
return (
|
|
|
<Banner
|
|
|
data={data}
|
|
|
width={width}
|
|
|
height={bannerHeight}
|
|
|
onPress={this.props.onPressBanner}
|
|
|
/>
|
|
|
);
|
|
|
case 'text':
|
|
|
return (
|
|
|
<Text style={styles.text}>{data}</Text>
|
|
|
);
|
|
|
case 'single_image':
|
|
|
let src = SlicedImage.getSlicedUrl(data.get('src'), 0, 0, 2);
|
|
|
return (
|
|
|
<TouchableOpacity
|
|
|
activeOpacity={0.8}
|
|
|
onPress={() => {
|
|
|
this.props.onPressImage && this.props.onPressImage(data.get('url'));
|
|
|
}}
|
|
|
>
|
|
|
<AutoSizeImage src={src}/>
|
|
|
</TouchableOpacity>
|
|
|
);
|
|
|
case 'getCoupon':
|
|
|
if(!data.get('couponID')){
|
|
|
return null;
|
|
|
}
|
|
|
let bg = SlicedImage.getSlicedUrl(data.get('image').get('src'), 0, 0, 2);
|
|
|
let optImage;
|
|
|
let resizeMode = 'contain';
|
|
|
let imageStyle = {};
|
|
|
if (data.get('status') == 1) {
|
|
|
optImage = require('../../images/click-txt.png');
|
|
|
resizeMode = 'contain';
|
|
|
let marginTop = (rightHeight - 27) / 2;
|
|
|
let marginLeft = (rightWidth - 26) / 2
|
|
|
imageStyle = {width: 26, height: 27, marginTop, marginLeft};
|
|
|
} else if (data.get('status') == 2) {
|
|
|
optImage = require('../../images/zero.png');
|
|
|
resizeMode = 'contain';
|
|
|
imageStyle = {marginTop: -9};
|
|
|
} else if (data.get('status') == 3) {
|
|
|
optImage = require('../../images/received.png');
|
|
|
resizeMode = 'contain';
|
|
|
imageStyle = {marginTop: -9};
|
|
|
}
|
|
|
return (
|
|
|
<Image source={{uri: bg}} style={styles.couponContainer}>
|
|
|
<TouchableOpacity
|
|
|
style={styles.couponLeft}
|
|
|
activeOpacity={0.8}
|
|
|
onPress={() => {
|
|
|
this.props.onPressCoupon && this.props.onPressCoupon(data.get('image').get('url'));
|
|
|
}}
|
|
|
>
|
|
|
</TouchableOpacity>
|
|
|
<TouchableOpacity
|
|
|
style={styles.couponRight}
|
|
|
activeOpacity={0.8}
|
|
|
onPress={() => {
|
|
|
if (data.get('status') == 1) {
|
|
|
this.props.onGetCoupon && this.props.onGetCoupon(data.get('couponID'));
|
|
|
} else {
|
|
|
this.props.onPressCoupon && this.props.onPressCoupon(data.get('image').get('url'));
|
|
|
}
|
|
|
}}
|
|
|
>
|
|
|
<Image source={optImage} resizeMode={resizeMode} style={[styles.rightImage, imageStyle]}/>
|
|
|
</TouchableOpacity>
|
|
|
</Image>
|
|
|
);
|
|
|
default:
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
let data = this.props.floors.toArray();
|
|
|
|
|
|
let errorMsg = this.props.error && this.props.error.message;
|
|
|
let errorCode = this.props.error && this.props.error.code;
|
|
|
let desc = errorMsg;
|
|
|
if (errorCode && errorCode == 401) {
|
|
|
|
|
|
} else {
|
|
|
let netError = errorMsg && (errorMsg.indexOf('Network request failed') != -1 || errorMsg.indexOf('Request timeout') != -1);
|
|
|
if (netError) {
|
|
|
desc = '网络异常!';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
<View style={styles.container}>
|
|
|
<ListView
|
|
|
enableEmptySections={true}
|
|
|
dataSource={this.dataSource.cloneWithRows(data)}
|
|
|
renderRow={this._renderRow}
|
|
|
/>
|
|
|
<LoadingIndicator
|
|
|
isVisible={this.props.isFetching}
|
|
|
/>
|
|
|
|
|
|
{this.props.showSuccessTip ? <Prompt
|
|
|
icon={require('../../images/hud_success.png')}
|
|
|
text={'领取成功'}
|
|
|
duration={800}
|
|
|
onPromptHidden={this.props.onPromptHidden}
|
|
|
/> : null}
|
|
|
|
|
|
{this.props.showNetErrorTip ? <Prompt
|
|
|
text={desc}
|
|
|
duration={800}
|
|
|
onPromptHidden={this.props.onNetPromptHidden}
|
|
|
/> : null}
|
|
|
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let {width, height} = Dimensions.get('window');
|
|
|
let bannerHeight = Math.ceil((310 / 640) * width);
|
|
|
let couponHeight = Math.ceil((180 / 640) * width);
|
|
|
let rightWidth = Math.ceil((110 / 640) * width);
|
|
|
let rightHeight = Math.ceil((180 / 110) * rightWidth);
|
|
|
|
|
|
let styles = StyleSheet.create({
|
|
|
container: {
|
|
|
flex: 1,
|
|
|
backgroundColor: 'white',
|
|
|
},
|
|
|
textContainer: {
|
|
|
|
|
|
},
|
|
|
text: {
|
|
|
fontFamily: 'helvetica',
|
|
|
fontSize: 18,
|
|
|
lineHeight: 48,
|
|
|
textAlign: 'center',
|
|
|
paddingBottom: (48 - 18) / 2,
|
|
|
},
|
|
|
couponContainer: {
|
|
|
width,
|
|
|
height: couponHeight,
|
|
|
flexDirection: 'row',
|
|
|
},
|
|
|
couponLeft: {
|
|
|
flex: 0.78,
|
|
|
},
|
|
|
couponRight: {
|
|
|
flex: 0.22,
|
|
|
// justifyContent: 'center',
|
|
|
// alignItems: 'center'
|
|
|
},
|
|
|
|
|
|
rightImage: {
|
|
|
width: rightWidth,
|
|
|
height: rightHeight,
|
|
|
// backgroundColor: 'red'
|
|
|
},
|
|
|
}); |
...
|
...
|
|