index.blade.php 11 KB

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