index.blade.php 8.9 KB

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