Authored by 陈林

融合商品收藏功能。review by 孙凯

... ... @@ -40,6 +40,10 @@ import {
setGlobalHost,
} from './reducers/app/appActions';
import {
setCurrentTab,
} from './reducers/product/productActions';
function getInitialState() {
const _initState = {
... ... @@ -72,6 +76,7 @@ export default function native(platform) {
store.dispatch(setHost(this.props.host));
store.dispatch(setServiceHost(this.props.serviceHost));
store.dispatch(setGlobalHost(this.props.globalHost));
store.dispatch(setCurrentTab(this.props.productType));
return (
<Provider store={store}>
... ...
... ... @@ -24,11 +24,11 @@ export default class Product extends Component {
super(props);
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.bind(this);
// this.renderHeader = this.renderHeader.bind(this);
this.handleScroll = this.handleScroll.bind(this);
this.onOpen = this.onOpen.bind(this);
this.onClose = this.onClose.bind(this);
this.renderSectionHeader = this.renderSectionHeader.bind(this);
// this.renderSectionHeader = this.renderSectionHeader.bind(this);
this.renderFooter = this.renderFooter.bind(this);
this.dataSource = new ListView.DataSource({
... ... @@ -164,72 +164,61 @@ export default class Product extends Component {
}
}
renderHeader() {
let {
commonProduct,
globalProduct,
editing,
currentTab,
} = this.props.data;
let {productList} = globalProduct;
let {selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
let isShow = currentTab === 'common' && selectedProductList.size > 0;
return (
<View>
{productList.size > 0 ? <TabHeader
currentTab={currentTab}
onPressTab={(tab)=>{
if (tab == currentTab) {
return;
}
this.state.currentlyOpenSwipeable && this.state.currentlyOpenSwipeable.recenter();
this.setState({currentlyOpenSwipeable: null});
this.props.onPressTab && this.props.onPressTab(tab);
}}
/> : null}
{isShow ? <CategorySelector
data={categoryList}
selectedCategoryIndex={selectedCategoryIndex}
onPressCategory={(rowData, rowID) => {
this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false});
this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
}}
/> : null}
</View>
)
}
renderSectionHeader(sectionData, sectionID) {
let {
commonProduct,
globalProduct,
editing,
currentTab,
} = this.props.data;
if (currentTab == 'global') {
return null;
}
if (currentTab == 'common') {
let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
if (selectedProductList.size == 0) {
return null;
}
return (
<CategorySelector
data={categoryList}
selectedCategoryIndex={selectedCategoryIndex}
onPressCategory={(rowData, rowID) => {
this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false});
this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
}}
/>
);
}
return null;
}
// renderHeader() {
// let {
// commonProduct,
// globalProduct,
// editing,
// currentTab,
// } = this.props.data;
// let {productList} = globalProduct;
// let {selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
// let isShow = currentTab === 'common' && selectedProductList.size > 0;
// return (
// <View>
// {isShow ? <CategorySelector
// data={categoryList}
// selectedCategoryIndex={selectedCategoryIndex}
// onPressCategory={(rowData, rowID) => {
// this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false});
// this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
// }}
// /> : null}
// </View>
// )
// }
// renderSectionHeader(sectionData, sectionID) {
// let {
// commonProduct,
// globalProduct,
// editing,
// currentTab,
// } = this.props.data;
// if (currentTab == 'global') {
// return null;
// }
// if (currentTab == 'common') {
// let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
// if (selectedProductList.size == 0) {
// return null;
// }
// return (
// <CategorySelector
// data={categoryList}
// selectedCategoryIndex={selectedCategoryIndex}
// onPressCategory={(rowData, rowID) => {
// this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false});
// this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
// }}
// />
// );
// }
// return null;
// }
render() {
... ... @@ -266,7 +255,7 @@ export default class Product extends Component {
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(dataArray)}
renderRow={this.renderRow}
renderHeader={this.renderHeader}
//renderHeader={this.renderHeader}
// renderSectionHeader={this.renderSectionHeader}
onScroll={this.handleScroll}
renderFooter={this.renderFooter}
... ...
... ... @@ -141,60 +141,61 @@ export default class Product extends Component {
}
renderHeader() {
let {
commonProduct,
globalProduct,
editing,
currentTab,
} = this.props.data;
let {productList} = globalProduct;
if (productList.size == 0) {
return null;
}
return (<TabHeader
currentTab={currentTab}
onPressTab={(tab)=>{
if (tab == currentTab) {
return;
}
this.props.onPressTab && this.props.onPressTab(tab);
}}
/>)
// let {
// commonProduct,
// globalProduct,
// editing,
// currentTab,
// } = this.props.data;
// let {productList} = globalProduct;
// if (productList.size == 0) {
// return null;
// }
// return (<TabHeader
// currentTab={currentTab}
// onPressTab={(tab)=>{
// if (tab == currentTab) {
// return;
// }
// this.props.onPressTab && this.props.onPressTab(tab);
// }}
// />)
}
renderSectionHeader(sectionData, sectionID) {
let {
commonProduct,
globalProduct,
editing,
currentTab,
} = this.props.data;
if (currentTab == 'global') {
return null;
}
let realHeight = 44;
let {productList} = globalProduct;
if (productList.size != 0) {
realHeight += 45;
}
if (currentTab == 'common') {
let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
if (selectedProductList.size == 0) {
return null;
}
return (
<CategorySelector
data={categoryList}
selectedCategoryIndex={selectedCategoryIndex}
onPressCategory={(rowData, rowID) => {
this.sectionList && this.sectionList.scrollToLocation({itemIndex: 0,sectionIndex: 0, viewOffset: realHeight, animated: false});
this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
}}
/>
);
}
return null;
// let {
// commonProduct,
// globalProduct,
// editing,
// currentTab,
// } = this.props.data;
// if (currentTab == 'global') {
// return null;
// }
// let realHeight = 44;
// let {productList} = globalProduct;
// if (productList.size != 0) {
// realHeight += 45;
// }
// if (currentTab == 'common') {
// let {isFetching, selectedProductList, categoryList, selectedCategoryIndex} = commonProduct;
// if (selectedProductList.size == 0) {
// return null;
// }
// return (
// <CategorySelector
// data={categoryList}
// selectedCategoryIndex={selectedCategoryIndex}
// onPressCategory={(rowData, rowID) => {
// this.sectionList && this.sectionList.scrollToLocation({itemIndex: 0,sectionIndex: 0, viewOffset: realHeight, animated: false});
// this.props.onPressCategory && this.props.onPressCategory(rowData, rowID);
// }}
// />
// );
// }
}
render() {
... ...
... ... @@ -66,4 +66,6 @@ export default keyMirror({
SET_EDITING: null,
SET_EDITED_INDEX: null,
SET_CATEGORY_LIST: null,
SET_CURRENT_TAB: null,
});
... ...
... ... @@ -28,8 +28,17 @@ const {
SET_EDITING,
SET_EDITED_INDEX,
SET_CATEGORY_LIST,
SET_CURRENT_TAB,
} = require('../../constants/actionTypes').default;
export function setCurrentTab(tab) {
return {
type: SET_CURRENT_TAB,
payload: tab
};
}
export function setCategoryList(categoryList) {
return (dispatch) => {
dispatch({
... ...
... ... @@ -26,13 +26,21 @@ const {
SET_EDITING,
SET_EDITED_INDEX,
SET_CATEGORY_LIST,
SET_CURRENT_TAB,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function productReducer(state=initialState, action) {
switch(action.type) {
case SET_CURRENT_TAB: {
console.log("chenlin")
console.log(action.payload)
return state.set('currentTab', action.payload);
}
case SET_EDITED_INDEX: {
let rowID = action.payload;
let {
... ...