index.blade.php 8.9 KB

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