index.blade.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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: 'id', title: 'ID', align: 'center' },
  54. { field: 'name', title: '名称', align: 'center' },
  55. { field: 'sort', title: '排序', align: 'center' },
  56. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  57. ]],
  58. page: {
  59. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  60. limit: 15
  61. },
  62. even: true,
  63. where: transformToJson($('#sg-search-form').serializeArray()),
  64. done: function(res, curr, count) {
  65. }
  66. });
  67. table.on('tool(tableEvent)', function(obj){
  68. var data = obj.data;
  69. if(obj.event === 'delete'){
  70. layer.confirm('确定要删除吗?', function(index) {
  71. $.ajax({
  72. method: 'POST',
  73. url: '{{ $pre_uri }}' + 'delete',
  74. headers: {
  75. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  76. },
  77. data: {
  78. id: data.id
  79. },
  80. success: function (data) {
  81. if(data.status === 'success') {
  82. obj.del();
  83. } else {
  84. layer.msg(data.info, {
  85. icon: 2
  86. });
  87. }
  88. layer.close(index);
  89. },
  90. error: function () {
  91. layer.close(index);
  92. layer.msg('删除失败', {
  93. icon: 2
  94. });
  95. }
  96. });
  97. });
  98. } else if(obj.event === 'edit') {
  99. layer.open({
  100. title: '编辑成员',
  101. type: 2,
  102. area: ['90%', '90%'],
  103. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  104. end: function () {
  105. top_window.location.reload();
  106. }
  107. });
  108. }
  109. });
  110. if($('#search-begin-date').length > 0) {
  111. laydate.render({
  112. elem: '#search-begin-date',
  113. done: function () {
  114. updateTableBySearch();
  115. }
  116. });
  117. }
  118. if($('#search-end-date').length > 0) {
  119. laydate.render({
  120. elem: '#search-end-date',
  121. done: function () {
  122. updateTableBySearch();
  123. }
  124. });
  125. }
  126. function transformToJson(formData){
  127. var obj={};
  128. for (var i in formData) {
  129. obj[formData[i].name]=formData[i]['value'];
  130. }
  131. return obj;
  132. }
  133. function updateTableBySearch() {
  134. table.reload('sg-main-table', {
  135. where: transformToJson($('#sg-search-form').serializeArray()),
  136. page: {
  137. curr: 1
  138. }
  139. });
  140. }
  141. $('#sg-search-btn').click(function() {
  142. updateTableBySearch();
  143. });
  144. // $('#sg-search-form').change(function () {
  145. // updateTableBySearch();
  146. // });
  147. //
  148. // form.on('select()', function(){
  149. // updateTableBySearch();
  150. // });
  151. $('#sg-create-btn').on('click', function () {
  152. layer.open({
  153. title: '创建' + '{{ $model_name }}',
  154. type: 2,
  155. area: ['90%', '90%'],
  156. content: '{{ $pre_uri }}' + 'create',
  157. end: function () {
  158. top_window.location.reload();
  159. }
  160. });
  161. });
  162. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  163. layer.confirm('确定要删除所有选中行吗?', function () {
  164. var data = table.checkStatus('sg-main-table').data;
  165. if(data.length <= 0) {
  166. layer.msg('选择不能为空', {
  167. icon: 2
  168. });
  169. return false;
  170. }
  171. var ids = [];
  172. for(var i = 0; i < data.length; ++i) {
  173. ids.push(data[i]['id']);
  174. }
  175. $.ajax({
  176. method: 'POST',
  177. url: '{{ $pre_uri }}' + 'deleteMany',
  178. headers: {
  179. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  180. },
  181. data: {
  182. ids: JSON.stringify(ids)
  183. },
  184. success: function (data) {
  185. if(data.status === 'success') {
  186. top_window.location.reload();
  187. } else {
  188. layer.msg(data.info, {
  189. icon: 2
  190. });
  191. }
  192. },
  193. error: function () {
  194. layer.msg('删除失败', {
  195. icon: 2
  196. });
  197. }
  198. });
  199. })
  200. });
  201. });
  202. })
  203. </script>
  204. @endsection