购物车弹出框 --code reviewed by LZF
Showing
4 changed files
with
69 additions
and
16 deletions
@@ -1261,7 +1261,7 @@ | @@ -1261,7 +1261,7 @@ | ||
1261 | chosed: true, | 1261 | chosed: true, |
1262 | name: '黄色', | 1262 | name: '黄色', |
1263 | colorNum:10, | 1263 | colorNum:10, |
1264 | - shortUrl:'', | 1264 | + sizeNumStr:'10/20/30' //对应的商品尺码数目,用斜杠分割 |
1265 | 1265 | ||
1266 | }, | 1266 | }, |
1267 | ... | 1267 | ... |
@@ -1271,7 +1271,8 @@ | @@ -1271,7 +1271,8 @@ | ||
1271 | id: 2, | 1271 | id: 2, |
1272 | chosed: true, | 1272 | chosed: true, |
1273 | name: 'X', | 1273 | name: 'X', |
1274 | - sizeNum: 2 | 1274 | + sizeNum: 2, |
1275 | + colorNumStr:'10/20/30' //对应的商品颜色数目用斜杠分割 | ||
1275 | }, | 1276 | }, |
1276 | ... | 1277 | ... |
1277 | ], | 1278 | ], |
@@ -58,21 +58,51 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -58,21 +58,51 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
58 | }).on('touchstart', '#chose-btn-sure', function() { | 58 | }).on('touchstart', '#chose-btn-sure', function() { |
59 | 59 | ||
60 | //确定 | 60 | //确定 |
61 | -}).on('touchstart', '.block', function() { | 61 | +}).on('touchstart', '.block', function(e) { |
62 | 62 | ||
63 | //尺寸颜色点选 | 63 | //尺寸颜色点选 |
64 | - var $this = $(this); | ||
65 | - | ||
66 | - if ($this.hasClass('.chosed') || $this.hasClass('disable')) { | 64 | + var $this = $(this), |
65 | + $that = $(e.target).closest('.chose-items'), | ||
66 | + numArray, | ||
67 | + index; | ||
68 | + | ||
69 | + if ($this.hasClass('chosed')) { | ||
70 | + $this.parent().find('.block').removeClass('chosed'); | ||
71 | + $that.find('.num .left-num').html(''); | ||
72 | + } else if ($this.hasClass('disable')) { | ||
73 | + $this.css('background-color', '#000'); | ||
67 | return; | 74 | return; |
75 | + } else if (!$this.hasClass('chosed')) { | ||
76 | + $this.siblings('.chosed').removeClass('chosed'); | ||
77 | + $this.addClass('chosed'); | ||
78 | + index = $this.index(); | ||
79 | + | ||
80 | + | ||
81 | + //根据颜色切换图片 | ||
82 | + if ($this.closest('.block-list').hasClass('color-list')) { | ||
83 | + $('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide'); | ||
84 | + } | ||
85 | + | ||
86 | + //剩余的商品数 | ||
87 | + if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) { | ||
88 | + numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/'); | ||
89 | + $that.find('.num .left-num').html('剩余' + numArray[index] + '件'); | ||
90 | + } else { | ||
91 | + $that.find('.num .left-num').html(''); | ||
92 | + } | ||
93 | + | ||
94 | + //点击切换 | ||
68 | } | 95 | } |
69 | 96 | ||
70 | - $this.siblings('.chosed').removeClass('chosed'); | ||
71 | - $this.addClass('chosed'); | ||
72 | }).on('touchstart', '.btn-minus', function() { | 97 | }).on('touchstart', '.btn-minus', function() { |
73 | var num = +$num.val(); | 98 | var num = +$num.val(); |
74 | 99 | ||
75 | - if (num === 1) { | 100 | + //若颜色和尺码没有被同时选中,则不能点击 |
101 | + if ($('.block-list>ul>li.chosed').length < 2) { | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + if (num === 0) { | ||
76 | return; | 106 | return; |
77 | } | 107 | } |
78 | 108 | ||
@@ -80,6 +110,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -80,6 +110,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
80 | }).on('touchstart', '.btn-plus', function() { | 110 | }).on('touchstart', '.btn-plus', function() { |
81 | var num = +$num.val(); | 111 | var num = +$num.val(); |
82 | 112 | ||
113 | + //若颜色和尺码没有被同时选中,则不能点击 | ||
114 | + if ($('.block-list>ul>li.chosed').length < 2) { | ||
115 | + return; | ||
116 | + } | ||
117 | + | ||
83 | //TODO:库存数验证 | 118 | //TODO:库存数验证 |
84 | $num.val(num + 1); | 119 | $num.val(num + 1); |
85 | }); | 120 | }); |
@@ -79,6 +79,11 @@ | @@ -79,6 +79,11 @@ | ||
79 | left: 0; | 79 | left: 0; |
80 | top: 20rem / $pxConvertRem; | 80 | top: 20rem / $pxConvertRem; |
81 | } | 81 | } |
82 | + >span.left-num{ | ||
83 | + position: absolute; | ||
84 | + left: pxToRem(380px); | ||
85 | + top: 20rem / $pxConvertRem; | ||
86 | + } | ||
82 | } | 87 | } |
83 | 88 | ||
84 | .block { | 89 | .block { |
@@ -99,6 +104,11 @@ | @@ -99,6 +104,11 @@ | ||
99 | background-position: bottom right; | 104 | background-position: bottom right; |
100 | color: #e10; | 105 | color: #e10; |
101 | } | 106 | } |
107 | + | ||
108 | + &.disable { | ||
109 | + color: #e0e0e0; | ||
110 | + border-color: #e0e0e0; | ||
111 | + } | ||
102 | } | 112 | } |
103 | 113 | ||
104 | .num { | 114 | .num { |
@@ -3,7 +3,13 @@ | @@ -3,7 +3,13 @@ | ||
3 | <div class="main"> | 3 | <div class="main"> |
4 | <div class="infos"> | 4 | <div class="infos"> |
5 | <div class="basic-info"> | 5 | <div class="basic-info"> |
6 | - <img class="thumb" src={{thumb}}> | 6 | + {{#thumbs}} |
7 | + {{#if @first}} | ||
8 | + <img class="thumb" src={{img}}> | ||
9 | + {{else}} | ||
10 | + <img class="thumb hide" src={{img}}> | ||
11 | + {{/if}} | ||
12 | + {{/thumbs}} | ||
7 | <div class="text-info"> | 13 | <div class="text-info"> |
8 | <p class="name">{{name}}</p> | 14 | <p class="name">{{name}}</p> |
9 | <p class="price"> | 15 | <p class="price"> |
@@ -15,21 +21,21 @@ | @@ -15,21 +21,21 @@ | ||
15 | </div> | 21 | </div> |
16 | </div> | 22 | </div> |
17 | <div class="chose-items"> | 23 | <div class="chose-items"> |
18 | - <div class="color-list"> | 24 | + <div class="color-list block-list"> |
19 | <span>颜色</span> | 25 | <span>颜色</span> |
20 | <ul class="clearfix" data-type="color"> | 26 | <ul class="clearfix" data-type="color"> |
21 | {{# colors}} | 27 | {{# colors}} |
22 | - <li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}> | 28 | + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{sizeNumStr}}"> |
23 | {{name}} | 29 | {{name}} |
24 | </li> | 30 | </li> |
25 | {{/ colors}} | 31 | {{/ colors}} |
26 | </ul> | 32 | </ul> |
27 | </div> | 33 | </div> |
28 | - <div class="size-list"> | 34 | + <div class="size-list block-list"> |
29 | <span>尺码</span> | 35 | <span>尺码</span> |
30 | - <ul class="clearfix {{#if @first}}{{^}}hide{{/if}}" data-type="size" > | 36 | + <ul class="clearfix" data-type="size" > |
31 | {{# sizes}} | 37 | {{# sizes}} |
32 | - <li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}> | 38 | + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{colorNumStr}}"> |
33 | {{name}} | 39 | {{name}} |
34 | </li> | 40 | </li> |
35 | {{/ sizes}} | 41 | {{/ sizes}} |
@@ -44,8 +50,9 @@ | @@ -44,8 +50,9 @@ | ||
44 | <input id="good-num" class="good-num" type="text" value={{num}}> | 50 | <input id="good-num" class="good-num" type="text" value={{num}}> |
45 | <a class="btn btn-plus" href="javascript:void(0);"> | 51 | <a class="btn btn-plus" href="javascript:void(0);"> |
46 | <span class="iconfont"></span> | 52 | <span class="iconfont"></span> |
47 | - </a> | 53 | + </a> |
48 | </div> | 54 | </div> |
55 | + <span class="left-num"></span> | ||
49 | </div> | 56 | </div> |
50 | </div> | 57 | </div> |
51 | </div> | 58 | </div> |
-
Please register or login to post a comment