SameCity.js
3.91 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
import React, {Component} from 'react';
import {DeviceEventEmitter, Image, NativeModules, StyleSheet, Text, View} from 'react-native';
import HomeList from '../home/HomeList';
import AppService from '../../service/AppService';
import {xnToast} from "../../utils/utils";
var Geolocation = require('Geolocation');
export default class Mine extends Component {
static navigationOptions = ({ navigation, screenProps }) => ({
header: null
});
constructor(props) {
super(props);
this.state = {
network: false,
location: '',
cityName: this.props.cityName,
cityCode: this.props.cityCode,
cityList:''
}
}
componentWillMount(){
const _this = this;
NativeModules.system.getLocation().then(data => {
});
this.getCityList();
// 获取网络状态
// NativeModules.system.getLocation().then((data)=>{
// console.log(this.state.location);
// })
};
//因为android原生网络请求需要引入一堆文件,故获取城市列表的数据放到RN来做
getCityList(){
let params = {
pageSize: 0,
}
AppService.citySearch(params).then((data)=>{
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
if (data.result !=null && data.result.length>0) {
this.setState({
cityList:JSON.stringify(data.result),
})
}
}
}).catch((error)=>{
xnToast(error);
console.log("===",error)
})
}
getLocation() {
const _this = this;
if (global.__IOS__){
NativeModules.system.cityChoose(this.state.cityName).then((result) => {
var data = JSON.parse(result) || {};
global.cityName = data.name || '';
_this.setState({
cityName: data.name || '',
cityCode: data.cityCode || ''
},function () {
DeviceEventEmitter.emit('refreshHomeList');
DeviceEventEmitter.emit('refreshCityName');
DeviceEventEmitter.emit('refreshHeader');
})
});
}else {
NativeModules.system.cityChoose(this.state.cityName,this.state.cityList).then((result) => {
var data = JSON.parse(result) || {};
global.cityName = data.name || '';
_this.setState({
cityName: data.name || '',
cityCode: data.cityCode || ''
},function () {
DeviceEventEmitter.emit('refreshHomeList');
DeviceEventEmitter.emit('refreshCityName');
DeviceEventEmitter.emit('refreshHeader');
})
});
}
}
render() {
return(
<View style={styles.background}>
<View style={styles.addressContainer}>
<Image style={{height: 12, width: 10,marginRight:5}} source={require('../../img/dw.png')} />
<Text onPress={this.getLocation.bind(this)}>切换城市</Text>
</View>
<HomeList tabLabel= {''} arr_keyValue = {[{'boardCityCode': this.state.cityCode},{tabIndex:this.props.tabIndex}]} navigation={this.props.navigation}/>
</View>
)
}
}
const styles = StyleSheet.create({
background:{
flex:1,
backgroundColor:'#F3F5F6',
display:'flex',
},
addressContainer: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
height: 34,
backgroundColor: '#F3F5F6'
}
});