CouponListContainer.js
8 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import React, { Component } from 'react';
import {
Dimensions,
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';
import SingleImage from '../../coupon/components/common/SingleImage';
import ReactNative from "react-native";
import YH_Image from "../../common/components/YH_Image";
const DEVICE_WIDTH_RATIO = Dimensions.get('window').width / 375;
const { width } = Dimensions.get('window');
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.fetchResourceCode();
props.actions.getCouponNums();
props.actions.getCouponList('notuse', true);
props.actions.getCouponList('use', true);
props.actions.getCouponList('overtime', true);
}
_resourceJumpWithUrl = (url, type, params) => {
if (!url) {
return;
}
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
renderImageJoin = (item) => {
{/*<SingleImage*/}
// data={singleImageData}
// resourceJumpWithUrl={this._resourceJumpWithUrl} />
item = item && item.toJS();
let imageUrl = '', jumurl = '';
let picWdith = 0, picHeight = 0
if (item.template_name === 'splitJointImg' && item.data) {
imageUrl = item.data.src;
jumurl = item.data.urls && item.data.urls[0]
let imageWidth = item.image_width;
let imageHeight = item.image_height;
picWdith = DEVICE_WIDTH_RATIO * imageWidth
picHeight = DEVICE_WIDTH_RATIO * imageHeight
}
return (
<TouchableOpacity style={{width: width, height: picHeight, alignItems: 'center', backgroundColor: '#f0f0f0', paddingTop: 10}} activeOpacity={1} onPress={() => {
jumurl && this._resourceJumpWithUrl(jumurl)
}}>
<YH_Image url={YH_Image.getSlicedUrl(imageUrl, picWdith, picHeight, 2)} resizeMode={'stretch'} style={{ width: picWdith, height: picHeight}}/>
</TouchableOpacity>
)
}
state = {couponCode: '', selectedTab: 0, showFilter: false, selectedFilter: 0}
render() {
const { showFilter, selectedFilter } = this.state;
const { couponNums, notuse, use, overtime, showSuccessTip, resourceInfo } = this.props.coupon;
let singleImageData = resourceInfo.get('resourceList').first()
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>
{/*{singleImageData ?this.renderImageJoin(singleImageData): null }*/}
<CouponList resourceJumpWithUrl ={this._resourceJumpWithUrl} isFetching={notuse.isFetching} data={notuse.list} onEndReached={() => this.props.actions.getCouponList('notuse')} type="notuse" singleImageData={singleImageData}/>
</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);