index.blade.php 11 KB

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