HaggleListContainer.js
7.61 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {AsyncStorage, Platform, StyleSheet, View, Dimensions, InteractionManager} from 'react-native'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as allianceActions from '../reducers/haggleListReducer/haggleActions';
import HaggleList from '../components/HaggleList'
import LoadingIndicator from '../../common/components/LoadingIndicator';
import { TipsAlertItem, TipsAlert } from '../../common/components/YH_TipsAlert';
import { YHAlert, YHAlertItem } from '../components/cell/YH_Alert.js';
import DeviceInfo from 'react-native-device-info';
import Prompt from '../../common/components/Prompt';
const actions = [
allianceActions,
];
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 HaggleListContainer extends Component {
constructor(props) {
super(props);
this.state = {showAlert:false, productItem:null, showVersionAlert:false};
this._onEndReached = this._onEndReached.bind(this);
this._onPressProduct = this._onPressProduct.bind(this);
this._jumpHaggleDetail = this._jumpHaggleDetail.bind(this);
this._onPressCategory = this._onPressCategory.bind(this);
this._hiddenTipsAlertDialog = this._hiddenTipsAlertDialog.bind(this);
this._timerStop = this._timerStop.bind(this);
this._resourceJumpWithUrl = this._resourceJumpWithUrl.bind(this);
this._onRefresh = this._onRefresh.bind(this);
this._onPromptHidden = this._onPromptHidden.bind(this);
}
componentDidMount() {
this.props.actions.getResourceInfo(function (json) {
json && json.forEach(item => {
})
});
this.props.actions.getHaggleProductList();
}
componentWillUnmount() {
}
_resourceJumpWithUrl(url, type, params) {
if (!url) {
return;
}
if (type === 'icon' && params) {
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_CPS_MAIN_ICON_C', params);
} else if (type === 'banner' && params) {
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_CPS_MAIN_BANNER_C', params);
} else if (type && params) {
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_CPS_MAIN_ACTIVITY_C', params);
}
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
_onEndReached(categoryType) {
if (categoryType == 0) {
this.props.actions.getHaggleProductList();
}else if (categoryType == 1){
this.props.actions.getMyHaggleProductList();
}
}
_onRefresh(categoryType) {
InteractionManager.runAfterInteractions(() => {
this.props.actions.refreshProductList(categoryType);
});
}
_timerStop() {
this.props.actions.refreshProductList(1);
}
_showTipsAlertDialog(){
this.props.actions.showTipsAlertDialog();
}
_hiddenTipsAlertDialog(){
this.setState({showAlert:false, productItem:null});
}
_onPressCategory(index) {
this.props.actions.setSelectedCategory(index);
}
_jumpHaggleDetail(product, status) {
let productSkn = product && product.get('productSkn', 0);
let activityId = product && product.get('activityId', 0);
let cutRecordId = product && product.get('cutRecordId', 0);
if (!productSkn) {
return;
}
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.haggleDetail","params":{"type":"haggleDetail","title":"砍价详情", "productSkn":"${productSkn}", "activityId":"${activityId}","status": "${status}","cutRecordId":"${cutRecordId}"}}`;
if (cutRecordId == 0) {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.haggleDetail","params":{"type":"haggleDetail","title":"砍价详情", "productSkn":"${productSkn}", "activityId":"${activityId}","status": "${status}"}}`;
}
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
_onPromptHidden() {
this.setState({showVersionAlert:false});
}
_onPressProduct(product) {
let app_version = DeviceInfo.getVersion();
if (Platform.OS === 'ios' && app_version === '6.8.3') {
this.setState({showVersionAlert:true});
return;
}
let {categoryType} = this.props.haggle;
let that = this;
if (categoryType == 1) {
this._jumpHaggleDetail(product, 0);
}else {
this.props.actions.getHaggleStatus(product.get('productSkn'), product.get('activityId'), function (json){
if (json) {
that.setState({showAlert:true, productItem:product});
}else {
that._jumpHaggleDetail(product, 1);
}
});
}
}
render() {
let {productList, myHaggleProductList, resourceInfo, isShowAlert, categoryType} = this.props.haggle;
let isFetching = productList.isFetching || myHaggleProductList.isFetching;
let isPullToRefresh = productList.isPullToRefresh || myHaggleProductList.isPullToRefresh;
return (
<View style={styles.container}>
<YHAlert
ref='YHAlert'
isShow = {this.state.showAlert}
title = '当前有未完成的砍价!'
content={'该商品正在砍价中,去邀请好友帮忙砍价吧!'}
>
<YHAlertItem key={'minCancel'} param={this.state.productItem} showStatus='LightGrayButton'
handleAction={(param) => {
{this._hiddenTipsAlertDialog()};
}}>取消</YHAlertItem>
<YHAlertItem key={'minSure'} param={this.state.productItem} showStatus='redButton'
handleAction={(param) => {
{this._hiddenTipsAlertDialog()};
{this._jumpHaggleDetail(param, 0)};
}}>查看详情</YHAlertItem>
</YHAlert>
<HaggleList
data= {categoryType==0 ? productList : myHaggleProductList}
resourceInfo = {resourceInfo}
onEndReached={this._onEndReached}
categoryType={categoryType}
onPressProduct={this._onPressProduct}
firstHaggle={this._firstHaggle}
continueHaggle={this._continueHaggle}
onPressCategory={this._onPressCategory}
onStop={this._timerStop}
resourceJumpWithUrl={this._resourceJumpWithUrl}
onRefresh={this._onRefresh}
/>
<LoadingIndicator isVisible={isFetching && !isPullToRefresh}/>
{this.state.showVersionAlert ? <Prompt
text={'您的版本不支持该功能,请更新版本!'}
duration={1600}
onPromptHidden={this._onPromptHidden}
/> : null}
</View>
);
}
}
let {width} = Dimensions.get('window');
const styles = StyleSheet.create({
container: {
flex: 1,
}
})
export default connect(mapStateToProps, mapDispatchToProps)(HaggleListContainer);