Blame view

public/js/product/sale.page.js 2.96 KB
阿达 authored
1 2 3 4 5
/**
 * sale页面
 * @author: da<abel.wang@yoho.cn>
 * @date: 2016/05/31
 */
514335620@qq.com authored
6
var $ = require('yoho-jquery'),
yyq authored
7
    lazyLoad = require('yoho-jquery-lazyload'),
阿达 authored
8
    product = require('./index/product');
514335620@qq.com authored
9
阿达 authored
10 11
var limitTime = [];
yyq authored
12 13 14
var $saleBox = $('.sale-box'),
    $navItem = $('.sale-nav li');
15
require('../common');
阿达 authored
16
require('./sale/banner');
阿达 authored
17 18 19
require('../plugins/slider');
require('../plugins/filter');
require('../plugins/sort-pager');
yyq authored
20
require('./detail/latest-walk');
阿达 authored
21
阿达 authored
22
product.init(4);
23
514335620@qq.com authored
24 25 26
lazyLoad($('img.lazy'));
$('.slide-container').slider();
阿达 authored
27 28
// 请求带导航的列表数据
function getNaviData(items) {
阿达 authored
29
    var location, url, goodItems, navTitle;
阿达 authored
30
阿达 authored
31 32
    navTitle = items.attr('urlLocation');
郭成尧 authored
33
    location = '/product/sale/goods';
阿达 authored
34 35 36

    goodItems = items.parent().parent('.sale-box').find('.goods');
阿达 authored
37
    url = location + navTitle;
阿达 authored
38 39 40 41 42 43 44 45
    $.ajax({
        type: 'GET',
        url: url,
        data: ''
    }).then(function(res) {

        goodItems.html('');
        goodItems.append(res);
阿达 authored
46
        lazyLoad(items.closest('.sale-box').find('.lazy'));
阿达 authored
47 48 49
    });
}
514335620@qq.com authored
50 51 52
$navItem.on('click', function() {
    $(this).siblings('.active').removeClass('active');
    $(this).addClass('active');
阿达 authored
53 54 55

    getNaviData($(this));
514335620@qq.com authored
56 57
});
58
阿达 authored
59 60 61 62
//  初始化页面数据
(function() {

    $saleBox.each(function() {
阿达 authored
63
        var item = $(this).find($navItem).eq(0);
阿达 authored
64 65 66 67

        getNaviData(item);
    });
}());
阿达 authored
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86


function convertTime(time) {
    var anHour = 3600000,
        aMinute = 60000,
        aSecond = 1000,
        showTime = '',
        d = 0,
        h = 0,
        m = 0,
        s = 0;

    if (time > 1000) {
        d = Math.floor(time / anHour / 24);
        h = Math.floor(time / anHour % 24);
        m = Math.floor(time / aMinute % 60);
        s = Math.floor(time / aSecond % 60);

        showTime += d > 0 ? d + '天' : '';
87 88
        showTime += h > 0 ? h + '时' : '';
        showTime += m > 0 ? m + '分' : '';
阿达 authored
89 90 91 92 93 94 95
        showTime += s > 0 ? s + '秒' : '';
    }

    return showTime;
}

function setPageTime() {
阿达 authored
96
    var i, text, showTime;
阿达 authored
97 98

    for (i = 0; i < limitTime.length; i++) {
阿达 authored
99
        if (limitTime[i].time < 0) {
张丽霞 authored
100
            $('.time').addClass('hide');
阿达 authored
101 102 103
            return;
        }
阿达 authored
104 105
        limitTime[i].time -= 1000;
        showTime = convertTime(limitTime[i].time);
阿达 authored
106 107 108 109 110
        if (showTime) {
            text = showTime;
            if (limitTime[i].pre) {
                text = limitTime[i].pre + ' ' + text;
            }
张丽霞 authored
111 112 113

            $('.time-calculate').removeClass('hide');
            $('.time-calculate').text(showTime);
阿达 authored
114 115
        } else {
            text = '活动已结束';
张丽霞 authored
116
            $('.time').addClass('hide');
阿达 authored
117
        }
张丽霞 authored
118 119 120
    }
    if (limitTime.length === 0) {
        $('.time').addClass('hide');
阿达 authored
121 122 123
    }
}
张丽霞 authored
124
if ($('.sale-discount-page').length > 0) {
阿达 authored
125 126

    $('.time-calculate').each(function() {
阿达 authored
127
        var data = $(this).attr('data');
阿达 authored
128 129 130 131 132 133 134 135 136 137 138 139

        if (data) {
            limitTime.push({
                dom: $(this),
                time: data
            });
        }
    });

    setInterval(setPageTime, 1000);
}