Authored by 于良

Merge branch 'brand_store' of http://git.yoho.cn/mobile/YH_RNComponent into brand_store

@@ -30,6 +30,7 @@ import Recommend from '../brandStore/brandStoreSubView/Cells/Recommend'; @@ -30,6 +30,7 @@ import Recommend from '../brandStore/brandStoreSubView/Cells/Recommend';
30 import BrandProductFilter from '../brandStore/brandStoreSubView/Cells/BrandProductFilter' 30 import BrandProductFilter from '../brandStore/brandStoreSubView/Cells/BrandProductFilter'
31 import BrandProductListCell from '../brandStore/brandStoreSubView/Cells/BrandProductListCell'; 31 import BrandProductListCell from '../brandStore/brandStoreSubView/Cells/BrandProductListCell';
32 import BrandStoreFilter from '../brandStore/brandStoreSubView/Cells/BrandStoreFilter'; 32 import BrandStoreFilter from '../brandStore/brandStoreSubView/Cells/BrandStoreFilter';
  33 +import HotProducts from '../brandStore/brandStoreSubView/Cells/HotProducts';
33 34
34 35
35 export default class BrandStore extends Component { 36 export default class BrandStore extends Component {
@@ -141,6 +142,16 @@ export default class BrandStore extends Component { @@ -141,6 +142,16 @@ export default class BrandStore extends Component {
141 ); 142 );
142 } 143 }
143 break; 144 break;
  145 + case '5':
  146 + {
  147 + return (
  148 + <HotProducts
  149 + resource={rowData}
  150 + onPressRecommendItem={this.props.onPressRecommendItem}
  151 + />
  152 + );
  153 + }
  154 + break;
144 default: 155 default:
145 return null; 156 return null;
146 break; 157 break;
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +
  6 +const {
  7 + Image,
  8 + View,
  9 + StyleSheet,
  10 + Dimensions,
  11 + Text,
  12 + ListView,
  13 + TouchableOpacity,
  14 +} = ReactNative;
  15 +import {Map} from 'immutable';
  16 +
  17 +export default class HotProducts extends React.Component {
  18 +
  19 + constructor(props) {
  20 + super (props);
  21 +
  22 + this.dataSource = new ListView.DataSource({
  23 + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
  24 + });
  25 + }
  26 +
  27 + componentDidMount() {
  28 + }
  29 +
  30 + _pressRow(rowData){
  31 + // this.props.onPressRecommendItem(rowData.url)
  32 + }
  33 +
  34 + renderRow(rowData,sectionID,rowID,highlightRow) {
  35 +
  36 + let data = rowData.toJS();
  37 + let path = data.default_images;
  38 + let url = data.default_images.replace('{width}', IMAGE_WIDTH).replace('{height}', IMAGE_HEIGHT);
  39 +
  40 + return (
  41 + <TouchableOpacity activeOpacity={0.5} onPress={() => this._pressRow(rowData)}>
  42 + <View style={{width:itemWidth,height:itemHeight,backgroundColor:'white',alignItems:'center',justifyContent:'center'}}>
  43 + <View style={{width:imageWidth,height:imageHeight,marginLeft:20,marginTop:10}}>
  44 + <Image
  45 + source={{uri: url}}
  46 + style={{width:imageWidth,height:imageHeight}}
  47 + resizeMode={'cover'}>
  48 + <View style={styles.itemTitle}>
  49 + <Text numberOfLines={1} style={styles.itemText}>{data.product_name}</Text>
  50 + <Text numberOfLines={1} style={styles.itemText}>{'¥'+data.market_price}</Text>
  51 + </View>
  52 + </Image>
  53 + </View>
  54 + </View>
  55 + </TouchableOpacity>
  56 +
  57 + );
  58 + }
  59 +
  60 + renderHeader(){
  61 + return(
  62 + <View style={styles.container}>
  63 + <View style={styles.title}>
  64 + <Text style={styles.text}>人气单品</Text>
  65 + </View>
  66 + </View>
  67 + );
  68 + }
  69 +
  70 + render() {
  71 + let list = this.props.resource;
  72 + if (list.length != 0) {
  73 + let backgroundWidth = Dimensions.get('window').width;
  74 + let backgroundHeight = 64 + 20 + Math.ceil(list.length/2) * (IMAGE_RATIO * backgroundWidth/2);
  75 + return (
  76 + <View style={{width: backgroundWidth,height:backgroundHeight,backgroundColor:'white'}}>
  77 + <ListView
  78 + automaticallyAdjustContentInsets={false}
  79 + contentContainerStyle={styles.grid}
  80 + dataSource={this.dataSource.cloneWithRows(list)}
  81 + renderRow={this.renderRow.bind(this)}
  82 + renderHeader = {this.renderHeader.bind(this)}
  83 + pageSize={Math.ceil(list.length/2)}
  84 + enableEmptySections = {true}
  85 + />
  86 + </View>
  87 + );
  88 + }else {
  89 + return null;
  90 + }
  91 +
  92 + }
  93 +};
  94 +
  95 +const IMAGE_WIDTH = 145;
  96 +const IMAGE_HEIGHT = 193;
  97 +const IMAGE_RATIO = IMAGE_HEIGHT / IMAGE_WIDTH;
  98 +const itemWidth= Dimensions.get('window').width/2-10;
  99 +const itemHeight= Dimensions.get('window').width/2 * IMAGE_RATIO;
  100 +const imageWidth= Dimensions.get('window').width/2 - 30;
  101 +const imageHeight= (Dimensions.get('window').width/2 - 30) * IMAGE_RATIO;
  102 +
  103 +const styles = StyleSheet.create({
  104 + grid:{
  105 + flex: 1,
  106 + flexDirection: 'row',
  107 + flexWrap: 'wrap',
  108 + alignItems:'flex-start',
  109 + },
  110 +
  111 + title:{
  112 + alignItems: 'center',
  113 + justifyContent: 'center',
  114 + height:64,
  115 + width:Dimensions.get('window').width,
  116 + backgroundColor:'white',
  117 + borderBottomColor: '#CCC',
  118 + borderBottomWidth: 0.5,
  119 + },
  120 + itemTitle:{
  121 + marginTop:imageHeight - 30,
  122 + justifyContent: 'center',
  123 + height:30,
  124 + width:imageWidth,
  125 + backgroundColor:'gray',
  126 + },
  127 + itemText: {
  128 + fontWeight: 'bold',
  129 + textAlign: 'left',
  130 + color: 'white',
  131 + fontSize: 10,
  132 + },
  133 + text: {
  134 + fontWeight: 'bold',
  135 + textAlign: 'left',
  136 + color: 'gray',
  137 + fontSize: 20,
  138 + },
  139 +});