Authored by 孙凯

add 品牌 列表 筛选 review by qiangbing

@@ -22,7 +22,7 @@ export default class ScreenSubCell extends React.Component { @@ -22,7 +22,7 @@ export default class ScreenSubCell extends React.Component {
22 } 22 }
23 23
24 render() { 24 render() {
25 - let resource = this.props.resource?this.props.resource.toJS():null; 25 + let resource = this.props.resource?this.props.resource:null;
26 let keys = this.props.keys?this.props.keys:null; 26 let keys = this.props.keys?this.props.keys:null;
27 if (!resource) { 27 if (!resource) {
28 return null; 28 return null;
@@ -66,7 +66,7 @@ export default class ScreenCategory extends Component { @@ -66,7 +66,7 @@ export default class ScreenCategory extends Component {
66 let {resource} = this.props; 66 let {resource} = this.props;
67 let key = resource?resource.get('key'):null; 67 let key = resource?resource.get('key'):null;
68 return( 68 return(
69 - <ScreenSubCell resource={rowData} keys={key} selectItem={this.selectItem}/> 69 + <ScreenSubCell resource={rowData?rowData.toJS():''} keys={key} selectItem={this.selectItem}/>
70 ); 70 );
71 } 71 }
72 72
@@ -3,7 +3,8 @@ @@ -3,7 +3,8 @@
3 3
4 import React, {Component} from 'react'; 4 import React, {Component} from 'react';
5 import ScreenSubCell from '../cell/ScreenSubCell'; 5 import ScreenSubCell from '../cell/ScreenSubCell';
6 - 6 +import Immutable, {Map} from 'immutable';
  7 +import IndexListView from '../../../classify/components/brand/IndexListView'
7 import ReactNative, { 8 import ReactNative, {
8 View, 9 View,
9 Text, 10 Text,
@@ -20,18 +21,33 @@ export default class ScreenSub extends Component { @@ -20,18 +21,33 @@ export default class ScreenSub extends Component {
20 21
21 constructor(props) { 22 constructor(props) {
22 super(props); 23 super(props);
23 - 24 + this.scrollToSection = this.scrollToSection.bind(this);
24 this.renderRow = this.renderRow.bind(this); 25 this.renderRow = this.renderRow.bind(this);
  26 + this.renderSectionHeader = this.renderSectionHeader.bind(this);
25 this.dataSource = new ListView.DataSource({ 27 this.dataSource = new ListView.DataSource({
26 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), 28 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
  29 + sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
27 }); 30 });
28 31
29 } 32 }
30 33
  34 + scrollToSection(index,sectionID){
  35 + console.log(sectionID);
  36 + }
  37 +
  38 + renderSectionHeader(sectionData, sectionID) {
  39 + return(
  40 + <View style={styles.Header}>
  41 + <Text style={styles.HeaderText}>{sectionID}</Text>
  42 + </View>
  43 + );
  44 + }
  45 +
31 renderRow(rowData,sectionID,rowID,highlightRow) { 46 renderRow(rowData,sectionID,rowID,highlightRow) {
32 let {resource} = this.props; 47 let {resource} = this.props;
33 let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null; 48 let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null;
34 let key = obj?obj.get('key'):null; 49 let key = obj?obj.get('key'):null;
  50 +
35 return( 51 return(
36 <ScreenSubCell resource={rowData} keys={key} selectItem={this.props.selectItem}/> 52 <ScreenSubCell resource={rowData} keys={key} selectItem={this.props.selectItem}/>
37 ); 53 );
@@ -40,19 +56,42 @@ export default class ScreenSub extends Component { @@ -40,19 +56,42 @@ export default class ScreenSub extends Component {
40 56
41 render() { 57 render() {
42 let {resource} = this.props; 58 let {resource} = this.props;
  59 +
43 let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null; 60 let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null;
  61 + let key = obj?obj.get('key'):null;
44 let list = obj?obj.get('list'):null; 62 let list = obj?obj.get('list'):null;
  63 + if (key == 'brand') {
  64 + let dataSourceList = list?list.toJS():{};
  65 + let keyList = list.keySeq()?list.keySeq().toJS():[];
  66 + keyList.shift();
  67 + keyList = Immutable.fromJS(keyList);
  68 + return (
  69 + <View style={styles.container}>
  70 + <ListView
  71 + ref='brandList'
  72 + contentContainerStyle={styles.contentContainer}
  73 + enableEmptySections={true}
  74 + dataSource={this.dataSource.cloneWithRowsAndSections(dataSourceList)}
  75 + renderRow={this.renderRow}
  76 + renderSectionHeader={this.renderSectionHeader}
  77 + />
  78 + <IndexListView dataSource={keyList.toArray()} onLetterPress={this.scrollToSection}/>
  79 + </View>
  80 + );
  81 + }else {
  82 + let dataSourceList = list?list.toJS():[];
45 return ( 83 return (
46 <View style={styles.container}> 84 <View style={styles.container}>
47 {list?<ListView 85 {list?<ListView
48 ref='ScreenSubList' 86 ref='ScreenSubList'
49 enableEmptySections={true} 87 enableEmptySections={true}
50 - dataSource={this.dataSource.cloneWithRows(list.toArray())} 88 + dataSource={this.dataSource.cloneWithRows(dataSourceList)}
51 renderRow={this.renderRow} 89 renderRow={this.renderRow}
52 />:null} 90 />:null}
53 </View> 91 </View>
54 ); 92 );
55 } 93 }
  94 + }
56 } 95 }
57 96
58 let {width, height} = Dimensions.get('window'); 97 let {width, height} = Dimensions.get('window');
@@ -61,4 +100,15 @@ let styles = StyleSheet.create({ @@ -61,4 +100,15 @@ let styles = StyleSheet.create({
61 flex: 1, 100 flex: 1,
62 backgroundColor: '#f4f4f4', 101 backgroundColor: '#f4f4f4',
63 }, 102 },
  103 + HeaderText: {
  104 + marginLeft: 10,
  105 + fontSize: 18,
  106 + fontWeight: 'bold',
  107 + color: 'rgb(146, 146, 146)'
  108 + },
  109 + Header: {
  110 + justifyContent: 'center',
  111 + width: width,
  112 + height: 30,
  113 + }
64 }); 114 });
@@ -9,13 +9,17 @@ const { @@ -9,13 +9,17 @@ const {
9 9
10 10
11 export function updateDataSource(data) { 11 export function updateDataSource(data) {
  12 + let key = data?data.key:'';
  13 + let json = data;
  14 + if (key == 'brand') {
  15 + json = processData(data);
  16 + }
12 return { 17 return {
13 type: SET_DATASOURCE_SUB, 18 type: SET_DATASOURCE_SUB,
14 - payload: data 19 + payload: json
15 }; 20 };
16 } 21 }
17 22
18 -  
19 export function setSelectItem(json) { 23 export function setSelectItem(json) {
20 return { 24 return {
21 type: SET_SELECT_ITEM, 25 type: SET_SELECT_ITEM,
@@ -43,3 +47,17 @@ function parseList(data,filterSub) { @@ -43,3 +47,17 @@ function parseList(data,filterSub) {
43 } 47 }
44 return list; 48 return list;
45 } 49 }
  50 +
  51 +function processData(data){
  52 + let list = data?data.list:[];
  53 + let latterObject={};
  54 + list.forEach((item, i) => {
  55 + let key = item.brand_alif?item.brand_alif:item.name;
  56 + if (!latterObject[key]) {
  57 + latterObject[key] = [];
  58 + }
  59 + latterObject[key].push(item);
  60 + });
  61 + data.list = latterObject;
  62 + return data;
  63 +}