Blame view

public/js/product/sale.page.js 2.76 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');
阿达 authored
20
阿达 authored
21
product.init(4);
22
514335620@qq.com authored
23 24 25
lazyLoad($('img.lazy'));
$('.slide-container').slider();
阿达 authored
26 27
// 请求带导航的列表数据
function getNaviData(items) {
阿达 authored
28
    var location, url, goodItems, navTitle;
阿达 authored
29
阿达 authored
30 31
    navTitle = items.attr('urlLocation');
郭成尧 authored
32
    location = '/product/sale/goods';
阿达 authored
33 34 35

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

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

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

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

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


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 + '天' : '';
86 87
        showTime += h > 0 ? h + '时' : '';
        showTime += m > 0 ? m + '分' : '';
阿达 authored
88 89 90 91 92 93 94
        showTime += s > 0 ? s + '秒' : '';
    }

    return showTime;
}

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

    for (i = 0; i < limitTime.length; i++) {
阿达 authored
98 99 100 101
        if (limitTime[i].time < 0) {
            return;
        }
阿达 authored
102 103
        limitTime[i].time -= 1000;
        showTime = convertTime(limitTime[i].time);
阿达 authored
104 105 106 107 108 109 110 111
        if (showTime) {
            text = showTime;
            if (limitTime[i].pre) {
                text = limitTime[i].pre + ' ' + text;
            }
        } else {
            text = '活动已结束';
        }
阿达 authored
112 113 114 115 116 117 118 119
        $('.time-calculate').removeClass('hidden');
        $('.time-calculate').text(showTime);
    }
}

if (('.sale-discount-page').length > 0) {

    $('.time-calculate').each(function() {
阿达 authored
120
        var data = $(this).attr('data');
阿达 authored
121 122 123 124 125 126 127 128 129 130 131 132

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

    setInterval(setPageTime, 1000);
}