CouponListContainer.js
6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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';
import Prompt from '../components/coupon/Prompt';
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: '', selectedTab: 0, showFilter: false, selectedFilter: 0}
render() {
const { showFilter, selectedFilter } = this.state;
const { couponNums, notuse, use, overtime, showSuccessTip } = this.props.coupon;
return (
<View style={styles.container}>
<ScrollableTabView
onChangeTab={this.onChangeTab}
renderTabBar={() => <CouponTabs couponNums={couponNums} selectTab={this.selectTab} showFilter={this.state.showFilter}/>}
>
<View style={styles.container} tabLabel="未使用">
<View style={styles.bindCouponContainer}>
<TextInput
style={styles.textInput}
onChangeText={text => this.setState({couponCode: text})}
placeholder="请输入优惠券码"
underlineColorAndroid="transparent"
/>
<TouchableOpacity
onPress={this.bindCoupon}
style={[styles.bindCouponBtn, this.state.couponCode.length > 0 && styles.blackBack]}
>
<Text style={styles.bindCouponText}>兑换</Text>
</TouchableOpacity>
</View>
<CouponList isFetching={notuse.isFetching} data={notuse.list} onEndReached={() => this.props.actions.getCouponList('notuse')} type="notuse"/>
</View>
<View style={styles.container} tabLabel="已使用">
<CouponList isFetching={use.isFetching} data={use.list} onEndReached={() => this.props.actions.getCouponList('use')} type="use"/>
</View>
<View style={styles.container} tabLabel="已失效">
<CouponList isFetching={overtime.isFetching} data={overtime.list} onEndReached={() => this.props.actions.getCouponList('overtime')} type="overtime"/>
</View>
</ScrollableTabView>
{showSuccessTip ? <Prompt
text={showSuccessTip}
duration={800}
onPromptHidden={this._onPromptHidden}
/> : null}
{showFilter ? <View style={styles.filterContianer}>
<View style={styles.filterTabs}>
{notuse.filters && notuse.filters.map((item, index) => {
return (
<TouchableOpacity
activeOpacity={0.9}
key={index}
style={[styles.filterTab, (selectedFilter == item.filter_id) && styles.selectedFilterTab]}
onPress={() => this.pressFilter(item.filter_id)}>
<Text style={[styles.filterText, (selectedFilter == item.filter_id) && styles.selectedFilterText]}>{item.filter_name}</Text>
</TouchableOpacity>
)
})}
</View>
<TouchableOpacity style={styles.container} onPress={() => this.setState({showFilter: false})} />
</View> : null}
</View>
)
}
selectTab = i => {
if (i == 0 && this.state.selectedTab == 0) {
this.setState({showFilter: !this.state.showFilter});
return false;
} else {
return true;
}
}
onChangeTab = tab => {
const { i } = tab;
let { showFilter } = this.state;
if (i != 0) {
showFilter = false;
}
this.setState({selectedTab: i, showFilter});
}
bindCoupon = () => {
this.props.actions.bindCoupon(this.state.couponCode);
}
pressFilter(filter_id) {
if (this.state.selectedFilter == filter_id) {
return
}
this.props.actions.getCouponList('notuse', true, filter_id);
this.setState({selectedFilter: filter_id, showFilter: false});
}
_onPromptHidden = () => {
this.props.actions.promptHidden();
}
_onNetPromptHidden() {
this.props.actions.netPromptHidden();
}
}
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',
},
filterContianer: {
position: 'absolute',
top: 45,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.4)'
},
filterTabs: {
height: 65,
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#ffffff'
},
filterTab: {
width: 73,
height: 33,
borderWidth: 1,
borderColor: '#e0e0e0',
borderRadius: 2,
justifyContent: 'center',
alignItems: 'center',
},
selectedFilterTab: {
backgroundColor: '#444444'
},
filterText: {
fontSize: 14,
color: '#444444',
},
selectedFilterText: {
color: '#ffffff',
}
})
export default connect(mapStateToProps, mapDispatchToProps)(CouponListContainer);