visual.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. @extends('layouts.app')
  2. @section('title')料箱分布 - 监视器@endsection
  3. @section('content')
  4. <div class="container-fluid d-none" id="container">
  5. <div class="row mt-5 mb-5 text-center">
  6. <div class="col-6 offset-3 row">
  7. <b>总占有率:</b>
  8. <div class="progress w-75">
  9. <div class="progress-bar bg-danger" :style="{width:statistic.np1+'%'}">@{{ statistic.np1+'%' }}</div>
  10. <div class="progress-bar bg-warning text-dark" :style="{width:statistic.np2+'%'}">@{{ statistic.np2+'%' }}</div>
  11. <div class="progress-bar bg-success" :style="{width:statistic.np3+'%'}">@{{ statistic.np3+'%' }}</div>
  12. </div>
  13. </div>
  14. <div class="col-6 offset-3 row mt-5">
  15. <b>共:@{{ this.statistic.sum }}</b>
  16. <div class="col-1 bg-danger text-white ml-2 font-weight-bold">@{{ this.statistic.number1 }}</div>
  17. <div class="col-1">非空</div>
  18. <div class="col-1 bg-warning offset-2 text-dark font-weight-bold">@{{ this.statistic.number2 }}</div>
  19. <div class="col-1">空架</div>
  20. <div class="col-1 bg-success offset-2 text-white font-weight-bold cursor-pointer" @click="getBoxes()">@{{ this.statistic.number3 }}</div>
  21. <div class="col-1">空箱</div>
  22. </div>
  23. </div>
  24. <div class="row bg-dark">
  25. <div class="col-6 row mt-2 mb-2" v-for="(arr,i) in data">
  26. <div class="offset-1 col-10 row">
  27. <div style="width: 12.5%" v-for="(val,j) in arr">
  28. <div class="progress mr-2" v-if="val===undefined">
  29. <div class="w-100 text-center d-inline-block"><i class="fa fa-spinner fa-pulse"></i></div>
  30. </div>
  31. <div class="progress mr-2" style="cursor: pointer" v-else @click="loadDetail(i,j)">
  32. <div class="progress-bar bg-danger" :style="{width:val[0]+'%'}">@{{ val[0]+'%' }}</div>
  33. <div class="progress-bar bg-warning" :style="{width:val[1]+'%'}">@{{ val[1]+'%' }}</div>
  34. <div class="progress-bar bg-success" :style="{width:val[2]+'%'}">@{{ val[2]+'%' }}</div>
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. @include("station.monitor._loadDetail")
  41. </div>
  42. @endsection
  43. @section('lastScript')
  44. <script>
  45. let vue = new Vue({
  46. el:"#container",
  47. data:{
  48. rowSize:8, //单排大小:X列
  49. columnSize:4,//单列大小 X竖
  50. heightSize:10,//高度大小 X行
  51. maxLoadSize:18,//最大加载大小 X排
  52. data:[],//数据池
  53. prefix:"HAI",
  54. mapping:[],
  55. details:{}, //详情池
  56. detail:[], //当前详情
  57. loadStatus:false,
  58. sum:0,
  59. quantity:0,
  60. val:0,
  61. statistic:{
  62. sum : 0,//总量
  63. number1 : 0,//空架
  64. number2 : 0,//非空箱
  65. number3 : 0,//空箱
  66. np1:100,
  67. np2:0,
  68. np3:0,
  69. },
  70. blacklist:{
  71. "HAI01-045-%":[
  72. "HAI01-045-01",
  73. "HAI01-045-02",
  74. "HAI01-045-03",
  75. "HAI01-045-04",
  76. ],
  77. "HAI01-046-%":[
  78. "HAI01-046-01",
  79. "HAI01-046-02",
  80. "HAI01-046-03",
  81. "HAI01-046-04",
  82. ],
  83. "HAI01-047-%":[
  84. "HAI01-047-01",
  85. "HAI01-047-02",
  86. "HAI01-047-03",
  87. "HAI01-047-04",
  88. ],
  89. "HAI01-048-%":[
  90. "HAI01-048-01",
  91. "HAI01-048-02",
  92. "HAI01-048-03",
  93. "HAI01-048-04",
  94. ],
  95. },
  96. },
  97. mounted() {
  98. let data = [];
  99. for (let i=this.maxLoadSize;i>0;i--){
  100. let arr = [];
  101. for (let j=0;j<this.rowSize;j++){
  102. arr.push(undefined);
  103. }
  104. data.push(arr);
  105. this.loadData(i,data.length);
  106. }
  107. this.data = data;
  108. $("#container").removeClass("d-none");
  109. },
  110. methods:{
  111. loadData(row,index){
  112. let size = this.rowSize*this.columnSize;
  113. if (row%2!==0){
  114. size *= 2;
  115. row += 1;
  116. }
  117. row = row/2;
  118. let len = row.toString().length;
  119. let before = "00";
  120. let location = (this.prefix+(len===2 ? (Math.ceil(row)).toString() :
  121. before.substr(0,2-len)+(Math.ceil(row)).toString()))+'-';
  122. let arr = [];
  123. let temp = [];
  124. for (let i=size-(this.rowSize*this.columnSize)+1;i<=size;i++){
  125. temp.push(location+(before.substr(0,3-(i.toString().length))+i.toString())+"-%");
  126. if (i%this.columnSize===0){arr.push(temp);temp = [];}
  127. }
  128. this.mapping.push(arr);
  129. let max = this.columnSize * this.heightSize;
  130. <<<<<<< HEAD
  131. console.log(arr);
  132. /*window.tempTip.postBasicRequest("{{url('station/monitor/visual/getData')}}",{arr:arr},res=>{
  133. =======
  134. window.tempTip.postBasicRequest("{{url('station/monitor/visual/getData')}}",{arr:arr},res=>{
  135. >>>>>>> b0347ca84d8eeedd9c1ac88b1c55b77c6a0613e8
  136. let sub = {};
  137. arr.forEach((ar,i)=>{
  138. for (let key in this.blacklist){
  139. if (ar.indexOf(key)!==-1){
  140. if (!sub['_'+i])sub['_'+i] = this.blacklist[key].length;
  141. else sub['_'+i] += this.blacklist[key].length;
  142. }
  143. }
  144. });
  145. res.forEach((ar,i)=>{
  146. let amount = max;
  147. if (sub['_'+i])amount -= sub['_'+i];
  148. let sum = Number(ar[0]);
  149. let quantity = Number(ar[1]);
  150. let number2 = Number(this.accSubtr(amount,sum));
  151. let number3 = Number(this.accSubtr(sum,quantity));
  152. let q1 = this.accDivCoupon(quantity,amount)
  153. let q2 = this.accDivCoupon(number2,amount)
  154. let q3 = this.accDivCoupon(number3,amount)
  155. this.$set(this.data[index-1],i,[q1,q2,q3]);
  156. this.statistic.sum += amount;
  157. this.statistic.number1 += quantity;
  158. this.statistic.number2 += number2;
  159. this.statistic.number3 += number3;
  160. this.statistic.np1 = this.accDivCoupon(this.statistic.number1,this.statistic.sum);
  161. this.statistic.np2 = this.accDivCoupon(this.statistic.number2,this.statistic.sum);
  162. this.statistic.np3 = this.accDivCoupon(this.statistic.number3,this.statistic.sum);
  163. });
  164. <<<<<<< HEAD
  165. });*/
  166. =======
  167. });
  168. >>>>>>> b0347ca84d8eeedd9c1ac88b1c55b77c6a0613e8
  169. },
  170. loadDetail(index,j){
  171. $("#modal").modal('show');
  172. let key = index+'-'+j;
  173. if (this.details[key]){ //缓存池存在取缓存池 转为即时后关闭缓存池即可
  174. this.detail = this.details[key];
  175. return;
  176. }
  177. let arr = this.mapping[index][j];
  178. let res = []; //扁平化的库位参数 一维数组
  179. let before = "00";//前缀
  180. let maxLen = 2;//最大高度 位数
  181. let rowIndex = 0;//行下标记录
  182. let mapping = {};//库位与数据池的下标映射
  183. let detail = [];//数据池
  184. for (let i=this.heightSize;i>0;i--){
  185. let columnIndex = 0;//列下标记录
  186. let detailTemp = [];//数据池第二维数组
  187. let suffix = i.toString().length<maxLen ? before.substr(0,maxLen-i.toString().length)+i.toString() : i.toString();
  188. for (let k=arr.length-1;k>=0;k--){
  189. let val = arr[k].substr(0,arr[k].length-1)+suffix;
  190. if (this.blacklist[arr[k]] && this.blacklist[arr[k]].indexOf(val)!==-1)continue;
  191. res.push(val);
  192. detailTemp.push({location:val,status:undefined});
  193. mapping[val] = [rowIndex,columnIndex];
  194. columnIndex++;
  195. }
  196. detail.push(detailTemp);
  197. rowIndex++;
  198. }//用对象将数据池结构组装占位,用mapping来映射库位与其应在数据池内的实际下标,拿到真实数据后根据映射进行填充
  199. this.loadStatus = true;//开启加载动画
  200. //启异步请求数据
  201. window.tempTip.postBasicRequest("{{url('station/monitor/visual/getDetail')}}",{arr:res},res=>{
  202. if (res){
  203. res.forEach(obj=>{
  204. if (mapping[obj.location]){
  205. detail[mapping[obj.location][0]][mapping[obj.location][1]] = obj;
  206. }
  207. });//真实数据查找映射填充
  208. }
  209. this.detail = detail;//扔进当前详情列表
  210. this.details[key] = detail;//缓存结果
  211. setTimeout(()=>{
  212. this.details[key] = undefined;
  213. },1800000);//缓存池半小时后清除
  214. this.loadStatus = false;//加载完毕
  215. });
  216. },
  217. accSubtr(arg1,arg2){
  218. let r1,r2,m,n;
  219. try{r1=arg1.toString().split(".")[1].length;}catch(e){r1=0;}
  220. try{r2=arg2.toString().split(".")[1].length;}catch(e){r2=0;}
  221. m=Math.pow(10,Math.max(r1,r2));
  222. //动态控制精度长度
  223. n=(r1>=r2)?r1:r2;
  224. return ((arg1*m-arg2*m)/m).toFixed(n);
  225. },
  226. accDivCoupon(arg1,arg2){
  227. let t1=0,t2=0,r1,r2;
  228. try{t1=arg1.toString().split(".")[1].length;}catch(e){}
  229. try{t2=arg2.toString().split(".")[1].length;}catch(e){}
  230. with(Math){
  231. r1=Number(arg1.toString().replace(".",""));
  232. r2=Number(arg2.toString().replace(".",""));
  233. return Math.round((r1/r2)*pow(10,t2-t1)*10000)/100;
  234. }
  235. },
  236. getBoxes(){
  237. console.warn("稍等下......");
  238. $("#modal").hide();
  239. for (let i=0;i<vue.data.length;i++){
  240. for (let j=0;j<vue.data[i].length;j++){
  241. if (vue.data[i][j][2]>0){
  242. vue.loadDetail(i,j);
  243. }
  244. }
  245. }
  246. setTimeout(()=>{
  247. let loc = [];
  248. for (let key in vue.details){
  249. for (let i=0;i<vue.details[key].length;i++){
  250. for (let j=0;j<vue.details[key][i].length;j++){
  251. let obj = vue.details[key][i][j];
  252. if (obj.status===false){
  253. loc.push(obj.location);
  254. }
  255. }
  256. }
  257. }
  258. window.tempTip.postBasicRequest("{{url('station/monitor/visual/getBoxes')}}",{arr:loc},res=>{
  259. console.log(res);
  260. });
  261. },3000)
  262. }
  263. },
  264. filters:{
  265. reduce(val){
  266. let r2,m,n;
  267. try{r2=val.toString().split(".")[1].length}catch(e){r2=0}
  268. m=Math.pow(10,Math.max(0,r2));
  269. n=(0>=r2)?0:r2;
  270. return (((100*m-val*m)/m).toFixed(n))+"%";
  271. }
  272. }
  273. });
  274. </script>
  275. @endsection