Authored by Lynnic

购物车逻辑修改

@@ -12,7 +12,11 @@ var $ = require('jquery'); @@ -12,7 +12,11 @@ var $ = require('jquery');
12 // var $page = $('.yoho-page'); 12 // var $page = $('.yoho-page');
13 13
14 var $num, 14 var $num,
15 - $chosed; 15 + $chosed,
  16 + re = /\d+/,
  17 + leftNum;
  18 +
  19 +// confirm;
16 20
17 // var tpl; 21 // var tpl;
18 22
@@ -37,6 +41,7 @@ var $num, @@ -37,6 +41,7 @@ var $num,
37 41
38 function show() { 42 function show() {
39 $('.chose-panel').show(); 43 $('.chose-panel').show();
  44 +
40 $('body').css('overflow', 'hidden'); 45 $('body').css('overflow', 'hidden');
41 $num = $('#good-num'); 46 $num = $('#good-num');
42 } 47 }
@@ -58,10 +63,44 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -58,10 +63,44 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
58 remove(); 63 remove();
59 }).on('touchstart', '#chose-btn-sure', function() { 64 }).on('touchstart', '#chose-btn-sure', function() {
60 65
61 - //确定  
62 -}).on('touchstart', '.block', function(e) { 66 + // var
  67 + // // goodId,
  68 + // // skuId,
  69 + // skcId = $('.color-list li.chosed').data('skcid'),
  70 + // colorIndex = $('.color-list li.chosed').index(),
  71 + // skuArray = $('.size-list').data('skustr').split('/');
  72 +
  73 + // //确定
  74 + // $chosed = $('.block-list>ul>li.chosed');
  75 +
  76 + // if (2 === $chosed.length && 2 !== $chosed.closest('.zero-stock').length) {
  77 +
  78 + // if (confirm) {
  79 + // return false;
  80 + // }
  81 +
  82 + // confirm = true;
  83 + // loading.showLoadingMask();
  84 + // $.ajax({
  85 + // method: 'POST',
  86 + // url: '/product/detail/xxxx',
  87 + // data: {
  88 + // product_id: productId,
  89 + // content: content
  90 + // }
  91 + // }).done(function(res) {
  92 + // if (res.code === 200) {
  93 + // loading.hideLoadingMask();
  94 + // confirm = false;
  95 + // remove();
  96 + // }
  97 + // }).fail(function() {
  98 + // tip.show('网络出了点问题~');
  99 + // confirm = false;
  100 + // });
  101 + // }
63 102
64 - //尺寸颜色点选 103 +}).on('touchstart', '.block', function(e) {
65 var $this = $(this), 104 var $this = $(this),
66 $that = $(e.target).closest('.chose-items'), 105 $that = $(e.target).closest('.chose-items'),
67 numArray, 106 numArray,
@@ -104,6 +143,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -104,6 +143,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
104 } 143 }
105 } 144 }
106 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) { 145 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
  146 + $('#chose-btn-sure').css('background-color', '#eb0313');
  147 + $('#chose-btn-sure').html('确定');
  148 +
107 $siblingBlock.find('ul>li').each(function() { 149 $siblingBlock.find('ul>li').each(function() {
108 $(this).removeClass('zero-stock'); 150 $(this).removeClass('zero-stock');
109 if (0 === $(this).data('num') - 0) { 151 if (0 === $(this).data('num') - 0) {
@@ -123,19 +165,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -123,19 +165,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
123 if (2 === $chosed.closest('.zero-stock').length) { 165 if (2 === $chosed.closest('.zero-stock').length) {
124 $('#chose-btn-sure').css('background-color', '#c0c0c0'); 166 $('#chose-btn-sure').css('background-color', '#c0c0c0');
125 $('#chose-btn-sure').html('已售罄'); 167 $('#chose-btn-sure').html('已售罄');
  168 + } else {
  169 + $('#chose-btn-sure').css('background-color', '#eb0313');
  170 + $('#chose-btn-sure').html('确定');
126 } 171 }
127 } 172 }
128 173
129 }).on('touchstart', '.btn-minus', function() { 174 }).on('touchstart', '.btn-minus', function() {
130 var num = +$num.val(), 175 var num = +$num.val(),
131 - $chosed = $('.block-list>ul>li.chosed'); 176 + $chosed = $('.block-list>ul>li.chosed'),
  177 + leftNum = re.exec($('.num .left-num').html());
132 178
133 //若颜色和尺码没有被同时选中,则不能点击 179 //若颜色和尺码没有被同时选中,则不能点击
134 if ($chosed.length < 2) { 180 if ($chosed.length < 2) {
135 return; 181 return;
136 } 182 }
137 183
138 - if (num === 0) { 184 + if (num === 1 || 0 === leftNum - 0) {
139 return; 185 return;
140 } 186 }
141 187
@@ -147,6 +193,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -147,6 +193,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
147 if ($('.block-list>ul>li.chosed').length < 2) { 193 if ($('.block-list>ul>li.chosed').length < 2) {
148 return; 194 return;
149 } 195 }
  196 + leftNum = re.exec($('.num .left-num').html());
  197 + if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
  198 + return;
  199 + }
150 200
151 //TODO:库存数验证 201 //TODO:库存数验证
152 $num.val(num + 1); 202 $num.val(num + 1);
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="chose-panel"> 2 <div class="chose-panel">
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 {{#thumbs}} 6 {{#thumbs}}
7 {{#if @first}} 7 {{#if @first}}
8 <img class="thumb" src={{img}}> 8 <img class="thumb" src={{img}}>
@@ -25,17 +25,18 @@ @@ -25,17 +25,18 @@
25 <span>颜色</span> 25 <span>颜色</span>
26 <ul class="clearfix" data-type="color"> 26 <ul class="clearfix" data-type="color">
27 {{# colors}} 27 {{# colors}}
28 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}"> 28 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-id="{{id}}" data-numstr="{{sizeNumStr}}" data-skcid="{{skcId}}">
29 {{name}} 29 {{name}}
30 </li> 30 </li>
31 {{/ colors}} 31 {{/ colors}}
32 </ul> 32 </ul>
33 </div> 33 </div>
34 <div class="size-list block-list"> 34 <div class="size-list block-list">
35 - <span>尺码</span> 35 + <span>尺码</span>
  36 +
36 <ul class="clearfix" data-type="size" > 37 <ul class="clearfix" data-type="size" >
37 {{# sizes}} 38 {{# sizes}}
38 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodId}}"> 39 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">
39 {{name}} 40 {{name}}
40 </li> 41 </li>
41 {{/ sizes}} 42 {{/ sizes}}
@@ -47,7 +48,7 @@ @@ -47,7 +48,7 @@
47 <a class="btn btn-minus" href="javascript:void(0);"> 48 <a class="btn btn-minus" href="javascript:void(0);">
48 <span class="iconfont">&#xe625;</span> 49 <span class="iconfont">&#xe625;</span>
49 </a> 50 </a>
50 - <input id="good-num" class="good-num" type="text" value={{num}}> 51 + <input id="good-num" class="good-num" type="text" value="1">
51 <a class="btn btn-plus" href="javascript:void(0);"> 52 <a class="btn btn-plus" href="javascript:void(0);">
52 <span class="iconfont">&#xe624;</span> 53 <span class="iconfont">&#xe624;</span>
53 </a> 54 </a>
@@ -57,7 +58,7 @@ @@ -57,7 +58,7 @@
57 </div> 58 </div>
58 </div> 59 </div>
59 <div class="btn-wrap"> 60 <div class="btn-wrap">
60 - <button id="chose-btn-sure" class="btn btn-sure">加入购物车</button> 61 + <button id="chose-btn-sure" class="btn btn-sure">确定</button>
61 </div> 62 </div>
62 </div> 63 </div>
63 </div> 64 </div>