Authored by 孙凯

添加 goodsGroup UI review jianqiu

... ... @@ -10,6 +10,7 @@ import GoodsCell from './GoodsCell';
import Header from './Header';
import MoreLink from './MoreLink';
import GoodsGroupHeader from './GoodsGroupHeader';
import GoodsGroupList from './GoodsGroupList';
import ReactNative, {
View,
... ... @@ -76,8 +77,16 @@ export default class Detail extends Component {
<Text>weixinPublic</Text>
);
}else if (template_name == 'goods_group') {
let {resource} = this.props;
let {goods_group_Filter} = resource;
let data = rowData.get('productList')?rowData.get('productList').toArray():null;
let list = data?data[goods_group_Filter]:null;
return (
<GoodsGroupHeader resource={rowData}/>
<View style={styles.GoodsGroupHeader}>
<GoodsGroupHeader resource={{rowData,goods_group_Filter}} onPressFilter= {this.props.onPressFilter}/>
<GoodsGroupList resource={list}/>
</View>
);
}else if (template_name == 'goods') {
return (
... ... @@ -111,6 +120,7 @@ export default class Detail extends Component {
brand,
otherArticle,
weixin,
goods_group_Filter,
} = resource;
let list = content?content.get('data'):[];
... ... @@ -143,4 +153,7 @@ let styles = StyleSheet.create({
contentContainer:{
},
GoodsGroupHeader: {
flex: 1,
}
});
... ...
... ... @@ -26,17 +26,7 @@ export default class GoodsGroupHeader extends React.Component {
rowHasChanged: (r1, r2) => r1.key != r2.key,
});
this.state = {
selectedIndex: 0,
};
}
shouldComponentUpdate(nextProps){
if (nextProps.dataSource == this.props.dataSource) {
return false;
} else {
return true;
}
this.selectedIndex = 0;
}
_renderRow(rowData, sectionID, rowID) {
... ... @@ -45,14 +35,18 @@ export default class GoodsGroupHeader extends React.Component {
let cover = rowData.get('cover');
let url = getSlicedUrl(cover.get('cover'), 640, 640, 2);
let borderWidth = 0;
if (this.state.selectedIndex == rowID) {
if (this.selectedIndex == rowID) {
borderWidth = 1;
}
return (
<View style={{backgroundColor: 'white'}}>
<View key={'row' + rowID} style={styles.rowContainer}>
<TouchableOpacity onPress={() => {
// this.props.onPressFilter && this.props.onPressFilter(rowID);
if (this.selectedIndex == rowID) {
return;
}
this.props.onPressFilter && this.props.onPressFilter(rowID);
}}>
<View style={{width: itemW - 20,height: itemH - 20,borderColor: 'black',borderWidth: borderWidth}}>
<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 {
render() {
let {resource} = this.props;
let list = resource.get('data');
let rowData = resource?resource.rowData:null;
this.selectedIndex = resource?resource.goods_group_Filter:0;
let list = rowData.get('data');
if (!list || list.size == 0) {
return null;
}
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class GoodsGroupList extends React.Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
this.renderRow = this.renderRow.bind(this);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
renderRow(rowData, sectionID, rowID, highlightRow) {
let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal;
let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft} : {paddingLeft};
return (
<BrandProductListCell
style={[styles.listContainer, customStyle]}
key={'row' + rowID}
rowID={rowID}
data={rowData}
// onPressProduct={this.props.onPressProduct}
/>
);
}
render() {
let {resource} = this.props;
let list = resource?resource.get('list'):null;
if (!list || list.size == 0) {
return null;
}
let backgroundWidth = width;
let backgroundHeight = 40 + Math.ceil(list.size / 2) * (rowHeight+rowMarginHorizontal) + 20;
return(
<View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}>
<ListView
contentContainerStyle={styles.contentContainer}
initialListSize={Math.ceil(list.size)}
dataSource={this.dataSource.cloneWithRows(list.toArray())}
enableEmptySections={true}
renderRow={this.renderRow}
scrollEnabled={false}
scrollsToTop={false}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let rowWidth = Math.ceil(137.5 * width / 320);
let rowMarginHorizontal = (width - rowWidth * 2) / 3;
const DEVICE_WIDTH_RATIO = width / 320;
let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);
let styles = StyleSheet.create({
listContainer: {
width: width / 2,
},
contentContainer:{
flexDirection: 'row',
flexWrap: 'wrap',
},
});
... ...
... ... @@ -6,7 +6,7 @@ export default keyMirror({
SET_HOST: null,
SET_SERVICE_HOST: null,
SET_CHANNEL: null,
SET_ARTICLE_ID: null,
GET_ARTICLE_REQUEST: null,
... ... @@ -40,9 +40,10 @@ export default keyMirror({
SET_LIST_TYPE: null,
SET_AUTHOR_ID: null,
SET_TAG: null,
GET_ARTICLE_LIST_REQUEST: null,
GET_ARTICLE_LIST_SUCCESS: null,
GET_ARTICLE_LIST_FAILURE: null,
SET_GOOESGROUP_FILTER: null,
});
... ...
... ... @@ -49,7 +49,7 @@ class DetailContainer extends Component {
this._onRefresh = this._onRefresh.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._onPressFilter = this._onPressFilter.bind(this);
}
... ... @@ -76,6 +76,10 @@ class DetailContainer extends Component {
});
}
_onPressFilter(value) {
this.props.actions.setGoodsGroupFilter(value);
}
render() {
let {detail} = this.props;
... ... @@ -88,6 +92,7 @@ class DetailContainer extends Component {
resource={detail}
onRefresh={this._onRefresh}
onEndReached={this._onEndReached}
onPressFilter= {this._onPressFilter}
/>
</View>
);
... ...
... ... @@ -37,6 +37,8 @@ const {
PRODUCT_BY_SKNS_SUCCESS,
PRODUCT_BY_SKNS_FAILURE,
SET_GOOESGROUP_FILTER,
} = require('../../constants/actionTypes').default;
export function setArticleId(id) {
... ... @@ -78,16 +80,16 @@ export function getArticle(reload = false) {
return;
}
}
dispatch(getArticleRequest());
return new DetailService(app.serviceHost).getArticle(articleId)
.then(json => {
.then(json => {
dispatch(getArticleSuccess(json));
dispatch(getAuthor(json));
dispatch(getOtherArticle(json));
// dispatch(dataExposure(payload.logFloors));
})
.catch(error => {
dispatch(getArticleFailure(error));
... ... @@ -137,7 +139,7 @@ export function getAuthor(article, reload = false) {
return new DetailService(app.serviceHost).getAuthor(authorId)
.then(json => {
let payload = json;
dispatch(getAuthorSuccess(json));
// dispatch(dataExposure(payload.logFloors));
})
... ... @@ -184,7 +186,7 @@ export function getArticleContent(reload = false) {
return new DetailService(app.serviceHost).getArticleContent(articleId)
.then(json => {
let payload = parseArticleContent(json);
payload.map((item, i) => {
if (item.template_name == 'goods') {
dispatch(goodsProductBySkns(item, i));
... ... @@ -229,9 +231,9 @@ function parseArticleContent(json) {
url: data.data[0].url,
};
} else if (templateName == 'goods_group') {
} else if (templateName == 'goods') {
} else if (templateName == 'text') {
}
... ... @@ -315,7 +317,7 @@ export function goodsProductBySkns(item, contentIndex) {
item3.default_images = helper.image(src, 235, 314);
productList.push(item3);
}
});
dispatch(productBySknsSuccess({
productList,
... ... @@ -332,7 +334,7 @@ export function goodsGroupProductBySkns(item, contentIndex) {
return (dispatch, getState) => {
let skns = [];
let productImages = {};
// 遍历取得SKN
item.data.map((item2) => {
item2.list.map((item3) => {
... ... @@ -359,7 +361,7 @@ export function goodsGroupProductBySkns(item, contentIndex) {
item4.default_images = helper.image(src, 235, 314);
products[item4.product_skn] = item4;
}
});
let productList = []
... ... @@ -482,7 +484,7 @@ export function getOtherArticle(article, reload = false) {
return new DetailService(app.serviceHost).getOtherArticle(articleId, tags, offset, limit)
.then(json => {
let payload = parseOtherArticle(json);
dispatch(getOtherArticleSuccess(payload));
// dispatch(dataExposure(payload.logFloors));
})
... ... @@ -539,4 +541,11 @@ export function getWeixinPublic() {
dispatch(getWeixinPublicFailure(error));
});
};
}
\ No newline at end of file
}
export function setGoodsGroupFilter(filter) {
return {
type: SET_GOOESGROUP_FILTER,
payload: filter
};
}
... ...
... ... @@ -34,6 +34,7 @@ let InitialState = Record({
error: null,
data: List(),
})),
goods_group_Filter: 0,
});
export default InitialState;
... ...
... ... @@ -32,6 +32,8 @@ const {
PRODUCT_BY_SKNS_SUCCESS,
SET_GOOESGROUP_FILTER,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -89,7 +91,7 @@ export default function detailReducer(state=initialState, action) {
return state.setIn(['content', 'isFetching'], false)
.setIn(['content', 'error'], action.payload);
}
case GET_BRAND_REQUEST: {
return state.setIn(['brand', 'isFetching'], true)
.setIn(['brand', 'error'], null);
... ... @@ -145,6 +147,9 @@ export default function detailReducer(state=initialState, action) {
} = action.payload;
return state.setIn(['content', 'data', contentIndex, 'productList'], Immutable.fromJS(productList));
}
case SET_GOOESGROUP_FILTER: {
return state.set('goods_group_Filter', action.payload);
}
}
return state;
... ...