ItemHeaderInfo.js 9.21 KB
import React, {Component} from 'react';
import {DeviceEventEmitter, Image, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import {zoomH, zoomW} from '../../utils/getSize';
import {dateToMsgTime, NoDoublePress,xnToast} from '../../utils/utils';
import AppService from "../../service/AppService";
import StashHead from '../../widget/StashHead';
import {scaleHeight, scaleSize, setSpText} from "../../utils/ScreenUtil";
import ActionSheet from "react-native-actionsheet-api";

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

    //点击事件,跳到个人详情
    _onPress(){

        NoDoublePress.onPress(()=>{
            let id = this.props.itemList.threadUserId;
            if (id == global.userId) {
                //自己
                this.props.nav.navigate("MyPage", { id: id,});
                return;
            }
            this.props.nav.navigate('PersonalHomePage',{userId:id})
        })




    };

    // TODO:这是为了应付苹果审核做的假的举报拉黑功能
    reportClick = ()=>{
        let _this = this;
        ActionSheet.showActionSheetWithOptions({
                options: [ '举报内容违规','举报内容作者骚扰', '屏蔽该内容作者', '取消'],
                cancelButtonIndex:3,
                tintColor: global.homeColor,
            },
            (buttonIndex) => {
                if (buttonIndex == 0) {
                    xnToast('举报成功,平台将会在24小时之内给出内容评审结果');
                }
                if (buttonIndex == 1) {
                    xnToast('举报成功,平台将会在24小时之内给出内容作者行为审核结果');
                }
                if (buttonIndex == 2) {
                    xnToast('屏蔽成功,平台将不再向您推送该用户发布的内容');
                    if (_this.props.reportCallback != undefined){
                        _this.props.reportCallback(buttonIndex);
                    }
                }
            }
        );
    }
    //点击事件
    _followClick = ()=>{//关注
        NoDoublePress.onPress(()=>{
            var data = this.props.itemList;
            if (!global.isConnected){
                xnToast('暂无网络连接,请稍后重试!');
                return;
            }
            let params = {
                forumId:data.forumId,//社区id
                targetType:1,//关注对象类型,目前固定1:社区用户
                targetUserId:data.threadUserId,//被关注者用户ID
                targetUserName:data.threadUserName,//被关注者用户名称
                attentionUserId: global.userId,//自己的id
                attentionUserName:global.userName,//自己的名字

            };
            console.log(params);

            AppService.attention(params).then((data) => {
                this.setState({
                    loading: false
                });
                if (data.message) {
                    xnToast(res.message);
                    return;
                }
                if (!!data.errors === true && !!data.errors.length > 0) {
                    xnToast(data.errors[0].message);
                } else {
                    xnToast('已关注');
                    //通知列表刷新
                    DeviceEventEmitter.emit('refreshHomeList');
                    DeviceEventEmitter.emit('refreshAllList');
                    DeviceEventEmitter.emit('reGetThreadDetailInfo');
                    DeviceEventEmitter.emit('refreshHomeHistory');
                    DeviceEventEmitter.emit('refreshCollectList');
                    DeviceEventEmitter.emit('refreshAttention');
                }
            }).catch((error) => {
                this.setState({
                    loading: false
                });
                xnToast(error)
            })
        })

    };

    //时间和认证省份信息显示
    getTimeAndIndentity(itemList){

        let time = dateToMsgTime(itemList.creationTime);
        let identity = !!itemList.user && !!itemList.user.agentName?itemList.user.agentName:'';
        if (identity != ''){
            return time + ' · ' + identity;
        }

        return time;

    }
   //获取帖子类型
    getThreadTypeStr(){
      let threadType = this.props.itemList.threadType;
      let str = "文章";
      switch (threadType){
          case 0:
              str = "图文";
              break;
          case 1:
              str = "图集";
              break;
          case 2:
              str = "视频";
              break;
          case 3:
              str = "问答";
              break;
          case 4:
              str = "文章";
              break;
          case 5:
              str = "课程";
              break;
          default:
              break
      }
      return str;

    }
    //个人信息
    render() {
        return (
            <View style = {{width:'100%',flexDirection:'row',alignItems:'center',paddingLeft:scaleSize(14), marginTop:scaleHeight(14), paddingRight:scaleSize(14),backgroundColor:'#ffffff'}} >
                <TouchableOpacity style={styles.avatar}  onPress = {()=>{this._onPress()}}>
                    <Image  style={styles.avatar}
                            source={!!this.props.itemList.threadUserHeadFileUrl?{uri: this.props.itemList.threadUserHeadFileUrl +'?x-oss-process=image/resize,w_100'}
                                :defaultIcon} resizeMode="cover" />
                    {!!this.props.itemList.user && !!this.props.itemList.user.isAuthented &&
                    <Image  style={styles.avatarV} source={vIcon} 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 style = {{flexDirection:'column'}}>
                            <View style = {{flexDirection:'row',alignItems:'center'}}>
                                <Text style = {[styles.userNameBlack]} numberOfLines = {1}>{this.props.itemList.threadUserName}</Text>
                                {this.props.itemList.isHot&&  <Image  style={{width:14,height:14,marginLeft:5}}  resizeMode={'contain'} source={require('../../img/hot.png')}></Image>}
                                {this.props.showReport && <TouchableOpacity  activeOpacity={0.8}  onPress = {()=>{this.reportClick()}}>
                                    <Text style = {[styles.reportStyle]} numberOfLines = {1}>{'  举报  '}</Text>
                                </TouchableOpacity>}
                            </View>

                            <View style={{flexDirection:'row', marginTop:5}}>
                                { ! this.props.hideTop && this.props.itemList.isBoardTop ? <StashHead /> : null}
                                { this.props.showType && <Text style={styles.type}>{this.getThreadTypeStr()}</Text> }
                                { ! this.props.hideTime && <Text style = {{fontSize:12,color:"rgba(0,0,0,0.45)"}}>{this.getTimeAndIndentity(this.props.itemList)}</Text>}
                                {/*this.props.showType &&*/}
                            </View>
                        </View>
                        {!!this.props.itemList.user && this.props.itemList.user.id != global.userId && (!this.props.itemList.user.hasBeenAttended)
                        && <TouchableOpacity  activeOpacity={0.8}  onPress = {this._followClick}>
                            <Text style = {{fontSize:setSpText(14),color:global.homeColor}}>关注</Text>
                        </TouchableOpacity>
                        }

                    </View>
                </View>
            </View>
        )
    }


}


// this.props.itemList.creationTime
const styles = StyleSheet.create({
    avatar:{
        width:scaleHeight(36),
        height:scaleHeight(36),
        borderRadius:scaleHeight(18),
    },
    avatarV:{
        width:scaleHeight(12),
        height:scaleHeight(12),
        position:'absolute',
        right:-scaleSize(4),
        bottom:scaleHeight(2),
    },
    userNameBlack:{
        fontSize:setSpText(14),
        color:'rgba(0,0,0,0.85)',
        fontWeight: 'bold',
    },
    reportStyle:{
        marginLeft:5,
        fontSize:setSpText(8),
        color:'gray',
        fontWeight: 'bold',
        borderColor: 'rgba(0,0,0,0.45)',
        borderWidth: 0.5,
        borderRadius: 2,
    },
    time:{
        fontSize:setSpText(12),
        color:'rgba(0,0,0,0.45)'
    },
    type:{
        fontSize: 10,
        color: 'rgba(0,0,0,0.65)',
        borderColor: 'rgba(0,0,0,0.45)',
        borderWidth: 1,
        borderRadius: 2,
        marginRight: 5,
        justifyContent: "center",
        alignItems: "center",
        textAlign: "center",
        paddingLeft: 4,
        paddingTop: 2,
        paddingRight: 4,
        paddingBottom: 1
    }

});