ExchangeRecord.js 4.34 KB
import React from 'react';
import { View, Text, Image, StyleSheet, TouchableOpacity, Platform, FlatList, PixelRatio } from 'react-native';
import { observer } from 'mobx-react/native';
import { zoomW, zoomH } from '../../../../utils/getSize';
import integralLogic from '../../../logic/integralLogic';
import ActivePage from '../../components/ActivePage';
import { withNavigationFocus } from 'react-navigation-is-focused-hoc';

const line = 1 / PixelRatio.get();
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#f4f4f4',
  },
  item: {
    height: 115,
    backgroundColor: 'white',
    flexDirection: 'row',
    paddingLeft: 15,
    alignItems: 'center',
  },
  itemImage: {
    height: 100,
    width: 100,
    marginRight: 15,
  },
  other: {
    flex: 1,
    height: 115,
    borderBottomColor: '#f4f4f4',
    borderBottomWidth: line,
    paddingTop: 15,
    paddingRight: 15,
    paddingLeft: 5,
  },
  name: {
    fontSize: 16,
    color: '#333333',
    marginBottom: 15,
  },
  row: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  count: {
    fontSize: 16,
    color: '#ea281a',
    flex: 1,
  },
  button: {
    width: 74,
    height: 26,
    alignItems: 'center',
    justifyContent: 'center',
    borderWidth: line,
    borderColor: '#999999',
    borderRadius: 2,
  },
  status: {
    fontSize: 14,
  },
  content1: {
    flex: 1,
    alignItems: 'center',
    paddingTop: 160,
  },
  img: {
    height: 85,
    width: 85,
    marginBottom: 15,
  },
  text: {
    fontSize: 14,
    color: '#999999',
  },
  pic: {
    height: 85,
    width: 85,
    marginBottom: 15,
  },
  size: {
    fontSize: 12,
    color: '#999999',
    marginBottom: 15,
  },
  backWrap: {
    justifyContent: 'center',
    paddingLeft: 15 / zoomW,
    paddingRight: 15 / zoomW,
    height: 44 / zoomH,
  },
});
@observer
class ExchangeRecord extends React.Component {
  static navigationOptions=({ navigation, screenProps }) => ({
    title: '积分兑换记录',
    tabBarIcon: ({ focused }) => <Image
      source={focused ? require('./imgs/mallActive.png') : require('./imgs/mall.png')}
      style={styles.tabIcon}
      resizeMode="contain"
    />,
    headerLeft: (
      <View />
        ),
    headerRight: (
      <View />
        ),
  });

  logic = new integralLogic()
  item = (v) => {
    const { orderLineList, status, totalPoint, id } = v;
    const { params } = this.props.navigation.state;
    let hasOffset = false;
    if (params) {
      hasOffset = params.hasOffset;
    }

    const {
			commodityTitle, itemSpec1AttributeName, itemSpec1ValueName, itemSpec2AttributeName,
			itemSpec2ValueName, quantity, pictureUrl, itemSpec3AttributeName, itemSpec3ValueName, commodityId, isVirtual,
		} = orderLineList.length > 0 ? orderLineList[0] : {};
    return (
      <View style={styles.item}>
        <Image style={styles.itemImage} source={{ uri: pictureUrl }} resizeMode={'contain'} />
        <View style={styles.other}>
          <Text style={styles.name}>{commodityTitle}</Text>
          <Text style={styles.size}>
            {!!itemSpec1ValueName && `${itemSpec1AttributeName}:${itemSpec1ValueName}`}
            {!!itemSpec2ValueName && `${itemSpec2AttributeName}:${itemSpec2ValueName}`}
            {!!itemSpec3ValueName && `${itemSpec3AttributeName}:${itemSpec3ValueName}`}
          </Text>
          <View style={styles.row}>
            <Text style={styles.count}>{totalPoint}积分</Text>
          </View>
        </View>
      </View>
    );
  }

  async componentWillMount() {
    await this.logic.get();
  }
  async componentWillReceiveProps(props) {
    if (props.isFocused) {
      await this.logic.get();
    } else {

    }
  }
  content1() {
    if (this.logic.loading) {
      return <ActivePage />;
    }
    if (this.logic.list.length === 0) {
      return (
        <View style={styles.content1}>
          <Image source={require('./imgs/exchange.png')} resizeMode={'contain'} style={styles.pic} />
          <Text style={styles.text}>暂无兑换记录</Text>
        </View>
      );
    }
    return (
      <FlatList
        keyExtractor={item => item.id}
        data={this.logic.list}
        extraData={this.logic.change}
        renderItem={({ item }) => this.item(item)}
      />);
  }

  render() {
    return (
      <View style={styles.container}>
        {this.content1()}
      </View>
    );
  }
}
export default withNavigationFocus(ExchangeRecord);