index.js 3.38 KB
import React, { Component } from "react";
import {
  StyleSheet,
  WebView,
  View,
  Image,
  Dimensions,
  ScrollView,
  Text,
  TouchableOpacity,
  Clipboard,
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";

export default class Discover extends Component {
  constructor(props) {
    super(props);
    this.state = {
      // image: "",
      word: "",
      date: {}
    };
  }
  componentWillMount() {
    this.getImages();
  }
  getImages() {
    let that = this,
      id = this.state.id,
      model = this.state.model;
    return fetch(`https://devpay.brae.co/test/insurance/wallpaper`, {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json"
      }
    })
      .then(resp => {
        console.log("大爷", 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({
            word: respJson.data.word,
            date: respJson.data.date
          });
          console.log("发现", respJson.data);
        }
      });
  }
  copyWords(string) {
    Clipboard.setString(string);
  }
  render() {
    const { word, date } = this.state;
    return (
      <Image
        style={styles.container}
        source={require("../../assets/discover/bg.png")}
      >
        <View style={styles.date}>
          <Text style={styles.day}>{date.day}</Text>
          <View style={styles.leftContaier}>
            <Text style={styles.month}>{date.month}</Text>
            <Text style={styles.week}>{date.week}</Text>
          </View>
        </View>
        <View style={styles.wordConatier}>
          <Text style={styles.word}>{word}}</Text>
        </View>
        <TouchableOpacity style={styles.button} onPress={() => {this.copyWords(word)}}>
          <Image style={styles.btnImg} source={require("../../assets/discover/ic_copy.png")} />
          <Text style={styles.btnText}>复制文案</Text>
        </TouchableOpacity>
      </Image>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    width: Dimensions.get("window").width,
    height: Dimensions.get("window").height
  },
  date: {
    backgroundColor: "rgba(255,255,255,0)",
    flexDirection: "row",
    justifyContent: "center",
    alignItems: "center",
    marginLeft: 100,
    marginRight: 100,
    marginTop: 25,
    marginBottom: 25
  },
  day: {
    fontSize: 75,
    color: "#fff"
  },
  leftContaier: {
    marginLeft: 12
  },
  month: {
    fontSize: 23,
    color: "#fff"
  },
  week: {
    fontSize: 17,
    color: "#fff"
  },
  wordConatier: {
    backgroundColor: "#FFFFFF",
    justifyContent: "center",
    alignItems: "center",
    borderRadius: 5,
    marginLeft: 20,
    marginRight: 20,
    paddingLeft: 22,
    paddingRight: 22,
    paddingTop: 28,
    paddingBottom: 28,
  },
  word: {
    fontSize: 15,
    color: "#242424",
    lineHeight: 24
  },
  button: {
    width: Dimensions.get("window").width,
    backgroundColor: "rgba(255,255,255,0)",
    flexDirection: "row",
    justifyContent: "center",
    alignItems: "center",
    position: "absolute",
    bottom: 150,
  },
  btnImg: {
    width: 13,
    height: 15,
    marginRight: 5,
  },
  btnText: {
    color: "white",
    fontSize: 15,
  }
});