index.blade.php 9.2 KB

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