opchangeprice.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <form class="form-horizontal form-validate" action="{:U('order/opchangeprice')}" method="post" enctype="multipart/form-data">
  2. <input type='hidden' name='id' value='{$id}' />
  3. <input type='hidden' id='changeprice-orderprice' value="{php echo $item['total']-$item['shipping_fare']}"/>
  4. <input type='hidden' id='changeprice-dispatchprice' value="{$item['shipping_fare']}"/>
  5. <div class="modal-dialog" style="width:800px;">
  6. <div class="modal-content">
  7. <div class="modal-header">
  8. <button data-dismiss="modal" class="close" type="button">×</button>
  9. <h4 class="modal-title">订单改价</h4>
  10. </div>
  11. <div class="modal-body">
  12. <table class="table" style='table-layout:fixed'>
  13. <tr>
  14. <th style="width:200px;" >商品名称</th>
  15. <th >单价</th>
  16. <th>数量</th>
  17. <th style="width: 150px">小计</th>
  18. <th>加价或减价</th>
  19. <th>运费 - <a href='javascript:;' onclick="$('#changeprice_dispatchprice').val('0');mc_calc()" >免运费</a></th>
  20. </tr>
  21. <tbody>
  22. <?php foreach( $order_goods as $key $goods ){ ?>
  23. <tr>
  24. <td style='overflow:hidden;'>{$goods['name']}</td>
  25. <td class='realprice'>{php echo number_format($goods['total']/$goods['quantity'],2)}</td>
  26. <td>{$goods['quantity']}</td>
  27. <td>
  28. {$goods['total']}
  29. <?php if( $goods['total']!=$goods['oldprice']){ ?>
  30. <label class='label label-danger'>改价</label>
  31. <?php } ?>
  32. </td>
  33. <td valign="top" >
  34. <input type='number' class='form-control changeprice_orderprice' name="changegoodsprice[{$goods['order_goods_id']}]" /></td>
  35. <?php if( $key==0){ ?>
  36. <td valign="top" rowspan='{php echo count($order_goods)}' style='vertical-align: top;' >
  37. <input type='number' class='form-control' id='changeprice_dispatchprice' value="{$item['shipping_fare']}" name='changedispatchprice' />
  38. </td>
  39. <?php } ?>
  40. </tr>
  41. <?php } ?>
  42. <tr>
  43. <td colspan='2'></td>
  44. <td colspan='' style='color:green'>应收款</td>
  45. <td colspan='' style='color:green'>{php echo number_format($item['total'],2)}</td>
  46. <td colspan='2' style='color:red'>改价后价格不能小于0元</td>
  47. </tr>
  48. </tbody>
  49. </table>
  50. <div class="form-group">
  51. <div class="col-xs-12 col-sm-9 col-md-8 col-lg-8">
  52. <div class="form-control-static">
  53. <b>购买者信息</b> {$province_info['name']}{$city_info['name']}{$area_info['name']}{$item['shipping_address']} {$item['shipping_name']} {$item['shipping_tel']}<br/>
  54. <b>买家实付</b>: <span id='orderprice'>{php echo number_format( $item['total']-$item['shipping_fare'],2)}</span> + <span id='dispatchprice'>{$item['shipping_fare']}</span> <span id='changeprice'></span> = <span id='lastprice'>{$item['total']}</span><br/>
  55. <b>买家实付</b> = 原价 + 运费 + 涨价或减价<br/><br/>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="modal-footer">
  61. <button class="btn btn-primary" type="submit" onclick="return mc_check()">提交</button>
  62. <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
  63. </div>
  64. </div>
  65. </form>
  66. <script language='javascript'>
  67. var order_price = 0;
  68. var dispatch_price = 0;
  69. mc_init();
  70. function mc_init() {
  71. order_price = parseFloat($('#changeprice-orderprice').val());
  72. dispatch_price = parseFloat($('#changeprice-dispatchprice').val());
  73. $('input', $('#ajaxModal')).blur(function () {
  74. if($.isNumber($(this).val())){
  75. mc_calc();
  76. }
  77. });
  78. }
  79. function mc_calc() {
  80. var change_dispatchprice = parseFloat($('#changeprice_dispatchprice').val());
  81. if(!$.isNumber($('#changeprice_dispatchprice').val())){
  82. change_dispatchprice = dispatch_price;
  83. }
  84. var dprice = change_dispatchprice;
  85. if (dprice <= 0) {
  86. dprice = 0;
  87. }
  88. $('#dispatchprice').html(dprice.toFixed(2));
  89. var oprice = 0;
  90. $('.changeprice_orderprice').each(function () {
  91. var p = 0;
  92. if ($.trim($(this).val()) != '') {
  93. p = parseFloat($.trim($(this).val()));
  94. }
  95. oprice += p;
  96. });
  97. if(Math.abs(oprice)>0){
  98. if (oprice < 0) {
  99. $('#changeprice').css('color', 'red');
  100. $('#changeprice').html( " - " + Math.abs(oprice));
  101. } else {
  102. $('#changeprice').css('color', 'green');
  103. $('#changeprice').html( " + " + Math.abs(oprice));
  104. }
  105. }
  106. var lastprice = order_price + dprice + oprice;
  107. $('#lastprice').html( lastprice.toFixed(2) );
  108. }
  109. function mc_check(){
  110. var can = true;
  111. var lastprice = 0;
  112. $('.changeprice_orderprice').each(function () {
  113. if( $.trim( $(this).val())==''){
  114. return true;
  115. }
  116. var p = 0;
  117. if ( !$.isNumber($(this).val())) {
  118. $(this).select();
  119. tip.msgbox.err('请输入数字!');
  120. can =false;
  121. return false;
  122. }
  123. var val = parseFloat( $(this).val() );
  124. if(val<=0 && Math.abs(val) > parseFloat( $(this).parent().prev().html())) {
  125. $(this).select();
  126. tip.msgbox.err('单个商品价格不能优惠到负数!');
  127. can =false;
  128. return false;
  129. }
  130. lastprice+=val;
  131. });
  132. var op = order_price + dispatch_price+ lastprice;
  133. if( op <0){
  134. tip.msgbox.err('订单价格不能小于0元!');
  135. return false;
  136. }
  137. if(!can){
  138. return false;
  139. }
  140. return true;
  141. }
  142. </script>