rent.blade.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. @extends('admin.layout-content')
  2. @section('header')
  3. <style>
  4. </style>
  5. @endsection
  6. @section('content')
  7. <div class="layui-card">
  8. <div class="layui-card-header sg-card-header">
  9. 租赁设备列表
  10. </div>
  11. <div class="layui-card-body">
  12. <form class="layui-form" id="sg-search-form">
  13. <input type="hidden" name="type" value="rent">
  14. {{--<div class="layui-form-item layui-row">--}}
  15. {{--<div class="layui-inline">--}}
  16. {{--<div class="layui-input-inline">--}}
  17. {{--<input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input" value="{{ request('name') }}">--}}
  18. {{--</div>--}}
  19. {{--</div>--}}
  20. {{--<div class="layui-inline">--}}
  21. {{--<div class="layui-btn" id="sg-search-btn">搜索</div>--}}
  22. {{--</div>--}}
  23. {{--</div>--}}
  24. </form>
  25. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  26. <script type="text/html" id="sg-table-bar">
  27. <div class="layui-btn-group">
  28. <div class="layui-btn-group">
  29. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  30. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  31. </div>
  32. </div>
  33. </script>
  34. </div>
  35. </div>
  36. @endsection
  37. @section('footer')
  38. <script>
  39. $(function () {
  40. layui.use(['table', 'layer'], function(){
  41. var table = layui.table,
  42. layer = layui.layer,
  43. form = layui.form,
  44. laydate = layui.laydate,
  45. top_window = window;
  46. $('#sg-back-btn').on('click', function () {
  47. window.history.go(-1);
  48. });
  49. table.render({
  50. elem: '#sg-main-table',
  51. url: '{{ $pre_uri }}' + 'get',
  52. cellMinWidth: 80,
  53. cols: [[
  54. { field: 'id', title: 'ID', align: 'center' },
  55. { field: 'device_type_name', title: '租赁设备类型', align: 'center' },
  56. { field: 'device_name_name', title: '租赁设备名称', align: 'center' },
  57. { field: 'spec_name', title: '设备规格型号', align: 'center' },
  58. { field: 'rent_type_name', title: '租赁方式', align: 'center' },
  59. { field: 'price', title: '租赁单价', align: 'center' },
  60. { field: 'quantity', title: '租赁数量', align: 'center' },
  61. { field: 'start_date', title: '租赁开始时间', align: 'center' },
  62. { field: 'end_date', title: '租赁结束时间', align: 'center' },
  63. { field: 'money', title: '租赁总金额', align: 'center' },
  64. // { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  65. ]],
  66. page: {
  67. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  68. limit: 15
  69. },
  70. even: true,
  71. where: transformToJson($('#sg-search-form').serializeArray()),
  72. done: function(res, curr, count) {
  73. }
  74. });
  75. table.on('tool(tableEvent)', function(obj){
  76. var data = obj.data;
  77. if(obj.event === 'delete'){
  78. layer.confirm('确定要删除吗?', function(index) {
  79. $.ajax({
  80. method: 'POST',
  81. url: '{{ $pre_uri }}' + 'delete',
  82. headers: {
  83. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  84. },
  85. data: {
  86. id: data.id
  87. },
  88. success: function (data) {
  89. if(data.status === 'success') {
  90. obj.del();
  91. } else {
  92. layer.msg(data.info, {
  93. icon: 2
  94. });
  95. }
  96. layer.close(index);
  97. },
  98. error: function () {
  99. layer.close(index);
  100. layer.msg('删除失败', {
  101. icon: 2
  102. });
  103. }
  104. });
  105. });
  106. } else if(obj.event === 'edit') {
  107. layer.open({
  108. title: '编辑成员',
  109. type: 2,
  110. area: ['90%', '90%'],
  111. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  112. end: function () {
  113. top_window.location.reload();
  114. }
  115. });
  116. }
  117. });
  118. if($('#search-begin-date').length > 0) {
  119. laydate.render({
  120. elem: '#search-begin-date',
  121. done: function () {
  122. updateTableBySearch();
  123. }
  124. });
  125. }
  126. if($('#search-end-date').length > 0) {
  127. laydate.render({
  128. elem: '#search-end-date',
  129. done: function () {
  130. updateTableBySearch();
  131. }
  132. });
  133. }
  134. function transformToJson(formData){
  135. var obj={};
  136. for (var i in formData) {
  137. obj[formData[i].name]=formData[i]['value'];
  138. }
  139. return obj;
  140. }
  141. function updateTableBySearch() {
  142. table.reload('sg-main-table', {
  143. where: transformToJson($('#sg-search-form').serializeArray()),
  144. page: {
  145. curr: 1
  146. }
  147. });
  148. }
  149. $('#sg-search-btn').click(function() {
  150. updateTableBySearch();
  151. });
  152. // $('#sg-search-form').change(function () {
  153. // updateTableBySearch();
  154. // });
  155. //
  156. // form.on('select()', function(){
  157. // updateTableBySearch();
  158. // });
  159. $('#sg-create-btn').on('click', function () {
  160. layer.open({
  161. title: '创建' + '{{ $model_name }}',
  162. type: 2,
  163. area: ['90%', '90%'],
  164. content: '{{ $pre_uri }}' + 'create',
  165. end: function () {
  166. top_window.location.reload();
  167. }
  168. });
  169. });
  170. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  171. layer.confirm('确定要删除所有选中行吗?', function () {
  172. var data = table.checkStatus('sg-main-table').data;
  173. if(data.length <= 0) {
  174. layer.msg('选择不能为空', {
  175. icon: 2
  176. });
  177. return false;
  178. }
  179. var ids = [];
  180. for(var i = 0; i < data.length; ++i) {
  181. ids.push(data[i]['id']);
  182. }
  183. $.ajax({
  184. method: 'POST',
  185. url: '{{ $pre_uri }}' + 'deleteMany',
  186. headers: {
  187. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  188. },
  189. data: {
  190. ids: JSON.stringify(ids)
  191. },
  192. success: function (data) {
  193. if(data.status === 'success') {
  194. top_window.location.reload();
  195. } else {
  196. layer.msg(data.info, {
  197. icon: 2
  198. });
  199. }
  200. },
  201. error: function () {
  202. layer.msg('删除失败', {
  203. icon: 2
  204. });
  205. }
  206. });
  207. })
  208. });
  209. });
  210. })
  211. </script>
  212. @endsection