index.blade.php 9.0 KB

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