ScreenSub.js
5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
'use strict';
import React, {Component} from 'react';
import ScreenSubCell from '../cell/ScreenSubCell';
import Immutable, {Map} from 'immutable';
import IndexListView from './IndexListView'
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
Platform,
} from 'react-native';
export default class ScreenSub extends Component {
constructor(props) {
super(props);
this.scrollToSection = this.scrollToSection.bind(this);
this.renderRow = this.renderRow.bind(this);
this.renderSectionHeader = this.renderSectionHeader.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
}
scrollToSection(index,sectionID){
let {resource} = this.props;
let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null;
let key = obj?obj.get('key'):null;
let list = obj?obj.get('list'):null;
let keyLists = obj?obj.get('keyList'):null;
let specialList = obj?obj.get('specialList'):null;
if (key == 'brand') {
let dataSourceList = list?list.toJS():{};
let keyList = keyLists?keyLists.toJS():[];
let object = specialList?specialList.toJS():[];
if (object && object.length>0) {
keyList.unshift('#');
}
let y = 30 + 40;
for (var i = 0; i < keyList.length; i++) {
if (sectionID == keyList[i]) {
break;
}
let count = 0;
if (keyList[i] == '#') {
count = object.length;
}else {
count = dataSourceList[keyList[i]].length;
}
y = y + 30 + 40 * count;
}
this.refs.brandList && this.refs.brandList.scrollTo({x: 0, y: y, animated: false});
}
}
renderSectionHeader(sectionData, sectionID) {
let title = sectionID;
if (sectionID == '特殊') {
title = '#';
}
return(
<View style={styles.Header}>
<Text style={styles.HeaderText}>{title}</Text>
</View>
);
}
renderRow(rowData,sectionID,rowID,highlightRow) {
let {resource} = this.props;
let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null;
let key = obj?obj.get('key'):null;
return(
<ScreenSubCell resource={rowData} keys={key} selectItem={this.props.selectItem}/>
);
}
render() {
let {resource} = this.props;
let obj = resource&&resource.get('filterSub')?resource.get('filterSub'):null;
let key = obj?obj.get('key'):null;
let list = obj?obj.get('list'):null;
if (key == 'brand') {
let object = obj?obj.toJS():null;
let keyList = obj?obj.get('keyList'):null;
let keyLists = keyList?keyList.toJS():[];
let allObj = object?object.allObj:null;
let specialList = object?object.specialList:null;
let dataSourceList = list?list.toJS():{};
let dataSource = {};
if (specialList && specialList.length>0) {
keyLists.unshift('#');
dataSource = {
所有品牌: [allObj],
特殊: specialList,
...dataSourceList,
};
}else {
dataSource = {
所有品牌: [allObj],
...dataSourceList,
};
}
let ketList_new = Immutable.fromJS(keyLists);
return (
<View style={styles.container}>
<ListView
ref='brandList'
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this.renderRow}
renderSectionHeader={this.renderSectionHeader}
/>
<IndexListView dataSource={ketList_new.toArray()} onLetterPress={this.scrollToSection}/>
</View>
);
}else {
let dataSourceList = list?list.toJS():[];
return (
<View style={styles.container}>
{list?<ListView
ref='ScreenSubList'
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(dataSourceList)}
renderRow={this.renderRow}
/>:null}
</View>
);
}
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f4f4f4',
},
HeaderText: {
marginLeft: 10,
fontSize: 18,
fontWeight: 'bold',
color: 'rgb(146, 146, 146)'
},
Header: {
justifyContent: 'center',
width: width,
height: 30,
}
});