file_upload.blade.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. @extends('admin/layout')
  2. @section('content')
  3. <body class="gray-bg">
  4. <div class="wrapper wrapper-content animated fadeInRight">
  5. <div class="row">
  6. <div class="col-sm-12">
  7. <div class="ibox float-e-margins">
  8. {{--如果已经处理过此流程处于处理中状态显示文件上传--}}
  9. {{--@if($siteProcess->active==2)--}}
  10. <div class="ibox-content">
  11. <form class="form-horizontal">
  12. <div class="form-group">
  13. <label class="col-sm-2 control-label">请选择文件:</label>
  14. <div class="col-sm-6">
  15. <input type="file" id="upload_file" class="form-control" onchange="units.fileUpload()">
  16. <input type="hidden" id="file_path">
  17. </div>
  18. <div class="col-sm-4">
  19. {{--<button class="btn btn-info" type="button" onclick="units.fileUpload()">上传--}}
  20. {{--</button>--}}
  21. <button class="btn btn-success" type="button" onclick="units.save()"
  22. style="margin-left: 40px">保存
  23. </button>
  24. </div>
  25. </div>
  26. </form>
  27. </div>
  28. {{--@endif--}}
  29. <div class="ibox-content" id="file_list">
  30. {{--@forelse ($siteProcess->file_list??[] as $item)--}}
  31. {{--<div class="alert alert-info">--}}
  32. {{--<a class="alert-link" href="{{$item['file_url']}}"--}}
  33. {{--download="{{$item['origin_name']}}">{{$item['origin_name']}}</a>--}}
  34. {{--</div>--}}
  35. {{--@empty--}}
  36. {{--<div class="alert alert-info no-data">--}}
  37. {{--<a class="alert-link">无数据</a>--}}
  38. {{--</div>--}}
  39. {{--@endforelse--}}
  40. <div class="alert alert-info">
  41. @php
  42. $fileList=$siteProcess->file_list??[];
  43. $latestFile=array_shift($fileList);
  44. @endphp
  45. <a class="alert-link" id="fileArea"
  46. @if($latestFile)
  47. href="{{$latestFile['file_url']??''}}"
  48. download="{{$latestFile['origin_name']}}"
  49. @endif
  50. >{{$latestFile['origin_name']??'无数据'}}</a>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </body>
  58. @endsection
  59. @section('footer')
  60. <script>
  61. var units = {
  62. fileUpload: function () {
  63. var config = {
  64. url: '/admin/tool/upload'
  65. };
  66. config.success = function (result) {
  67. $("#file_path").val(result.data.file_url);
  68. layer.msg(result.message, {icon: 6, time: 1500});
  69. // var str = '<div class="alert alert-info">' +
  70. // '<a class="alert-link" href="' + result.data.file_url + '" name="file_list">' + result.data.original_name + '</a>' +
  71. // '</div>';
  72. // var file_list = $("#file_list");
  73. //
  74. // var noData = file_list.find(".no-data");
  75. // if (noData.length > 0) {
  76. // noData.remove();
  77. // }
  78. // file_list.prepend(str);
  79. $("#fileArea").text(result.data.original_name).attr('href', result.data.file_url).attr('download', result.data.original_name);
  80. };
  81. tips.fileUpload($("#upload_file"), config);
  82. },
  83. save: function () {
  84. var fileList = [];
  85. // $("[name=file_list]").each(function () { //只记录上传新增的
  86. // fileList.push({
  87. // file_url: $(this).attr('href'),
  88. // origin_name: $(this).text()
  89. // });
  90. // });
  91. var fileArea = $("#fileArea");
  92. fileList.push({
  93. file_url: fileArea.attr('href'),
  94. origin_name: fileArea.text()
  95. });
  96. if (fileList.length < 1) {
  97. layer.alert('请先上传文件再保存', {icon: 0});
  98. return;
  99. }
  100. var ajaxConfig = {
  101. url: '/admin/process/file-upload/{{$siteProcess->id}}',
  102. type: 'post',
  103. data: {file_list: fileList},
  104. success: function (result) {
  105. layer.msg(result.message, {icon: 6, time: 1000}, function () {
  106. parent.window.location.reload();
  107. tips.closeParentLayer();
  108. });
  109. }
  110. };
  111. tips.ajax(ajaxConfig);
  112. }
  113. };
  114. var siteProcessId = "{{$siteProcess->id}}";
  115. $(document).on('click', '[name=file_upload]', function () {
  116. $(this).next().trigger('click');
  117. });
  118. // $(document).on('change', '[name=uploadFile]', function () {
  119. //
  120. // if (!$(this)[0].files[0]) {
  121. // return;
  122. // }
  123. //
  124. // var formData = new FormData();
  125. // formData.append('file', $(this)[0].files[0]);
  126. //
  127. // formData.append('siteProcessId', siteProcessId);
  128. // var ln;
  129. // $.ajax({
  130. // url: '/admin/process/file-upload',
  131. // type: 'POST',
  132. // cache: false,
  133. // data: formData,
  134. // processData: false,
  135. // contentType: false,
  136. // beforeSend: function () {
  137. // ln = layer.load();
  138. // },
  139. // complete: function () {
  140. // layer.close(ln);
  141. // },
  142. // success: function (result) {
  143. // var data = result.data;
  144. // console.log(units);
  145. // return;
  146. // $("#file").append(units.generateHtml(data.file_url, data.original_name));
  147. // },
  148. // error: function (XMLHttpRequest) {
  149. // if (XMLHttpRequest.status === 500) {
  150. // layer.alert("异步请求失败", {icon: 5});
  151. // return;
  152. // }
  153. // layer.alert(JSON.parse(XMLHttpRequest.responseText).message, {icon: 0});
  154. // }
  155. // });
  156. // });
  157. $(document).on('click', '#confirm', function () {
  158. var config = {};
  159. config.url = '/admin/process/confirm';
  160. config.type = 'put';
  161. config.data = {siteProcessId: siteProcessId};
  162. tips.ajax(config);
  163. });
  164. </script>
  165. @endsection