OrderList.js
5.42 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
InteractionManager,
Platform,
RefreshControl,
PickerIOS,
} from 'react-native';
import {List} from 'immutable';
import YH_PtrRefresh from '../../../common/components/YH_PtrRefresh';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import EmptyView from './EmptyView';
import ListHeader from './ListHeader';
import ListFooter from './ListFooter';
import ProductListCell from '../detail/ProductListCell';
export default class OrderList extends Component {
constructor(props) {
super(props);
this.triggePullToRefresh=this.triggePullToRefresh.bind(this);
this.renderRow = this.renderRow.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
componentDidMount() {
this.triggePullToRefresh();
}
componentWillUnmount() {
}
triggePullToRefresh() {
if (Platform.OS === 'ios') {
this.listView && this.listView.getScrollResponder().startPullToRefresh();
} else {
this.props.onRefresh && this.props.onRefresh(this.props.type);
}
}
renderRow(rowData, sectionID, rowID) {
let isVirtualOrder = rowData.get('attribute','1') == '3';//虚拟商品订单
let isPresaleOrder = rowData.get('attribute','1') == '9';//预售商品订单
let productListBlob = {
isVirtualOrder,
isPresaleOrder,
list: rowData && rowData.get('order_goods'),
};
return (
<View style= {styles.cellContainer}>
<ListHeader data={rowData}/>
<ProductListCell
onPressProduct={() =>{
this.props.onGoDetail && this.props.onGoDetail(rowData);
}}
data={productListBlob}
bottomStyle={{borderBottomWidth:0,borderColor:'#e5e5e5'}}
onPressDelayNotice={this.props.onPressDelayNotice}
/>
<ListFooter
data={rowData}
orderAction={(link) =>{
this.props.orderAction && this.props.orderAction(this.props.type,rowData, link);
}}
/>
</View>
);
}
render() {
let {dataSource} = this.props;
let isFetching = dataSource.get('isFetching',false);
let endReached = dataSource.get('endReached',true);
let list = dataSource.get('list',List());
let total = dataSource.get('total',0);
let isFirstLoad = dataSource.get('firstLoad',true);
let currentPage = dataSource.get('currentPage');
let isPullToRefresh = isFetching && dataSource.get('currentPage') < 1;
let isLoadingMore = list.size != total && !endReached;
let isShowLoading = list.size == 0 && isFetching;
let shouldShowEmpty = list.size == 0 && !isFetching;
if (shouldShowEmpty && !isFirstLoad) {
return(
<View style={styles.container}>
<EmptyView
onPressEmptyItem={this.props.onPressEmptyItem}
/>
</View>
);
}
return (
<View style={styles.container}>
<ListView
ref={(c) => {
this.listView = c;
}}
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(list.toArray())}
renderRow={this.renderRow}
enableEmptySections={true}
enablePullToRefresh={true}
isOnPullToRefresh={isPullToRefresh}
onRefreshData={() => {
this.props.onRefresh && this.props.onRefresh(this.props.type);
}}
onEndReached={() => {
if (list.size != 0) {
this.props.onLoadMore && this.props.onLoadMore(this.props.type);
}
}}
renderFooter={() => {
if (endReached) {
} else {
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={true}
/>;
}
}}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex:1,
flexDirection: 'column',
width: width,
backgroundColor: '#f0f0f0',
},
emptyContainer: {
position: 'absolute',
},
cellContainer: {
backgroundColor: 'transparent',
flexDirection: 'column',
borderColor: '#f0f0f0',
borderBottomWidth: 10
},
contentContainer: {
marginTop: 10,
backgroundColor: '#ededed',
flexWrap: 'wrap'
},
separatorStyle: {
height: 10,
backgroundColor: '#ededed',
},
pickerStyle: {
width,
height:216,
}
});