SeckillContainer.js 5 KB
'use strict'

import React, {Component} from "react";
import {StyleSheet, Dimensions, Platform, View, NativeModules} from "react-native";
import {bindActionCreators} from "redux";
import {connect} from "react-redux";
import {Map} from "immutable";
import * as seckillActions from "../reducers/seckill/seckillActions";
import * as discountProductActions from "../reducers/discountProduct/DiscountProductActions";
import Seckill from "../components/seckill/Seckill";

const actions = [
    seckillActions,
    discountProductActions
];

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 SeckillContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressTimeItem = this._onPressTimeItem.bind(this);
        this._onPressProductItem = this._onPressProductItem.bind(this);
        this._onPressRemindBtn = this._onPressRemindBtn.bind(this);
        this._onPressGuangShopWithURL = this._onPressGuangShopWithURL.bind(this);
        this._onRefresh = this._onRefresh.bind(this);
        this._onClearTipMessage = this._onClearTipMessage.bind(this);
        this._onFocusToCurStartedActivity = this._onFocusToCurStartedActivity.bind(this);
        this._onFetchDiscountProductList = this._onFetchDiscountProductList.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
        this._onPressProduct = this._onPressProduct.bind(this);
    }

    _onPressProduct(product) {

        this.props.actions.clickProductItem(product);
        let productSkn = product && product.get('product_skn', 0);
        
        if (!productSkn) {
            return;
        }

        let pageName = 'iFP_Alliance';
        if (Platform.OS === 'android') {
            pageName = 'aFP_Alliance';
        }
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}", "from_page_name":"${pageName}"}}`;
        
        NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    _onPressTimeItem(activity) {
        this.props.actions.clickActivityTimeItem(activity);
    }

    _onPressProductItem(product) {
        this.props.actions.clickProductItem(product);
    }

    _onPressGuangShopWithURL(url) {
        if (url && url.length) {
            NativeModules.YH_CommonHelper.jumpWithUrl(url);
        }
    }

    _onPressRemindBtn(product) {
        this.props.actions.clickRemindBtn(product);
    }

    _onRefresh(activityId) {
        this.props.actions.refreshList(activityId);
    }

    _onClearTipMessage() {
        this.props.actions.clearTipMessage();
    }

    _onFocusToCurStartedActivity(activity) {
        if (this.props.seckill.ptr) {
            return;
        }
        this.props.actions.clickActivityTimeItem(activity);
        // this.props.actions.getSeckillQueryActivity(activity.startTime / 1000);
    }

    _onFetchDiscountProductList() {
        // this.props.actions.getDiscountProductList()
    }

    _onEndReached() {
        // this.props.actions.getDiscountProductList()
    }

    render() {

        let {
            isFetching,
            error,
            queryActivityInfo,
            queryProductList,
            queryRemindList,
            tipMessage,
            ptr,
            curActivity,
            localServerTimeDiff,
        } = this.props.seckill;
        if (queryProductList) {
            queryProductList = queryProductList.toJS();
        }
        let productList = queryProductList[curActivity.get('activityId')];
        let discountProduct = this.props.discountProduct;
        return (
            <Seckill
                isFetching={isFetching}
                error={error}
                ptr={ptr}
                queryActivityInfo={queryActivityInfo}
                queryProductList={productList}
                queryRemindList={queryRemindList}
                tipMessage={tipMessage}
                curActivity={curActivity}
                discountProduct={discountProduct}
                localServerTimeDiff={localServerTimeDiff}
                onPressTimeItem={this._onPressTimeItem}
                onPressProductItem={this._onPressProductItem}
                onPressRemindBtn={this._onPressRemindBtn}
                onPressGuangShopWithURL={this._onPressGuangShopWithURL}
                onRefresh={this._onRefresh}
                onEndReached={this._onEndReached}
                onFetchDiscountProductList={this._onFetchDiscountProductList}
                onClearTipMessage={this._onClearTipMessage}
                onFocusToCurStartedActivity={this._onFocusToCurStartedActivity}
                onPressProduct={this._onPressProduct}
            />
        );
    }
}

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

});
export default connect(mapStateToProps, mapDispatchToProps)(SeckillContainer);