BrandContainer.js 3.19 KB
'use strict'

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

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as brandActions from '../reducers/brand/brandActions';

import Brand from '../components/brand/Brand';
import Browse from '../components/browse/Browse';


const actions = [
    brandActions,
];

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 BrandContainer extends Component {
    constructor(props) {
        super(props);

        this.onEndReached = this.onEndReached.bind(this);
        this.onPressProduct = this.onPressProduct.bind(this);
        this.onPressLike = this.onPressLike.bind(this);
        this.onPressHome = this.onPressHome.bind(this);
        this.onPromptHidden = this.onPromptHidden.bind(this);
        this.onPressGuangGuang = this.onPressGuangGuang.bind(this);
    }

    componentDidMount() {
        this.props.actions.brandList();

    }

    componentWillUnmount() {

    }

    onPressGuangGuang() {
        ReactNative.NativeModules.YH_RecorderHelper.onPressGuangGuang();
    }

    onEndReached() {
        this.props.actions.brandList();
    }

    onPressProduct(product) {
        let productSkn = product.get('product_skn', 0)
        if (!productSkn) {
          return;
        }

        let isGlobalProduct = product.get('is_global', 'N') == 'Y'; // 是否全球购商品
        let action = '';
        if (isGlobalProduct) {
            action = 'go.globalpurchase';
        } else {
            action = 'go.productDetail';
        }

        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"${action}","params":{"product_skn":"${productSkn}","from_page_name":"${Platform.OS === 'ios'?'iFP_MineCollectionBrand':'aFP_MineCollectionBrand'}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    onPressLike(brand, index) {
        this.props.actions.favoriteOperation(index);
    }

    onPressHome(brand) {
        if (!brand) {
            return;
        }

        brand = brand.toJS();
        brand.id = brand.brand_id;
        ReactNative.NativeModules.YH_CommonHelper.pushBrandVC(brand);
    }

    onPromptHidden() {
        this.props.actions.hidePromt();
    }

    render() {
        let {
            brand,
        } = this.props;

        return (
            <Brand
                data={brand}
                onEndReached={this.onEndReached}
                onPressProduct={this.onPressProduct}
                onPressLike={this.onPressLike}
                onPressHome={this.onPressHome}
                onPromptHidden={this.onPromptHidden}
                onPressGuangGuang={this.onPressGuangGuang}
            />
        );
    }
}

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