RedPersonBrandContainer.js 12.3 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._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();
    }

    componentWillUnmount() {

    }

    _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);
        try {
            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,
              KEY_WORD: this.props.redBrand.keyWord,
              FROM_WHERE: this.props.redBrand.keyWord ? "1" : "",
            }
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_TAB_C', param);
        } catch (e) {
            __DEV__ && console.error(e);
        } finally {

        }
    }

    _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}","from_page_name":"${Platform.OS === 'ios'?'iFP_RedPersonBrand':'aFP_RedPersonBrand'}","from_page_param":"${this.props.redBrand.shopId}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        try {
            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,
              KEY_WORD: this.props.redBrand.keyWord,
              FROM_WHERE: this.props.redBrand.keyWord ? "1" : "",
            }
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_HOME_FLR_C', param);
        } catch (e) {
            __DEV__ && console.error(e);
        } finally {

        }
    }

    _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}","from_page_name":"${Platform.OS === 'ios'?'iFP_RedPersonBrand':'aFP_RedPersonBrand'}","from_page_param":"${this.props.redBrand.shopId}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        try {
            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,
              KEY_WORD: this.props.redBrand.keyWord,
              FROM_WHERE: this.props.redBrand.keyWord ? "1" : "",
            }
            if (tabID != '1') {
                param.FILTER_VALUE = this.props.redBrand.filterNameFactors.toJS();
                param.SORT_TYPE = orderWithString(this.props.redBrand.productList.order);
            }
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_GOODS_LIST_C', param);
        } catch (e) {
            __DEV__ && console.error(e);
        } finally {

        }
    }

    _onPressProduct(url,moduleOrder,moduleType,i_index){
        if (!url || url == '') {
            return;
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        try {
            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,
              KEY_WORD: this.props.redBrand.keyWord,
              FROM_WHERE: this.props.redBrand.keyWord ? "1" : "",
            }
            ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_BRAND_SHOP_HOME_FLR_C', param);
        } catch (e) {
            __DEV__ && console.error(e);
        } finally {

        }
    }

    _onPressProductFilter(value) {
        try {
            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);
            }
        } catch (e) {
            __DEV__ && console.error(e);
        } finally {
        }
    }

    _onEndReached(filter) {
        if (filter == 1) {
            this.props.actions.getProductListForNew();
        } else {
            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){
        let {productList} = this.props.redBrand;
        if (value == productList.get('order')) {
            this.props.actions.setFilterMoreView(false);
            return;
        }
        this.props.actions.updateMoreFilterSelectOrder(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 == 3) {
            this.props.actions.couponHasRecived();
        }else {
            this.props.actions.getCoupon(rowData.id);
        }
    }

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

    render() {

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

        return (
            <RedBrand
                shopId={shopId}
                productList={productList}
                productListForNew={productListForNew}
                launchProfile={launchProfile}
                fliter={fliter}
                moreFilterSelectOrder={moreFilterSelectOrder}
                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}
            />
        );
    }
}

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

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