index.blade.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. @extends('admin.layout-content')
  2. @section('header')
  3. <style>
  4. .sg-search-box {
  5. display: flex;
  6. align-items: center;
  7. justify-content: space-between;
  8. }
  9. .sg-import-box {
  10. display: none;
  11. }
  12. .sg-import-box.sg-show {
  13. display: block;
  14. }
  15. .sg-import-box .layui-col-sm8 {
  16. float: none;
  17. }
  18. .layui-card .layui-form-item .layui-inline {
  19. margin-bottom: 0;
  20. }
  21. .sg-export-list {
  22. margin: 50px 0;
  23. }
  24. .sg-export-list .sg-item {
  25. margin: 20px 0;
  26. }
  27. .sg-export-list .sg-item .sg-title {
  28. margin: 20px 0;
  29. }
  30. .sg-export-list .sg-item .sg-desc,
  31. .sg-export-list .sg-item ul {
  32. color: rgb(140, 140, 140);
  33. margin-left: 30px;
  34. }
  35. .sg-down-link {
  36. color: blue;
  37. text-decoration: underline;
  38. }
  39. .sg-down-link:hover {
  40. color: blue;
  41. }
  42. #sg-import-all{
  43. }
  44. </style>
  45. @endsection
  46. @section('content')
  47. <div class="layui-card">
  48. <div class="layui-card-header sg-card-header">
  49. {{ $model_name }}管理
  50. <div class="sg-card-create">
  51. <button id="sg-create-btn" class="layui-btn layui-btn-sm">创建</button>
  52. </div>
  53. </div>
  54. <div class="layui-card-body">
  55. <form class="layui-form layui-inline" id="sg-search-form">
  56. <div class="layui-form-item layui-row">
  57. @include('share.device-select', ['device_id' => '', 'device_name_id' => '', 'spec_id' => '', 'options' => $options, 'hide_spec' => true])
  58. <div class="layui-inline">
  59. <div class="layui-input-inline">
  60. <input type="text" name="name" placeholder="请输入规格型号" autocomplete="off" class="layui-input" value="{{ request('name') }}">
  61. </div>
  62. </div>
  63. <div class="layui-inline">
  64. <div class="layui-btn" id="sg-search-btn">搜索</div>
  65. </div>
  66. </div>
  67. </form>
  68. <div>
  69. <button id="sg-import-all" class="layui-btn layui-btn-normal">导入</button>
  70. </div>
  71. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  72. <script type="text/html" id="sg-table-bar">
  73. <div class="layui-btn-group">
  74. <div class="layui-btn-group">
  75. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  76. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  77. </div>
  78. </div>
  79. </script>
  80. </div>
  81. </div>
  82. <div id="sg-import-box" class="sg-import-box">
  83. <div class="layui-row">
  84. {{--<input type="file" id="sg-upload-file">--}}
  85. <div class="layui-col-sm8 layui-col-sm-offset2">
  86. <div class="sg-export-list">
  87. <div class="sg-item">
  88. <h3 class="sg-title">一、请按照数据模板的格式准备要导入的数据。<a href="{{ $pre_uri . 'exportTemplate?t=' . time() }}" class="sg-down-link">点击下载</a>《设备导入模板》</h3>
  89. <ul>
  90. <li>注意事项</li>
  91. <li>1、模板中的表头名称不能更改,表头行不能删除</li>
  92. <li>2、导入文件请勿超过 20 MB</li>
  93. </ul>
  94. </div>
  95. <div class="sg-item">
  96. <h3 class="sg-title">二、请选择需要导入的文件</h3>
  97. <div class="sg-desc"><input type="file" id="sg-upload-file"></div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. @endsection
  104. @section('footer')
  105. <script>
  106. $(function () {
  107. layui.use(['table', 'layer'], function(){
  108. var table = layui.table,
  109. layer = layui.layer,
  110. form = layui.form,
  111. laydate = layui.laydate,
  112. top_window = window;
  113. $('#sg-import-all').click(function() {
  114. layer.open({
  115. title: '导入设备',
  116. type: 1,
  117. area: ['90%', '90%'],
  118. content: $('#sg-import-box'),
  119. btn: ['导入', '取消'],
  120. yes: function () {
  121. importFile();
  122. }
  123. });
  124. // $('#sg-upload-file').click();
  125. });
  126. function importFile() {
  127. var file = $('#sg-upload-file')[0].files[0];
  128. if(file) {
  129. var name = file['name'];
  130. var ext = name.split('.').pop();
  131. if(['xls', 'xlsx'].indexOf(ext) !== -1) {
  132. var formData = new FormData();
  133. formData.append('file', file);
  134. $.ajax({
  135. method: 'POST',
  136. url: '{{ $pre_uri }}' + 'import',
  137. headers: {
  138. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  139. },
  140. data: formData,
  141. contentType: false,
  142. cache: false,
  143. processData: false,
  144. success: function (data) {
  145. if(data.status === 'success') {
  146. layer.msg('上传成功', {
  147. icon: 1
  148. });
  149. setTimeout(function() {
  150. top_window.location.reload();
  151. }, 1000)
  152. } else {
  153. layer.alert(data.info, {
  154. icon: 2
  155. });
  156. }
  157. },
  158. error: function () {
  159. layer.msg('导入失败', {
  160. icon: 2
  161. });
  162. }
  163. });
  164. }
  165. } else {
  166. layer.msg('只支持xls,xlsx格式的文件', {
  167. icon: 2
  168. });
  169. }
  170. this.value = '';
  171. }
  172. table.render({
  173. elem: '#sg-main-table',
  174. url: '{{ $pre_uri }}' + 'get',
  175. cellMinWidth: 80,
  176. cols: [[
  177. { field: 'id', title: 'ID', align: 'center' },
  178. { field: 'device_type', title: '租赁设备类型', align: 'center' },
  179. { field: 'device_name_name', title: '租赁设备名称', align: 'center' },
  180. { field: 'name', title: '设备规格型号', align: 'center' },
  181. { field: 'sort', title: '排序', align: 'center' },
  182. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  183. ]],
  184. page: {
  185. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  186. limit: 15
  187. },
  188. even: true,
  189. where: transformToJson($('#sg-search-form').serializeArray()),
  190. done: function(res, curr, count) {
  191. }
  192. });
  193. table.on('tool(tableEvent)', function(obj){
  194. var data = obj.data;
  195. if(obj.event === 'delete'){
  196. layer.confirm('确定要删除吗?', function(index) {
  197. $.ajax({
  198. method: 'POST',
  199. url: '{{ $pre_uri }}' + 'delete',
  200. headers: {
  201. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  202. },
  203. data: {
  204. id: data.id
  205. },
  206. success: function (data) {
  207. if(data.status === 'success') {
  208. obj.del();
  209. } else {
  210. layer.msg(data.info, {
  211. icon: 2
  212. });
  213. }
  214. layer.close(index);
  215. },
  216. error: function () {
  217. layer.close(index);
  218. layer.msg('删除失败', {
  219. icon: 2
  220. });
  221. }
  222. });
  223. });
  224. } else if(obj.event === 'edit') {
  225. layer.open({
  226. title: '编辑成员',
  227. type: 2,
  228. area: ['90%', '90%'],
  229. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  230. end: function () {
  231. top_window.location.reload();
  232. }
  233. });
  234. }
  235. });
  236. if($('#search-begin-date').length > 0) {
  237. laydate.render({
  238. elem: '#search-begin-date',
  239. done: function () {
  240. updateTableBySearch();
  241. }
  242. });
  243. }
  244. if($('#search-end-date').length > 0) {
  245. laydate.render({
  246. elem: '#search-end-date',
  247. done: function () {
  248. updateTableBySearch();
  249. }
  250. });
  251. }
  252. function transformToJson(formData){
  253. var obj={};
  254. for (var i in formData) {
  255. obj[formData[i].name]=formData[i]['value'];
  256. }
  257. return obj;
  258. }
  259. function updateTableBySearch() {
  260. table.reload('sg-main-table', {
  261. where: transformToJson($('#sg-search-form').serializeArray()),
  262. page: {
  263. curr: 1
  264. }
  265. });
  266. }
  267. $('#sg-search-btn').click(function() {
  268. updateTableBySearch();
  269. });
  270. // $('#sg-search-form').change(function () {
  271. // updateTableBySearch();
  272. // });
  273. //
  274. // form.on('select()', function(){
  275. // updateTableBySearch();
  276. // });
  277. $('#sg-create-btn').on('click', function () {
  278. layer.open({
  279. title: '创建' + '{{ $model_name }}',
  280. type: 2,
  281. area: ['90%', '90%'],
  282. content: '{{ $pre_uri }}' + 'create',
  283. end: function () {
  284. top_window.location.reload();
  285. }
  286. });
  287. });
  288. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  289. layer.confirm('确定要删除所有选中行吗?', function () {
  290. var data = table.checkStatus('sg-main-table').data;
  291. if(data.length <= 0) {
  292. layer.msg('选择不能为空', {
  293. icon: 2
  294. });
  295. return false;
  296. }
  297. var ids = [];
  298. for(var i = 0; i < data.length; ++i) {
  299. ids.push(data[i]['id']);
  300. }
  301. $.ajax({
  302. method: 'POST',
  303. url: '{{ $pre_uri }}' + 'deleteMany',
  304. headers: {
  305. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  306. },
  307. data: {
  308. ids: JSON.stringify(ids)
  309. },
  310. success: function (data) {
  311. if(data.status === 'success') {
  312. top_window.location.reload();
  313. } else {
  314. layer.msg(data.info, {
  315. icon: 2
  316. });
  317. }
  318. },
  319. error: function () {
  320. layer.msg('删除失败', {
  321. icon: 2
  322. });
  323. }
  324. });
  325. })
  326. });
  327. });
  328. })
  329. </script>
  330. @endsection