index.blade.php 9.8 KB

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