index.blade.php 9.6 KB

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