Authored by 孙凯

添加 goodsGroup UI review jianqiu

@@ -10,6 +10,7 @@ import GoodsCell from './GoodsCell'; @@ -10,6 +10,7 @@ import GoodsCell from './GoodsCell';
10 import Header from './Header'; 10 import Header from './Header';
11 import MoreLink from './MoreLink'; 11 import MoreLink from './MoreLink';
12 import GoodsGroupHeader from './GoodsGroupHeader'; 12 import GoodsGroupHeader from './GoodsGroupHeader';
  13 +import GoodsGroupList from './GoodsGroupList';
13 14
14 import ReactNative, { 15 import ReactNative, {
15 View, 16 View,
@@ -76,8 +77,16 @@ export default class Detail extends Component { @@ -76,8 +77,16 @@ export default class Detail extends Component {
76 <Text>weixinPublic</Text> 77 <Text>weixinPublic</Text>
77 ); 78 );
78 }else if (template_name == 'goods_group') { 79 }else if (template_name == 'goods_group') {
  80 + let {resource} = this.props;
  81 + let {goods_group_Filter} = resource;
  82 + let data = rowData.get('productList')?rowData.get('productList').toArray():null;
  83 + let list = data?data[goods_group_Filter]:null;
  84 +
79 return ( 85 return (
80 - <GoodsGroupHeader resource={rowData}/> 86 + <View style={styles.GoodsGroupHeader}>
  87 + <GoodsGroupHeader resource={{rowData,goods_group_Filter}} onPressFilter= {this.props.onPressFilter}/>
  88 + <GoodsGroupList resource={list}/>
  89 + </View>
81 ); 90 );
82 }else if (template_name == 'goods') { 91 }else if (template_name == 'goods') {
83 return ( 92 return (
@@ -111,6 +120,7 @@ export default class Detail extends Component { @@ -111,6 +120,7 @@ export default class Detail extends Component {
111 brand, 120 brand,
112 otherArticle, 121 otherArticle,
113 weixin, 122 weixin,
  123 + goods_group_Filter,
114 } = resource; 124 } = resource;
115 let list = content?content.get('data'):[]; 125 let list = content?content.get('data'):[];
116 126
@@ -143,4 +153,7 @@ let styles = StyleSheet.create({ @@ -143,4 +153,7 @@ let styles = StyleSheet.create({
143 contentContainer:{ 153 contentContainer:{
144 154
145 }, 155 },
  156 + GoodsGroupHeader: {
  157 + flex: 1,
  158 + }
146 }); 159 });
@@ -26,17 +26,7 @@ export default class GoodsGroupHeader extends React.Component { @@ -26,17 +26,7 @@ export default class GoodsGroupHeader extends React.Component {
26 rowHasChanged: (r1, r2) => r1.key != r2.key, 26 rowHasChanged: (r1, r2) => r1.key != r2.key,
27 }); 27 });
28 28
29 - this.state = {  
30 - selectedIndex: 0,  
31 - };  
32 - }  
33 -  
34 - shouldComponentUpdate(nextProps){  
35 - if (nextProps.dataSource == this.props.dataSource) {  
36 - return false;  
37 - } else {  
38 - return true;  
39 - } 29 + this.selectedIndex = 0;
40 } 30 }
41 31
42 _renderRow(rowData, sectionID, rowID) { 32 _renderRow(rowData, sectionID, rowID) {
@@ -45,14 +35,18 @@ export default class GoodsGroupHeader extends React.Component { @@ -45,14 +35,18 @@ export default class GoodsGroupHeader extends React.Component {
45 let cover = rowData.get('cover'); 35 let cover = rowData.get('cover');
46 let url = getSlicedUrl(cover.get('cover'), 640, 640, 2); 36 let url = getSlicedUrl(cover.get('cover'), 640, 640, 2);
47 let borderWidth = 0; 37 let borderWidth = 0;
48 - if (this.state.selectedIndex == rowID) { 38 + if (this.selectedIndex == rowID) {
49 borderWidth = 1; 39 borderWidth = 1;
50 } 40 }
  41 +
51 return ( 42 return (
52 <View style={{backgroundColor: 'white'}}> 43 <View style={{backgroundColor: 'white'}}>
53 <View key={'row' + rowID} style={styles.rowContainer}> 44 <View key={'row' + rowID} style={styles.rowContainer}>
54 <TouchableOpacity onPress={() => { 45 <TouchableOpacity onPress={() => {
55 - // this.props.onPressFilter && this.props.onPressFilter(rowID); 46 + if (this.selectedIndex == rowID) {
  47 + return;
  48 + }
  49 + this.props.onPressFilter && this.props.onPressFilter(rowID);
56 }}> 50 }}>
57 <View style={{width: itemW - 20,height: itemH - 20,borderColor: 'black',borderWidth: borderWidth}}> 51 <View style={{width: itemW - 20,height: itemH - 20,borderColor: 'black',borderWidth: borderWidth}}>
58 <Image source={{uri: url}} style={{width: itemW - 20 - 2*borderWidth,height: itemH - 20 - 2*borderWidth,backgroundColor:'white',}} resizeMode={'contain'}></Image> 52 <Image source={{uri: url}} style={{width: itemW - 20 - 2*borderWidth,height: itemH - 20 - 2*borderWidth,backgroundColor:'white',}} resizeMode={'contain'}></Image>
@@ -65,7 +59,10 @@ export default class GoodsGroupHeader extends React.Component { @@ -65,7 +59,10 @@ export default class GoodsGroupHeader extends React.Component {
65 59
66 render() { 60 render() {
67 let {resource} = this.props; 61 let {resource} = this.props;
68 - let list = resource.get('data'); 62 + let rowData = resource?resource.rowData:null;
  63 + this.selectedIndex = resource?resource.goods_group_Filter:0;
  64 +
  65 + let list = rowData.get('data');
69 if (!list || list.size == 0) { 66 if (!list || list.size == 0) {
70 return null; 67 return null;
71 } 68 }
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import Immutable, {Map} from 'immutable';
  6 +import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
  7 +
  8 +const {
  9 + AppRegistry,
  10 + StyleSheet,
  11 + Text,
  12 + View,
  13 + Image,
  14 + ListView,
  15 + Dimensions,
  16 + TouchableOpacity,
  17 +} = ReactNative;
  18 +
  19 +
  20 +export default class GoodsGroupList extends React.Component {
  21 + constructor(props) {
  22 + super(props);
  23 + this.dataSource = new ListView.DataSource({
  24 + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
  25 + });
  26 + this.renderRow = this.renderRow.bind(this);
  27 + }
  28 +
  29 + shouldComponentUpdate(nextProps){
  30 + if (Immutable.is(nextProps.resource, this.props.resource)) {
  31 + return false;
  32 + } else {
  33 + return true;
  34 + }
  35 + }
  36 +
  37 + renderRow(rowData, sectionID, rowID, highlightRow) {
  38 +
  39 + let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
  40 + let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft} : {paddingLeft};
  41 +
  42 + return (
  43 + <BrandProductListCell
  44 + style={[styles.listContainer, customStyle]}
  45 + key={'row' + rowID}
  46 + rowID={rowID}
  47 + data={rowData}
  48 + // onPressProduct={this.props.onPressProduct}
  49 + />
  50 + );
  51 + }
  52 +
  53 + render() {
  54 + let {resource} = this.props;
  55 + let list = resource?resource.get('list'):null;
  56 +
  57 + if (!list || list.size == 0) {
  58 + return null;
  59 + }
  60 +
  61 + let backgroundWidth = width;
  62 + let backgroundHeight = 40 + Math.ceil(list.size / 2) * (rowHeight+rowMarginHorizontal) + 20;
  63 + return(
  64 + <View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}>
  65 + <ListView
  66 + contentContainerStyle={styles.contentContainer}
  67 + initialListSize={Math.ceil(list.size)}
  68 + dataSource={this.dataSource.cloneWithRows(list.toArray())}
  69 + enableEmptySections={true}
  70 + renderRow={this.renderRow}
  71 + scrollEnabled={false}
  72 + scrollsToTop={false}
  73 + />
  74 + </View>
  75 + );
  76 + }
  77 +};
  78 +
  79 +
  80 +let {width, height} = Dimensions.get('window');
  81 +let rowWidth = Math.ceil(137.5 * width / 320);
  82 +let rowMarginHorizontal = (width - rowWidth * 2) / 3;
  83 +const DEVICE_WIDTH_RATIO = width / 320;
  84 +let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);
  85 +
  86 +let styles = StyleSheet.create({
  87 + listContainer: {
  88 + width: width / 2,
  89 + },
  90 + contentContainer:{
  91 + flexDirection: 'row',
  92 + flexWrap: 'wrap',
  93 + },
  94 +});
@@ -45,4 +45,5 @@ export default keyMirror({ @@ -45,4 +45,5 @@ export default keyMirror({
45 GET_ARTICLE_LIST_SUCCESS: null, 45 GET_ARTICLE_LIST_SUCCESS: null,
46 GET_ARTICLE_LIST_FAILURE: null, 46 GET_ARTICLE_LIST_FAILURE: null,
47 47
  48 + SET_GOOESGROUP_FILTER: null,
48 }); 49 });
@@ -49,7 +49,7 @@ class DetailContainer extends Component { @@ -49,7 +49,7 @@ class DetailContainer extends Component {
49 49
50 this._onRefresh = this._onRefresh.bind(this); 50 this._onRefresh = this._onRefresh.bind(this);
51 this._onEndReached = this._onEndReached.bind(this); 51 this._onEndReached = this._onEndReached.bind(this);
52 - 52 + this._onPressFilter = this._onPressFilter.bind(this);
53 53
54 } 54 }
55 55
@@ -76,6 +76,10 @@ class DetailContainer extends Component { @@ -76,6 +76,10 @@ class DetailContainer extends Component {
76 }); 76 });
77 } 77 }
78 78
  79 + _onPressFilter(value) {
  80 + this.props.actions.setGoodsGroupFilter(value);
  81 + }
  82 +
79 render() { 83 render() {
80 let {detail} = this.props; 84 let {detail} = this.props;
81 85
@@ -88,6 +92,7 @@ class DetailContainer extends Component { @@ -88,6 +92,7 @@ class DetailContainer extends Component {
88 resource={detail} 92 resource={detail}
89 onRefresh={this._onRefresh} 93 onRefresh={this._onRefresh}
90 onEndReached={this._onEndReached} 94 onEndReached={this._onEndReached}
  95 + onPressFilter= {this._onPressFilter}
91 /> 96 />
92 </View> 97 </View>
93 ); 98 );
@@ -37,6 +37,8 @@ const { @@ -37,6 +37,8 @@ const {
37 PRODUCT_BY_SKNS_SUCCESS, 37 PRODUCT_BY_SKNS_SUCCESS,
38 PRODUCT_BY_SKNS_FAILURE, 38 PRODUCT_BY_SKNS_FAILURE,
39 39
  40 + SET_GOOESGROUP_FILTER,
  41 +
40 } = require('../../constants/actionTypes').default; 42 } = require('../../constants/actionTypes').default;
41 43
42 export function setArticleId(id) { 44 export function setArticleId(id) {
@@ -540,3 +542,10 @@ export function getWeixinPublic() { @@ -540,3 +542,10 @@ export function getWeixinPublic() {
540 }); 542 });
541 }; 543 };
542 } 544 }
  545 +
  546 +export function setGoodsGroupFilter(filter) {
  547 + return {
  548 + type: SET_GOOESGROUP_FILTER,
  549 + payload: filter
  550 + };
  551 +}
