chose-panel.js
1.45 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
/**
* 购物车选择尺寸、颜色和数量面板
* 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/21
*/
var $ = require('yoho.zepto');
var 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);
$page.append(html);
$num = $('#good-num');
}
//移除当前Panel
function remove() {
$('.chose-panel').remove();
}
$('.yoho-page').delegate('.chose-panel', 'tap', function(e) {
var $cur = $(e.target);
if ($cur.closest('.main').length > 0) {
return;
}
//点击蒙版消失
remove();
}).delegate('#chose-btn-sure', 'tap', function() {
//确定
}).delegate('.block', 'tap', function() {
//尺寸颜色点选
var $this = $(this);
if ($this.hasClass('.chosed') || $this.hasClass('disable')) {
return;
}
$this.siblings('.chosed').removeClass('chosed');
$this.addClass('chosed');
}).delegate('.btn-minus', 'tap', function() {
var num = +$num.val();
if (num === 1) {
return;
}
$num.val(num - 1);
}).delegate('.btn-plus', 'tap', function() {
var num = +$num.val();
//TODO:库存数验证
$num.val(num + 1);
});
exports.show = show;