InterestHeader.js
4.75 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
import SlicedImage from '../../../common/components/SlicedImage';
import DeleteLineText from '../../../common/components/DeleteLineText';
export default class InterestHeader extends Component {
constructor(props) {
super(props);
}
render() {
let {data, rowID} = this.props;
let brandIconUrl = SlicedImage.getSlicedUrl(data.get('brand_img', ''), 150, 80, 2);
let typeText = '';
let extra = '';
let textBgColor = '#FD9E2B';
let type = data.get('brand_type', '');
if (type == 'new') {
typeText = 'NEW';
textBgColor = '#86BF4A';
} else if (type == 'sale') {
typeText = 'SALE';
let discount = data.get('discount', '');
if (discount) {
extra = ` ${discount}折起`;
}
textBgColor = '#D00822';
} else if (type == 'recommend') {
typeText = '推荐';
textBgColor = '#FD9E2B';
} else if (type == 'activity') {
typeText = '活动';
textBgColor = '#D1011C';
}
if (extra) {
typeText = typeText + extra;
}
let buttonImage = data.get('is_fav', '') == 'Y' ? require('../../images/shared_enterbuttom_normal.png') : require('../../images/wsc_icon.png');
return (
<TouchableOpacity
activeOpacity={1}
onPress={() => {
this.props.onPressBrand && this.props.onPressBrand(data, rowID);
}}
>
<View style={styles.header}>
<View style={styles.leftContainer}>
<Image style={styles.brandIcon} source={{uri: brandIconUrl}} />
<View style={styles.nameDateContainer}>
<Text style={styles.brandName} numberOfLines={1}>{data.get('brand_name', '')}</Text>
<Text style={styles.date} numberOfLines={1}>{data.get('date', '')}</Text>
</View>
</View>
<View style={styles.rightContainer}>
<Text style={[styles.type, {backgroundColor: textBgColor}]}>{typeText}</Text>
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => {
this.props.onInterestLike && this.props.onInterestLike(data, rowID, data.get('is_fav', '') == 'Y' ? true : false);
}}
>
<Image style={styles.button} source={buttonImage} />
</TouchableOpacity>
</View>
</View>
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let headerHeight = 50 * DEVICE_WIDTH_RATIO;
let brandIconWidth = 75 * DEVICE_WIDTH_RATIO;
let brandIconHeight = 40 * DEVICE_WIDTH_RATIO;
let favWidth = 40 * DEVICE_WIDTH_RATIO;
let styles = StyleSheet.create({
header: {
flexDirection: 'row',
alignItems: 'center',
// alignSelf: 'center',
justifyContent: 'space-between',
height: headerHeight,
backgroundColor: 'white',
},
leftContainer: {
flexDirection: 'row',
alignItems: 'center',
},
brandIcon: {
marginLeft: 15 * DEVICE_WIDTH_RATIO,
width: 75 * DEVICE_WIDTH_RATIO,
height: 40 * DEVICE_WIDTH_RATIO,
resizeMode: 'contain',
},
nameDateContainer: {
marginLeft: 15 * DEVICE_WIDTH_RATIO,
},
brandName: {
fontSize: 14 * DEVICE_WIDTH_RATIO,
color: '#444444',
fontWeight: 'bold',
marginTop: 5 * DEVICE_WIDTH_RATIO,
},
date: {
fontSize: 12 * DEVICE_WIDTH_RATIO,
color: '#b0b0b0',
marginTop: 5 * DEVICE_WIDTH_RATIO,
},
rightContainer: {
flexDirection: 'row',
alignItems: 'center',
},
type: {
fontSize: 14 * DEVICE_WIDTH_RATIO,
color: 'white',
fontWeight: 'bold',
paddingLeft: 8,
paddingRight: 8,
paddingTop: 1,
paddingBottom: 1,
borderRadius: 16 * DEVICE_WIDTH_RATIO / 2,
backgroundColor: '#FD9E2B',
overflow: 'hidden',
},
buttonContainer: {
justifyContent: 'center',
alignItems: 'center',
width: favWidth,
height: headerHeight,
},
button: {
width: 17,
height: 17,
resizeMode: 'contain',
},
});