all.blade.php 9.7 KB

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