Blame view

public/js/product/global-detail/view.js 5.47 KB
沈志敏 authored
1 2 3 4 5 6
import {
    View
} from 'yoho-mvc';

let Swiper = require('yoho-swiper');
let lazyLoad = require('yoho-jquery-lazyload');
沈志敏 authored
7
let dialog = require('plugin/dialog');
沈志敏 authored
8 9 10 11 12

export class DetailView extends View {
    constructor() {
        super('#global-detail-page');
沈志敏 authored
13 14 15 16 17 18 19
        this.on('click', '.addto-cart', this.showDownLoadDialog.bind(this));
        this.on('click', '.illustrate-title', this.illustrateDown.bind(this));
        this.on('click', '.illustrate-contents', this.illustrateUp.bind(this));
        this.illustrateTitle = $('.illustrate-title');
        this.illustrateContents = $('.illustrate-contents');
        this.illustrateContents.hide().addClass('down-animate');
沈志敏 authored
20
        setTimeout(() => {
沈志敏 authored
21
            let swiper = new Swiper('.banner-swiper', {
沈志敏 authored
22 23 24 25 26 27 28 29 30 31
                preloadImages: false,
                lazyLoading: true,
                lazyLoadingInPrevNext: true,
                lazyLoadingOnTransitionStart: true,
                paginationClickable: true,
                pagination: '.banner-top .pagination-inner',
                nextButton: '.my-swiper-button-next',
                prevButton: '.my-swiper-button-prev',
                spaceBetween: 3
            });
沈志敏 authored
32 33 34 35 36 37 38 39

            $('.banner-swiper').click(function() {
                $('.banner-top').toggleClass('hover');
                swiper.onResize();
            });
            $('.banner-top-single').click(function() {
                $('.banner-top-single').toggleClass('hover');
            });
沈志敏 authored
40 41 42 43 44 45 46 47 48 49 50 51 52
        }, 500);

        let $cartBar = $('.cart-bar');
        let timer = setInterval(function() {
            if ($cartBar) {
                window.reMarginFooter('.cart-bar');
                clearInterval(timer);
            } else {
                $cartBar = $('.cart-bar');
            }
        }, 500);
    }
沈志敏 authored
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
    showDownLoadDialog() {
        dialog.showDialog({
            dialogText: '进入有货APP',
            hasFooter: {
                rightBtnText: '打开Yoho!Buy有货APP'
            }
        }, function() {
            let appUrl = $('#main-wrap').data('apppath');
            let ifr = document.createElement('iframe');

            ifr.src = appUrl;
            ifr.style.display = 'none';
            document.body.appendChild(ifr);
            window.location.href = appUrl;

            let time = Date.now();

            window.setTimeout(function() {
                document.body.removeChild(ifr);
                if (Date.now() - time < 3200) {
                    window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
                }
            }, 3000);

        }, null, true);

        $('.dialog-wrapper').off('touchstart').on('touchstart', function(para) {
            para.stopPropagation();
            if ($(para.target).hasClass('dialog-wrapper')) {
                dialog.hideDialog();
            }
        });
    }

    illustrateDown() {
        this.illustrateTitle.hide();
        this.illustrateContents.show();
        setTimeout(()=>{
            this.illustrateContents.removeClass('down-animate');
        }, 10);
    }

    illustrateUp() {
        this.illustrateContents.addClass('down-animate');
        setTimeout(()=>{
            this.illustrateContents.hide();
            this.illustrateTitle.show();
        }, 500);
    }

    getCart() {
        return $('#remove-cart-count').length;
    }

    setCartCount(count) {
        $('.cart-bar').find('.num-tag').html(count).removeClass('hide');
    }
沈志敏 authored
111 112
    setDetailHtml(htmldata) {
        let $productDesc = $('#productDesc');
沈志敏 authored
113
沈志敏 authored
114
        $productDesc.append(htmldata);
沈志敏 authored
115 116

        window.rePosFooter && window.rePosFooter();
沈志敏 authored
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

        lazyLoad($productDesc.find('img.lazy'));

        this.productDescStyle();
    }

    productDescStyle() {
        new Swiper('#swiper-recommend', {
            slidesPerView: 'auto',
            grabCursor: true,
            slideElement: 'a',
            lazyLoading: true,
            watchSlidesVisibility: true
        });
沈志敏 authored
132
        let $service = $('.service-cont'),
沈志敏 authored
133 134
            serviceH = $service.height(),
            serviceLi = $service.find('li'),
沈志敏 authored
135
            showH = parseInt(serviceLi.eq(0).height()) + parseInt(serviceLi.eq(1).height()) - parseInt(serviceLi.eq(1).find('.service-answer').height()) / 2; // eslint-disable-line
沈志敏 authored
136 137 138 139 140 141 142 143 144

        $service.css({
            height: showH,
            overflow: 'hidden'
        });

        this.operation = {
            showH,
            serviceH
沈志敏 authored
145
        };
沈志敏 authored
146 147 148
        this.on('click', '.service-operation', this.serviceOperation.bind(this));
    }
沈志敏 authored
149
    serviceOperation(e) {
沈志敏 authored
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        function serviceState(opt) {
            opt.dom.html(opt.txt + '<i class="service-icon shrink-btn-' + opt.btnClass + '"></i>');

            $('.service-cont').animate({
                height: opt.height
            }, 0, function() {
                $(this).css({
                    overflow: opt.of
                });
            });
        }

        let $this = $(e.currentTarget);
        let curState = $this.find('i').hasClass('shrink-btn-up');

        if (curState) {
            serviceState({
沈志敏 authored
167 168 169 170 171
                dom: $this,
                txt: '展开',
                btnClass: 'down',
                height: this.operation.showH,
                of: 'hidden'
沈志敏 authored
172 173 174
            });
        } else {
            serviceState({
沈志敏 authored
175 176 177 178 179
                dom: $this,
                txt: '收起',
                btnClass: 'up',
                height: this.operation.serviceH,
                of: 'visible'
沈志敏 authored
180 181 182 183 184 185 186
            });
        }
    }

    getSkn() {
        return this.$base.data('skn');
    }
沈志敏 authored
187
}