chose-panel.js
2.97 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* 购物车选择尺寸、颜色和数量面板
* 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/21
*/
var $ = require('jquery');
// Handlebars = require('yoho.handlebars');
// var $page = $('.yoho-page');
var $num;
// var tpl;
//读取partials
// $.ajax({
// type: 'GET',
// url: '/shoppingCart/tpl',
// success: function(data) {
// tpl = Handlebars.compile(data);
// }
// });
//显示
// function show(data) {
// // var html = tpl(data);
// $('.chose-panel').show();
// // $page.append(html);
// $('.chose-panel')
// $num = $('#good-num');
// }
function show() {
$('.chose-panel').show();
$('body').css('overflow', 'hidden');
$num = $('#good-num');
}
//移除当前Panel
function remove() {
$('.chose-panel').hide();
$('body').css('overflow', 'auto');
}
$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
var $cur = $(e.target);
if ($cur.closest('.main').length > 0) {
return;
}
//点击蒙版消失
remove();
}).on('touchstart', '#chose-btn-sure', function() {
//确定
}).on('touchstart', '.block', function(e) {
//尺寸颜色点选
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
numArray,
index;
if ($this.hasClass('chosed')) {
$this.parent().find('.block').removeClass('chosed');
$that.find('.num .left-num').html('');
} else if ($this.hasClass('disable')) {
$this.css('background-color', '#000');
return;
} else if (!$this.hasClass('chosed')) {
$this.siblings('.chosed').removeClass('chosed');
$this.addClass('chosed');
index = $this.index();
//根据颜色切换图片
if ($this.closest('.block-list').hasClass('color-list')) {
$('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
}
//剩余的商品数
if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) {
numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/');
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
} else {
$that.find('.num .left-num').html('');
}
//点击切换
}
}).on('touchstart', '.btn-minus', function() {
var num = +$num.val();
//若颜色和尺码没有被同时选中,则不能点击
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
if (num === 0) {
return;
}
$num.val(num - 1);
}).on('touchstart', '.btn-plus', function() {
var num = +$num.val();
//若颜色和尺码没有被同时选中,则不能点击
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
//TODO:库存数验证
$num.val(num + 1);
});
exports.show = show;