index.blade.php 17 KB

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