rent-list.blade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. @extends('admin.layout-content')
  2. @section('header')
  3. <style>
  4. </style>
  5. @endsection
  6. @section('content')
  7. <div class="layui-card">
  8. <div class="layui-card-header sg-card-header">
  9. 租赁订单设备列表
  10. <div class="sg-card-create">
  11. <button id="sg-import-all" class="layui-btn layui-btn-sm layui-btn-normal">导出订单</button>
  12. </div>
  13. </div>
  14. <div class="layui-card-body">
  15. <form class="layui-form" id="sg-search-form">
  16. <input type="hidden" name="type" value="rent">
  17. <div class="layui-form-item">
  18. <div class="layui-inline" style="display: flex;align-items: center">
  19. @include('share.device-select-form', ['device_id' => '', 'device_name_id' => '', 'spec_id' => '', 'options' => $options])
  20. </div>
  21. <div class="layui-inline" style="display: flex;align-items: center">
  22. @include('share.project-work-point-select-form', ['project_id' => '', 'work_point_id' => '', 'options' => $project_work_point_options])
  23. <div class="layui-inline " style="margin-left: 20px;margin-bottom: 15px">
  24. <div class="layui-btn" id="sg-search-btn">搜索</div>
  25. </div>
  26. </div>
  27. </div>
  28. </form>
  29. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  30. <script type="text/html" id="sg-table-bar">
  31. <div class="layui-btn-group">
  32. <div class="layui-btn-group">
  33. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  34. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  35. </div>
  36. </div>
  37. </script>
  38. </div>
  39. </div>
  40. @endsection
  41. @section('footer')
  42. <script>
  43. $(function () {
  44. layui.use(['table', 'layer'], function(){
  45. var table = layui.table,
  46. layer = layui.layer,
  47. form = layui.form,
  48. laydate = layui.laydate,
  49. top_window = window;
  50. $('#sg-back-btn').on('click', function () {
  51. window.history.go(-1);
  52. });
  53. table.render({
  54. elem: '#sg-main-table',
  55. url: '{{ $pre_uri }}' + 'get',
  56. cellMinWidth: 80,
  57. cols: [[
  58. { field: 'order_id', title: '订单ID', align: 'center' },
  59. { field: 'order_number', title: '订单编号', align: 'center' },
  60. { field: 'project_name', title: '在用项目', align: 'center' },
  61. { field: 'work_point_name', title: '工点', align: 'center' },
  62. { field: 'device_type_name', title: '租赁设备类型', align: 'center' },
  63. { field: 'device_name_name', title: '租赁设备名称', align: 'center' },
  64. { field: 'spec_name', title: '设备规格型号', align: 'center' },
  65. { field: 'rent_type_name', title: '租赁方式', align: 'center' },
  66. { field: 'price', title: '租赁单价', align: 'center' },
  67. { field: 'quantity', title: '租赁计数', align: 'center' },
  68. { field: 'start_date', title: '租赁开始时间', align: 'center' },
  69. { field: 'end_date', title: '租赁结束时间', align: 'center' },
  70. { field: 'money', title: '租赁总金额', align: 'center' },
  71. // { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  72. ]],
  73. page: {
  74. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  75. limit: 15
  76. },
  77. even: true,
  78. where: transformToJson($('#sg-search-form').serializeArray()),
  79. done: function(res, curr, count) {
  80. }
  81. });
  82. table.on('tool(tableEvent)', function(obj){
  83. var data = obj.data;
  84. if(obj.event === 'delete'){
  85. layer.confirm('确定要删除吗?', function(index) {
  86. $.ajax({
  87. method: 'POST',
  88. url: '{{ $pre_uri }}' + 'delete',
  89. headers: {
  90. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  91. },
  92. data: {
  93. id: data.id
  94. },
  95. success: function (data) {
  96. if(data.status === 'success') {
  97. obj.del();
  98. } else {
  99. layer.msg(data.info, {
  100. icon: 2
  101. });
  102. }
  103. layer.close(index);
  104. },
  105. error: function () {
  106. layer.close(index);
  107. layer.msg('删除失败', {
  108. icon: 2
  109. });
  110. }
  111. });
  112. });
  113. } else if(obj.event === 'edit') {
  114. layer.open({
  115. title: '编辑成员',
  116. type: 2,
  117. area: ['90%', '90%'],
  118. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  119. end: function () {
  120. top_window.location.reload();
  121. }
  122. });
  123. }
  124. });
  125. if($('#search-begin-date').length > 0) {
  126. laydate.render({
  127. elem: '#search-begin-date',
  128. done: function () {
  129. updateTableBySearch();
  130. }
  131. });
  132. }
  133. if($('#search-end-date').length > 0) {
  134. laydate.render({
  135. elem: '#search-end-date',
  136. done: function () {
  137. updateTableBySearch();
  138. }
  139. });
  140. }
  141. function transformToJson(formData){
  142. var obj={};
  143. for (var i in formData) {
  144. obj[formData[i].name]=formData[i]['value'];
  145. }
  146. return obj;
  147. }
  148. function updateTableBySearch() {
  149. table.reload('sg-main-table', {
  150. where: transformToJson($('#sg-search-form').serializeArray()),
  151. page: {
  152. curr: 1
  153. }
  154. });
  155. }
  156. $('#sg-search-btn').click(function() {
  157. updateTableBySearch();
  158. });
  159. // $('#sg-search-form').change(function () {
  160. // updateTableBySearch();
  161. // });
  162. //
  163. // form.on('select()', function(){
  164. // updateTableBySearch();
  165. // });
  166. $('#sg-create-btn').on('click', function () {
  167. layer.open({
  168. title: '创建' + '{{ $model_name }}',
  169. type: 2,
  170. area: ['90%', '90%'],
  171. content: '{{ $pre_uri }}' + 'create',
  172. end: function () {
  173. top_window.location.reload();
  174. }
  175. });
  176. });
  177. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  178. layer.confirm('确定要删除所有选中行吗?', function () {
  179. var data = table.checkStatus('sg-main-table').data;
  180. if(data.length <= 0) {
  181. layer.msg('选择不能为空', {
  182. icon: 2
  183. });
  184. return false;
  185. }
  186. var ids = [];
  187. for(var i = 0; i < data.length; ++i) {
  188. ids.push(data[i]['id']);
  189. }
  190. $.ajax({
  191. method: 'POST',
  192. url: '{{ $pre_uri }}' + 'deleteMany',
  193. headers: {
  194. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  195. },
  196. data: {
  197. ids: JSON.stringify(ids)
  198. },
  199. success: function (data) {
  200. if(data.status === 'success') {
  201. top_window.location.reload();
  202. } else {
  203. layer.msg(data.info, {
  204. icon: 2
  205. });
  206. }
  207. },
  208. error: function () {
  209. layer.msg('删除失败', {
  210. icon: 2
  211. });
  212. }
  213. });
  214. })
  215. });
  216. /**
  217. *下载订单
  218. */
  219. $('#sg-import-all').click(function() {
  220. var data = transformToJson($('#sg-search-form').serializeArray());
  221. var url = '{{ $pre_uri }}' + 'export?device_id='+data.device_id
  222. +'&device_name_id='+data.device_name_id
  223. +'&project_id='+data.project_id
  224. +'&spec_id='+data.spec_id
  225. +'&type='+data.type
  226. +'&work_point_id='+data.work_point_id;
  227. window.location = url;
  228. console.log(data)
  229. $.ajax({
  230. method: 'POST',
  231. url: '{{ $pre_uri }}' + 'export',
  232. headers: {
  233. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  234. },
  235. data:data,
  236. success: function (data) {
  237. // var blob = new Blob([data]); //data.Body是文件
  238. // let blobUrl = URL.createObjectURL(blob)
  239. // var blob = new Blob([data], {type:'application/vnd.ms-excel'}),
  240. // fileName = '租赁设备.xls';
  241. // downFile(blob, fileName);
  242. },
  243. error: function () {
  244. }
  245. });
  246. });
  247. function downFile(blob, fileName) {
  248. if (window.navigator.msSaveOrOpenBlob) {
  249. navigator.msSaveBlob(blob, fileName);
  250. } else {
  251. var link = document.createElement('a');
  252. link.href = window.URL.createObjectURL(blob);
  253. link.download = fileName;
  254. link.click();
  255. window.URL.revokeObjectURL(link.href);
  256. link.remove;
  257. }
  258. }
  259. function blobify(strData) { var buf = new ArrayBuffer(strData.length), view = new Uint8Array(buf); for (var i=0; i!=strData.length; ++i) view[i] = strData.charCodeAt(i) & 0xFF; return buf;
  260. }
  261. });
  262. })
  263. </script>
  264. @endsection