Question.js
3.55 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
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ScrollView,
ListView,
Dimensions
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
QuesList: [
{
title: "1.我该称呼您先生还是女士呢?",
type: "select",
answers: ["先生", "女士"]
},
{
title: "2.请问您是否有家庭负债?",
type: "select",
answers: ["有贷款", "无贷款"]
},
{
title: "3.您要为哪些家人投保呢?",
type: "select",
answers: ["先生", "配偶", "儿子", "女儿", "母亲", "父亲"]
},
{
title: "4.选择出生日期",
type: "date",
answers: "1994.06.06"
}
],
answerList: []
};
}
componentWillMount() {}
componentDidMount() {}
getListData() {
let that = this;
return fetch(`https://devpay.brae.co/test/insurance/topic`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
})
.then(resp => {
if (resp.status === 200) {
return resp.json();
} else {
console.error("something went wrong!");
}
})
.then(respJson => {
if (respJson.enmsg != "ok") {
alert(respJson.cnmsg);
} else {
that.setState({
ListData: respJson.data.topic
});
console.log("首页列表", this.state.ListData);
}
});
}
_renderQuestion() {
return this.state.QuesList.map((item, index) => {
return (
<View style={styles.itemQuesContainer} key={index}>
<View style={styles.titleContaier}>
<Text style={styles.title}>{item.title}</Text>
</View>
<View style={styles.answerContainer}>
{item.type == "select" ? (
item.answers.map((x, index2) => {
return (
<TouchableOpacity key={index2} style={styles.answerWrapper}>
<Text style={styles.answer}>{x}</Text>
</TouchableOpacity>
);
})
) : (
<TouchableOpacity>
<Text>{item.answers}</Text>
</TouchableOpacity>
)}
</View>
</View>
);
});
}
render() {
const { navigate } = this.props.navigation;
return <View style={styles.container}>{this._renderQuestion()}</View>;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
alignItems: "stretch",
backgroundColor: "#F0F0F0",
paddingHorizontal: 12,
paddingTop: 12
},
itemQuesContainer: {
backgroundColor: "white",
marginBottom: 12,
borderRadius: 4
},
titleContaier: {
paddingHorizontal: 14,
paddingVertical: 17
},
answerContainer: {
borderStyle: "solid",
borderColor: "#E6E6E6",
borderTopWidth: 0.5,
paddingHorizontal: 14,
paddingBottom: 17,
flexDirection: "row",
flexWrap: "wrap"
},
answerWrapper: {
marginRight: 18,
marginTop: 17,
paddingHorizontal: 10,
paddingVertical: 4,
borderStyle: "solid",
borderColor: "#ccc",
borderWidth: 0.5,
justifyContent: "center",
alignItems: "center",
borderRadius: 3
},
answer: {
fontSize: 15,
}
});