Blame view

js/home/components/floor/PopularSingleProduct.js 4.85 KB
chenl authored
1 2 3 4 5
'use strict';

import React, {Component} from 'react';
import ReactNative, {
    View,
6 7
    Text,
    ListView,
chenl authored
8 9 10 11
    TouchableOpacity,
    StyleSheet,
    Dimensions,
} from 'react-native';
12
import Immutable, {Map, List} from 'immutable';
chenl authored
13 14 15


import SlicedImage from '../../../common/components/SlicedImage';
16
import YH_Image from '../../../common/components/YH_Image';
chenl authored
17
import HeadTitleCell from '../cell/HeadTitleCell';
18 19
import ImageSlider from '../cell/ImageSlider';
chenl authored
20 21 22 23 24 25 26 27 28 29

/**
 *   人气单品楼层,
 *   这个楼层是上边一个banner大图(数据是列表,但未处理列表逻辑),下边是滚动列表图
 **/
export default class PopularSingleProduct extends Component{


	constructor(props) {
	  super(props);
30 31 32 33
      this.dataSource = new ListView.DataSource({
          rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
      });
      this.renderRow = this.renderRow.bind(this);
chenl authored
34 35
	}
36
    renderRow(rowData,sectionID,rowID,highlightRow){
37 38 39 40
        let data = this.props.data;
        let banner = data.get("banner_image");
        let bannerLength = banner.toJS().length;
        let index = parseInt(rowID)+bannerLength;
41
42
        let goodsImageUrl = rowData.get('default_images', '');
43
        goodsImageUrl = SlicedImage.getSlicedUrl(goodsImageUrl, goodsImageWidth, goodsImageHeight, 2);
44
        let goodsPrice = "¥" + parseFloat(rowData.get('sales_price', 0)).toFixed(2);
45 46
        let goodsLookNum = rowData.get('sales_num') + "人";
47 48 49
        let yh_exposureData = rowData.get('yh_exposureData') ? rowData.get('yh_exposureData').toJS() : null;

50
        return (
51
            <TouchableOpacity
52
                activeOpacity={1} yh_exposureData={yh_exposureData}
53
                onPress={() => this.props.onPressToProductDetail && this.props.onPressToProductDetail(rowData, goodsImageUrl, index)}
54
            >
55 56

                <View style={styles.goodsContainer}>
57 58
                    <YH_Image
                        style={styles.goodsImage}
59 60
                        masksToBounds={true}
                        radius={{'topLeft':'2','topRight':'2','bottomRight':'2','bottomLeft':'2'}}
61
                        url={goodsImageUrl}
62
                    />
63 64
                    <Text style={styles.goodsPrice} numberOfLines={1}>{goodsPrice}</Text>
                    <Text style={styles.goodsLookNum} numberOfLines={1}>{goodsLookNum}</Text>
65
                    <Text style={[styles.goodsLookNum, {marginTop: -5}]} numberOfLines={1}>正在浏览</Text>
66 67 68 69 70 71 72
                </View>

            </TouchableOpacity>
        );

    }
chenl authored
73 74 75

	render(){
76
        let data = this.props.data;
77 78
        let background =  data.get("background");
        let banner = data.get("banner_image");
79
80
		let title = data.get("title");
81 82
		let imglst = data.get("list", List());
83 84 85
        let yh_exposureDataTitle = title.get('yh_exposureData') ? title.get('yh_exposureData').toJS() : null;

chenl authored
86
		return(
87
			<View style={styles.container}>
88
				<HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')} 
89
                    onPressTitleMore={this.props.onPressTitleMore} yh_exposureData={yh_exposureDataTitle} />
90 91 92 93 94 95
                <ImageSlider
                    resource={banner}
                    sliderWidth={width}
                    sliderHeight={bannerHeight}
                    onPressSlideItem={this.props.onPressSlideItem}
                />
96 97 98 99
                <ListView
                    style={styles.listViewContainer}
                    dataSource={this.dataSource.cloneWithRows(imglst.toArray())}
                    horizontal={true}
100
                    renderRow={this.renderRow}
101
                    enableEmptySections={true}
102
                />
chenl authored
103 104 105 106 107 108 109 110 111
			</View>
        );
	}

};

let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
112
let bannerHeight = Math.ceil(width * 234 / 750);
113 114
let goodsImageWidth = Math.ceil(90);
let goodsImageHeight = Math.ceil(120);
115
let containerHeight = 40 + bannerHeight + 192;
116
chenl authored
117 118 119 120 121

let styles = StyleSheet.create({

	container: {
        width: width,
122
        height: containerHeight,
123
        backgroundColor: 'white'
chenl authored
124 125 126 127 128 129 130
    },

    bannerImage: {
        width: width,
        height: bannerHeight,
    },
131 132
    listViewContainer: {
        width: width,
133 134 135
        height: 202,
        paddingTop: 12,
        paddingBottom: 12,
136
        backgroundColor: '#ffffff',
chenl authored
137 138
    },
139
    goodsContainer: {
140 141 142
        width: 90,
        height: 178,
        marginLeft: 11,
143
        // backgroundColor: '#f0f0f0',
chenl authored
144 145
    },
146 147 148
    goodsImage: {
        width: goodsImageWidth,
        height: goodsImageHeight,
149
        borderRadius: 2,
chenl authored
150 151
    },
152 153
    goodsPrice: {
        width: goodsImageWidth,
154
        height: 20,
155
        fontSize: 12,
156
        fontWeight: 'bold',
157 158
        color: '#444444',
        textAlign: 'center',
159
        marginTop: 5,
chenl authored
160 161
    },
162 163
    goodsLookNum: {
        width: goodsImageWidth,
164
        height: 15,
165 166
        fontSize: 9,
        fontWeight: 'bold',
167 168
        color: '#b0b0b0',
        textAlign: 'center',
chenl authored
169 170 171
    },

});