shop.page.js
2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
42
43
44
45
46
47
48
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
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
var lazyload = require('yoho-jquery-lazyload');
var Dialog = require('../plugins/dialog').Dialog;
var tplFn = require('../../tpl/product/shop-goods.hbs');
require('../common/header');
require('./list/favorite');
lazyload();
$(function() {
var shopId = $('.yoho-shop-index').data('id');
var $order = $('.yoho-shop-index .order-page');
var $nextPage = $('.page.page-next', $order);
var $prePage = $('.page.page-pre', $order);
var total = parseInt($('.total-page', $order).text(), 10);
var page = 1;
var orderBy;
var infoDaialog = new Dialog({
className: 'brand-info-dialog',
content: $('.brand-info-wrapper').html(),
keep: true
});
function refreshProducts(data) {
$('.cur-page', $order).text(page);
if (page === 1) {
$($prePage).addClass('disable');
$($nextPage).removeClass('disable');
} else if (page === total) {
$($nextPage).addClass('disable');
$($prePage).removeClass('disable');
} else {
$($nextPage).removeClass('disable');
$($prePage).removeClass('disable');
}
$('.yoho-shop-index .all-product-warp .goods-wrap').html(tplFn(data));
}
$($nextPage).click(function() {
if (!$(this).hasClass('disable') && page < total) {
page += 1;
$.get('/product/shop/query/all', {
page: page,
shopId: shopId
}, function(data) {
refreshProducts(data);
});
}
});
$($prePage).click(function() {
if (!$(this).hasClass('disable') && page > 1) {
page -= 1;
$.get('/product/shop/query/all', {
page: page,
shopId: shopId
}, function(data) {
refreshProducts(data);
});
}
});
$('.order-area .order').click(function() {
var order = $(this).data('order');
var target = $(this).data('target');
var orders = order.split(',');
var newOrder = '';
if (orderBy === orders[0]) {
newOrder = orders[1] || '';
} else {
newOrder = orders[0];
}
$('.order-area .order').removeClass('selected');
$(this).addClass('selected');
$('.' + target).find('.iconfont').each(function() {
if ($(this).hasClass(newOrder)) {
$(this).addClass('selected');
} else {
$(this).removeClass('selected');
}
});
orderBy = newOrder;
page = 1;
$.get('/product/shop/query/all', {
page: page,
shopId: shopId,
order: newOrder
}, function(data) {
refreshProducts(data);
});
});
$('#brand-info').click(function() {
infoDaialog.show();
$('.brand-info').addClass('nano');
$('.brand-info').nanoScroller();
});
});