罗广聪

接口OK

@@ -7,36 +7,56 @@ import { @@ -7,36 +7,56 @@ import {
7 Dimensions, 7 Dimensions,
8 ScrollView, 8 ScrollView,
9 Text, 9 Text,
10 - TouchableOpacity, 10 + TouchableOpacity
11 } from "react-native"; 11 } from "react-native";
12 import { StackNavigator, TabNavigator } from "react-navigation"; 12 import { StackNavigator, TabNavigator } from "react-navigation";
13 13
14 export default class ProductTemplate extends Component { 14 export default class ProductTemplate extends Component {
  15 + static navigationOptions = {
  16 + title: "产品详情"
  17 + };
  18 +
15 constructor(props) { 19 constructor(props) {
16 super(props); 20 super(props);
17 this.state = { 21 this.state = {
18 - products: [ 22 + id: this.props.navigation.state.params.id,
19 - { 23 + productDetais: {}
20 - headerImage: require("../assets/home/product_header_1.jpg"),  
21 - title: "平安e生保2017版-100万(有社保含新农合)",  
22 - subscribe: "200万医疗险/续保至99岁免审核",  
23 - price: "¥174.00",  
24 - detailImage: "",  
25 - },  
26 - {  
27 - headerImage: require("../assets/home/product_header_2.jpg"),  
28 - title: "泰康在线“住院宝”必备版(0-49周岁)",  
29 - subscribe: "承保疾病,意外伤害,性价比高,住院有补贴,30-49岁一家三口可买",  
30 - price: "¥249.00",  
31 - detailImage: "",  
32 - }  
33 - ]  
34 }; 24 };
35 } 25 }
  26 + componentWillMount() {
  27 + this.getDetails();
  28 + }
  29 + getDetails() {
  30 + const id = this.state.id;
  31 + const that = this;
  32 + return fetch(`https://devpay.brae.co/test/insurance/product/${id}`, {
  33 + method: "POST",
  34 + headers: {
  35 + Accept: "application/json",
  36 + "Content-Type": "application/json"
  37 + }
  38 + })
  39 + .then(resp => {
  40 + if (resp.status === 200) {
  41 + return resp.json();
  42 + } else {
  43 + console.error("something went wrong!");
  44 + }
  45 + })
  46 + .then(respJson => {
  47 + if (respJson.enmsg != "ok") {
  48 + alert(respJson.cnmsg);
  49 + } else {
  50 + that.setState({
  51 + productDetais: respJson.data.product
  52 + });
  53 + console.log("产品详情", respJson.data.product);
  54 + }
  55 + });
  56 + }
36 render() { 57 render() {
37 - console.log("Image index", this.props.navigation.state.params.index);  
38 const index = this.props.navigation.state.params.index; 58 const index = this.props.navigation.state.params.index;
39 - const item = this.state.products[index]; 59 + const item = this.state.productDetais;
40 return ( 60 return (
41 <View style={styles.container}> 61 <View style={styles.container}>
42 <ScrollView style={styles.scrollViewContainer}> 62 <ScrollView style={styles.scrollViewContainer}>
@@ -45,7 +65,7 @@ export default class ProductTemplate extends Component { @@ -45,7 +65,7 @@ export default class ProductTemplate extends Component {
45 <Image 65 <Image
46 style={styles.headerImage} 66 style={styles.headerImage}
47 resizeMode="contain" 67 resizeMode="contain"
48 - source={item.headerImage} 68 + source={{ uri: item.headerImage }}
49 /> 69 />
50 {/* 标题 */} 70 {/* 标题 */}
51 <View style={styles.titleContainer}> 71 <View style={styles.titleContainer}>
@@ -55,7 +75,10 @@ export default class ProductTemplate extends Component { @@ -55,7 +75,10 @@ export default class ProductTemplate extends Component {
55 </View> 75 </View>
56 {/* 产品特色 */} 76 {/* 产品特色 */}
57 <View style={styles.midContaier}> 77 <View style={styles.midContaier}>
58 - <Image source={require("../assets/home/ic_feature.png")} style={{width: 16, height: 17,}} /> 78 + <Image
  79 + source={require("../assets/home/ic_feature.png")}
  80 + style={{ width: 16, height: 17 }}
  81 + />
59 <Text style={styles.midText}>产品特色</Text> 82 <Text style={styles.midText}>产品特色</Text>
60 </View> 83 </View>
61 {/* 图片详情 */} 84 {/* 图片详情 */}
@@ -104,7 +127,7 @@ const styles = StyleSheet.create({ @@ -104,7 +127,7 @@ const styles = StyleSheet.create({
104 paddingLeft: 15, 127 paddingLeft: 15,
105 paddingRight: 15, 128 paddingRight: 15,
106 paddingTop: 10, 129 paddingTop: 10,
107 - paddingBottom: 10, 130 + paddingBottom: 10
108 }, 131 },
109 title: { 132 title: {
110 fontSize: 16, 133 fontSize: 16,
@@ -123,12 +146,12 @@ const styles = StyleSheet.create({ @@ -123,12 +146,12 @@ const styles = StyleSheet.create({
123 flexDirection: "row", 146 flexDirection: "row",
124 paddingLeft: 13, 147 paddingLeft: 13,
125 alignItems: "center", 148 alignItems: "center",
126 - marginBottom: 1, 149 + marginBottom: 1
127 }, 150 },
128 midText: { 151 midText: {
129 marginLeft: 10, 152 marginLeft: 10,
130 fontSize: 15, 153 fontSize: 15,
131 - color: "#242424", 154 + color: "#242424"
132 }, 155 },
133 imgOne: { 156 imgOne: {
134 width: Dimensions.get("window").width, 157 width: Dimensions.get("window").width,
@@ -148,26 +171,26 @@ const styles = StyleSheet.create({ @@ -148,26 +171,26 @@ const styles = StyleSheet.create({
148 flex: 1, 171 flex: 1,
149 borderColor: "#E4E4E4", 172 borderColor: "#E4E4E4",
150 borderStyle: "solid", 173 borderStyle: "solid",
151 - borderTopWidth: 1, 174 + borderTopWidth: 1
152 }, 175 },
153 footerLeft: { 176 footerLeft: {
154 flex: 1, 177 flex: 1,
155 justifyContent: "center", 178 justifyContent: "center",
156 alignItems: "flex-start", 179 alignItems: "flex-start",
157 - paddingLeft: 15, 180 + paddingLeft: 15
158 }, 181 },
159 price: { 182 price: {
160 color: "#1B9341", 183 color: "#1B9341",
161 - fontSize: 18, 184 + fontSize: 18
162 }, 185 },
163 footerRight: { 186 footerRight: {
164 backgroundColor: "#1B9341", 187 backgroundColor: "#1B9341",
165 width: 144, 188 width: 144,
166 justifyContent: "center", 189 justifyContent: "center",
167 - alignItems: "center", 190 + alignItems: "center"
168 }, 191 },
169 button: { 192 button: {
170 color: "white", 193 color: "white",
171 - fontSize: 16, 194 + fontSize: 16
172 - }, 195 + }
173 }); 196 });
@@ -9,31 +9,47 @@ import { @@ -9,31 +9,47 @@ import {
9 Image 9 Image
10 } from "react-native"; 10 } from "react-native";
11 import { StackNavigator, TabNavigator } from 'react-navigation'; 11 import { StackNavigator, TabNavigator } from 'react-navigation';
12 -import CommonWebView from "../../Components/CommonWebView";  
13 -// import CommonImageView from "../../Components/CommonImageView";  
14 12
15 export default class AllProduct extends Component { 13 export default class AllProduct extends Component {
16 -  
17 constructor(props) { 14 constructor(props) {
18 super(props); 15 super(props);
19 this.state = { 16 this.state = {
20 - ListData: [ 17 + ListData: []
21 - {  
22 - id: 0,  
23 - title: "平安e生保2017版-100万(有社保含新农合)",  
24 - Subtitle: "200万医疗险,续保至99岁免审核",  
25 - imgurl: require("../../assets/home/product_1.png")  
26 - },  
27 - {  
28 - id: 1,  
29 - title: "泰康在线“住院宝”必备版(0-49周岁)",  
30 - Subtitle: "疾病意外全面保障,补充社保不足,公共交通意外双倍赔付",  
31 - imgurl: require("../../assets/home/product_2.png")  
32 - },  
33 - ]  
34 }; 18 };
35 } 19 }
36 20
  21 + componentWillMount() {
  22 + this.getProducts();
  23 + }
  24 +
  25 + getProducts() {
  26 + let that = this;
  27 + return fetch(`https://devpay.brae.co/test/insurance/product`, {
  28 + method: "POST",
  29 + headers: {
  30 + Accept: "application/json",
  31 + "Content-Type": "application/json"
  32 + }
  33 + })
  34 + .then(resp => {
  35 + if (resp.status === 200) {
  36 + return resp.json();
  37 + } else {
  38 + console.error("something went wrong!");
  39 + }
  40 + })
  41 + .then(respJson => {
  42 + if (respJson.enmsg != "ok") {
  43 + alert(respJson.cnmsg);
  44 + } else {
  45 + that.setState({
  46 + ListData: respJson.data.data.ListData
  47 + })
  48 + console.log("全部产品列表",respJson.data.data.ListData);
  49 + }
  50 + });
  51 + }
  52 +
37 render() { 53 render() {
38 const { navigate } = this.props.navigation; 54 const { navigate } = this.props.navigation;
39 return ( 55 return (
@@ -47,9 +63,9 @@ export default class AllProduct extends Component { @@ -47,9 +63,9 @@ export default class AllProduct extends Component {
47 <TouchableOpacity 63 <TouchableOpacity
48 style={styles.itemContainer} 64 style={styles.itemContainer}
49 key={index} 65 key={index}
50 - onPress={() => navigate("ProductTemplate", { index: index })} 66 + onPress={() => navigate("ProductTemplate", { index: index,id: item.id })}
51 > 67 >
52 - <Image style={styles.itemImgWrapper} source={item.imgurl} /> 68 + <Image style={styles.itemImgWrapper} source={{uri: item.imgurl}} />
53 <View style={styles.itemRightWrapper}> 69 <View style={styles.itemRightWrapper}>
54 <Text style={styles.itemTextTop} numberOfLines={2}> 70 <Text style={styles.itemTextTop} numberOfLines={2}>
55 {item.title} 71 {item.title}