inner-devices.blade.php 14 KB

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