index.blade.php 10 KB

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