index.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. </style>
  43. @endsection
  44. @section('content')
  45. <div class="layui-card">
  46. <div class="layui-card-header sg-card-header">
  47. {{ $model_name }}管理
  48. <div class="sg-card-create">
  49. <button id="sg-import-all" class="layui-btn layui-btn-sm layui-btn-normal">批量导入</button>
  50. </div>
  51. <div class="sg-card-create" style="margin-right: 10px">
  52. <button id="sg-create-btn" class="layui-btn layui-btn-sm">创建</button>
  53. </div>
  54. </div>
  55. <div class="layui-card-body">
  56. <form class="layui-form" id="sg-search-form">
  57. <div class="layui-form-item layui-row">
  58. <div class="layui-inline">
  59. <div class="layui-input-inline">
  60. <select name="project_id">
  61. <option value="0">所属项目</option>
  62. @foreach($project_id as $option)
  63. <option value="{{ $option['id'] }}" {{ request('project_id') == $option['id'] ? 'selected' : '' }}>{{ $option['name'] }}</option>
  64. @endforeach
  65. </select>
  66. </div>
  67. </div>
  68. <div class="layui-inline">
  69. <div class="layui-input-inline">
  70. <input type="text" name="name" placeholder="请输入工点名称" autocomplete="off" class="layui-input" value="{{ request('name') }}">
  71. </div>
  72. </div>
  73. <div class="layui-inline">
  74. <div class="layui-btn" id="sg-search-btn">搜索</div>
  75. </div>
  76. </div>
  77. </form>
  78. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  79. <script type="text/html" id="sg-table-bar">
  80. <div class="layui-btn-group">
  81. <div class="layui-btn-group">
  82. <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="device">借用设备</a>
  83. @{{# if(d.status == 1) { }}
  84. <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="disable">禁用</a>
  85. @{{# } else { }}
  86. <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="active">激活</a>
  87. @{{# } }}
  88. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  89. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  90. </div>
  91. </div>
  92. </script>
  93. </div>
  94. </div>
  95. <div id="sg-import-box" class="sg-import-box">
  96. <div class="layui-row">
  97. {{--<input type="file" id="sg-upload-file">--}}
  98. <div class="layui-col-sm8 layui-col-sm-offset2">
  99. <div class="sg-export-list">
  100. <div class="sg-item">
  101. <h3 class="sg-title">一、请按照数据模板的格式准备要导入的数据。<a href="{{ $pre_uri . 'exportTemplate?t=' . time() }}" class="sg-down-link">点击下载</a>《工点导入模板》</h3>
  102. <ul>
  103. <li>注意事项</li>
  104. <li>1、模板中的表头名称不能更改,表头行不能删除</li>
  105. <li>2、导入文件请勿超过 20 MB</li>
  106. </ul>
  107. </div>
  108. <div class="sg-item">
  109. <h3 class="sg-title">二、请选择需要导入的文件</h3>
  110. <div class="sg-desc"><input type="file" id="sg-upload-file"></div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. @endsection
  117. @section('footer')
  118. <script>
  119. $(function () {
  120. layui.use(['table', 'layer'], function(){
  121. var table = layui.table,
  122. layer = layui.layer,
  123. form = layui.form,
  124. laydate = layui.laydate,
  125. top_window = window;
  126. $('#sg-import-all').click(function() {
  127. layer.open({
  128. title: '导入设备',
  129. type: 1,
  130. area: ['90%', '90%'],
  131. content: $('#sg-import-box'),
  132. btn: ['导入', '取消'],
  133. yes: function () {
  134. importFile();
  135. }
  136. });
  137. // $('#sg-upload-file').click();
  138. });
  139. function importFile() {
  140. var file = $('#sg-upload-file')[0].files[0];
  141. if(file) {
  142. var name = file['name'];
  143. var ext = name.split('.').pop();
  144. if(['xls', 'xlsx'].indexOf(ext) !== -1) {
  145. var formData = new FormData();
  146. formData.append('file', file);
  147. $.ajax({
  148. method: 'POST',
  149. url: '{{ $pre_uri }}' + 'import',
  150. headers: {
  151. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  152. },
  153. data: formData,
  154. contentType: false,
  155. cache: false,
  156. processData: false,
  157. success: function (data) {
  158. if(data.status === 'success') {
  159. layer.msg('上传成功', {
  160. icon: 1
  161. });
  162. setTimeout(function() {
  163. top_window.location.reload();
  164. }, 1000)
  165. } else {
  166. layer.alert(data.info, {
  167. icon: 2
  168. });
  169. }
  170. },
  171. error: function () {
  172. layer.msg('导入失败', {
  173. icon: 2
  174. });
  175. }
  176. });
  177. }
  178. } else {
  179. layer.msg('只支持xls,xlsx格式的文件', {
  180. icon: 2
  181. });
  182. }
  183. this.value = '';
  184. }
  185. table.render({
  186. elem: '#sg-main-table',
  187. url: '{{ $pre_uri }}' + 'get',
  188. cellMinWidth: 80,
  189. cols: [[
  190. { field: 'id', title: 'ID', align: 'center' },
  191. { field: 'project_name', title: '所属项目', align: 'center' },
  192. { field: 'name', title: '工点名称', align: 'center' },
  193. { field: 'status_label', title: '状态', align: 'center' },
  194. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  195. ]],
  196. page: {
  197. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  198. limit: 15
  199. },
  200. even: true,
  201. where: transformToJson($('#sg-search-form').serializeArray()),
  202. done: function(res, curr, count) {
  203. }
  204. });
  205. table.on('tool(tableEvent)', function(obj){
  206. var data = obj.data;
  207. if(obj.event === 'delete'){
  208. layer.confirm('确定要删除吗?', function(index) {
  209. $.ajax({
  210. method: 'POST',
  211. url: '{{ $pre_uri }}' + 'delete',
  212. headers: {
  213. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  214. },
  215. data: {
  216. id: data.id
  217. },
  218. success: function (data) {
  219. if(data.status === 'success') {
  220. obj.del();
  221. } else {
  222. layer.msg(data.info, {
  223. icon: 2
  224. });
  225. }
  226. layer.close(index);
  227. },
  228. error: function () {
  229. layer.close(index);
  230. layer.msg('删除失败', {
  231. icon: 2
  232. });
  233. }
  234. });
  235. });
  236. } else if(obj.event === 'edit') {
  237. layer.open({
  238. title: '编辑成员',
  239. type: 2,
  240. area: ['90%', '90%'],
  241. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  242. end: function () {
  243. top_window.location.reload();
  244. }
  245. });
  246. } else if(obj.event === 'disable') {
  247. changeStatus(data, '确定要禁用吗?', 2);
  248. } else if(obj.event === 'active') {
  249. changeStatus(data, '确定要激活吗?', 1);
  250. } else if(obj.event === 'device') {
  251. layer.open({
  252. title: '借用设备',
  253. type: 2,
  254. area: ['90%', '90%'],
  255. content: '{{ $pre_uri }}' + 'innerDevices?work_point_id=' + data.id,
  256. end: function () {
  257. // top_window.location.reload();
  258. }
  259. });
  260. }
  261. });
  262. function changeStatus(data, msg, status) {
  263. layer.confirm(msg, function(index) {
  264. $.ajax({
  265. method: 'POST',
  266. url: '{{ $pre_uri }}' + 'change',
  267. headers: {
  268. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  269. },
  270. data: {
  271. id: data.id,
  272. status: status
  273. },
  274. success: function (data) {
  275. if(data.status === 'success') {
  276. top_window.location.reload()
  277. } else {
  278. layer.msg(data.info, {
  279. icon: 2
  280. });
  281. }
  282. layer.close(index);
  283. },
  284. error: function () {
  285. layer.close(index);
  286. layer.msg('操作失败', {
  287. icon: 2
  288. });
  289. }
  290. });
  291. });
  292. }
  293. if($('#search-begin-date').length > 0) {
  294. laydate.render({
  295. elem: '#search-begin-date',
  296. done: function () {
  297. updateTableBySearch();
  298. }
  299. });
  300. }
  301. if($('#search-end-date').length > 0) {
  302. laydate.render({
  303. elem: '#search-end-date',
  304. done: function () {
  305. updateTableBySearch();
  306. }
  307. });
  308. }
  309. function transformToJson(formData){
  310. var obj={};
  311. for (var i in formData) {
  312. obj[formData[i].name]=formData[i]['value'];
  313. }
  314. return obj;
  315. }
  316. function updateTableBySearch() {
  317. table.reload('sg-main-table', {
  318. where: transformToJson($('#sg-search-form').serializeArray()),
  319. page: {
  320. curr: 1
  321. }
  322. });
  323. }
  324. $('#sg-search-btn').click(function() {
  325. updateTableBySearch();
  326. });
  327. // $('#sg-search-form').change(function () {
  328. // updateTableBySearch();
  329. // });
  330. //
  331. // form.on('select()', function(){
  332. // updateTableBySearch();
  333. // });
  334. $('#sg-create-btn').on('click', function () {
  335. layer.open({
  336. title: '创建' + '{{ $model_name }}',
  337. type: 2,
  338. area: ['90%', '90%'],
  339. content: '{{ $pre_uri }}' + 'create',
  340. end: function () {
  341. top_window.location.reload();
  342. }
  343. });
  344. });
  345. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  346. layer.confirm('确定要删除所有选中行吗?', function () {
  347. var data = table.checkStatus('sg-main-table').data;
  348. if(data.length <= 0) {
  349. layer.msg('选择不能为空', {
  350. icon: 2
  351. });
  352. return false;
  353. }
  354. var ids = [];
  355. for(var i = 0; i < data.length; ++i) {
  356. ids.push(data[i]['id']);
  357. }
  358. $.ajax({
  359. method: 'POST',
  360. url: '{{ $pre_uri }}' + 'deleteMany',
  361. headers: {
  362. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  363. },
  364. data: {
  365. ids: JSON.stringify(ids)
  366. },
  367. success: function (data) {
  368. if(data.status === 'success') {
  369. top_window.location.reload();
  370. } else {
  371. layer.msg(data.info, {
  372. icon: 2
  373. });
  374. }
  375. },
  376. error: function () {
  377. layer.msg('删除失败', {
  378. icon: 2
  379. });
  380. }
  381. });
  382. })
  383. });
  384. });
  385. })
  386. </script>
  387. @endsection