MineContainer.js 16.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
'use strict'

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

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as mineActions from '../reducers/mine/mineActions';
import MineList from '../components/mine/MineList';
const actions = [
    mineActions,
];
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 MineContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressItem = this._onPressItem.bind(this);
        this._onPressProductListProduct = this._onPressProductListProduct.bind(this);
        this._onMineCenterRefresh = this._onMineCenterRefresh.bind(this);
        this._onLongPressProduct = this._onLongPressProduct.bind(this);
        this._onPressFindSimilar = this._onPressFindSimilar.bind(this);

        //资源位点击楼层
        this._onPressFloorItem = this._onPressFloorItem.bind(this);

        this.subscription1 = NativeAppEventEmitter.addListener(
            'UserDidLoginEvent',
            (reminder) => {
                this.props.actions.loginInSuccess(reminder.uid);
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription2 = NativeAppEventEmitter.addListener(
            'UserDidLogoutEvent',
            (reminder) => {
                this.props.actions.loginOutSuccess();
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription3 = NativeAppEventEmitter.addListener(
            'ChannelDidChangeEvent',
            (reminder) => {
                this.props.actions.setIsMineViewAppeared(false);
                this.props.actions.getProductListForMineCenter();
            }
        );

        this.subscription4 = NativeAppEventEmitter.addListener(
            'MineCenterResumeEvent',
            (reminder) => {
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription5 = NativeAppEventEmitter.addListener(
            'UserDidRegisterEvent',
            (reminder) => {
                this.props.actions.onMineCenterRefresh();
            }
        );

        this.subscription6 = NativeAppEventEmitter.addListener(
            'ProfilesInfoEvent',
            (reminder) => {
                if (reminder) {
                    let profilesInfo = reminder.profilesInfo;
                    let memberBillNew = reminder.memberBillNew;

                    if (profilesInfo) {
                        profilesInfo = JSON.parse(profilesInfo);
                    }
                    profilesInfo && this.props.actions.getMineUserInfoSuccess(profilesInfo);
                    this.props.actions.getMemberBillTaskRedDotSuccess(memberBillNew);
                }
            }
        );

        this.subscription7 = NativeAppEventEmitter.addListener(
            'MineViewDidAppearEvent',
            (reminder) => {
                let {productListForMineCenter} = this.props.mine.open;
                this.props.actions.setIsMineViewAppeared(true);
                productListForMineCenter && this.props.actions.reportFavoriteDataNotJudgeViewAppear(productListForMineCenter.toJS());
            }
        );
    }

    componentDidMount() {
        this.props.actions.getProductListForMineCenter();
        this.props.actions.onMineCenterRefresh();
        this.props.actions.getMineAllIcon();
        this.props.actions.getMineResource();
        // this.props.actions.setShowSimilarGuider(true);
    }

    componentWillUnmount() {
        this.subscription1 && this.subscription1.remove();
        this.subscription2 && this.subscription2.remove();
        this.subscription3 && this.subscription3.remove();
        this.subscription4 && this.subscription4.remove();
        this.subscription5 && this.subscription5.remove();
        this.subscription6 && this.subscription6.remove();
        this.subscription7 && this.subscription7.remove();
    }

    _onPressItem(viewId, data) {
        let url = "";
        let params = {};
        switch (viewId) {
            case 'mineSetting':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.setting","params":{}}`;
                break;
            case 'mineMessageHome':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.messagehome","params":{}}`;
                params = {
                    ENTER_SRC:1,
                };
                NativeModules.YH_CommonHelper.logEvent('YB_MY_MESS', params);
                break;
            case 'mineInfo':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineinfo","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_PERSONAL_INFO_C', params);
                break;
            case 'mineVip':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.vipInfo","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_VIP_C', params);
                break;
            case 'mineStudentHome':
                //学生认证
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.studenthome","params":{}}`;
                params = {
                    SRC_ID: 2,
                }
                NativeModules.YH_CommonHelper.logEvent('YB_MY_STU_IDENTIFY', params);
                break;
            case 'mineLogin':
                //登陆,直接return了,不需要再去调用跳转规则
                ReactNative.NativeModules.YH_CommonHelper.login();
                return;
            case 'mineFavProduct':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_FAVPRD', {});
                break;
            case 'mineFavBrand':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.fav","params":{"favType":"1"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_FAVBRND', {});
                break;
            case 'mineBrowseHis':
                //浏览记录
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.browserhistory","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_BROWSE', {});
                break;
            case 'mineCertification':
                //设置安全性
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.associatephone","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_GO_BIND_C', {});
                break;
            case 'mineAnnounce':
                //通知
                url = data;
                if (!url) {
                    return;
                }
                params = {
                    POS_ID: 1,
                }
                NativeModules.YH_CommonHelper.logEvent('YB_MY_NOTICE_C', params);
                break;
            case 'mineOrder':
                //我的订单
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"0"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_ORD', {});
                break;
            case 'dfkOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"1"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTPAY', {});
                break;
            case 'dfhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"2"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTOUT', {});
                break;
            case 'dshOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.order","params":{"index":"3"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTREV', {});
                break;
            case 'dsdOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.showgoods","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_WTAPP', {});
                break;
            case 'thhOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.orderService","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_RETURN', {});
                break;
            case 'mineCoupon':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.coupon","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_COUP', {});
                break;
            case 'mineYohoCoin':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.yohocoin","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_YOHO', {});
                break;
            case 'mineLimitCode':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minerestrictioncode","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_RESTRICTION_CODE_C', {});
                break;
            case 'mineInstallment':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.myInstalment","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_INST', {});
                break;
            case 'mineRedPackage':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineredenvelop","params":{}}`;
                break;
            case 'mineGuang':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineguang","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_STROLL', {});
                break;
            case 'mineShareOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minesharelist","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_SHOW', {});
                break;
            case 'mineMemberInfo':
                if (!data) {
                    return;
                }
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.memberbill","params":{"mine_memberbill_title":"${data.title}","mine_memberbill_url":"${data.url}"}}`;
                NativeModules.YH_MineHelper.setMemberBillNew(false);
                this.props.actions.getMemberBillTaskRedDotSuccess(false);
                break;
            case 'mineActivity':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.mineactivity","params":{"act_name":"${data.get('act_name')}","act_id":"${data.get('act_id')}","url":"${data.get('url')}","link":"${data.get('url')}"}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_INV', {});
                NativeModules.YH_MineHelper.setMineActivityClicked(data.get('act_id'));
                break;
            case 'mineFeedback':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.sfhome","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_FEEDBACK_C', {});
                break;
            case 'mineGlobalOrder':
                url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.globalorderlist","params":{}}`;
                NativeModules.YH_CommonHelper.logEvent('YB_MY_GLOBAL', {});
            default:
                break;
        }
        // 去设置界面不需要判断登陆
        if (viewId === 'mineSetting') {
            ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
        }
        else {
            ReactNative.NativeModules.YH_CommonHelper.uid()
                .then(data => {
                    ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
                })
                .catch(error => {
                    ReactNative.NativeModules.YH_CommonHelper.login()
                        .then(uid => {
                            ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
                        })
                        .catch(error => {

                        });
                });
        }
    }

    _onPressProductListProduct(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 productId = product && product.get('product_id', 0);
        let rec_id = this.props.mine.open.productListForMineCenter.rec_id;
        let rec_pose = '100004';

        let chooseForYouParam = {
            'PRD_ID': productId,
            'PRD_NUM': parseInt(rowId)+1,
            'ACTION_ID': 1,
            'REC_ID': rec_id?rec_id:'',
            'REC_POSE': rec_pose
        };

        NativeModules.YH_CommonHelper.logEvent('YB_CHOOSE_FOR_YOU', chooseForYouParam);
    }

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

    _onMineCenterRefresh() {
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.onMineCenterRefresh();
        });
    }

    //点击资源位楼层数据
    _onPressFloorItem(jumpUrl, imageUrl, index, floorData, floorIndex) {
        if (!jumpUrl) {
            return;
        }
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(jumpUrl);

        let floorID = floorData.get('template_id','');
        let floorName = floorData.get('template_name','');
        let param = {
                        'F_ID': floorID,
                        'F_NAME': floorName,
                        'F_URL': jumpUrl,
                        'F_INDEX': parseInt(floorIndex) + 1 + "",
                        'I_INDEX': parseInt(index) + 1 + "",
                    };
        NativeModules.YH_CommonHelper.logEvent('YB_MY_BANNER_C', param);
    }

    render() {
        let {
            isFetching,
            isNeedShowXsrz,
            isLogin,
            open,
            profile,
            mineInfoNum,
            redPackageNum,
            activityListInfo,
            memberBill,
            showRedPacket,
            certificationInfo,
            announcement,
            globalOrderData,
            iconAll,
            instalmentStatus,
            showSimilarGuider,
            mineResource,
        } = this.props.mine;
        return (
            <MineList
                isFetching={isFetching}
                isNeedShowXsrz={isNeedShowXsrz}
                isLogin={isLogin}
                productListForMineCenter={open.productListForMineCenter}
                mineCenterInfo={open.mineCenterInfo}
                profile={profile}
                mineInfoNum={mineInfoNum}
                redPackageNum={redPackageNum}
                activityListInfo={activityListInfo}
                memberBill={memberBill}
                showRedPacket={showRedPacket}
                certificationInfo={certificationInfo}
                announcement={announcement}
                globalOrderData={globalOrderData}
                iconAll={iconAll}
                instalmentStatus={instalmentStatus}
                mineResource={mineResource}

                onPressItem={this._onPressItem}
                onPressProductListProduct={this._onPressProductListProduct}
                onMineCenterRefresh={this._onMineCenterRefresh}
                getProductListForMineCenter={this.props.actions.getProductListForMineCenter}
                onLongPressProduct={this._onLongPressProduct}
                onPressFindSimilar={this._onPressFindSimilar}
                onPressFloorItem={this._onPressFloorItem}
                showSimilarGuider={showSimilarGuider}
            />
        );
    }
}
let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

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