|
1 | | -var React = require('react-native'); |
2 | | -var Util = require('./util'); |
3 | | -var FoodDetail = require('./foodDetail'); |
4 | | - |
5 | | -var { |
6 | | - View, |
7 | | - ScrollView, |
8 | | - Text, |
9 | | - StyleSheet, |
10 | | - TextInput, |
11 | | - ActivityIndicatorIOS, |
12 | | - TouchableOpacity |
13 | | - } = React; |
14 | 1 |
|
| 2 | +var React = require('react-native'); |
| 3 | +var List = require('./list'); |
15 | 4 | var Food = React.createClass({ |
16 | | - getInitialState: function() { |
17 | | - return { |
18 | | - list: null, |
19 | | - count: 0, |
20 | | - keywords: '' |
21 | | - }; |
22 | | - }, |
23 | 5 | render: function(){ |
24 | | - var items = []; |
25 | | - if(this.state.list){ |
26 | | - var len = this.state.list.length > 10 ? 10 : this.state.list.length; |
27 | | - for(var i = 0; i < len; i++){ |
28 | | - var obj = this.state.list[i]; |
29 | | - items.push( |
30 | | - <TouchableOpacity style={styles.item} onPress={this._loadDetail.bind(this, obj.id, obj.name)}> |
31 | | - <View style={styles.row}> |
32 | | - <View style={{flex:1}}> |
33 | | - <Text numberOfLines={1} style={styles.name}>{obj.name}</Text> |
34 | | - <Text numberOfLines={1} style={styles.type}>{obj.type}</Text> |
35 | | - </View> |
36 | | - <View style={styles.distance}> |
37 | | - <Text numberOfLines={1} style={styles.mi}>{obj.distance}米</Text> |
38 | | - <Text numberOfLines={1} style={styles.address}>{obj.address}</Text> |
39 | | - </View> |
40 | | - </View> |
41 | | - |
42 | | - <TouchableOpacity style={styles.phone}> |
43 | | - <Text numberOfLines={1} >电话</Text> |
44 | | - </TouchableOpacity> |
45 | | - </TouchableOpacity> |
46 | | - ); |
47 | | - } |
48 | | - } |
49 | | - return ( |
50 | | - <ScrollView style={styles.container}> |
51 | | - <View style={styles.searchBg}> |
52 | | - <TextInput style={styles.input} placeholder="搜索美食" |
53 | | - onChangeText={this._onChangeText} |
54 | | - onEndEditing={this._onEndEditing}/> |
55 | | - <View> |
56 | | - <Text style={styles.tip}> |
57 | | - 已为您筛选 |
58 | | - <Text style={{color:'#FA2530'}}>{this.state.count}</Text> |
59 | | - 条数据 |
60 | | - </Text> |
61 | | - </View> |
62 | | - </View> |
63 | | - {items} |
64 | | - {items.length? null : <View style={styles.activity}><ActivityIndicatorIOS color="#248BFD"/></View>} |
65 | | - <View style={{height:40}}></View> |
66 | | - </ScrollView> |
| 6 | + return( |
| 7 | + <List type="餐饮" nav={this.props.navigator}/> |
67 | 8 | ); |
68 | | - }, |
69 | | - componentDidMount: function(){ |
70 | | - var url = Util.searchURL + 'key=' + Util.amapKey + '&keywords=美食&location=121.390686,31.213976&extensions=base'; |
71 | | - var that = this; |
72 | | - Util.getJSON(url, function(data){ |
73 | | - if(data.status && data.info === 'OK'){ |
74 | | - var count = data.pois.length > 10? 10: data.pois.length; |
75 | | - that.setState({ |
76 | | - list: data.pois, |
77 | | - count: count |
78 | | - }); |
79 | | - }else{ |
80 | | - alert('没有查询到相应的数据'); |
81 | | - } |
82 | | - }); |
83 | | - }, |
84 | | - |
85 | | - /*加载详情页*/ |
86 | | - _loadDetail: function(id, name){ |
87 | | - this.props.navigator.push({ |
88 | | - component: FoodDetail, |
89 | | - title: name, |
90 | | - passProps:{ |
91 | | - id: id |
92 | | - } |
93 | | - }); |
94 | | - }, |
95 | | - |
96 | | - _onChangeText: function(val){ |
97 | | - this.setState({ |
98 | | - keywords: val |
99 | | - }); |
100 | | - }, |
101 | | - _onEndEditing: function(){ |
102 | | - var that = this; |
103 | | - var keywords = this.state.keywords; |
104 | | - var url = Util.searchURL + 'key=' + Util.amapKey + '&keywords=' |
105 | | - + keywords + '&types=餐饮&location=121.390686,31.213976&extensions=base'; |
106 | | - that.setState({ |
107 | | - list: null |
108 | | - }); |
109 | | - Util.getJSON(url, function(data){ |
110 | | - if(data.status && data.info === 'OK' && data.pois.length){ |
111 | | - var count = data.pois.length > 10? 10: data.pois.length; |
112 | | - that.setState({ |
113 | | - list: data.pois, |
114 | | - count: count |
115 | | - }); |
116 | | - }else{ |
117 | | - alert('没有查询到相应的数据'); |
118 | | - } |
119 | | - }); |
120 | 9 | } |
121 | | - |
122 | 10 | }); |
123 | | - |
124 | | -var styles = StyleSheet.create({ |
125 | | - container:{ |
126 | | - flex:1, |
127 | | - backgroundColor:'#ddd' |
128 | | - }, |
129 | | - input:{ |
130 | | - height:38, |
131 | | - marginLeft:10, |
132 | | - marginRight:10, |
133 | | - borderWidth:Util.pixel, |
134 | | - paddingLeft:5, |
135 | | - marginTop:10, |
136 | | - borderColor: '#868687', |
137 | | - borderRadius:3, |
138 | | - fontSize:15 |
139 | | - }, |
140 | | - tip:{ |
141 | | - fontSize:12, |
142 | | - marginLeft:10, |
143 | | - marginTop:5, |
144 | | - color: '#505050' |
145 | | - }, |
146 | | - row:{ |
147 | | - flexDirection:'row', |
148 | | - marginLeft:10, |
149 | | - marginRight:10, |
150 | | - marginTop:10, |
151 | | - paddingTop:5 |
152 | | - }, |
153 | | - distance:{ |
154 | | - width:120, |
155 | | - alignItems:'flex-end', |
156 | | - }, |
157 | | - name:{ |
158 | | - fontSize:15, |
159 | | - marginBottom:6 |
160 | | - }, |
161 | | - type:{ |
162 | | - fontSize:12, |
163 | | - color:'#686868' |
164 | | - }, |
165 | | - mi:{ |
166 | | - fontSize:12, |
167 | | - color:'#686868' |
168 | | - }, |
169 | | - address:{ |
170 | | - fontSize:14, |
171 | | - color:'#686868' |
172 | | - }, |
173 | | - phone:{ |
174 | | - marginLeft:10, |
175 | | - marginRight:10, |
176 | | - height:33, |
177 | | - marginTop:10, |
178 | | - justifyContent:'center', |
179 | | - alignItems:'center', |
180 | | - borderWidth:Util.pixel, |
181 | | - borderColor:'#ccc' |
182 | | - }, |
183 | | - searchBg:{ |
184 | | - backgroundColor:'#fff', |
185 | | - paddingBottom:10 |
186 | | - }, |
187 | | - item:{ |
188 | | - marginTop:10, |
189 | | - backgroundColor:'#fff', |
190 | | - paddingBottom:10, |
191 | | - borderTopWidth:Util.pixel, |
192 | | - borderBottomWidth:Util.pixel, |
193 | | - borderColor:'#ccc' |
194 | | - }, |
195 | | - activity:{ |
196 | | - marginTop:50, |
197 | | - justifyContent:'center', |
198 | | - alignItems:'center', |
199 | | - } |
200 | | -}); |
201 | | - |
202 | 11 | module.exports = Food; |
203 | 12 |
|
0 commit comments