team.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. $(function(){
  2. $('#sku-quit').on('click',function(){
  3. $('#sku_selector').hide();
  4. });
  5. $(".checked").each(function(){
  6. var quantity = parseInt($(this).attr('relquantity'));
  7. if(quantity < max_quantity)
  8. {
  9. max_quantity = quantity;
  10. }
  11. });
  12. $('.goods').on('click',function(){
  13. if($(this).hasClass('disableds')){
  14. return false;
  15. }
  16. $(this).parent().siblings().children('span').removeClass('checked');
  17. $(this).addClass('checked');
  18. var sku_info_length = $('.sku-info').length;
  19. var sku_infock_length = $('.goods.checked ').length;
  20. if(sku_infock_length < sku_info_length)
  21. {
  22. return false;
  23. }
  24. var relimg = $(this).attr('relimg');
  25. //#sku-price-depends ¥ 0.01
  26. var mult_option_ckids = get_option_check_ids();
  27. if(mult_option_ckids != '' && mul_op_image[mult_option_ckids] != undefined)
  28. {
  29. if(mul_op_image[mult_option_ckids] != '')
  30. $('#sku-image').attr('src',mul_op_image[mult_option_ckids]);
  31. }else {
  32. if(relimg && relimg != ''){
  33. $('#sku-image').attr('src',relimg);
  34. }
  35. }
  36. /**
  37. var mul_op_pin_price = Array();
  38. var mul_op_dan_price = Array();
  39. **/
  40. var pin_type = $('#pin_type').val();
  41. //$('#pin_type').val('dan'); 'pin'
  42. var new_price = 0;
  43. if(pin_type == 'pin')
  44. {
  45. new_price = mul_op_pin_price[mult_option_ckids];
  46. } else{
  47. new_price = mul_op_dan_price[mult_option_ckids];
  48. }
  49. //¥ 0.01 sku-price-depends
  50. $('#sku-price-depends').html('¥ '+new_price);
  51. if(mult_option_ckids != '' && mul_op_quitity[mult_option_ckids] != undefined)
  52. {
  53. max_quantity = mul_op_quitity[mult_option_ckids];
  54. }else {
  55. $(".checked").each(function(){
  56. var quantity = parseInt($(this).attr('relquantity'));
  57. if(quantity < max_quantity)
  58. {
  59. max_quantity = quantity;
  60. }
  61. });
  62. }
  63. });
  64. $("#skuNum").keyup(function(){
  65. $(this).val($(this).val().replace(/[^0-9]/g,'1'));
  66. var num = parseInt($(this).val());
  67. if(num > max_quantity) {
  68. $(this).val(max_quantity);
  69. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  70. }
  71. if($(this).val() >1){
  72. $('.sku-buy-amount-reduce span').removeClass('button-disabled');
  73. }
  74. }).bind("paste",function(){ //CTR+V事件处理 $(this).val($(this).val().replace(/[^0-9.]/g,''));
  75. }).css("ime-mode", "disabled"); //CSS设置输入法不可用
  76. $('.sku-buy-amount-increase').click(function(){
  77. $('#skuNum').val($('#skuNum').val().replace(/[^0-9]/g,'1'));
  78. var num = parseInt($('#skuNum').val())+1;
  79. if(num > max_quantity) {
  80. $('#skuNum').val(max_quantity);
  81. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  82. }else {
  83. $('#skuNum').val(num);
  84. }
  85. })
  86. $('.sku-buy-amount-reduce').click(function(){
  87. $('#skuNum').val($('#skuNum').val().replace(/[^0-9]/g,'1'));
  88. var num = parseInt($('#skuNum').val());
  89. if(num > max_quantity) {
  90. $('#skuNum').val(max_quantity);
  91. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  92. return false;
  93. }
  94. num = parseInt($('#skuNum').val()) - 1;
  95. if(num == 0){
  96. $('#skuNum').val(1);
  97. $('.sku-buy-amount-reduce span').addClass('button-disabled');
  98. }else {
  99. $('#skuNum').val(num);
  100. }
  101. })
  102. $('#sku-buy').on('click',function(){
  103. //relgoods_option_id="{$option.goods_option_id}" relgoods_option_value_id
  104. var num = parseInt($('#skuNum').val());
  105. var mult_option_ckids = get_option_check_ids();
  106. if(mult_option_ckids != '' && mul_op_quitity[mult_option_ckids] != undefined)
  107. {
  108. max_quantity = mul_op_quitity[mult_option_ckids];
  109. }
  110. if(num > max_quantity) {
  111. $('#skuNum').val(max_quantity);
  112. if(max_quantity == 0)
  113. {
  114. showTip('该规格已售罄');
  115. }else {
  116. showTip('很抱歉,该商品当前至多能购买'+max_quantity+'份');
  117. }
  118. return false;
  119. }
  120. if(has_option){
  121. var sku_info_length = $('.sku-info').length;
  122. var sku_infock_length = $('.goods.checked ').length;
  123. if(sku_infock_length < sku_info_length)
  124. {
  125. showTip('请选择商品规格');
  126. return false;
  127. }
  128. }
  129. var data ={};
  130. var optionc = [];
  131. $(".checked").each(function(){
  132. var tp_goods_option_id = $(this).attr('relgoods_option_id');
  133. var tp_relgoods_option_value_id = $(this).attr('relgoods_option_value_id');
  134. var s_gvi = tp_goods_option_id + '_' +tp_relgoods_option_value_id;
  135. optionc.push(s_gvi)
  136. });
  137. data.goods_id = $('#goods_id').val();
  138. data.pin_id = $('#pin_id').val();
  139. data.quantity = $('#skuNum').val();
  140. data.pin_type = $('#pin_type').val();
  141. data.optionc = optionc;
  142. sub_cart(data);
  143. })
  144. $('#tuan_more_btn').click(function(){
  145. $('#pin_type').val('pin');
  146. if(has_option){
  147. var sku_info_length = $('.sku-info').length;
  148. var sku_infock_length = $('.goods.checked ').length;
  149. if(sku_infock_length != undefined && sku_infock_length == sku_info_length)
  150. {
  151. var mult_option_ckids = get_option_check_ids();
  152. var pin_type = $('#pin_type').val();
  153. var new_price = 0;
  154. if(pin_type == 'pin')
  155. {
  156. new_price = mul_op_pin_price[mult_option_ckids];
  157. } else{
  158. new_price = mul_op_dan_price[mult_option_ckids];
  159. }
  160. $('#sku-price-depends').html('¥ '+new_price);
  161. }else{
  162. $('#sku-price-depends').html( $('#tuan_more_price').html() );
  163. }
  164. $('#sku_selector').show();
  165. } else{
  166. var data = {};
  167. data.goods_id = $('#goods_id').val();
  168. data.pin_id = $('#pin_id').val();
  169. data.option = [];
  170. data.quantity = 1;
  171. data.pin_type = $('#pin_type').val();
  172. sub_cart(data);
  173. }
  174. })
  175. $('#tuan_one_btn').click(function(){
  176. $('#pin_type').val('dan');
  177. var type = $('#type').val();
  178. if(type == 'lottery')
  179. {
  180. showTip('抽奖活动暂不支持单独购买');
  181. return false;
  182. }
  183. if(type == 'zeyuan')
  184. {
  185. showTip('免费试用活动暂不支持单独购买');
  186. return false;
  187. }
  188. if(has_option){
  189. var sku_info_length = $('.sku-info').length;
  190. var sku_infock_length = $('.goods.checked ').length;
  191. if(sku_infock_length != undefined && sku_infock_length == sku_info_length)
  192. {
  193. var mult_option_ckids = get_option_check_ids();
  194. var pin_type = $('#pin_type').val();
  195. var new_price = 0;
  196. if(pin_type == 'pin')
  197. {
  198. new_price = mul_op_pin_price[mult_option_ckids];
  199. } else{
  200. new_price = mul_op_dan_price[mult_option_ckids];
  201. }
  202. $('#sku-price-depends').html('¥ '+new_price);
  203. } else{
  204. $('#sku-price-depends').html( $('#tuan_one_price').html() );
  205. }
  206. $('#sku_selector').show();
  207. } else{
  208. var data = {};
  209. data.goods_id = $('#goods_id').val();
  210. data.pin_id = 0;
  211. data.option = [];
  212. data.quantity = 1;
  213. data.pin_type = $('#pin_type').val();
  214. sub_cart(data);
  215. }
  216. })
  217. })
  218. function get_option_check_ids()
  219. {
  220. var ck_arr = [];
  221. $(".checked").each(function(){
  222. var option_value_id = parseInt($(this).attr('option_value_id'));
  223. ck_arr.push(option_value_id);
  224. });
  225. if(ck_arr.length >0)
  226. {
  227. return ck_arr.join('_');
  228. }else
  229. return '';
  230. }
  231. /**
  232. *
  233. * 购物车提交
  234. */
  235. function sub_cart(datobj)
  236. {
  237. //name="option[<?php echo $option['goods_option_id']; ?>]"
  238. //value="<?php echo $option_value['goods_option_value_id']; ?>"
  239. //goods_id,quantity,option
  240. $.ajax({
  241. url: add_cart_url,
  242. type: 'post',
  243. data: datobj,
  244. dataType: 'json',
  245. success: function(json) {
  246. //{success: "成功加入购物车!!", total: 1}
  247. if (json['error']) {
  248. if (json['error']['option']) {
  249. var error_tip_html = '';
  250. for (i in json['error']['option']) {
  251. error_tip_html += json['error']['option'][i];
  252. }
  253. }
  254. showTip(error_tip_html);
  255. }
  256. if (json['success']) {
  257. location.href = add_cart_success_url;
  258. return false;
  259. }else if(json['error']['quantity']){
  260. showTip(json['error']['quantity']);
  261. }
  262. }
  263. });
  264. }