CouponListContainer.js 2.89 KB
import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  TextInput,
  TouchableOpacity,
  View,
} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import {Map} from 'immutable';
import * as couponActions from '../reducers/coupon/couponActions';
import CouponList from '../components/coupon/CouponList';
import CouponTabs from '../components/coupon/CouponTabs';

const actions = [
  couponActions,
];

function mapStateToProps(state) {
  return {
      ...state
  };
}

function mapDispatchToProps(dispatch) {

  const creators = Map()
      .merge(...actions)
      .filter(value => typeof value === 'function')
      .toObject();

  return {
      actions: bindActionCreators(creators, dispatch),
      dispatch
  };
}

class CouponListContainer extends Component {
  constructor(props) {
    super(props);
    props.actions.getCouponNums();
    props.actions.getCouponList('notuse', true);
    props.actions.getCouponList('use', true);
    props.actions.getCouponList('overtime', true);
  }

  state = {couponCode: ''}

  render() {
    const { couponNums } = this.props.coupon;
    return (
      <ScrollableTabView
        renderTabBar={() => <CouponTabs couponNums={couponNums} />}
      >
        <View style={styles.container} tabLabel="未使用">
          <View style={styles.bindCouponContainer}>
            <TextInput
              style={styles.textInput}
              onChangeText={text => this.setState({couponCode: text})}
              placeholder="请输入优惠券码"
              underlineColorAndroid="transparent"
            />
            <TouchableOpacity
              onPress={() => null}
              style={[styles.bindCouponBtn, this.state.couponCode.length > 0 && styles.blackBack]}
            >
              <Text style={styles.bindCouponText}>兑换</Text>
            </TouchableOpacity>
          </View>
          <CouponList />
        </View>
        <View style={{flex: 1, backgroundColor: 'yellow'}} tabLabel="已使用"/>
        <View style={{flex: 1, backgroundColor: 'green'}} tabLabel="已失效"/>
      </ScrollableTabView>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  bindCouponContainer: {
    height: 45,
    paddingHorizontal: 10,
    paddingVertical: 8,
    flexDirection: 'row',
  },
  textInput: {
    flex: 1,
    height: 30,
    marginRight: 10,
    fontSize: 12,
    padding: 0,
    paddingLeft: 10,
    backgroundColor: '#f0f0f0',
    borderRadius: 2,
  },
  bindCouponBtn: {
    width: 60,
    height: 30,
    backgroundColor: '#b0b0b0',
    borderRadius: 2,
    justifyContent: 'center',
    alignItems: 'center',
  },
  blackBack: {
    backgroundColor: '#444444',
  },
  bindCouponText: {
    fontSize: 14,
    color: '#ffffff',
  }
})

export default connect(mapStateToProps, mapDispatchToProps)(CouponListContainer);