index.blade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. <div class="layui-inline">
  18. <div class="layui-input-inline">
  19. <select name="project_id">
  20. <option value="0">所属项目</option>
  21. @foreach($project_id as $option)
  22. <option value="{{ $option['id'] }}" {{ request('project_id') == $option['id'] ? 'selected' : '' }}>{{ $option['name'] }}</option>
  23. @endforeach
  24. </select>
  25. </div>
  26. </div>
  27. <div class="layui-inline">
  28. <div class="layui-input-inline">
  29. <input type="text" name="name" placeholder="请输入工点名称" autocomplete="off" class="layui-input" value="{{ request('name') }}">
  30. </div>
  31. </div>
  32. <div class="layui-inline">
  33. <div class="layui-btn" id="sg-search-btn">搜索</div>
  34. </div>
  35. </div>
  36. </form>
  37. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  38. <script type="text/html" id="sg-table-bar">
  39. <div class="layui-btn-group">
  40. <div class="layui-btn-group">
  41. <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="device">借用设备</a>
  42. @{{# if(d.status == 1) { }}
  43. <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="disable">禁用</a>
  44. @{{# } else { }}
  45. <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="active">激活</a>
  46. @{{# } }}
  47. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  48. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  49. </div>
  50. </div>
  51. </script>
  52. </div>
  53. </div>
  54. @endsection
  55. @section('footer')
  56. <script>
  57. $(function () {
  58. layui.use(['table', 'layer'], function(){
  59. var table = layui.table,
  60. layer = layui.layer,
  61. form = layui.form,
  62. laydate = layui.laydate,
  63. top_window = window;
  64. table.render({
  65. elem: '#sg-main-table',
  66. url: '{{ $pre_uri }}' + 'get',
  67. cellMinWidth: 80,
  68. cols: [[
  69. { field: 'id', title: 'ID', align: 'center' },
  70. { field: 'project_name', title: '所属项目', align: 'center' },
  71. { field: 'name', title: '工点名称', align: 'center' },
  72. { field: 'status_label', title: '状态', align: 'center' },
  73. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  74. ]],
  75. page: {
  76. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  77. limit: 15
  78. },
  79. even: true,
  80. where: transformToJson($('#sg-search-form').serializeArray()),
  81. done: function(res, curr, count) {
  82. }
  83. });
  84. table.on('tool(tableEvent)', function(obj){
  85. var data = obj.data;
  86. if(obj.event === 'delete'){
  87. layer.confirm('确定要删除吗?', function(index) {
  88. $.ajax({
  89. method: 'POST',
  90. url: '{{ $pre_uri }}' + 'delete',
  91. headers: {
  92. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  93. },
  94. data: {
  95. id: data.id
  96. },
  97. success: function (data) {
  98. if(data.status === 'success') {
  99. obj.del();
  100. } else {
  101. layer.msg(data.info, {
  102. icon: 2
  103. });
  104. }
  105. layer.close(index);
  106. },
  107. error: function () {
  108. layer.close(index);
  109. layer.msg('删除失败', {
  110. icon: 2
  111. });
  112. }
  113. });
  114. });
  115. } else if(obj.event === 'edit') {
  116. layer.open({
  117. title: '编辑成员',
  118. type: 2,
  119. area: ['90%', '90%'],
  120. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  121. end: function () {
  122. top_window.location.reload();
  123. }
  124. });
  125. } else if(obj.event === 'disable') {
  126. changeStatus(data, '确定要禁用吗?', 2);
  127. } else if(obj.event === 'active') {
  128. changeStatus(data, '确定要激活吗?', 1);
  129. } else if(obj.event === 'device') {
  130. layer.open({
  131. title: '借用设备',
  132. type: 2,
  133. area: ['90%', '90%'],
  134. content: '{{ $pre_uri }}' + 'innerDevices?work_point_id=' + data.id,
  135. end: function () {
  136. // top_window.location.reload();
  137. }
  138. });
  139. }
  140. });
  141. function changeStatus(data, msg, status) {
  142. layer.confirm(msg, function(index) {
  143. $.ajax({
  144. method: 'POST',
  145. url: '{{ $pre_uri }}' + 'change',
  146. headers: {
  147. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  148. },
  149. data: {
  150. id: data.id,
  151. status: status
  152. },
  153. success: function (data) {
  154. if(data.status === 'success') {
  155. top_window.location.reload()
  156. } else {
  157. layer.msg(data.info, {
  158. icon: 2
  159. });
  160. }
  161. layer.close(index);
  162. },
  163. error: function () {
  164. layer.close(index);
  165. layer.msg('操作失败', {
  166. icon: 2
  167. });
  168. }
  169. });
  170. });
  171. }
  172. if($('#search-begin-date').length > 0) {
  173. laydate.render({
  174. elem: '#search-begin-date',
  175. done: function () {
  176. updateTableBySearch();
  177. }
  178. });
  179. }
  180. if($('#search-end-date').length > 0) {
  181. laydate.render({
  182. elem: '#search-end-date',
  183. done: function () {
  184. updateTableBySearch();
  185. }
  186. });
  187. }
  188. function transformToJson(formData){
  189. var obj={};
  190. for (var i in formData) {
  191. obj[formData[i].name]=formData[i]['value'];
  192. }
  193. return obj;
  194. }
  195. function updateTableBySearch() {
  196. table.reload('sg-main-table', {
  197. where: transformToJson($('#sg-search-form').serializeArray()),
  198. page: {
  199. curr: 1
  200. }
  201. });
  202. }
  203. $('#sg-search-btn').click(function() {
  204. updateTableBySearch();
  205. });
  206. // $('#sg-search-form').change(function () {
  207. // updateTableBySearch();
  208. // });
  209. //
  210. // form.on('select()', function(){
  211. // updateTableBySearch();
  212. // });
  213. $('#sg-create-btn').on('click', function () {
  214. layer.open({
  215. title: '创建' + '{{ $model_name }}',
  216. type: 2,
  217. area: ['90%', '90%'],
  218. content: '{{ $pre_uri }}' + 'create',
  219. end: function () {
  220. top_window.location.reload();
  221. }
  222. });
  223. });
  224. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  225. layer.confirm('确定要删除所有选中行吗?', function () {
  226. var data = table.checkStatus('sg-main-table').data;
  227. if(data.length <= 0) {
  228. layer.msg('选择不能为空', {
  229. icon: 2
  230. });
  231. return false;
  232. }
  233. var ids = [];
  234. for(var i = 0; i < data.length; ++i) {
  235. ids.push(data[i]['id']);
  236. }
  237. $.ajax({
  238. method: 'POST',
  239. url: '{{ $pre_uri }}' + 'deleteMany',
  240. headers: {
  241. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  242. },
  243. data: {
  244. ids: JSON.stringify(ids)
  245. },
  246. success: function (data) {
  247. if(data.status === 'success') {
  248. top_window.location.reload();
  249. } else {
  250. layer.msg(data.info, {
  251. icon: 2
  252. });
  253. }
  254. },
  255. error: function () {
  256. layer.msg('删除失败', {
  257. icon: 2
  258. });
  259. }
  260. });
  261. })
  262. });
  263. });
  264. })
  265. </script>
  266. @endsection