index.blade.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. @extends('admin.layouts')
  2. @section('css')
  3. <link href="/assets/global/vendor/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
  4. @endsection
  5. @section('content')
  6. <div class="page-content container-fluid">
  7. <div class="panel">
  8. <div class="panel-heading">
  9. <h1 class="panel-title">卡券列表</h1>
  10. @canany(['admin.coupon.export', 'admin.coupon.create'])
  11. <div class="panel-actions btn-group">
  12. @can('admin.coupon.export')
  13. <button class="btn btn-info" onclick="exportCoupon()"><i class="icon wb-code"></i>批量导出</button>
  14. @endcan
  15. @can('admin.coupon.create')
  16. <a href="{{route('admin.coupon.create')}}" class="btn btn-primary"><i class="icon wb-plus"></i>生成</a>
  17. @endcan
  18. </div>
  19. @endcanany
  20. </div>
  21. <div class="panel-body">
  22. <div class="form-row">
  23. <div class="form-group col-lg-3 col-sm-4">
  24. <input type="text" class="form-control" name="sn" id="sn" value="{{Request::input('sn')}}" placeholder="券码" autocomplete="off"/>
  25. </div>
  26. <div class="form-group col-lg-3 col-sm-4">
  27. <select class="form-control" name="type" id="type" onChange="Search()">
  28. <option value="" hidden>类型</option>
  29. <option value="1">现金券</option>
  30. <option value="2">折扣券</option>
  31. <option value="3">充值券</option>
  32. </select>
  33. </div>
  34. <div class="form-group col-lg-3 col-sm-4">
  35. <select class="form-control" name="status" id="status" onChange="Search()">
  36. <option value="" hidden>状态</option>
  37. <option value="0">生效中</option>
  38. <option value="1">已使用</option>
  39. <option value="2">已失效</option>
  40. </select>
  41. </div>
  42. <div class="form-group col-lg-3 col-sm-4 btn-group">
  43. <button class="btn btn-primary" onclick="Search()">搜 索</button>
  44. <a href="{{route('admin.coupon.index')}}" class="btn btn-danger">重 置</a>
  45. </div>
  46. </div>
  47. <table class="text-md-center" data-toggle="table" data-mobile-responsive="true">
  48. <thead class="thead-default">
  49. <tr>
  50. <th> #</th>
  51. <th> 名称</th>
  52. <th> 券码</th>
  53. <th> 图片</th>
  54. <th> 类型</th>
  55. <th> 使用次数</th>
  56. <th> 优惠</th>
  57. <th> 有效期</th>
  58. <th> 状态</th>
  59. <th> 操作</th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. @foreach($couponList as $coupon)
  64. <tr>
  65. <td> {{$coupon->id}} </td>
  66. <td> {{$coupon->name}} </td>
  67. <td> {{$coupon->sn}} </td>
  68. <td> @if($coupon->logo) <img src="{{asset($coupon->logo)}}" class="h-50" alt="优惠码logo"/> @endif </td>
  69. <td>
  70. @if($coupon->type === 1)
  71. 抵用券
  72. @elseif($coupon->type === 2)
  73. 折扣券
  74. @else
  75. 充值券
  76. @endif
  77. </td>
  78. <td> {{$coupon->type === 3 ? '一次性' : ($coupon->usable_times ?? '无限制')}} </td>
  79. <td>
  80. {{$coupon->value}}@if($coupon->type === 2)%@else元@endif
  81. </td>
  82. <td> {{$coupon->start_time}} ~ {{$coupon->end_time}} </td>
  83. <td>
  84. @if($coupon->status === 1)
  85. <span class="badge badge-lg badge-default"> 已使用 </span>
  86. @elseif ($coupon->status === 2)
  87. <span class="badge badge-lg badge-default"> 已失效 </span>
  88. @else
  89. <span class="badge badge-lg badge-success"> 生效中 </span>
  90. @endif
  91. </td>
  92. <td>
  93. @if($coupon->status !== 1)
  94. @can('admin.coupon.destroy')
  95. <button class="btn btn-danger" onclick="delCoupon('{{$coupon->id}}','{{$coupon->name}}')">
  96. <i class="icon wb-close"></i>
  97. </button>
  98. @endcan
  99. @endif
  100. </td>
  101. </tr>
  102. @endforeach
  103. </tbody>
  104. </table>
  105. </div>
  106. <div class="panel-footer">
  107. <div class="row">
  108. <div class="col-sm-4">
  109. 共 <code>{{$couponList->total()}}</code> 张优惠券
  110. </div>
  111. <div class="col-sm-8">
  112. <nav class="Page navigation float-right">
  113. {{$couponList->links()}}
  114. </nav>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. @endsection
  121. @section('javascript')
  122. <script src="/assets/global/vendor/bootstrap-table/bootstrap-table.min.js"></script>
  123. <script src="/assets/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
  124. <script>
  125. $(document).ready(function() {
  126. $('#sn').val({{Request::input('sn')}});
  127. $('#type').val({{Request::input('type')}});
  128. $('#status').val({{Request::input('status')}});
  129. });
  130. //回车检测
  131. $(document).on('keypress', 'input', function(e) {
  132. if (e.which === 13) {
  133. Search();
  134. return false;
  135. }
  136. });
  137. // 搜索
  138. function Search() {
  139. window.location.href = '{{route('admin.coupon.index')}}?sn=' + $('#sn').val() + '&type=' + $('#type').val() + '&status=' +
  140. $('#status').val();
  141. }
  142. @can('admin.coupon.export')
  143. // 批量导出卡券
  144. function exportCoupon() {
  145. swal.fire({
  146. title: '卡券导出',
  147. text: '确定导出所有卡券吗?',
  148. icon: 'question',
  149. showCancelButton: true,
  150. cancelButtonText: '{{trans('home.ticket_close')}}',
  151. confirmButtonText: '{{trans('home.ticket_confirm')}}',
  152. }).then((result) => {
  153. if (result.value) {
  154. window.location.href = '{{route('admin.coupon.export')}}';
  155. }
  156. });
  157. }
  158. @endcan
  159. @can('admin.coupon.destroy')
  160. // 删除卡券
  161. function delCoupon(id, name) {
  162. swal.fire({
  163. title: '确定删除卡券 【' + name + '】 吗?',
  164. icon: 'question',
  165. allowEnterKey: false,
  166. showCancelButton: true,
  167. cancelButtonText: '{{trans('home.ticket_close')}}',
  168. confirmButtonText: '{{trans('home.ticket_confirm')}}',
  169. }).then((result) => {
  170. if (result.value) {
  171. $.ajax({
  172. method: 'DELETE',
  173. url: '{{route('admin.coupon.destroy', '')}}/' + id,
  174. data: {_token: '{{csrf_token()}}'},
  175. dataType: 'json',
  176. success: function(ret) {
  177. if (ret.status === 'success') {
  178. swal.fire({title: ret.message, icon: 'success', timer: 1000, showConfirmButton: false}).then(() => window.location.reload());
  179. } else {
  180. swal.fire({title: ret.message, icon: 'error'}).then(() => window.location.reload());
  181. }
  182. },
  183. });
  184. }
  185. });
  186. }
  187. @endcan
  188. </script>
  189. @endsection