addOrder.blade.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. @extends('user.layouts')
  2. @section('css')
  3. <link href="/assets/pages/css/invoice-2.min.css" rel="stylesheet" type="text/css" />
  4. @endsection
  5. @section('title', trans('home.panel'))
  6. @section('content')
  7. <!-- BEGIN CONTENT BODY -->
  8. <div class="page-content" style="padding-top:0;">
  9. <!-- BEGIN PAGE BASE CONTENT -->
  10. <div class="invoice-content-2 bordered">
  11. <div class="row invoice-body">
  12. <div class="col-xs-12 table-responsive">
  13. <table class="table table-hover">
  14. <thead>
  15. <tr>
  16. <th class="invoice-title"> {{trans('home.service_name')}} </th>
  17. <th class="invoice-title text-center"> {{trans('home.service_price')}} </th>
  18. <th class="invoice-title text-center"> {{trans('home.service_quantity')}} </th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <tr>
  23. <td style="padding: 10px;">
  24. <h2>{{$goods->name}}</h2>
  25. <p> {{trans('home.service_traffic')}} {{$goods->traffic}}({{trans('home.service_days')}} {{$goods->days}}{{trans('home.day')}}) </p>
  26. </td>
  27. <td class="text-center"> ¥{{$goods->price}} </td>
  28. <td class="text-center"> x 1 </td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. </div>
  34. <div class="row invoice-subtotal">
  35. <div class="col-xs-3">
  36. <h2 class="invoice-title"> {{trans('home.service_total_price')}} </h2>
  37. <p class="invoice-desc"> ¥{{$goods->price}} </p>
  38. </div>
  39. <div class="col-xs-3">
  40. <h2 class="invoice-title"> {{trans('home.coupon')}} </h2>
  41. <p class="invoice-desc">
  42. <div class="input-group">
  43. <input class="form-control" type="text" name="coupon_sn" id="coupon_sn" placeholder="{{trans('home.coupon')}}" />
  44. <span class="input-group-btn">
  45. <button class="btn btn-default" type="button" onclick="redeemCoupon()"><i class="fa fa-refresh"></i> {{trans('home.redeem_coupon')}} </button>
  46. </span>
  47. </div>
  48. </p>
  49. </div>
  50. <div class="col-xs-6">
  51. <h2 class="invoice-title"> {{trans('home.service_settlement_price')}} </h2>
  52. <p class="invoice-desc grand-total"> ¥{{$goods->price}} </p>
  53. </div>
  54. </div>
  55. <div class="row">
  56. <div class="col-xs-12">
  57. <a class="btn btn-lg green-haze hidden-print uppercase print-btn" onclick="addOrder()"> {{trans('home.service_pay_button')}} </a>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- END PAGE BASE CONTENT -->
  62. </div>
  63. <!-- END CONTENT BODY -->
  64. @endsection
  65. @section('script')
  66. <script src="/js/layer/layer.js" type="text/javascript"></script>
  67. <script type="text/javascript">
  68. // 校验优惠券是否可用
  69. function redeemCoupon() {
  70. var coupon_sn = $('#coupon_sn').val();
  71. var goods_price = '{{$goods->price}}';
  72. $.ajax({
  73. type: "POST",
  74. url: "{{url('user/redeemCoupon')}}",
  75. async: false,
  76. data: {_token:'{{csrf_token()}}', coupon_sn:coupon_sn},
  77. dataType: 'json',
  78. success: function (ret) {
  79. console.log(ret);
  80. $("#coupon_sn").parent().removeClass("has-error");
  81. $("#coupon_sn").parent().removeClass("has-success");
  82. $(".input-group-addon").remove();
  83. if (ret.status == 'success') {
  84. $("#coupon_sn").parent().addClass('has-success');
  85. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-check fa-fw"></i></span>');
  86. // 根据类型计算折扣后的总金额
  87. var total_price = 0;
  88. if (ret.data.type == '2') {
  89. total_price = goods_price * ret.data.discount;
  90. } else {
  91. total_price = goods_price - ret.data.amount;
  92. }
  93. $(".grand-total").text("¥" + total_price);
  94. } else {
  95. $("#coupon_sn").parent().addClass('has-error');
  96. $("#coupon_sn").parent().remove('.input-group-addon');
  97. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-remove fa-fw"></i></span>');
  98. }
  99. }
  100. });
  101. }
  102. // 添加订单
  103. function addOrder() {
  104. var goods_id = '{{$goods->id}}';
  105. var coupon_sn = $('#coupon_sn').val();
  106. $.ajax({
  107. type: "POST",
  108. url: "{{url('user/addOrder')}}",
  109. async: false,
  110. data: {_token:'{{csrf_token()}}', goods_id:goods_id, coupon_sn:coupon_sn},
  111. dataType: 'json',
  112. success: function (ret) {
  113. layer.msg(ret.message, {time:1300}, function() {
  114. if (ret.status == 'success') {
  115. window.location.href = '{{url('user/orderList')}}';
  116. }
  117. });
  118. }
  119. });
  120. }
  121. </script>
  122. @endsection