index.blade.php 16 KB

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