ProductTemplate.js
4.9 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
import React, { Component } from "react";
import {
StyleSheet,
WebView,
View,
Image,
Dimensions,
ScrollView,
Text,
TouchableOpacity,
Alert,
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
export default class ProductTemplate extends Component {
static navigationOptions = {
title: "产品详情"
};
constructor(props) {
super(props);
this.state = {
id: this.props.navigation.state.params.id,
productDetais: {}
};
}
componentWillMount() {
this.getDetails();
}
getDetails() {
const id = this.state.id;
const that = this;
return fetch(`https://devpay.brae.co/test/insurance/product/${id}`, {
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({
productDetais: respJson.data.product
});
console.log("产品详情", respJson.data.product);
}
});
}
render() {
const index = this.props.navigation.state.params.index;
const item = this.state.productDetais;
return (
<View style={styles.container}>
<ScrollView style={styles.scrollViewContainer}>
<View style={styles.headerContainer}>
{/* 顶部图片 */}
<Image
style={styles.headerImage}
resizeMode="contain"
source={{ uri: item.headerImage }}
/>
{/* 标题 */}
<View style={styles.titleContainer}>
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.subscribe}>{item.subscribe}</Text>
</View>
</View>
{/* 产品特色 */}
<View style={styles.midContaier}>
<Image
source={require("../assets/home/ic_feature.png")}
style={{ width: 16, height: 17 }}
/>
<Text style={styles.midText}>产品特色</Text>
</View>
{/* 图片详情 */}
{index == 0 ? (
<Image
style={styles.imgOne}
resizeMode="contain"
source={require("../assets/home/product_long_1.jpg")}
/>
) : (
<Image
style={styles.imgTwo}
resizeMode="contain"
source={require("../assets/home/product_long_2.jpg")}
/>
)}
</ScrollView>
{/* 悬浮按钮 */}
<View style={styles.footer}>
<View style={styles.footerLeft}>
<Text style={styles.price}>{item.price}</Text>
</View>
<TouchableOpacity
style={styles.footerRight}
onPress={() => {
Alert.alert("您好,网站正在备案中,暂时无法投保。")
}}
>
<Text style={styles.button}>立即投保</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "flex-start",
backgroundColor: "#EFEFEF"
},
scrollViewContainer: {
marginBottom: 49,
},
headerContainer: {},
headerImage: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").width * 300 / 750
},
titleContainer: {
backgroundColor: "white",
paddingLeft: 15,
paddingRight: 15,
paddingTop: 10,
paddingBottom: 10
},
title: {
fontSize: 16,
color: "#242424",
lineHeight: 22
},
subscribe: {
fontSize: 13,
color: "#7A7A7A",
lineHeight: 15
},
midContaier: {
marginTop: 10,
height: 45,
backgroundColor: "white",
flexDirection: "row",
paddingLeft: 13,
alignItems: "center",
marginBottom: 1
},
midText: {
marginLeft: 10,
fontSize: 15,
color: "#242424"
},
imgOne: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").width * 3118 / 640
},
imgTwo: {
width: Dimensions.get("window").width,
height: Dimensions.get("window").width * 1651 / 690
},
footer: {
position: "absolute",
bottom: 0,
backgroundColor: "white",
height: 49,
width: Dimensions.get("window").width,
flexDirection: "row",
flex: 1,
borderColor: "#E4E4E4",
borderStyle: "solid",
borderTopWidth: 1
},
footerLeft: {
flex: 1,
justifyContent: "center",
alignItems: "flex-start",
paddingLeft: 15
},
price: {
color: "#1B9341",
fontSize: 18
},
footerRight: {
backgroundColor: "#1B9341",
width: 144,
justifyContent: "center",
alignItems: "center"
},
button: {
color: "white",
fontSize: 16
}
});