installment.page.js 6.33 KB
/**
 * ajax 分期首页
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/08/17
 */

let $ = require('yoho-jquery'),
    cookie = require('yoho-cookie'),
    Swiper = require('yoho-swiper'),

    // ListData = require('./installment-goods'),
    bp = require('./burying-point'),
    PullRefresh = require('plugin/pull-refresh'),
    uuid = require('uuid');
const yoho = require('yoho-app');

let installment = {
    init: function() {
        let self = this;

        self.paramsInit();

        $(window).on('mousewheel', false);
        $('body').attr('ontouchstart', true);
        $('img.lazy').lazyload({
            effect: 'fadeIn'
        });

        if (self.$isOpen.val() === 'true') {
            self.iscrollAction();
        }

        // 5.7分期推荐商品没有分页
        // else {
        //     // 商品列表翻页加载数据
        //     new ListData({
        //         url: '/home/installment/get-goods',
        //         page: 1,
        //         boxArea: $('#goods-list'),
        //         uuid: self.uuidVal
        //     });
        // }

        if (self.cookieTab) {
            self.$tab.eq(self.cookieTab).addClass('on').siblings().removeClass('on');
            self.$installmentCont.hide().eq(self.cookieTab).fadeIn();
        } else {
            self.$tab.eq(0).addClass('on').siblings().removeClass('on');
            self.$installmentCont.hide().eq(0).fadeIn();
        }
        self.noticeScroll('.notice', $('.notice').data('time') * 1000);

        cookie.remove('installmentTab');

        // 已开通tab 切换
        self.$tab.on('click', function() {
            self.tabChangeAction(this);
        });

        // 统计:开通按钮点击时
        $('.open-btn').on('click', function() {
            bp.setContYas({
                op: 'YB_INST_OPEN',
                appop: 'YB_H5_INST_OPEN_C'
            }, {}, true);
        });

        $(document).on('click', '.good-info', function() {

            // 统计:商品点击时
            bp.setContYas({
                op: 'YB_INST_HOME_GDS_LIST',
                appop: 'YB_H5_INST_HOME_GDS_LIST_C'
            }, {
                PRD_NUM: parseInt($(this).index()) + 1, //eslint-disable-line
                PRD_ID: $(this).data('goodId'),
                ACTION_ID: 1,
                REC_ID: self.uuidVal
            }, true);
        });

        // 统计:开通后模块位点击时
        $('.nav-bit').on('click', function() {
            bp.setContYas('YB_INST_REPAYMENT_CLICK', {
                POS_ID: $(this).data('id')
            }, true);
        });

        if (window.queryString.status === '2') {
            setTimeout(function() {
                $('.advertisement-area').fadeIn();
            }, 2000);

            $('.advertisement-area .close-box, .advertisement-area .mask-bg').on('click', function() {
                $('.advertisement-area').fadeOut();
                return false;
            });
        }

        self.setCookies();
    },
    noticeScroll: function(selecter, time) {
        new Swiper(selecter, {
            autoplay: time,
            direction: 'vertical',
            speed: 500,
            loop: true,
            noSwiping: true
        });
    },
    tabChangeAction: function(dom) {
        let self = this,
            labId = 1,
            index = $(dom).index();

        $(dom).addClass('on').siblings().removeClass('on');
        self.$installmentCont.hide().eq(index).show();
        window.setCookie('installmentTab', index);

        if (index === 1) {
            labId = 2;
            $('img.lazy').lazyload({
                effect: 'fadeIn'
            });
        }

        // 统计:开通成功后首页头部tab切换
        bp.setContYas({
            op: 'YB_INST_OPENED_HOME_CLICK',
            appop: 'YB_H5_INST_OPENED_HOME_TAB_C'
        }, {
            LAB_ID: labId
        }, true);

        self.starIScroll.iScroll.refresh();
    },
    iscrollAction: function() {
        // 下拉刷新
        let starIScroll = new PullRefresh('.installment-main', {
            pullDown: function() {
                window.setCookie('installmentTab', $('.detail-tab .on').index());
                location.reload();
            }
        });

        // 解决部分安卓手机不识别calc(100vh)的问题
        $('.installment-main').css({height: $(window).height()});

        $('img').on('load', function() {
            starIScroll && starIScroll.iScroll.refresh();
        });

        this.starIScroll = starIScroll;
    },
    paramsInit: function() {
        let self = this;

        $.extend(self, {
            uuidVal: uuid.v4(),
            $tab: $('.detail-tab span'),
            $isOpen: $('.is-open'),
            $installmentCont: $('.installment-cont'),
            cookieTab: +window.cookie('installmentTab'),
            starIScroll: ''
        });
    },
    setCookies: function() {
        // window.setCookie('installmentUid', window.queryString.uid);
        // window.setCookie('yhChannel', window.queryString.yh_channel);
        // window.setCookie('udid', window.queryString.udid);
        // window.setCookie('clientType', window.queryString.client_type);
        // window.setCookie('appVersion', window.queryString.app_version);
    }
};

require('common');
require('yoho-jquery-lazyload');

$(window).load(function() {

    if ($('.installment-only').length > 0) {
        // 统计:进入页面时
        bp.setContYas('YB_INST_HOME', {
            IS_OPEN: installment.$isOpen.val()
        }, true);

        // 统计:商品第一页加载时
        bp.setContYas({
            op: 'YB_INST_HOME_GDS_LIST',
            appop: 'YB_H5_INST_HOME_GDS_LIST_C'
        }, {
            PRD_NUM: $('.installment-only .good-info').length,
            PRD_ID: bp.countGoodsId(),
            ACTION_ID: 0,
            REC_ID: installment.uuidVal
        }, true);

        if (installment.$isOpen.val() === 'true') {

            // 统计:待还款金额默认页面加载时
            bp.setContYas('YB_INST_OPENED_HOME_LOAD', {
                LAB_ID: 1
            }, true);
        }
    }
});

$(function() {
    installment.init();

    // 商品曝光事件上报
    if (yoho.isApp) {
        let GoodsShowYasRpter = require('common/goods-show-yas-rpter').default;

        new GoodsShowYasRpter({
            goodsContainer: $('#goods-list'),
            goodsSelectorStr: '.good-info'
        });
    }
});