PlaceDeparture.js
3.04 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
/**
* Created by yzdd on 2018/3/17.
*/
import React, {Component} from 'react';
import {
View,
Text,
StyleSheet,
Image,
TextInput,
FlatList,
ScrollView,
TouchableOpacity
} from 'react-native';
import SearchBox from "../components/SearchBox";
import region from '../utils/region';
import {observer} from 'mobx-react';
import {observable} from 'mobx';
import {width} from "../utils/publiscStyle";
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFFFFF"
},
placeItem: {
width,
height: 44,
flexDirection: "row",
alignItems: 'center',
paddingLeft: 15
}
});
//出发地
@observer
export default class PlaceDeparture extends Component {
static navigationOptions = ({navigation}) => {
return {
title: navigation.state.params.title
}
};
@observable
place = "";
@observable
placeArray = [];
componentWillMount() {
console.log(region)
}
changePlace = (text) => {
this.place = text;
this.timer = setTimeout(() => {
let array = [];
region.forEach((v, i) => {
let timeArray = [];
if (v.type === "district" || v.type === "city") {
if (v.name.indexOf(text) !== -1) {
timeArray.push(v);
array.push(timeArray)
}
}
});
array.forEach((item, index) => {
if (item[0].type === "city") {
region.forEach((v, i) => {
if (v.type === "province" && v.id.toString() === item[0].pid) {
item.push(v);
}
});
} else {
region.forEach((v, i) => {
if (v.type === "city" && v.id.toString() === item[0].pid) {
item.push(v);
region.forEach((province, pid) => {
if (province.type === "province" && province.id.toString() === item[1].pid) {
item.push(province);
}
});
}
});
}
});
this.placeArray.replace(array);
}, 500);
};
//选择地区
selectPlace = (v) => {
console.log(123);
console.log(v);
console.log(345);
const {goBack} = this.props.navigation;
const {type, detailItem} = this.props.navigation.state.params;
if (type === 1) {
detailItem.startPlace = v;
} else {
detailItem.endPlace = v;
}
goBack();
};
renderPlaceItem = (v, i) => {
let s = "";
v.forEach((item, index) => {
s += `${item.name} `
});
return (
<TouchableOpacity key={i} style={styles.placeItem} onPress={() => this.selectPlace(v)}>
<Text>{s}</Text>
</TouchableOpacity>
)
};
render() {
return (
<View style={styles.container}>
<SearchBox
placeholder={`输入地点,如"北京"`}
icon={true}
onChangeText={(text) => this.changePlace(text)}
value={this.place}
autoFocus
/>
<ScrollView>
{
this.placeArray.map((v, i) => this.renderPlaceItem(v, i))
}
</ScrollView>
</View>
);
}
}