cart.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {include file="../application/h5/view/wx_book_dinner/header.html"}
  2. <div class="weui_cells weui_cells_checkbox">
  3. {foreach $data as $key => $value}
  4. <label class="weui_cell weui_check_label" for="s{$key}" id='cartId'>
  5. <div class="weui_cell_hd">
  6. <input type="checkbox" class="weui_check" name="checkbox" id="s{$key}" checked="checked">
  7. <i class="weui_icon_checked"></i>
  8. </div>
  9. <div class="weui_cell_bd weui_cell_primary">
  10. <p>{$value.name}</p>
  11. </div>
  12. <div style="font-size: 0px;" class="weui_cell_ft">
  13. <a href="javascript:;" class="weui-number weui-number-sub needsclick">-</a>
  14. <input pattern="[0-9]*" class="weui-number-input" style="width: 50px;" data-id="{$value.cart_id}" value="{$value.count}" data-min="0" data-max="100" data-step="1" onchange="changevaule(this);">
  15. <a href="javascript:;" class="weui-number weui-number-plus needsclick">+</a>
  16. </div>
  17. <div class="weui_cell_ft" style="display: none;"> 0 </div>
  18. </label>
  19. {/foreach}
  20. </div>
  21. {if $cartCount>0}
  22. <div class="weui-flex weui-list-btm" style="margin-bottom: 60px;">
  23. <div class="weui-flex-item" id="submitorder"><a href="javascript:count_order();" class="weui_btn weui_btn_warn">去结算</a></div>
  24. <!-- <div class="weui-flex-item"><a href="/WXBookDinner/BuildOrderAndPay" class="weui_btn weui_btn_warn">去结算新</a></div> -->
  25. </div>
  26. {else}
  27. <div class="weui_msg" style="display: block; opacity: 1;">
  28. <div class="weui_icon_area"><i class="weui_icon_msg weui_icon_info"></i></div>
  29. <div class="weui_text_area">
  30. <h2 class="weui_msg_title"></h2>
  31. <p class="weui_msg_desc">购物车里什么也没有</p>
  32. </div>
  33. <div class="weui_opr_area">
  34. <p class="weui_btn_area">
  35. <a href="{:url('index')}" class="weui_btn bg-blue-b">现在去挑选商品</a>
  36. </p>
  37. </div>
  38. <div class="weui_extra_area">
  39. </div>
  40. </div>
  41. {/if}
  42. <script type="text/javascript">
  43. function upDownOperation(element)
  44. {
  45. var _input = element.parent().find('input'),
  46. _value = _input.val(),
  47. _step = _input.attr('data-step') || 1;
  48. //检测当前操作的元素是否有disabled,有则去除
  49. element.hasClass('disabled') && element.removeClass('disabled');
  50. //检测当前操作的元素是否是操作的添加按钮(.input-num-up)‘是’ 则为加操作,‘否’ 则为减操作
  51. if ( element.hasClass('weui-number-plus') )
  52. {
  53. var _new_value = parseInt( parseFloat(_value) + parseFloat(_step) ),
  54. _max = _input.attr('data-max') || false,
  55. _down = element.parent().find('.weui-number-sub');
  56. //若执行‘加’操作且‘减’按钮存在class='disabled'的话,则移除‘减’操作按钮的class 'disabled'
  57. _down.hasClass('disabled') && _down.removeClass('disabled');
  58. if (_max && _new_value >= _max) {
  59. _new_value = _max;
  60. element.addClass('disabled');
  61. }
  62. _input.val( _new_value );
  63. changevaule(_input);
  64. } else {
  65. var _new_value = parseInt( parseFloat(_value) - parseFloat(_step) ),
  66. _min = _input.attr('data-min') || false,
  67. _up = element.parent().find('.weui-number-plus');
  68. //若执行‘减’操作且‘加’按钮存在class='disabled'的话,则移除‘加’操作按钮的class 'disabled'
  69. _up.hasClass('disabled') && _up.removeClass('disabled');
  70. if (_min && _new_value <= _min) {
  71. _new_value = _min;
  72. element.addClass('disabled');
  73. }
  74. _input.val( _new_value );
  75. changevaule(_input);
  76. //如果减到0了,就移除这个
  77. if(_new_value<=0){
  78. element.closest('#cartId').remove();
  79. // alert(JSON.stringify(it));
  80. // it.parent().remove(it);
  81. }
  82. }
  83. }
  84. $('.weui-number-plus').click(function(e){
  85. console.log(111);
  86. cancelBubble($(this));
  87. upDownOperation( $(this) );
  88. return false;
  89. });
  90. $('.weui-number-sub').click(function(e){
  91. cancelBubble($(this));
  92. upDownOperation( $(this) );
  93. return false;
  94. });
  95. function cancelBubble(e) {
  96. var evt = e ? e : window.event;
  97. if (evt.stopPropagation) { //W3C
  98. evt.stopPropagation();
  99. }else { //IE
  100. evt.cancelBubble = true;
  101. }
  102. }
  103. </script>
  104. <script type="text/javascript">
  105. function changevaule(self) {
  106. var _new_value = $(self).val();
  107. var DinnerCartId = $(self).attr('data-id');
  108. get_data('updateCart?id='+DinnerCartId+'&num='+_new_value,function(result){
  109. if(result.code==0){
  110. $('#badgecart').html(result.data.count);
  111. if(result.data.count>0){
  112. $('#badgecart').show();
  113. $('#submitorder').show();
  114. }else{
  115. $('#submitorder').hide();
  116. $('#badgecart').hide();
  117. window.location.href = 'cart';
  118. }
  119. }else{
  120. $.alert(result.message);
  121. }
  122. });
  123. }
  124. function count_order(){
  125. var Ids = '';
  126. $('.weui_cell').each(function(index, item){
  127. if($(item).find('.weui_check').prop("checked")){
  128. var DinnerCartId = $(item).find('.weui-number-input').attr('data-id');
  129. if(index>0){
  130. Ids +=',';
  131. }
  132. Ids +=DinnerCartId;
  133. }
  134. });
  135. if(Ids==''){
  136. $.alert('没有选择订单');
  137. }
  138. var url = 'submitorder?orders='+Ids;
  139. window.location.href = url;
  140. }
  141. </script>