RedPersonBrandContainer.js 11.9 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Platform,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as redBrandActions from '../reducers/redBrand/redBrandActions';
import RedBrand from '../components/redBrand/RedBrand';

const actions = [
    redBrandActions,
];

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {

    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    };
}


function orderWithString(str) {

   if (str.indexOf('s_w')>=0) {
     return 0;
   }
   if (str.indexOf('s_t')>=0) {
     return 2;
   }
   if (str.indexOf('s_p')>=0) {
     return 3;
   }
   if (str.indexOf('p_d')>=0) {
     return 4;
   }
   return 0;
}

class RedPersonBrandContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressStoreFilter = this._onPressStoreFilter.bind(this);
        this._onPressLaunchProfile = this._onPressLaunchProfile.bind(this);
        this._onPressVideo = this._onPressVideo.bind(this);
        this._onPressProduct = this._onPressProduct.bind(this);
        this._onPressProductCell = this._onPressProductCell.bind(this);
        this._onPressProductFilter = this._onPressProductFilter.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
        this._onPressProductFilterLeftItem=this._onPressProductFilterLeftItem.bind(this);
        this._onPressProductFilterRightItem=this._onPressProductFilterRightItem.bind(this);
        this._onPressMoreFilter=this._onPressMoreFilter.bind(this);
        this._onPressCloseMoreFilter=this._onPressCloseMoreFilter.bind(this);
        this._onPressCoupon = this._onPressCoupon.bind(this);
        this.resetReceiveCouponResult=this.resetReceiveCouponResult.bind(this);
        this._onPressCollection = this._onPressCollection.bind(this);
        this._onPressLink = this._onPressLink.bind(this);
        this._onLongPressProduct = this._onLongPressProduct.bind(this);
        this._onPressFindSimilar = this._onPressFindSimilar.bind(this);
        this._onPressProductRecommend = this._onPressProductRecommend.bind(this);
    }

    componentDidMount() {
        this.props.actions.getIntro();
        this.props.actions.getRedBrandDecorator();
        this.props.actions.getProductList(true);
        this.props.actions.getProductListForNew(true);
        this.props.actions.getShopCouponList();
        this.props.actions.getFavoriteCount();
        this.props.actions.getFavoriteState();
        // this.props.actions.setShowSimilarGuider(true);
    }

    componentWillUnmount() {

    }

    _onLongPressProduct(rowID) {
        if (rowID) {
            this.props.actions.setSimilarIndex(rowID);
        }
    }

    _onPressFindSimilar(product) {
        if (!product) {
            return;
        }

        ReactNative.NativeModules.YH_CommonHelper.jumpFindSimilar(product.toJS());
        ReactNative.NativeModules.YH_CommonHelper.setSimilarGuiderVisible(false);
        this.props.actions.setSimilarIndex(-1);
        this.props.actions.setShowSimilarGuider(false, false);
    }


    _onPressCollection(isCollected) {
        if (!isCollected) {
            this.props.actions.addFavorite();
        } else {
            this.props.actions.cancelFavorite();
        }
    }

    _onPressLaunchProfile(value){
        this.props.actions.setLaunchProfile(value);
    }

    _onPressStoreFilter(value) {
        this.props.actions.setFilter(value);
        let name = '首页';
        if (value == 1) {
            name = '新品';
        }else if (value == 2) {
            name = '全部商品';
        }
        let param = {
          SHOP_ID: this.props.redBrand.shopId,
          TAB_ID: value,
          TAB_NAME: name,
          TEMPLATE_TYPE: this.props.redBrand.shopIntro.shop_template_type,
          IS_RED: 1,
        }
        ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_TAB_C', param);
    }

    _onPressLink(url) {
        ReactNative.NativeModules.YH_CommonHelper.goLinkUrl(url);
    }

    _onPressVideo(room,bgpic){
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.videolive", "params":{"room":"${room}","bgpic":"${bgpic}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    _onPressProductRecommend(product, rowId=0, moduleOrder, moduleType) {
        let productSkn = product && product.get('product_skn', 0);
        if (!productSkn) {
            return;
        }
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);

        let param = {
          SHOP_ID: this.props.redBrand.shopId,
          FLR_INDEX: moduleOrder,
          FLR_NAME: moduleType,
          I_INDEX: parseInt(rowId) + 1,
          F_URL: url,
          TEMPLATE_TYPE:this.props.redBrand.shopIntro.shop_template_type,
          IS_RED: 1,
        }
        console.log('------各楼层---red---');
        console.log(param);
        ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_HOME_FLR_C', param);
    }

    _onPressProductCell(product, rowId=0) {
        let productSkn = product && product.get('product_skn', 0);
        if (!productSkn) {
            return;
        }
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        let tabID = this.props.redBrand.fliter;
        let tabName = '首页';
        if (tabID == '1') {
            tabName = '新品';
        } else if (tabID == '2') {
            tabName = '全部商品';
        }
        let param = {
          SHOP_ID: this.props.redBrand.shopId,
          TAB_ID: tabID,
          TAB_NAME: tabName,
          PRD_SKN: productSkn,
          TEMPLATE_TYPE: this.props.redBrand.shopIntro.shop_template_type,
          IS_RED: 1,
          SORT_TYPE: 1,
        }
        if (tabID != '1') {
            param.FILTER_VALUE = this.props.redBrand.filterNameFactors.toJS();
            param.SORT_TYPE = orderWithString(this.props.redBrand.productList.order);
        }
        console.log('------点击品牌店铺页中全部TAB中的商品列表时---red---');
        console.log(param);
        ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_GOODS_LIST_C', param);
    }

    _onPressProduct(linkType,linkReource,moduleOrder,moduleType,i_index){
        let url = '';
        if (!linkReource) {
            return;
        }
        if (linkType == '0') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource}"}}`;
        } else if (linkType == '1') {
            url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource}"}}`;
        } else if (linkType == '2') {
            url = linkReource;
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);

        let param = {
          SHOP_ID: this.props.redBrand.shopId,
          FLR_INDEX: moduleOrder,
          FLR_NAME: moduleType,
          I_INDEX: i_index,
          F_URL: url,
          TEMPLATE_TYPE:this.props.redBrand.shopIntro.shop_template_type,
          IS_RED: 1,
        }
        console.log('------各楼层---red---');
        console.log(param);
        ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_HOME_FLR_C', param);
    }

    _onPressProductFilter(value) {

        if (value === 'filter') {
            this.props.actions.setFilterView(!this.props.redBrand.productList.isFilter);
            this.props.actions.setFilterMoreView(false);
        } else if(value === 'default'){
            this.props.actions.setFilterMoreView(!this.props.redBrand.productList.isMoreFilter);
            this.props.actions.setFilterView(false);
        }else{
            this.props.actions.setFilterMoreView(false);
            this.props.actions.setFilterView(false);
            this.props.actions.resetListPageInfo();
            this.props.actions.setProductListFilter(value);
            this.props.actions.getProductList(true);
        }
    }

    _onEndReached() {
        this.props.actions.getProductList();
    }

    _onPressProductFilterLeftItem(value) {
        this.props.actions.setProductFilterFactors(value);
    }

    _onPressProductFilterRightItem(item, value) {
        this.props.actions.setProductFilterFactors(item, value);
        this.props.actions.setFilterView(false);
        this.props.actions.resetListPageInfo();
        this.props.actions.getProductList(true);
    }
    _onPressMoreFilter(value){
        this.props.actions.setFilterMoreView(false);
        this.props.actions.setProductListFilter(value);
        this.props.actions.resetListPageInfo();
        this.props.actions.getProductList(true);
    }
    _onPressCloseMoreFilter(){
         this.props.actions.setFilterMoreView(false);
    }

    _onPressCoupon(rowData) {
        if (rowData.status) {
            this.props.actions.getCoupon(rowData.id);
        }else {
            this.props.actions.couponHasRecived();
        }
    }

    resetReceiveCouponResult(){
        this.props.actions.resetReceiveCouponResult();
    }

    render() {

        let {
            shopId,
        	launchProfile,
        	fliter,
        	categoryFilterList,
        	filterCategoryDetailFilterList,
        	shopIntro,
        	shopsdecorator,
        	productList,
            productListForNew,
        	filterFactors,
            filterNameFactors,
            receiveCouponResult,
            coupon,
            similarIndex,
            showSimilarGuider,
        } = this.props.redBrand;

        return (
            <RedBrand
                shopId={shopId}
                similarIndex = {similarIndex}
                productList={productList}
                productListForNew={productListForNew}
                launchProfile={launchProfile}
                fliter={fliter}
                receiveCouponResult={receiveCouponResult}
                coupon={coupon}
                categoryFilterList={categoryFilterList}
                filterCategoryDetailFilterList={filterCategoryDetailFilterList}
                filterNameFactors={filterNameFactors}
                filterFactors={filterFactors}
                shopIntro={shopIntro}
                shopsdecorator={shopsdecorator}
                onPressLaunchProfile={this._onPressLaunchProfile}
                onPressStoreFilter={this._onPressStoreFilter}
                onPressVideo={this._onPressVideo}
                onPressProduct={this._onPressProduct}
                onEndReached={this._onEndReached}
                onPressProductFilterLeftItem={this._onPressProductFilterLeftItem}
                onPressProductFilterRightItem={this._onPressProductFilterRightItem}
                onPressMoreFilter={this._onPressMoreFilter}
                onPressCloseMoreFilter={this._onPressCloseMoreFilter}
                onPressProductFilter={this._onPressProductFilter}
                onPressCoupon={this._onPressCoupon}
                resetReceiveCouponResult={this.resetReceiveCouponResult}
                onPressCollection={this._onPressCollection}
                onPressLink={this._onPressLink}
                onPressProductCell={this._onPressProductCell}
                onPressProductRecommend={this._onPressProductRecommend}
                onLongPressProduct={this._onLongPressProduct}
                onPressFindSimilar={this._onPressFindSimilar}
                showSimilarGuider={showSimilarGuider}
            />
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});

export default connect(mapStateToProps, mapDispatchToProps)(RedPersonBrandContainer);