result.js 5.17 KB
/*
 * 潮流优选、明星原创
 */

'use strict';

import React, {Component} from 'react';
import StudentProductListCell from './StudentProductListCell';
import ReactNative, {
    View,
    ScrollView,
    Text,
    NativeAppEventEmitter,
    StyleSheet,
    ListView,
    Image,
    TouchableOpacity,
    Dimensions,
} from 'react-native';

export default class Result extends Component {
  constructor(props) {
    super(props);
    this._renderRow = this._renderRow.bind(this);
    this._renderHeader = this._renderHeader.bind(this);
    this._renderSectionHeader = this._renderSectionHeader.bind(this);
    this.dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
  }

  componentDidMount() {
      this.props.fetchStudentProducts();
  }

  _renderRow(rowData: object, sectionID: number, rowID: number) {
      let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
      let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft, marginTop: 0} : {paddingLeft};
          return (
              <StudentProductListCell
                    style={[styles.listContainer, customStyle]}
                    key={'row' + rowID}
                    rowID={rowID}
                    data={rowData}
                    onPressProduct={this.props.onPressProduct}
               />
            );
        }

  _renderHeader(){
      let {resource} = this.props;
      let {verifyResult} = resource?resource:null;
      let text  = verifyResult?'认证成功!100有货币已放入您的账户':'太遗憾了,您的学校信息未通过审核!';
      let {count} = resource?resource:null;
      let aaaaa = true;

      return (
          aaaaa?
          <View style={styles.subview}>
              <Image style={styles.thumb} source={{uri: 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'}}/>
              <Text style={styles.title}>{text}</Text>
              <View style={styles.reVerifyView}>
                  <Text style={styles.customColorTips}>您是所在城市第</Text>
                  <Text style={styles.redColorTips}>100000</Text>
                  <Text style={styles.customColorTips}>位认证学生~</Text>
              </View>
          </View>
              :<View style={styles.subview}>
                  <Image style={styles.thumb} source={{uri: 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'}}/>
                  <Text style={styles.title}>{text}</Text>
                  <View style={styles.reVerifyView}>
                  <Text style={styles.customColorTips}>您可以</Text>
                  <TouchableOpacity activeOpacity={0.5} onPress={() => {
                                  this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.url);
                              }}>
                              <Text style={styles.redColorTips}>重新验证></Text>
                              </TouchableOpacity>
                  </View>
              </View>
      );
  }

  _renderSectionHeader(){
      return (
            <Text style={styles.sectionHeader}>学生专属商品</Text>
      );
  }

  render() {
      let {resource}=this.props;
      let obj= resource?resource.get('studentProducts'):null;
      let dataSource = obj?obj.get('product_list'):[];
      if (!dataSource || dataSource.size == 0) {
          return null;
      }
      return (
      <View style={styles.container}>
        <ListView
          contentContainerStyle={styles.grid}
          dataSource={this.dataSource.cloneWithRows(dataSource.toArray())}
          renderRow={this._renderRow}
          renderHeader={this._renderHeader}
          pressRow={this._pressRow}
          renderSectionHeader={this._renderSectionHeader}
          enableEmptySections = {true}
        />
      </View>
    );
}
}

let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;

let styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#ffffff',
    },
    grid: {
        flexDirection: 'row',
        flexWrap: 'wrap',
    },
    title: {
        color: '#dc143c',
        fontSize: 14,
        textAlign:'center',
        marginTop:8,
    },
    subview:{
        paddingTop:50,
        alignItems:'center',
        height:200,
        width,
    },
    thumb:{
        width:60,
        height:60,
        alignItems: 'center',
    },
    reVerifyView:{
        alignItems:'center',
        flexDirection: 'row',
        justifyContent: 'center',
        marginTop:8,
    },
    redColorTips:{
        color:'#dc143c',
        marginLeft: 5,
        fontSize:12,
    },
    customColorTips:{
        color:'#a9a9a9',
        fontSize:12,
    },
    listContainer: {
        width: width / 2,
    },
    sectionHeader: {
        height: 33,
        width,
        backgroundColor: 'gainsboro',
        fontSize: 14,
        textAlign:'center',
        flex: 1,
        paddingTop:10,

        // borderTopWidth: 0.5,         // borderTopWidth 在iPhone 6P上显示有bug
        // borderTopColor: '#e0e0e0',
    },
});