index.blade.php 10 KB

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