index.blade.php 8.6 KB

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