StockStats.js
4.82 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
'use strict';
import React, {Component} from 'react';
import PlainTextSection from './PlainTextSection';
import Placeholder from './Placeholder';
import LoadMoreIndicator from './indicator/LoadMoreIndicator';
import LoadingIndicator from './indicator/LoadingIndicator';
import moment from 'moment';
import {
StyleSheet,
View,
Text,
ListView,
Image,
Dimensions,
TouchableHighlight,
} from 'react-native';
export default class StockStats extends Component {
constructor(props) {
super (props);
this.ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this._renderRow = this._renderRow.bind(this);
}
_renderRow(rowData, sectionID, rowID) {
switch (sectionID) {
case 'SECTION_HEADER':
return (
<View style={styles.container}>
<PlainTextSection content={rowData.section2} />
<Placeholder containerStyle={{borderBottomWidth: 0}}/>
</View>
);
case 'SECTION_TIME':
return (
<View style={styles.container}>
<View style={styles.dateContainer}>
<Image source={require('../images/date.png')}/>
<Text style={styles.date}>{moment().subtract(1, 'days').format('YYYY年M月D日')}</Text>
</View>
<Placeholder containerStyle={{borderBottomWidth: 0}}/>
</View>
);
case 'SECTION_CONTENT':
return (
<TouchableHighlight underlayColor={'white'} onPress={() => {}}>
<View style={styles.row}>
<Image source={{uri: rowData.imageUrl}} style={styles.thumb}/>
<View style={styles.detail}>
<Text style={styles.brand}>{rowData.brandName}</Text>
<Text style={styles.product}>{rowData.goodsName}</Text>
<Text style={styles.brand}>{'厂家编号:' + rowData.factoryCode + ' sku:' + rowData.productSku}</Text>
<Text style={styles.product}>{'进货价:' + rowData.purchasePrice + '元 库存:' + rowData.storeNums}</Text>
</View>
</View>
</TouchableHighlight>
);
default:
return (
<Text>Error data source</Text>
);
}
}
render() {
let isFetching = this.props.isFetching;
let loadText = '暂无更多数据';
if (!this.props.reachEnd) {
loadText = isFetching ? '正在加载...' : '上拉加载更多';
}
return (
<View style={styles.container}>
<ListView
dataSource={this.ds.cloneWithRowsAndSections(this.props.section.toJS())}
renderRow={this._renderRow}
renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator}/>}
onEndReached={this.props.requestData}
enableEmptySections={true}
removeClippedSubviews={false}
renderFooter={()=>{
return <LoadMoreIndicator
hidden={this.props.hideLoadingFooter}
loadingText={loadText}
animating={isFetching}
/>
}}
/>
{!this.props.hideLoadingFooter ? null : <LoadingIndicator isVisible={isFetching}/>}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
dateContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
height: 45,
backgroundColor: 'white',
},
date: {
fontSize: 14,
color: '#444444',
textAlign: 'center',
marginLeft: 10,
},
separator: {
height: 1,
},
row: {
flexDirection: 'row',
paddingLeft: 10,
paddingRight: 10,
paddingTop: 10,
paddingBottom: 10,
backgroundColor: 'white',
alignItems: 'center',
},
detail: {
flexDirection: 'column',
justifyContent: 'center',
flex: 1,
paddingLeft: 20,
},
thumb: {
width: 60,
height: 80,
},
brand: {
color: '#B0B0B0',
fontSize: 12,
},
product: {
color: '#444444',
fontSize: 12,
},
});