...
|
...
|
@@ -4,73 +4,107 @@ import React, { Component } from 'react'; |
|
|
import { Dimensions, ListView, Image, StyleSheet, View ,Text, TouchableOpacity} from 'react-native';
|
|
|
import { Immutable } from 'immutable';
|
|
|
import ProductCell from './cell/productCell';
|
|
|
import Focus from './floor/Focus';
|
|
|
|
|
|
const DEVICE_WIDTH_RATIO = Dimensions.get('window').width / 375;
|
|
|
|
|
|
export default class HaggleList extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {categoryType:0};
|
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
this._changeCategory = this._changeCategory.bind(this);
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
|
|
|
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_renderRow(rowData, sectionID, rowID) {
|
|
|
_renderResourceInfoListRow(item) {
|
|
|
if (item.get('template_name') === 'focus' && item.get('data')) {
|
|
|
return (
|
|
|
<ProductCell
|
|
|
key={'row' + rowID}
|
|
|
rowID={rowID}
|
|
|
data={rowData}
|
|
|
onPressProduct={this.props.onPressProduct}
|
|
|
firstHaggle={this.props.firstHaggle}
|
|
|
continueHaggle={this.props.continueHaggle}
|
|
|
onStop = {this.props.onStop && this.props.onStop(this.state.categoryType)}
|
|
|
<View style={styles.topImageView}>
|
|
|
<Focus
|
|
|
data={item.get('data')}
|
|
|
height={121}
|
|
|
resourceJumpWithUrl={this.props.resourceJumpWithUrl}
|
|
|
/>
|
|
|
</View>
|
|
|
|
|
|
);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
_renderRow(rowData, sectionID, rowID) {
|
|
|
if(sectionID === 'resourceInfoList'){
|
|
|
return this._renderResourceInfoListRow(rowData)
|
|
|
}else if (sectionID === 'productList') {
|
|
|
return (
|
|
|
<ProductCell
|
|
|
key={'row' + rowID}
|
|
|
rowID={rowID}
|
|
|
data={rowData}
|
|
|
onPressProduct={this.props.onPressProduct}
|
|
|
firstHaggle={this.props.firstHaggle}
|
|
|
continueHaggle={this.props.continueHaggle}
|
|
|
onStop = {this.props.onStop}
|
|
|
/>
|
|
|
);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_changeCategory(index) {
|
|
|
if (index == this.state.categoryType) {
|
|
|
let {
|
|
|
categoryType,
|
|
|
} = this.props;
|
|
|
|
|
|
if (index == categoryType) {
|
|
|
return
|
|
|
}
|
|
|
console.log(this.state.categoryType);
|
|
|
this.setState({categoryType:index});
|
|
|
|
|
|
this.props.onPressCategory && this.props.onPressCategory(index);
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
let {
|
|
|
data,
|
|
|
categoryType,
|
|
|
resourceInfo,
|
|
|
} = this.props;
|
|
|
|
|
|
let productList = data.list ? data.list.toArray() : [];
|
|
|
let color = this.state.categoryType == 0 ? '#444444' : '#b0b0b0';
|
|
|
let subcolor = this.state.categoryType == 1 ? '#444444' : '#b0b0b0';
|
|
|
|
|
|
let productList = data.list ? data.list.toArray() : [];
|
|
|
let color = categoryType == 0 ? '#444444' : '#b0b0b0';
|
|
|
let subcolor = categoryType == 1 ? '#444444' : '#b0b0b0';
|
|
|
let dataSource = null;
|
|
|
if (categoryType == 0) {
|
|
|
dataSource = {
|
|
|
resourceInfoList: resourceInfo.resourceList ? resourceInfo.resourceList.toArray() : [],
|
|
|
productList: data.list ? data.list.toArray() : [],
|
|
|
}
|
|
|
}else {
|
|
|
dataSource = {
|
|
|
productList: data.list ? data.list.toArray() : [],
|
|
|
}
|
|
|
}
|
|
|
return (
|
|
|
<View style={styles.container}>
|
|
|
|
|
|
{this.state.categoryType == 0 ? <View style={styles.topImageView}>
|
|
|
<Image style={styles.topImageView} source={{uri:'https://cdn.yoho.cn/app/yohogain/invite/banner.jpg'}} resizeMode={'contain'}/>
|
|
|
</View>
|
|
|
: null }
|
|
|
|
|
|
<ListView
|
|
|
ref={(c) => {
|
|
|
this.listView = c;
|
|
|
}}
|
|
|
contentContainerStyle={styles.contentContainer}
|
|
|
enableEmptySections={true}
|
|
|
dataSource={this.dataSource.cloneWithRows(productList)}
|
|
|
renderRow={this._renderRow}
|
|
|
renderFooter={this._renderFooter}
|
|
|
|
|
|
onEndReached={() => {
|
|
|
if (productList.size !== 0) {
|
|
|
this.props.onEndReached && this.props.onEndReached(this.state.categoryType);
|
|
|
}
|
|
|
}}/>
|
|
|
<ListView
|
|
|
ref={(c) => {
|
|
|
this.listView = c;
|
|
|
}}
|
|
|
enableEmptySections={true}
|
|
|
contentContainerStyle={styles.contentContainer}
|
|
|
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
|
|
|
renderRow={this._renderRow}
|
|
|
renderHeader={this._renderHeader}
|
|
|
renderFooter={this._renderFooter}
|
|
|
onEndReached={() => {
|
|
|
if (productList.size !== 0) {
|
|
|
this.props.onEndReached && this.props.onEndReached(categoryType);
|
|
|
}
|
|
|
}}/>
|
|
|
|
|
|
<View style={styles.bottomView}>
|
|
|
<TouchableOpacity activeOpacity={1} style={styles.textItemStyle} onPress={() => {
|
...
|
...
|
@@ -78,7 +112,7 @@ _renderRow(rowData, sectionID, rowID) { |
|
|
}}>
|
|
|
<Text style={[styles.textsStyle, {color: color}]}>砍价商品</Text>
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
<View style={styles.separator}/>
|
|
|
<TouchableOpacity activeOpacity={1} style={styles.textItemStyle} onPress={() => {
|
|
|
this._changeCategory && this._changeCategory(1);
|
|
|
}}>
|
...
|
...
|
@@ -100,7 +134,7 @@ let styles = StyleSheet.create({ |
|
|
},
|
|
|
topImageView: {
|
|
|
width: width,
|
|
|
height: 118 * DEVICE_WIDTH_RATIO,
|
|
|
height: 121 * DEVICE_WIDTH_RATIO,
|
|
|
},
|
|
|
|
|
|
contentContainer: {
|
...
|
...
|
@@ -116,7 +150,10 @@ let styles = StyleSheet.create({ |
|
|
bottom: 0,
|
|
|
flexDirection: 'row',
|
|
|
backgroundColor: 'white',
|
|
|
borderTopColor: '#e0e0e0',
|
|
|
borderTopWidth: 1,
|
|
|
},
|
|
|
|
|
|
textItemStyle: {
|
|
|
width: width/2,
|
|
|
height: 50 * DEVICE_WIDTH_RATIO,
|
...
|
...
|
@@ -132,6 +169,11 @@ let styles = StyleSheet.create({ |
|
|
height: 50 * DEVICE_WIDTH_RATIO,
|
|
|
backgroundColor: '#f0f0f0'
|
|
|
},
|
|
|
|
|
|
topLineSeparator: {
|
|
|
width:width,
|
|
|
height: 1,
|
|
|
bottom: 55,
|
|
|
backgroundColor: '#f0f0f0'
|
|
|
},
|
|
|
})
|
|
|
; |
...
|
...
|
|