index.blade.php 11 KB

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