Blame view

public/js/product/detail/comments-consults.js 2.84 KB
1 2 3 4 5
/**
 *  商品详情  --评论和咨询tab
 * @author: Lynnic
 * @date: 2015/11/18
 */
lijing authored
6
let $ = require('yoho-jquery'),
郝肖肖 authored
7
    tip = require('plugin/tip'),
8 9
    Hammer = require('yoho-hammer');
lijing authored
10
let commentsNum, consultsNum;
11
lijing authored
12
let navtabEle = document.getElementById('nav-tab'),
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
    navtabHammer = navtabEle && new Hammer(navtabEle),

    gotoConsultEle = document.getElementById('goto-consult'),
    gotoConsultHammer = gotoConsultEle && new Hammer(gotoConsultEle),

    readmore = document.getElementById('readmore'),
    readmoreHammer = readmore && new Hammer(readmore);

(function() {
    consultsNum = $('#nav-tab .consults-num').html() - 0;

    commentsNum = $('#nav-tab .comments-num').html() - 0;

    $('#nav-tab li').each(function() {
        $(this).removeClass('focus');
    });

    $('#feedback-content .content').each(function() {
        $(this).addClass('hide');
    });
    if (commentsNum !== 0) {
        $('#nav-tab .comment-nav').addClass('focus');
        $('#feedback-content .comment-content').removeClass('hide');

    } else if (consultsNum !== 0) {
        $('#nav-tab .consult-nav').addClass('focus');
        $('#feedback-content .consult-content').removeClass('hide');
    }
42
    $('.goods-consults .consult-item:lt(2)').removeClass('hide');
43 44 45 46
}());

if (navtabHammer) {
    navtabHammer.on('tap', function(e) {
lijing authored
47 48
        let $this = $(e.target).closest('li');
        let index = $this.index();
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

        if ($this.hasClass('comment-nav') && commentsNum === 0) {
            tip.show('暂无商品评价');
        } else {
            if (!$this.hasClass('focus')) {

                $('#nav-tab li').each(function() {
                    $(this).removeClass('focus');
                });
                $('#feedback-content .content').each(function() {
                    $(this).addClass('hide');
                });

                $this.addClass('focus');
                $('#feedback-content .content:eq(' + index + ')').removeClass('hide');
            }
        }
    });
}

// if (consultFooterHammer) {
//     consultFooterHammer.on('tap', function() {
//         location.href = $(consultFooterEle).data('href');
//     });
// }

if (gotoConsultHammer) {
    gotoConsultHammer.on('tap', function() {
lijing authored
77
        let link = $(gotoConsultEle).find('a').attr('href');
郭成尧 authored
78
沈志敏 authored
79
        link += (link.indexOf('?') >= 0 ? '&' : '?') + 'from=' + encodeURIComponent(location.href);
陈峰 authored
80
        location.href = link;
81 82 83 84 85
    });
}

// 咨询页面固定header
if ($('.goods-consults-page').length > 0) {
沈志敏 authored
86
    //    $('#yoho-header').css('position', 'fixed').css('top', '0');
87 88 89 90 91 92 93 94 95
}

if ($('.goods-consults-page').length > 0) {
    $('#yoho-footer').css('border-top', '1px solid #e0e0e0');
}

if (readmoreHammer) {
    readmoreHammer.on('tap', function() {
        $('.readmore').hide();
96
        $('.goods-consults').find('.consult-item').removeClass('hide');
97 98 99 100 101
        return false;
    });
}

require('./fav');