ProvinceSchoolView.js
9.61 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
ScrollView,
Text,
NativeAppEventEmitter,
StyleSheet,
ListView,
Dimensions,
TouchableOpacity,
} from 'react-native';
import Immutable, {Map} from 'immutable';
import LatterListView from './LatterListView';
import YH_SearchBar from '../../../common/components/YH_SearchBar';
export default class ProvinceSchoolView extends Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._scrollToSection = this._scrollToSection.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this._onTextChange = this._onTextChange.bind(this);
this.listView = null;
this.dataList = [];
this.latterList = [];
this.dataListShow = [];
this.latterListShow = [];
}
componentDidMount() {
}
_onTextChange(text){
let newDataList = [];
let curViewType = this.props.resource.get('type');
let searchResultPageInfo = {
show: false,
type: {curViewType},
leftList: [],
rightList: [],
};
console.log(this.dataList);
console.log('this.dataList');
if (text != '') {
this.dataList.forEach((dataListItem, i) => {
let latter = this.latterList[i];
let list = dataListItem[latter].list;
let newDataListItem = {};
let newList = [];
list.forEach((listItem, i) => {
let name = curViewType=='school' ? listItem.schoolName:listItem.addresseeName;
if (name.indexOf(text) != -1) {
newList.push(listItem);
}
});
if (newList.length) {
newDataListItem[latter]={list:newList,count:0,separatorCount:0};
newDataList.push(newDataListItem);
}
});
console.log('====0000');
console.log(newDataList);
if (newDataList.length) {
searchResultPageInfo.show = true;
searchResultPageInfo.leftList = newDataList;
}
}
this.props.updateSearchResultPageInfo && this.props.updateSearchResultPageInfo(searchResultPageInfo);
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
let separatorLatter='';
let latterObject = this.dataListShow[rowID];
for (var key in latterObject) {
if (latterObject.hasOwnProperty(key)) {
separatorLatter = key;
}
}
let rowDataList = rowData[separatorLatter].list;
let rowDataListImmulate = Immutable.fromJS(rowDataList);
let curViewType = this.props.resource.get('type');
return (
<View>
<View key={'sep' + rowID} style={styles.provinceLatterCell}>
<Text>
{separatorLatter}
</Text>
</View>
{rowDataListImmulate.map((provinceItem, i) => {
return (
<TouchableOpacity activeOpacity={1.0} onPress={() => {
this._onTextChange('');
switch (this.props.resource.get('type')) {
case 'province':
this.props.hideProvinceSelectView && this.props.hideProvinceSelectView(provinceItem);
break;
case 'school':
this.props.hideSchoolSelectView && this.props.hideSchoolSelectView(provinceItem);
break;
default:
}
}}>
<View style={styles.provinceCell}>
<Text style={{marginLeft: 15}}>
{curViewType == 'province' ?
provinceItem.get('addresseeName')
:provinceItem.get('schoolName')
}
</Text>
</View>
{i !== (rowDataListImmulate.size -1) ?
<View style={styles.provinceSeparatorLine}>
</View>
:null
}
</TouchableOpacity>
);
})}
</View>
);
}
_scrollToSection(index,sectionID){
console.log(index);
console.log(sectionID);
console.log('-------qqqq');
let {resource} = this.props;
let leftList = resource.get('leftList');
let rightList = resource.get('rightList');
rightList = rightList.toArray();
let item = this.dataListShow[index];
if (item) {
let distanceY = 30 * index + item[sectionID].count * 40 + item[sectionID].separatorCount * 1.5;
this.listView.scrollTo({x: 0, y: distanceY, animated: false});
}
}
render() {
let {resource,searchResultPageInfo} = this.props;
let leftList = resource.get('leftList');
let rightList = resource.get('rightList');
let searchPlaceHolder = this.props.resource.get('type') == 'school' ? '搜索学校' : '搜索省份';
this.dataList = (leftList && leftList.size) ? leftList.toJS() : [];
this.latterList = rightList.toArray();
this.dataListShow = this.dataList;
this.latterListShow = this.latterList;
if (searchResultPageInfo.get('show')) {
leftList = searchResultPageInfo.get('leftList');
rightList = searchResultPageInfo.get('rightList');
this.dataListShow = (leftList && leftList.size) ? leftList.toJS() : [];
this.latterListShow = rightList.toArray();
}
return (
<View style={styles.container}>
<View style={styles.listViewContainer}>
<ListView
ref={(ref)=>this.listView=ref}
contentContainerStyle={[styles.contentContainerStyle]}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(this.dataListShow)}
renderRow={this._renderRow}
showsHorizontalScrollIndicator={false}
/>
<LatterListView
style={{height: height - 64 - 200}}
dataSource={this.latterListShow}
distanceToContainer={200}
onLetterPress={this._scrollToSection}/>
</View>
<View style={styles.header}>
<YH_SearchBar
ref={(c) => {
this.searchBar = c;
}}
placeholder={searchPlaceHolder}
onClickCancel={this._onTextChange}
onTextChange={this._onTextChange}
/>
</View>
<TouchableOpacity activeOpacity={1.0} onPress={() => {
console.log('--close');
switch (this.props.resource.get('type')) {
case 'province':{
this.props.hideProvinceSelectView && this.props.hideProvinceSelectView();
}
break;
case 'school':{
this.props.hideSchoolSelectView && this.props.hideSchoolSelectView();
}
break;
default:
}
}}>
<View style={styles.closeContainer}>
<Text style={styles.closeText}>
close
</Text>
</View>
</TouchableOpacity>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
width: width,
height:height - 64,
backgroundColor: 'rgba(0,0,0,0.3)',
flexDirection: 'column-reverse',
flex: 1,
},
closeContainer: {
height: 40,
flexDirection: 'row-reverse',
},
closeText: {
paddingLeft: 15,
paddingRight: 15,
paddingTop: 10,
color: '#dfe3e2',
},
listViewContainer: {
height: height - 64 - 200,
backgroundColor: 'white',
},
contentContainerStyle: {
width: width - 20,
backgroundColor: '#dfe3e2',
},
contentContainer: {
flexDirection: 'column',
backgroundColor:'white',
},
provinceLatterCell: {
marginLeft: 15,
height: 30,
backgroundColor: '#dfe3e2',
justifyContent: 'center',
},
row: {
backgroundColor: 'white',
height: 30,
},
header: {
justifyContent: 'center',
backgroundColor: 'white',
height: 40,
},
provinceCell: {
justifyContent: 'center',
height: 40,
backgroundColor: 'white',
},
provinceSeparatorLine: {
height: 1.5,
backgroundColor: '#dfe3e2',
marginLeft: 15,
}
});