index.blade.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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-normal layui-btn-xs" lay-event="member">成员管理</a>
  32. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  33. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  34. </div>
  35. </div>
  36. </script>
  37. </div>
  38. </div>
  39. @endsection
  40. @section('footer')
  41. <script>
  42. $(function () {
  43. layui.use(['table', 'layer'], function(){
  44. var table = layui.table,
  45. layer = layui.layer,
  46. form = layui.form,
  47. laydate = layui.laydate,
  48. top_window = window;
  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: 'name', title: '名称', align: 'center' },
  56. { field: 'created_at', 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 === 'delete'){
  71. layer.confirm('确定要删除吗?', function(index) {
  72. $.ajax({
  73. method: 'POST',
  74. url: '{{ $pre_uri }}' + 'delete',
  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. } else {
  85. layer.msg(data.info, {
  86. icon: 2
  87. });
  88. }
  89. layer.close(index);
  90. },
  91. error: function () {
  92. layer.close(index);
  93. layer.msg('删除失败', {
  94. icon: 2
  95. });
  96. }
  97. });
  98. });
  99. } else if(obj.event === 'edit') {
  100. layer.open({
  101. title: '编辑成员',
  102. type: 2,
  103. area: ['90%', '90%'],
  104. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  105. end: function () {
  106. top_window.location.reload();
  107. }
  108. });
  109. } else if(obj.event === 'member') {
  110. console.log('ProjectUser/index?project_id=' + data.id)
  111. window.location = '/admin/ProjectUser/index?project_id=' + data.id
  112. }
  113. });
  114. if($('#search-begin-date').length > 0) {
  115. laydate.render({
  116. elem: '#search-begin-date',
  117. done: function () {
  118. updateTableBySearch();
  119. }
  120. });
  121. }
  122. if($('#search-end-date').length > 0) {
  123. laydate.render({
  124. elem: '#search-end-date',
  125. done: function () {
  126. updateTableBySearch();
  127. }
  128. });
  129. }
  130. function transformToJson(formData){
  131. var obj={};
  132. for (var i in formData) {
  133. obj[formData[i].name]=formData[i]['value'];
  134. }
  135. return obj;
  136. }
  137. function updateTableBySearch() {
  138. table.reload('sg-main-table', {
  139. where: transformToJson($('#sg-search-form').serializeArray()),
  140. page: {
  141. curr: 1
  142. }
  143. });
  144. }
  145. $('#sg-search-btn').click(function() {
  146. updateTableBySearch();
  147. });
  148. // $('#sg-search-form').change(function () {
  149. // updateTableBySearch();
  150. // });
  151. //
  152. // form.on('select()', function(){
  153. // updateTableBySearch();
  154. // });
  155. $('#sg-create-btn').on('click', function () {
  156. layer.open({
  157. title: '创建' + '{{ $model_name }}',
  158. type: 2,
  159. area: ['90%', '90%'],
  160. content: '{{ $pre_uri }}' + 'create',
  161. end: function () {
  162. top_window.location.reload();
  163. }
  164. });
  165. });
  166. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  167. layer.confirm('确定要删除所有选中行吗?', function () {
  168. var data = table.checkStatus('sg-main-table').data;
  169. if(data.length <= 0) {
  170. layer.msg('选择不能为空', {
  171. icon: 2
  172. });
  173. return false;
  174. }
  175. var ids = [];
  176. for(var i = 0; i < data.length; ++i) {
  177. ids.push(data[i]['id']);
  178. }
  179. $.ajax({
  180. method: 'POST',
  181. url: '{{ $pre_uri }}' + 'deleteMany',
  182. headers: {
  183. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  184. },
  185. data: {
  186. ids: JSON.stringify(ids)
  187. },
  188. success: function (data) {
  189. if(data.status === 'success') {
  190. top_window.location.reload();
  191. } else {
  192. layer.msg(data.info, {
  193. icon: 2
  194. });
  195. }
  196. },
  197. error: function () {
  198. layer.msg('删除失败', {
  199. icon: 2
  200. });
  201. }
  202. });
  203. })
  204. });
  205. });
  206. })
  207. </script>
  208. @endsection