RedPersonBrandContainer.js 8.33 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
    };
}

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);
    }

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

    componentWillUnmount() {

    }

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

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

        ReactNative.NativeModules.YH_CommonHelper.jumpFindSimilar(product.toJS());
    }


    _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);
    }

    _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);
    }

    _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);
    }

    _onPressProduct(linkType,linkReource){
        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);
    }

    _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,
        	filterFactors,
            filterNameFactors,
            receiveCouponResult,
            coupon,
            similarIndex,
        } = this.props.redBrand;

        return (
            <RedBrand
                similarIndex = {similarIndex}
                productList={productList}
                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}
                onLongPressProduct={this._onLongPressProduct}
                onPressFindSimilar={this._onPressFindSimilar}
            />
        );
    }
}

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

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