...
|
...
|
@@ -6,16 +6,25 @@ import { |
|
|
Dimensions,
|
|
|
Platform,
|
|
|
View,
|
|
|
Text,
|
|
|
Alert,
|
|
|
Image,
|
|
|
ListView,
|
|
|
NativeModules,
|
|
|
InteractionManager,
|
|
|
NativeAppEventEmitter,
|
|
|
TouchableOpacity,
|
|
|
PixelRatio,
|
|
|
} from 'react-native'
|
|
|
|
|
|
import {bindActionCreators} from 'redux';
|
|
|
import {connect} from 'react-redux';
|
|
|
import {Map} from 'immutable';
|
|
|
import * as brandStoreActions from '../reducers/brandStore/brandStoreActions';
|
|
|
import BrandStoreCenter from '../components/common/brandStoreHome/BrandStoreCenter';
|
|
|
import BrandStoreHeaderView from '../components/brandStore/brandStoreSubView/SessionHeader/BrandStoreHeaderView';
|
|
|
import CouponCell from '../components/brandStore/brandStoreSubView/Cells/CouponCell';
|
|
|
import BrandListCell from '../components/brandStore/brandStoreSubView/Cells/BrandListCell';
|
|
|
import BrandSwiper from '../components/brandStore/brandStoreSubView/Cells/BrandSwiper';
|
|
|
|
|
|
const actions = [
|
|
|
brandStoreActions,
|
...
|
...
|
@@ -43,23 +52,175 @@ function mapDispatchToProps(dispatch) { |
|
|
class BrandStoreContainer extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
|
|
|
let getSectionData = (dataBlob, sectionID) => {
|
|
|
return dataBlob[sectionID];
|
|
|
};
|
|
|
|
|
|
let getRowData = (dataBlob, sectionID, rowID) => {
|
|
|
return dataBlob[sectionID + ':' + rowID];
|
|
|
};
|
|
|
|
|
|
this.state = {
|
|
|
dataSource: new ListView.DataSource({
|
|
|
getSectionData: getSectionData, // 获取组中数据
|
|
|
getRowData: getRowData, // 获取行中的数据
|
|
|
rowHasChanged: (r1, r2) => r1 != r2,
|
|
|
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
|
|
|
})
|
|
|
};
|
|
|
|
|
|
this.loadDataFromJason();
|
|
|
this._onPressCollection = this._onPressCollection.bind(this);
|
|
|
this._onPressCoupon = this._onPressCoupon.bind(this);
|
|
|
this._onPressBrandItem= this._onPressBrandItem.bind(this);
|
|
|
this.onPressImage1 = this._onPressImage1.bind(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
this.props.actions.getShopsIntro();
|
|
|
// this.props.actions.getShopsIntro();
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
|
}
|
|
|
|
|
|
_onPressCollection(){
|
|
|
this.props.actions.onPressCollection();
|
|
|
}
|
|
|
_onPressCoupon(){
|
|
|
this.props.actions.onPressCoupon();
|
|
|
}
|
|
|
_onPressBrandItem(){
|
|
|
this.props.actions.onPressBrandItem();
|
|
|
}
|
|
|
_onPressImage1(){
|
|
|
|
|
|
}
|
|
|
loadDataFromJason() {
|
|
|
let jsonData = require('../image/Car.json');
|
|
|
let dataBlob = {},
|
|
|
sectionIDs = [],
|
|
|
rowIDs = [],
|
|
|
cars = [];
|
|
|
let datas = jsonData.data;
|
|
|
for (let i in datas) {
|
|
|
//step 1、把组数据放入sectionIDs数组中
|
|
|
sectionIDs.push(i);
|
|
|
//step 2、把组中内容放dataBlob对象中
|
|
|
dataBlob[i] = datas[i].title;
|
|
|
//step 3、取出该组中所有的车
|
|
|
cars = datas[i].cars;
|
|
|
//step 4记录每一行中的数据
|
|
|
rowIDs[i] = [];
|
|
|
//step 5、获取行中每一组数据
|
|
|
for (let j in cars) {
|
|
|
//把行号放入rowIDs中
|
|
|
rowIDs[i].push(j);
|
|
|
//把每一行中的内容放dataBlob对象中
|
|
|
dataBlob[i + ':' + j] = cars[j];
|
|
|
}
|
|
|
}
|
|
|
this.state = {
|
|
|
dataSource: this.state.dataSource.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs)
|
|
|
};
|
|
|
}
|
|
|
render() {
|
|
|
let {brandStore} = this.props;
|
|
|
let {shopId} = brandStore;
|
|
|
|
|
|
|
|
|
return (
|
|
|
<ListView
|
|
|
dataSource={this.state.dataSource}
|
|
|
renderRow={this.renderRow.bind(this)}
|
|
|
renderSectionHeader={this.renderSectionHeader.bind(this)}
|
|
|
renderHeader = {this.renderHeader.bind(this)}
|
|
|
contentContainerStyle={styles.listViewStyle}//设置cell的样式
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
// 每一行的数据
|
|
|
renderRow(rowData,sectionID,rowID,highlightRow) {
|
|
|
|
|
|
if (sectionID === '0') {
|
|
|
switch (rowID) {
|
|
|
case '0':
|
|
|
{
|
|
|
return (
|
|
|
<CouponCell
|
|
|
src={'aa'}
|
|
|
onPressCoupon={this._onPressCoupon}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
case '1':
|
|
|
{
|
|
|
return (
|
|
|
<BrandListCell
|
|
|
src={'aa'}
|
|
|
onPressBrandItem={this._onPressBrandItem}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
{
|
|
|
return (
|
|
|
<BrandSwiper
|
|
|
src={'aa'}
|
|
|
// onPressBrandItem={this._onPressBrandItem}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}else {
|
|
|
return (
|
|
|
<BrandStoreCenter />
|
|
|
<TouchableOpacity activeOpacity={0.5}>
|
|
|
<View style={styles.row}>
|
|
|
<Text style={styles.text}>
|
|
|
{rowData.name}
|
|
|
</Text>
|
|
|
</View>
|
|
|
</TouchableOpacity>
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 每一组中的数据
|
|
|
renderSectionHeader(sectionData, sectionID) {
|
|
|
|
|
|
//根据数据显示不同的header
|
|
|
switch (sectionData) {
|
|
|
case 'A':
|
|
|
{
|
|
|
return (
|
|
|
<View style={styles.headerViewStyle}>
|
|
|
<Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
{
|
|
|
return (
|
|
|
<View style={styles.headerViewStyle}>
|
|
|
<Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
|
|
|
</View>
|
|
|
);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
renderHeader(){
|
|
|
return(
|
|
|
<BrandStoreHeaderView
|
|
|
src={'aa'}
|
|
|
onPressCollection={this._onPressCollection}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -67,7 +228,54 @@ let styles = StyleSheet.create({ |
|
|
container: {
|
|
|
flex: 1,
|
|
|
},
|
|
|
|
|
|
separator: {
|
|
|
height: 0.5,
|
|
|
backgroundColor: 'rgba(255,255,255,0.5)',
|
|
|
},
|
|
|
listViewStyle:{
|
|
|
justifyContent: 'space-around',
|
|
|
flexDirection: 'row',
|
|
|
flexWrap: 'wrap',
|
|
|
alignItems:'flex-start'
|
|
|
},
|
|
|
rowStyle: {
|
|
|
flexDirection: 'row',
|
|
|
alignItems: 'center',
|
|
|
padding: 10,
|
|
|
borderBottomColor: 'grey',
|
|
|
borderBottomWidth: 1 / PixelRatio.get()
|
|
|
},
|
|
|
headerViewStyle: {
|
|
|
height: 64,
|
|
|
backgroundColor: 'blue',
|
|
|
justifyContent: 'center',
|
|
|
alignItems: 'center',
|
|
|
width: Dimensions.get('window').width,
|
|
|
},
|
|
|
row: {
|
|
|
justifyContent: 'center',
|
|
|
padding: 5,
|
|
|
margin: 3,
|
|
|
width: 150,
|
|
|
height: 200,
|
|
|
backgroundColor: '#F6F6F6',
|
|
|
alignItems: 'center',
|
|
|
borderWidth: 1,
|
|
|
borderRadius: 5,
|
|
|
borderColor: '#CCC'
|
|
|
},
|
|
|
text: {
|
|
|
flex: 1,
|
|
|
marginTop: 5,
|
|
|
fontWeight: 'bold'
|
|
|
},
|
|
|
list: {
|
|
|
marginTop:5,
|
|
|
justifyContent: 'space-around',
|
|
|
flexDirection: 'row',
|
|
|
flexWrap: 'wrap'
|
|
|
},
|
|
|
});
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(BrandStoreContainer); |
...
|
...
|
|