index.blade.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. @extends('layouts.app')
  2. @section('title')设备@endsection
  3. @section('content')
  4. @component('weight.menu')@endcomponent
  5. <div class="page-holder w-100 d-flex flex-wrap" id="list">
  6. <div class="container-fluid px-xl-5">
  7. <section class="py-5">
  8. <div class="row">
  9. <div class="col-lg-12 mb-4">
  10. <audio id="audio" src="" autoplay></audio>
  11. <div class="card">
  12. <div class="card-header">
  13. <div class="form-inline">
  14. <h5>
  15. <ul class="nav nav-pills">
  16. <b style="padding: 10px">请选择设备:</b>
  17. <li v-for="measuringMachine in measuringMachines" @click="clickMeasuringMachine(measuringMachine.id)" :class="[measuringMachine.name==package.measuringMachine ? selectedMachine : otherMachine] " style="padding: 10px">
  18. <span v-if="package.measuringMachine==measuringMachine.name" :class="[package.measuringMachine_status=='离线' ? off : on] " style="font-size:12px;"></span>
  19. <span v-else :class="[measuringMachine.status=='离线' ? off : on] " style="font-size:12px;"></span>
  20. <a style="text-decoration:none;cursor:pointer" class="text-dark" >@{{measuringMachine.name}}</a>
  21. </li>
  22. </ul>
  23. </h5>
  24. </div>
  25. <div class="card-body" v-if="package.id">
  26. <h1>
  27. <table class="table card-text dashboard" :class="[package.measuringMachine_status=='在线'?'on':'off']" style="height: 800px">
  28. <tr>
  29. <th class="tag" scope="row">货主</th>
  30. <td style="border-right:thick double #aaaaaa;">@{{package.owner}}</td>
  31. <th class="tag" scope="row" scope="row">重量(KG)</th>
  32. <td>@{{package.weight}}</td>
  33. </tr>
  34. <tr>
  35. <th class="tag" scope="row" scope="row">发货单号</th>
  36. <td style="border-right:thick double #aaaaaa;">@{{package.delivery_number}}</td>
  37. <th class="tag" scope="row" scope="row">收件人</th>
  38. <td>@{{package.recipient}}</td>
  39. </tr>
  40. <tr>
  41. <th class="tag" scope="row" scope="row">承运商</th>
  42. <td style="border-right:thick double #aaaaaa;">@{{package.logistic}}</td>
  43. <th class="tag" scope="row" scope="row">快递单号</th>
  44. <td>@{{package.logistic_number}}</td>
  45. </tr>
  46. <tr>
  47. <th class="tag" scope="row" scope="row">纸箱名称</th>
  48. <td style="border-right:thick double #aaaaaa;">@{{package.paperBox}}</td>
  49. <th class="tag" scope="row" scope="row">体积(CM³)</th>
  50. <td>@{{package.bulk}}</td>
  51. </tr>
  52. <tr>
  53. <th class="tag" scope="row" scope="row">状态</th>
  54. <td style="border-right:thick double #aaaaaa;">@{{package.status}}</td>
  55. <th class="tag" scope="row" scope="row">操作时间</th>
  56. <td>@{{package.weighed_at}}</td>
  57. </tr>
  58. </table>
  59. </h1>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </section>
  66. </div>
  67. </div>
  68. @endsection
  69. @section('lastScript')
  70. <style>
  71. #selected a:hover{background-color: #4aa0e6;display: block;cursor:pointer}
  72. .dashboard.off .tag {color:red;}
  73. .dashboard.on .tag {color:green;}
  74. </style>
  75. <script>
  76. let vue=new Vue({
  77. el:'#list',
  78. data:{
  79. package:
  80. {id:'',logistic_number:'',delivery_number:'',
  81. weight:'',owner:'',paperBox:'',
  82. measuringMachine:'',recipient:'',measuringMachine_status:'',
  83. status:'',weighed_at:'',bulk:'',logistic:''},
  84. measuringMachines:[
  85. @foreach($measuringMachines as $measuringMachine)
  86. {id:'{{$measuringMachine->id}}',name:'{{$measuringMachine->name}}',code:'{{$measuringMachine->code}}',status:'{{$measuringMachine->status}}',},
  87. @endforeach
  88. ],
  89. on:'fa fa-circle text-success',
  90. off:'fa fa-circle text-danger',
  91. selectedMachine:'nav-item btn btn-primary',
  92. otherMachine:'nav-item',
  93. onColor:{color:'green'},
  94. offColor:{color:'red'},
  95. },
  96. mounted(){
  97. initEcho();
  98. Echo.channel('bswas_database_package').listen('.weight',(e)=>{
  99. let package=e.package;
  100. let _this=this;
  101. let audio=document.getElementById('audio');
  102. if (package){
  103. if (package.id===_this.package.id){
  104. _this.package.measuringMachine_status=package.measuringMachine_status;
  105. tempTip.setDuration(4000);
  106. tempTip.showSuccess('暂无新数据');
  107. }else {
  108. _this.updateData(_this,package);
  109. axios.post('/package/measureMonitor/speech',{logistic:package.logistic_name})
  110. .then(function (response) {
  111. if (response.data){
  112. audio.src=response.data;
  113. audio.play();
  114. }else {
  115. tempTip.setDuration(4000);
  116. tempTip.showSuccess('文件名不规范!');
  117. }
  118. })
  119. .catch(function (err) {
  120. tempTip.setDuration(4000);
  121. tempTip.showSuccess('语音合成发生错误:'+err);
  122. });
  123. tempTip.setDuration(4000);
  124. tempTip.showSuccess('刷新成功!');
  125. }
  126. }
  127. });
  128. /* if(this.timer){
  129. clearInterval(this.timer);
  130. }else {
  131. this.timer=setInterval(()=>{this.flushData();},18000);
  132. }*/
  133. },
  134. methods:{
  135. clickMeasuringMachine(e){
  136. let _this=this;
  137. axios.post('/package/measureMonitor/data',{id:e})
  138. .then(function (response) {
  139. if (response.data.id){
  140. let package=response.data;
  141. _this.updateData(_this,package);
  142. }else {
  143. tempTip.setDuration(4000);
  144. tempTip.showSuccess('暂无数据!');
  145. }
  146. })
  147. .catch(function (err) {
  148. tempTip.setDuration(4000);
  149. tempTip.showSuccess('切换设备错误:'+err);
  150. });
  151. },
  152. updateData(_this,package){
  153. _this.package.id=package.id;
  154. _this.package.logistic_number=package.logistic_number;_this.package.delivery_number=package.delivery_number;
  155. _this.package.weight=package.weight;_this.package.owner=package.owner_name;
  156. _this.package.paperBox=package.paperBox_name;_this.package.measuringMachine=package.measuringMachine_name;
  157. _this.package.recipient=package.recipient;_this.package.status=package.status;
  158. _this.package.weighed_at=package.weighed_at;_this.package.bulk=package.bulk;
  159. _this.package.logistic=package.logistic_name;
  160. _this.package.measuringMachine_status=package.measuringMachine_status;
  161. }
  162. },
  163. });
  164. </script>
  165. @endsection