index.blade.php 11 KB

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