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