Authored by yoho-js001

修复blk brand导航条无法跳转的问题, reviewed by 凯总。

... ... @@ -50,12 +50,14 @@ export default class Brand extends Component {
scrollToSection(index,sectionID){
let item = this.sectionDataKey[sectionID];
console.log('........');
console.log(item);
if (item) {
if (!item.y) {
this.needScrollSection = sectionID;
item.count = ScrollCount(sectionID,this.sectionData);
this.props.setInitialListSize && this.props.setInitialListSize(item.count);
item.y = ScrollY(sectionID,this.sectionData);
this.props.setBrandData && this.props.setBrandData(this.sectionDataKey, this.props.selectedChannelId);
this.listView && this.listView.scrollTo({x: 0, y: item.y, animated: false});
} else {
this.listView && this.listView.scrollTo({x: 0, y: item.y, animated: false});
}
... ... @@ -67,9 +69,6 @@ export default class Brand extends Component {
if (this.sectionDataKey && this.sectionDataKey[sectionID].y != y) {
this.sectionDataKey[sectionID].y = y;
this.props.setBrandData && this.props.setBrandData(this.sectionDataKey, this.props.selectedChannelId);
if (this.needScrollSection == sectionID) {
this.listView && this.listView.scrollTo({x: 0, y, animated: false});
}
}
}
... ... @@ -96,7 +95,13 @@ export default class Brand extends Component {
if (this.props.brandFliter == 0) {
let title = sectionID == '0-9' ? '0' : sectionID;
return (
<BLKBrandCell title={title} rowData={rowData} onPressBrandItem={this.props.onPressBrandItem}/>
<View onLayout={this.onLayout.bind(this, sectionID)}>
<BLKBrandCell title={title} rowData={rowData} onPressBrandItem={this.props.onPressBrandItem}/>
</View>
);
} else {
return (
... ... @@ -179,7 +184,7 @@ export default class Brand extends Component {
<ListView
ref={(ref)=>this.listView=ref}
initialListSize={initialListSize}
initialListSize={1000}
contentContainerStyle={contentContainerStyle}
enableEmptySections={true}
dataSource={listDataSource}
... ...
... ... @@ -31,9 +31,15 @@ export default class IndexListView extends React.Component {
onTouchMove(e) {
let {dataSource} = this.props;
let Y = e.nativeEvent.pageY - Math.ceil((viewHeight - dataSource.length * (itemHeight+2))/2) - 8;
let Y = e.nativeEvent.pageY - Math.ceil((viewHeight - dataSource.length * (itemHeight+2))/2) - 8-28;
var index = Math.ceil(Y/(itemHeight+2))-1;
if (dataSource.length - index < 4) {
return;
}
let sectionID = dataSource[index];
if (!sectionID) {
return;
}
this.props.onLetterPress && this.props.onLetterPress(index,sectionID);
}
... ...
... ... @@ -208,6 +208,9 @@ export default class BrandStore extends Component {
resource={rowData}
onPressProduct={this.props.onPressFloorProduct}
onPressMoreProducts={this.props.onPressMoreProducts}
similarIndex={this.props.similarIndex}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
/>
);
}
... ... @@ -224,7 +227,10 @@ export default class BrandStore extends Component {
key={'row' + rowID}
rowID={rowID}
data={rowData}
similarIndex={this.props.similarIndex}
onPressProduct={this.props.onPressProduct}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
/>
);
} else if (sectionID == 'productList') {
... ... @@ -237,6 +243,9 @@ export default class BrandStore extends Component {
rowID={rowID}
data={rowData}
onPressProduct={this.props.onPressProductListProduct}
similarIndex={this.props.similarIndex}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
/>
);
}
... ...
... ... @@ -51,6 +51,9 @@ export default class HotProducts extends React.Component {
rowID={rowID}
data={rowData}
onPressProduct={this.props.onPressProduct}
similarIndex={this.props.similarIndex}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
/>
);
}
... ...
... ... @@ -60,4 +60,5 @@ export default keyMirror({
FILTER_LIST_VIEW:null,
FILTER_MORE_VIEW:null,
SET_SIMILAR_PRODUCT_INDEX: null,
});
... ...
... ... @@ -79,6 +79,8 @@ class BrandStoreContainer extends Component {
this._onPressCloseMoreFilter=this._onPressCloseMoreFilter.bind(this);
this.resetReceiveCouponResult=this.resetReceiveCouponResult.bind(this);
this._onLongPressProduct = this._onLongPressProduct.bind(this);
this._onPressFindSimilar = this._onPressFindSimilar.bind(this);
}
componentDidMount() {
... ... @@ -94,6 +96,16 @@ class BrandStoreContainer extends Component {
}
_onLongPressProduct(rowID) {
if (rowID) {
this.props.actions.setSimilarIndex(rowID);
}
}
_onPressFindSimilar(product) {
ReactNative.NativeModules.YH_CommonHelper.jumpFindSimilar(product);
}
resetReceiveCouponResult(){
this.props.actions.resetReceiveCouponResult();
}
... ... @@ -307,6 +319,7 @@ class BrandStoreContainer extends Component {
TAB_NAME: name,
}
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_TAB_C', param);
this.props.actions.setSimilarIndex(-1);
}
... ... @@ -324,6 +337,7 @@ class BrandStoreContainer extends Component {
this.props.actions.setProductListFilter(value);
this.props.actions.getProductList(true);
}
this.props.actions.setSimilarIndex(-1);
}
_onEndReached() {
... ... @@ -365,6 +379,7 @@ class BrandStoreContainer extends Component {
filterCategoryDetailFilterList,
filterNameFactors,
filterFactors,
similarIndex,
} = this.props.brandStore;
let isFetching = (storeFilter == 0 && resource.isFetching)
... ... @@ -405,6 +420,9 @@ class BrandStoreContainer extends Component {
resetReceiveCouponResult={this.resetReceiveCouponResult}
onPressFloorProduct={this._onPressFloorProduct}
onPressProductListProduct={this._onPressProductListProduct}
onLongPressProduct={this._onLongPressProduct}
onPressFindSimilar={this._onPressFindSimilar}
similarIndex={similarIndex}
/>
);
}
... ...
... ... @@ -63,8 +63,17 @@ const {
FILTER_LIST_VIEW,
FILTER_MORE_VIEW,
SET_SIMILAR_PRODUCT_INDEX,
} = require('../../constants/actionTypes').default;
export function setSimilarIndex(rowID) {
return {
type: SET_SIMILAR_PRODUCT_INDEX,
payload: rowID
}
}
export function onPressCoupon() {
return {
type: SEL_COUPONITEM,
... ...
... ... @@ -116,6 +116,8 @@ let InitialState = Record({
sort: '所有品类', //品类
brand: '所有品牌', //品牌
})),
similarIndex: -1,
});
export default InitialState;
... ...
... ... @@ -56,6 +56,7 @@ const {
FILTER_LIST_VIEW,
FILTER_MORE_VIEW,
SET_SIMILAR_PRODUCT_INDEX,
} = require('../../constants/actionTypes').default;
... ... @@ -90,7 +91,10 @@ export default function brandStoreReducer(state=initialState, action) {
case SET_STOREFILTER: {
return state.set('storeFilter', action.payload);
}
case SET_SIMILAR_PRODUCT_INDEX: {
let newState = state.set( 'similarIndex', action.payload);
return newState;
}
case SET_PRODUCT_LIST_FILTER: {
return state.setIn(['productList', 'order'], action.payload);
}
... ...
... ... @@ -50,6 +50,7 @@ export default class Brand extends Component {
scrollToSection(index,sectionID){
let item = this.sectionDataKey[sectionID];
console.log(item);
if (item) {
if (!item.y) {
this.needScrollSection = sectionID;
... ... @@ -64,6 +65,8 @@ export default class Brand extends Component {
onLayout(sectionID, e) {
let {y} = e.nativeEvent.layout;
console.log(sectionID);
console.log(y);
if (this.sectionDataKey && this.sectionDataKey[sectionID].y != y) {
this.sectionDataKey[sectionID].y = y;
this.props.setBrandData && this.props.setBrandData(this.sectionDataKey, this.props.selectedChannelId);
... ...
... ... @@ -74,6 +74,7 @@ export default class ProductListCell extends Component {
<SimilarProductAnim
onPressFindSimilar={this.props.onPressFindSimilar}
product={data}
similarIndex={similarIndex}
onPressDislike={this.props.onPressDislike}
/>
:null}
... ...
... ... @@ -72,7 +72,7 @@ export default class SimilarProductAnim extends Component {
alignItems: 'center',
marginTop: 15,
}}
onPress={()=>{this.props.onPressDislike&&this.props.onPressDislike(this.props.product);}}
onPress={()=>{this.props.onPressDislike&&this.props.onPressDislike(this.props.product, this.props.similarIndex);}}
>
<Text style={{fontSize:14, color:'white'}}>不喜欢</Text>
</TouchableOpacity>
... ...
... ... @@ -52,4 +52,7 @@ export default keyMirror({
HOME_RECOMMEND_PRODUCT_SELECTED: null,
SET_SIMILAR_PRODUCT_INDEX: null,
DISLIKE_REQUEST: null,
DISLIKE_SUCCESS: null,
DISLIKE_FAILURE: null,
});
... ...
... ... @@ -108,8 +108,14 @@ class HomeContainer extends Component {
ReactNative.NativeModules.YH_CommonHelper.jumpFindSimilar(product);
}
onPressDislike() {
console.log('dislike....');
onPressDislike(product, similarIndex) {
this.props.actions.setSimilarIndex(-1);
let product_skn = product && product.get('product_skn', 0);
console.log(product_skn);
if (!product_skn) {
return;
}
this.props.actions.fetchDislike(similarIndex, product_skn);
}
onPressProductListProduct(product, rowId=0) {
... ...
... ... @@ -52,6 +52,9 @@ const {
HOME_RECOMMEND_PRODUCT_SELECTED,
DISLIKE_REQUEST,
DISLIKE_SUCCESS,
DISLIKE_FAILURE,
} = require('../../constants/actionTypes').default;
export function setSimilarIndex(rowID) {
... ... @@ -65,6 +68,29 @@ export function setSimilarIndex(rowID) {
});
}
}
export function fetchDislike(rowID, product_skn) {
return (dispatch, getState) => {
let {app, home} = getState();
let channel = app.channel;
let channelStr = channelTransfer.number2String(channel);
return new HomeService(app.serviceHost).fetchDislike(channel, product_skn)
.then(json => {
let data = json.product_list&&json.product_list.length?json.product_list[0]:{};
dispatch(fetchDislikeSuccess(rowID, data, channelStr));
})
.catch(error => {
});
}
}
function fetchDislikeSuccess(rowID, json, channelStr) {
return {
type: DISLIKE_SUCCESS,
payload: {rowID, json, channelStr}
}
}
/**
** 加载缓存
**/
... ...
... ... @@ -48,6 +48,9 @@ const {
HOME_RECOMMEND_PRODUCT_FAILURE,
HOME_RECOMMEND_PRODUCT_SELECTED,
DISLIKE_REQUEST,
DISLIKE_SUCCESS,
DISLIKE_FAILURE,
} = require('../../constants/actionTypes').default;
... ... @@ -67,6 +70,11 @@ export default function homeReducer(state=initialState, action) {
let newState = state.setIn([channelStr, 'similarIndex'], rowID);
return newState;
}
case DISLIKE_SUCCESS: {
let {rowID, json, channelStr} = action.payload;
let newState = state.setIn([channelStr, 'favorite', 'list', rowID], Immutable.fromJS(json));
return newState;
}
case HOME_FLOOR_SUCCESS:{
let {channelStr, json} = action.payload;
return state.setIn([channelStr, 'isFetching'], false)
... ...
... ... @@ -68,6 +68,39 @@ export default class HomeService {
});
}
async fetchDislike(channel, product_skn) {
let rec_pos = '';
switch (channel) {
case "1":
rec_pos = '100001';
break;
case "2":
rec_pos = '100002';
break;
case "3":
rec_pos = '100003';
break;
default:
break;
}
return await this.api.get({
url: '',
body: {
method: 'app.product.notlike',
yh_channel: channel,
gender,
rec_pos,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async fetchHomeKidFavoriteData(fromPage, page) {
return await this.api.get({
url: '',
... ...
... ... @@ -261,7 +261,6 @@ export default class NewArrival extends Component {
onPressProduct={this.props.onPressProductListProduct}
onLongPressProduct={this.props.onLongPressProduct}
onPressFindSimilar={this.props.onPressFindSimilar}
onPressDislike={this.props.onPressDislike}
/>
);
}
... ...