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 }}管理:{{$user->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. <input type="hidden" name="user_id" value="{{ request('user_id') }}">
  17. {{--@php(dd($user->id))--}}
  18. {{--<div class="layui-form-item layui-row">--}}
  19. {{--<div class="layui-inline">--}}
  20. {{--<div class="layui-input-inline">--}}
  21. {{--<input type="text" name="name" placeholder="请输入用户名" autocomplete="off" class="layui-input" value="{{ request('name') }}">--}}
  22. {{--</div>--}}
  23. {{--</div>--}}
  24. {{--<div class="layui-inline">--}}
  25. {{--<div class="layui-btn" id="sg-search-btn">搜索</div>--}}
  26. {{--</div>--}}
  27. {{--</div>--}}
  28. </form>
  29. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  30. <script type="text/html" id="sg-table-bar">
  31. <div class="layui-btn-group">
  32. <div class="layui-btn-group">
  33. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  34. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  35. </div>
  36. </div>
  37. </script>
  38. </div>
  39. </div>
  40. @endsection
  41. @section('footer')
  42. <script>
  43. $(function () {
  44. layui.use(['table', 'layer'], function(){
  45. var table = layui.table,
  46. layer = layui.layer,
  47. form = layui.form,
  48. laydate = layui.laydate,
  49. top_window = window;
  50. table.render({
  51. elem: '#sg-main-table',
  52. url: '{{ $pre_uri }}' + 'get',
  53. cellMinWidth: 80,
  54. cols: [[
  55. { field: 'id', title: 'ID', align: 'center' },
  56. { field: 'project_name', title: '项目', align: 'center' },
  57. { field: 'role_name', title: '角色', align: 'center' },
  58. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  59. ]],
  60. page: {
  61. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  62. limit: 15
  63. },
  64. even: true,
  65. where: transformToJson($('#sg-search-form').serializeArray()),
  66. done: function(res, curr, count) {
  67. }
  68. });
  69. table.on('tool(tableEvent)', function(obj){
  70. var data = obj.data;
  71. if(obj.event === 'delete'){
  72. layer.confirm('确定要删除吗?', function(index) {
  73. $.ajax({
  74. method: 'POST',
  75. url: '{{ $pre_uri }}' + 'delete',
  76. headers: {
  77. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  78. },
  79. data: {
  80. id: data.id
  81. },
  82. success: function (data) {
  83. if(data.status === 'success') {
  84. obj.del();
  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+'?user_id='+'{{ request('user_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?user_id=' + '{{ request('user_id') }}',
  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