ItemHeaderInfo.js 3.94 KB
import React, {Component} from "react";
import {Image, StyleSheet, Text, TouchableOpacity, View} from "react-native";
import _ from "lodash";
import {dateToMsgTime,NoDoublePress} from "../../../utils/utils";
import StashHead from '../../../widget/StashHead';
import { height, width,zoomW,zoomH } from "../../../utils/getSize";
import {scaleHeight, scaleSize, setSpText} from "../../../utils/ScreenUtil";

//图片资源
const defaultIcon = require("../../../img/defaultIcon.png");
/**
 * 图集列表item 中个人信息部分
 * 调用者需要传入的参数 personInfoData : 个人信息数据源
 */
export default class itemHeaderInfo extends Component {
  // 构造
  constructor(props) {
    super(props);
  }

  //点击事件,跳到个人详情
  _onPress() {
      NoDoublePress.onPress(()=>{
          let id = this.props.item.user.id;
          if (id == global.userId) {
              //自己
              this.props.nav.navigate("MyPage", { id: id });
              return;
          }
          this.props.nav.navigate("PersonalHomePage", { userId: id });
      })

  }

  //个人信息
  render() {
      let identifyTypeNames = this.state.userInfo.identifyTypeNames?(this.state.userInfo.identifyTypeNames!=''?
          this.state.userInfo.identifyTypeNames.replace(/\,/g,' '):global.defaultInentifyTypeName):
          global.defaultInentifyTypeName;
    return (
      <View
        style={{
          width: "100%",
          flexDirection: "row",
          alignItems: "center",
          paddingLeft: scaleSize(15),
          marginTop: scaleHeight(17)
        }}
      >
        <TouchableOpacity
          onPress={() => {
            this._onPress();
          }}
        >
          <Image
            style={styles.avatar}
            source={
              this.props.item.user.avatar &&
              !!!_.isEmpty(this.props.item.user.avatar) &&
              this.props.item.user.avatar.indexOf("http") != -1
                ? { uri: this.props.item.user.avatar }
                : defaultIcon
            }
            resizeMode="cover"
          />
        </TouchableOpacity>
        <View
          style={{
            width: "100%",

            flex: 1,
            display: "flex",
            marginLeft: 8/zoomW
          }}
        >
          <View
            style={{
              width: "100%",
              flex: 1,
              flexDirection: "row",
              justifyContent: "space-between",
              alignItems: "center"
            }}
          >
            <View>
              <Text style={styles.userNameBlack} numberOfLines={1}>
                {this.props.item.user.name}
              </Text>
              <View
                style={{ flex: 1, flexDirection: "row", alignItems: "center" }}
              >
                {this.props.item.isBoardTop ? (
                  <StashHead />
                ) : null}
                <Text style={{ fontSize: setSpText(12), color: 'rgba(0,0,0,0.45)' }}>
                  {dateToMsgTime(this.props.item.creationTime)}
                </Text>
                <View
                  style={{
                    height: 2,
                    width: 2,
                    borderRadius: 1,
                    backgroundColor: "rgba(0,0,0,0.45)",
                    opacity: 0.55,
                    marginLeft: 5,
                    marginRight: 5
                  }}
                />

                <Text style={{ fontSize: setSpText(12), color: 'rgba(0,0,0,0.45)'  }}>
                  {this.props.item.user.isAuthented ? identifyTypeNames : "未认证"}
                </Text>
              </View>
            </View>
          </View>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  avatar: {
    width: scaleHeight(36),
    height: scaleHeight(36),
    borderRadius: scaleHeight(18)
  },
  userNameBlack: {
    flex: 1,
    fontSize: setSpText(14),
      color: 'rgba(0,0,0,0.85)',
  },
  time: {
    fontSize: setSpText(12),
    color: 'rgba(0,0,0,0.45)',
  }
});