index.js 4.35 KB
import React, { Component } from "react";
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  Image,
  AlertIOS
} from "react-native";
import { StackNavigator, TabNavigator } from 'react-navigation';

export default class Mine extends Component {
  // static navigationOptions = {
  //   title: '我的',
  // };
  constructor(props) {
    super(props);
    this.state = {
      name: "哈哈哈",
      identity: "职业代理人",
    };
    this.saveResponse1 = this.saveResponse1.bind(this);
    this.saveResponse2 = this.saveResponse2.bind(this);
  }
  saveResponse1(d) {
    this.setState({ name: d });
  }
  saveResponse2(d) {
    this.setState({ identity: d });
  }
  loginOut() {
    console.log("看看this是什么", this);
    this.props.onLogin(false);
  }
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.header}>
            <Image
              source={require("../../assets/Mine/iconpic1.png")}
              style={styles.mineIcon}
            />
        </View>
        <View style={styles.midContainer}>
          <TouchableOpacity
            style={styles.itemContainer}
            onPress={() => {
              AlertIOS.prompt("更改昵称", null, this.saveResponse1);
            }}
          >
            <View style={styles.itemLeft}>
              <Image
                style={styles.leftIcon}
                source={require("../../assets/tabbar/ic_circle_s.png")}
              />
              <Text style={styles.leftTitle}>昵称</Text>
            </View>
            <View style={styles.itemRight}>
              <Text style={styles.itemRightContent}>{this.state.name}</Text>
              <Image
                style={styles.itemRightImg}
                source={require("../../assets/Mine/rightArrow_gray.png")}
              />
            </View>
          </TouchableOpacity>
          <TouchableOpacity
            style={styles.itemContainer}
            onPress={() => {
              AlertIOS.prompt("更改职业", null, this.saveResponse2);
            }}
          >
            <View style={styles.itemLeft}>
              <Image
                style={styles.leftIcon}
                source={require("../../assets/tabbar/ic_circle_s.png")}
              />
              <Text style={styles.leftTitle}>职业</Text>
            </View>
            <View style={styles.itemRight}>
              <Text style={styles.itemRightContent}>{this.state.identity}</Text>
              <Image
                style={styles.itemRightImg}
                source={require("../../assets/Mine/rightArrow_gray.png")}
              />
            </View>
          </TouchableOpacity>
        </View>

        {/* 退出登录 */}
        <TouchableOpacity
          style={styles.loginOut}
          onLogin={this.props.onLogin}
          onPress={() => {
            this.loginOut();
          }}
        >
          <Text style={styles.loginOutText}>退出登录</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "flex-start",
    alignItems: "stretch",
    backgroundColor: "#EFEFEF",
  },
  header: {
    backgroundColor: "#1B9341",
    height: 154,
    flexDirection: "row",
    justifyContent: "center",
    alignItems: "center",
    marginBottom: 10
  },
  mineIcon: {
    width: 86,
    height: 86,
  },
  mineName: {
    fontSize: 16,
    lineHeight: 22,
    color: "#fff"
  },
  headerRight: {
    width: 14,
    height: 14
  },
  midContainer: {},
  itemContainer: {
    height: 46,
    paddingLeft: 16,
    paddingRight: 16,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    backgroundColor: "#fff",
    borderStyle: "solid",
    borderColor: "#F0F0F0",
    borderBottomWidth: 1
  },
  itemLeft: {
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center"
  },
  leftIcon: {
    marginRight: 11,
    width: 16,
    height: 16
  },
  leftTitle: {
    fontSize: 15,
    color: "#242424"
  },
  itemRight: {
    flexDirection: "row",
    justifyContent: "flex-start",
    alignItems: "center"
  },
  itemRightContent: {
    marginRight: 5
  },
  itemRightImg: {
    width: 14,
    height: 14
  },
  loginOut: {
    marginTop: 10,
    height: 46,
    backgroundColor: "#fff",
    justifyContent: "center"
  },
  loginOutText: {
    textAlign: "center",
    fontSize: 15
  }
});