@@ -34,6 +34,7 @@ let InitialState = Record({ @@ -34,6 +34,7 @@ let InitialState = Record({
34 error: null, 34 error: null,
35 data: List(), 35 data: List(),
36 })), 36 })),
  37 + goods_group_Filter: 0,
37 }); 38 });
38 39
39 export default InitialState; 40 export default InitialState;
@@ -32,6 +32,8 @@ const { @@ -32,6 +32,8 @@ const {
32 32
33 PRODUCT_BY_SKNS_SUCCESS, 33 PRODUCT_BY_SKNS_SUCCESS,
34 34
  35 + SET_GOOESGROUP_FILTER,
  36 +
35 } = require('../../constants/actionTypes').default; 37 } = require('../../constants/actionTypes').default;
36 38
37 const initialState = new InitialState; 39 const initialState = new InitialState;
@@ -145,6 +147,9 @@ export default function detailReducer(state=initialState, action) { @@ -145,6 +147,9 @@ export default function detailReducer(state=initialState, action) {
145 } = action.payload; 147 } = action.payload;
146 return state.setIn(['content', 'data', contentIndex, 'productList'], Immutable.fromJS(productList)); 148 return state.setIn(['content', 'data', contentIndex, 'productList'], Immutable.fromJS(productList));
147 } 149 }
  150 + case SET_GOOESGROUP_FILTER: {
  151 + return state.set('goods_group_Filter', action.payload);
  152 + }
148 } 153 }
149 154
150 return state; 155 return state;