index.blade.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. <!DOCTYPE html>
  2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <link rel="icon" href="{{asset('icon/faviconc.ico')}}" type="image/x-icon"/>
  7. <!-- CSRF Token -->
  8. <meta name="csrf-token" content="{{ csrf_token() }}">
  9. <title>设备平面</title>
  10. <link href="{{ mix('css/app.css') }}" rel="stylesheet">
  11. <link href="{{ mix('css/animation.css') }}" rel="stylesheet">
  12. <style>
  13. html{
  14. width: 100%;
  15. height: 100%;
  16. }
  17. body{
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .p1{
  22. overflow: hidden;
  23. text-overflow: ellipsis;
  24. display: -webkit-box;
  25. -webkit-line-clamp: 2;
  26. -webkit-box-orient: vertical;
  27. }
  28. .el-center{
  29. display:flex;
  30. align-items:center;
  31. justify-content:center;
  32. }
  33. .el-left-bottom{
  34. position: absolute;
  35. bottom: 0;
  36. left: 0;
  37. }
  38. .el-right-bottom{
  39. position: absolute;
  40. bottom: 0;
  41. right: 0;
  42. }
  43. .txt-sty{
  44. filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
  45. font-family: "Microsoft YaHei Light","sans-serif";
  46. font-size: 10px;
  47. white-space:nowrap;
  48. font-weight:bold;
  49. }
  50. .re{transform:rotate(-90deg);
  51. -ms-transform:rotate(-90deg); /* Internet Explorer 9*/
  52. -moz-transform:rotate(-90deg); /* Firefox */
  53. -webkit-transform:rotate(-90deg); /* Safari 和 Chrome */
  54. -o-transform:rotate(-90deg); /* Opera */
  55. }
  56. /*opacity是设置遮罩透明度的,可以自己调节*/
  57. #loading{position:fixed;top:0;left:0;width:100%;height:100%;background:#f8f8f8;opacity:0.6;z-index:15000;}
  58. #loading i{position:absolute;top:50%;left:50%;font-size:33px;margin-top:-15px;margin-left:-40px;}
  59. #loading p{position:absolute;top:55%;left:48%;width:33px;height:33px;margin-top:-15px;margin-left:-15px;}
  60. .equipment{
  61. cursor: pointer
  62. }
  63. .equipment-exist{
  64. border-width:2px;
  65. border-style: groove;
  66. border-color: #0000FF;
  67. }
  68. .equipment-not-exist{
  69. opacity: 0.5;
  70. border-width:1px;
  71. border-style: dashed;
  72. border-color: #0070C0;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <div class="container-fluid w-100 h-100" id="container" @mousemove="eqMove()" @mouseup="eqUp()">
  78. <div class="row w-100 h-100">
  79. <div class="col-2 " style="user-select: none;" id="tool">
  80. <div class="dropdown">
  81. <button type="button" class="btn p-0 w-100" id="dropdownMenu"
  82. data-toggle="dropdown">
  83. <h4 class="text-muted mt-1 p1">@{{ name }}&nbsp;&nbsp;<i class="fa fa-exchange text-info"></i></h4>
  84. </button>
  85. <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
  86. <li role="presentation" v-for="warehouse in warehouses" v-if="warehouse.id!==selected">
  87. <a role="menuitem" tabindex="-1" style="cursor: pointer" class="ml-3"
  88. @click="selectedWarehouse(warehouse)">@{{ warehouse.name }}</a>
  89. </li>
  90. <li role="presentation" class="text-center" @click="showAddWarehouseDetail()">
  91. <a role="menuitem" tabindex="-1" style="cursor: pointer" class="ml-3 text-primary"
  92. ><i class="fa fa-plus"></i> 新增</a>
  93. </li>
  94. </ul>
  95. </div>
  96. <button class="btn btn-info mt-5 w-100 text-white" @click="openRepository()">新增库区</button>
  97. <button class="btn btn-success mt-5 w-100 text-white" @click="searchingSelectEq()">批量构建库位</button>
  98. <p class="font-weight-bold p-0 mb-0 mt-1">位置</p>
  99. <div class="row text-muted small">
  100. <small class="col-6">X</small>
  101. <small class="col-6">Y</small>
  102. </div>
  103. <div class="row m-0 p-0">
  104. <input type="number" class="col-5 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.x"
  105. @blur="changeNumber('x')"></input>
  106. <input type="number" class="col-5 offset-1 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.y"
  107. @blur="changeNumber('y')"></input>
  108. </div>
  109. <p class="font-weight-bold p-0 mb-0 mt-3">大小</p>
  110. <div class="row text-muted small">
  111. <small class="col-6">高</small>
  112. <small class="col-6">宽</small>
  113. </div>
  114. <div class="row m-0 p-0">
  115. <input type="number" class="col-5 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.height" @blur="changeNumber('height')"></input>
  116. <input type="number" class="col-5 offset-1 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.width" @blur="changeNumber('width')"></input>
  117. </div>
  118. <p class="font-weight-bold p-0 mb-0 mt-3">其他</p>
  119. <div class="row text-muted small">
  120. <small class="col-6">层级</small>
  121. <small class="col-6">颜色</small>
  122. </div>
  123. <div class="row m-0 p-0">
  124. <input type="number" class="col-5 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.index" @blur="changeNumber('index')"></input>
  125. <input class="col-5 offset-1 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.color" @blur="changeText('color')"></input>
  126. </div>
  127. <div class="row text-muted small">
  128. <small class="col-6">名称</small>
  129. <small class="col-6">名称位置</small>
  130. </div>
  131. <div class="row m-0 p-0">
  132. <input class="col-5 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" :value="currentEl.name" @blur="changeText('name')"></input>
  133. <select class="col-5 offset-1 form-control form-control-sm p-0" :disabled="currentEl.x===undefined" v-model="currentEl.coords">
  134. <option value="左上">左上</option>
  135. <option value="左下">左下</option>
  136. <option value="右上">右上</option>
  137. <option value="右下">右下</option>
  138. <option value="居中">居中</option>
  139. <option value="中上">中上</option>
  140. </select>
  141. </div>
  142. <div class="row text-muted small">
  143. <small class="col-6">边框</small>
  144. </div>
  145. <div class="m-0 small row">
  146. <div class="col-6 p-0">
  147. <div class="form-check">
  148. <label class="form-check-label">
  149. <input type="checkbox" class="form-check-input" v-model="currentEl.border" value="top" :disabled="currentEl.x===undefined">上
  150. </label>
  151. </div>
  152. <div class="form-check">
  153. <label class="form-check-label">
  154. <input type="checkbox" class="form-check-input" v-model="currentEl.border" value="bottom" :disabled="currentEl.x===undefined">下
  155. </label>
  156. </div>
  157. <div class="form-check">
  158. <label class="form-check-label">
  159. <input type="checkbox" class="form-check-input" v-model="currentEl.border" value="left" :disabled="currentEl.x===undefined">左
  160. </label>
  161. </div>
  162. <div class="form-check">
  163. <label class="form-check-label">
  164. <input type="checkbox" class="form-check-input" v-model="currentEl.border" value="right" :disabled="currentEl.x===undefined">右
  165. </label>
  166. </div>
  167. </div>
  168. <div class="col-6 p-0">
  169. <div class="form-check">
  170. <label class="form-check-label">
  171. <button class="btn btn-sm btn-success" @click="addCoords()">生成场景元素</button>
  172. </label>
  173. </div>
  174. <div class="form-check mt-1">
  175. <label class="form-check-label">
  176. <button class="btn btn-sm btn-success" @click="openBuildEquipmentGroup()">构建设备组</button>
  177. </label>
  178. </div>
  179. </div>
  180. </div>
  181. <p class="font-weight-bold p-0 mb-0 mt-5 h5">全局</p>
  182. <div class="row text-muted">
  183. <div class="col-4">缩放</div>
  184. <div class="input-group input-group-sm col-8 m-0">
  185. <input type="number" class="form-control" step="1" v-model="scale"></input>
  186. <div class="input-group-append">
  187. <span class="input-group-text">%</span>
  188. </div>
  189. </div>
  190. </div>
  191. <div class="row text-muted mt-1">
  192. <div class="col-4">库位比</div>
  193. <div class="input-group input-group-sm col-8 m-0">
  194. <input class="switch" type="checkbox" @change="loadElement()"/>
  195. </div>
  196. </div>
  197. <div class="row mt-3">
  198. <h5 class="font-weight-bold ml-3">设备</h5>
  199. <div class="form-check ml-3">
  200. <label class="form-check-label">
  201. <input type="checkbox" class="form-check-input" v-model="grid">网格
  202. </label>
  203. <label class="form-check-label ml-4">
  204. <input type="checkbox" class="form-check-input" v-model="turn">翻转
  205. </label>
  206. </div>
  207. </div>
  208. <div style="height: 250px;overflow-y: auto;overflow-x: hidden" class="w-100">
  209. <div class="row" v-for="equipment in equipments" @mousedown="eqDown(equipment)">
  210. <div class="col-5">
  211. <div style="border: 1px #0070C0 solid" :style="[{backgroundColor:equipment.color},{width:(equipment.h*ratio)+'px'},{height:(equipment.w*ratio)+'px'}]"></div>
  212. </div>
  213. <div class="col-7 p1">
  214. @{{ equipment.describe }}
  215. </div>
  216. </div>
  217. </div>
  218. <button @click="clickEditOrSave()" :class="isNotEdit ? 'btn-info' : 'btn-success'"
  219. style="position:absolute;bottom: 20px;cursor: pointer" class="btn col-10 text-white">
  220. <span v-if="isNotEdit">开启场景编辑</span>
  221. <span v-else>保存更改</span>
  222. </button>
  223. </div>
  224. <div class="col-10 p-0">
  225. <div class="w-100 bg-secondary" id="canvasApp" style="height: 100vh;overflow: auto;user-select: none;">
  226. <div id="canvas" v-if="isLoad" @keydown.delete="delElement()" :style="[{width:container.width*(scale/100)+'px'},{height:container.height*(scale/100)+'px'},{transform: 'scale('+(scale/100)+')'}]"
  227. style="position: relative;transform-origin: 0 0" class="bg-white"
  228. @mousedown="contentOnmousedown" @mousemove="contentOnmousemove" @mouseup="contentOnmouseup">
  229. <vue-drag-resize v-for="(element,index) in elements" v-if="!element.removeSign"
  230. @activated="onActivated(element)"
  231. @dragging="onDragging"
  232. @resizing="onResizing"
  233. :minw="1" :minh="1"
  234. :style="[{backgroundColor:element.color},
  235. element.border.indexOf('left')===-1 ? {borderLeft:'none'} : {},
  236. element.border.indexOf('right')===-1 ? {borderRight:'none'} : {},
  237. element.border.indexOf('top')===-1 ? {borderTop:'none'} : {},
  238. element.border.indexOf('bottom')===-1 ? {borderBottom:'none'} : {}]"
  239. style="border-width:1px;border-color: #000000;border-style: solid"
  240. :key="index" :prevent-active-behavior="isNotEdit"
  241. :parent-limitation="true" :w="element.width*ratio" :h="element.height*ratio"
  242. :x="element.x" :y="element.y" :z="element.index">
  243. <div :class="coordsMapping[element.coords]">@{{ element.name }}</div>
  244. </vue-drag-resize>
  245. <vue-drag-resize class="equipment"
  246. v-for="(element,index) in equipmentElements" @clicked="showDetail(element)"
  247. :id="'eq-'+index" :class="element.exist ? 'equipment-exist' : 'equipment-not-exist'"
  248. v-if="!element.removeSign"
  249. :is-resizable="false" :snap-to-grid="grid" :grid-x="40" :grid-y="30"
  250. :style="[{backgroundColor:element.color}]"
  251. @activated="onActivated(element)"
  252. @dragging="equipmentDrag"
  253. :key="'eq-'+index+element.turn" :prevent-active-behavior="isNotEdit"
  254. :parent-limitation="true" :w="(element.turn ? element.w : element.h)*ratio"
  255. :h="(element.turn ? element.h : element.w)*ratio"
  256. :x="element.x" :y="element.y" :z="90">
  257. <div class="h-100 w-100" v-if="isShowRatio">
  258. <div class="h-100 w-100 p-0" v-if="element.children && element.children.length>0">
  259. <div :style="{height:100/element.children.length+'%'}" v-for="(child,idx) in element.children"
  260. :class="(element.children[element.children.length-1-idx]).location_tab==='0-0' ? '' : 'bg-danger'"
  261. class="border border-dark text-dark small el-center w-100 m-0">
  262. @{{ (element.children[element.children.length-1-idx]).location_tab | formatCount }}
  263. </div>
  264. </div>
  265. <div class="h-100 w-100 txt-sty el-center" v-else>
  266. <i class="fa fa-spinner fa-spin"></i>
  267. </div>
  268. </div>
  269. <div class="h-100 txt-sty w-100 el-center" :class="element.turn ? 're' : ''" v-else>@{{ element.code}}</div>
  270. </vue-drag-resize>
  271. </div>
  272. </div>
  273. </div>
  274. <textarea hidden id="clipboardDiv" style="opacity:0"></textarea>
  275. <div id="loading" class="list-item">
  276. <i class="fa fa-spinner fa-spin"></i>
  277. <p style="line-height: 24px;">loading...</p>
  278. </div>
  279. </div>
  280. @include("equipment._detailInfo")
  281. @include("equipment._location")
  282. @include("equipment._warehouseDetail")
  283. @include("equipment._repository")
  284. @include("equipment._buildGroup")
  285. @include("equipment._locationAttr")
  286. @include("equipment._failTipList")
  287. </div>
  288. </body>
  289. <script src="{{ mix('js/app.js') }}"></script>
  290. <script src="{{ asset('js/utilities/drawCheckbox.js') }}"></script>
  291. <script src="{{ asset('js/utilities/h2can.min.js') }}"></script>
  292. <script src="{{ asset('js/utilities/jcanvas.min.js') }}"></script>
  293. <script src="{{ asset('js/utilities/toast.js') }}"></script>
  294. <script type="text/javascript">
  295. var vue = new Vue({
  296. el:"#container",
  297. data:{
  298. increment:true,
  299. group:[],//库区列表
  300. ws:[],//仓库列表
  301. locationMapping:{},//库位的信息映射
  302. warehouseDetail:{},//当前操作的仓库
  303. repository:{},//当前操作的库区
  304. warehouses:[], //仓库描述
  305. repositories:[], //库区
  306. selected:"", //当前选中的仓库ID
  307. container:{width:90,height:60}, //容器初始大小
  308. ratio:20, //设备大小缩放比例值
  309. name:"", //当前选中的仓库NAME
  310. isNotEdit:true, //是否允许编辑
  311. isLoad:true, //是否加载
  312. currentEl:{}, //当前选中的元素
  313. coordsMapping:{ //元素信息映射
  314. "居中":"h-100 w-100 el-center",
  315. "中上":"text-center",
  316. "左上":"",
  317. "左下":"el-left-bottom",
  318. "右上":"text-right",
  319. "右下":"el-right-bottom",
  320. },
  321. elements:[], //场景元素池
  322. clientCoords:{}, //坐标系记录
  323. scale:100, //缩放值
  324. equipments:[ //备选设备池
  325. ],
  326. currentEq:{ //选中的设备
  327. el:null,
  328. obj:null,
  329. },
  330. equipmentElements:[], //设备元素池
  331. grid:false, //设备拖拽是否开启网格
  332. turn:true, //设备是否翻转
  333. isLoadLocation:false, //开启加载库位
  334. //baseUrl:"http://127.0.0.1:8112/",
  335. baseUrl:"https://api.baoshi56.com/",
  336. current:{}, //当前操作的设备
  337. error:{},
  338. locations:[], //库位信息
  339. currentEqChildIndex:null, //当前节点下标
  340. buildPool:{}, //库位构建信息
  341. client:{}, //复制后的坐标记录
  342. buildEqInfo:{}, //设备组构建信息
  343. charArr : [...Array(26).keys()].map(i => String.fromCharCode(i + 65)), //A-Z字符
  344. elSeList:[
  345. {id:-1,w:1.2,h:2.4,grid:2,color:"RGB(255,255,0)",describe:"消防栓设施或立柱,不可设库位"},
  346. ],//场景元素预设列表
  347. locationAttr:null,//库位建立时的可选择属性
  348. batchEquipment:{
  349. },//设备类型 与设备下标的映射
  350. batchEquipmentSign:"",//当前选择的batchEquipment下标
  351. batchSign:false,//当前是否为批量构建
  352. failTipList:{},//构建失败的库位提示信息
  353. isShowRatio:undefined,//是否展示库位现存比例
  354. },
  355. mounted() {
  356. this._loadEquipmentCategory().then(()=>{
  357. this.initPage();
  358. let content = document.getElementById("canvasApp");
  359. content.onmousemove = (event)=>{
  360. this.client = {x:event.clientX,y:event.clientY};
  361. }
  362. })
  363. },
  364. computed:{
  365. flipLayer(){
  366. let layer = [];
  367. for (let i=this.current.layer;i>0;i--){
  368. layer.push(i);
  369. }
  370. return layer;
  371. },
  372. flipChildren(){
  373. if(!this.current.children){
  374. return [];
  375. }
  376. let children = [];
  377. for (let i=this.current.children.length - 1;i>=0;i--){
  378. children.push(this.current.children[i]);
  379. }
  380. return children;
  381. },
  382. },
  383. created: function() {
  384. let content = document.getElementById("canvasApp");
  385. document.onkeydown = e=> {
  386. if (this.isNotEdit || !this.current)return;
  387. let key = e.keyCode;
  388. if (key === 8) {
  389. this.delElement();
  390. }
  391. if(key===67 && e.ctrlKey){
  392. this.copyEle();
  393. }
  394. if(key===86 && e.ctrlKey){
  395. let val = $('#clipboardDiv').val();
  396. if (!val || JSON.stringify(val)==="{}")return;
  397. let toolWid = document.getElementById("tool").offsetWidth;
  398. let obj = Object.assign({},JSON.parse(val));
  399. obj.x = this.client.x-toolWid+content.scrollLeft;
  400. obj.y = this.client.y+content.scrollTop;
  401. obj.children = [];
  402. for (let i=0;i<obj.layer;i++)obj.children.push({});
  403. if (this.currentEl.eqId){
  404. obj.eqId = undefined;
  405. this.current = obj;
  406. this.currentEl = obj;
  407. this.showAddModal(obj);
  408. }else{
  409. this.elements.push(obj);
  410. }
  411. }
  412. };
  413. },
  414. methods:{
  415. // 加载设备种类
  416. _loadEquipmentCategory() {
  417. return new Promise((resolve, reject)=>{
  418. $.ajax({
  419. url : this.baseUrl+"api/equipment/category",
  420. type : "GET",
  421. success : (res,status)=>{
  422. if(res.code != 200 || !res.data) {
  423. window.tempTip.show(res.message);
  424. return;
  425. }
  426. /*
  427. * {id:1,w:1.2,h:2.4,grid:2,layer:4,color:"RGB(252,228,214)",describe:"4层高位货架,可设八个标准托盘位"},
  428. {id:2,w:1.2,h:2.4,grid:2,layer:5,color:"RGB(255,255,255)",describe:"5层高位货架,可设十个标准托盘位"},
  429. {id:3,w:1.2,h:3.3,grid:3,layer:1,color:"RGB(169,208,142)",describe:"叉车通道,可设三个标准托盘位"},
  430. {id:4,w:1.2,h:3.3,grid:3,layer:2,color:"RGB(221,235,247)",describe:"叉车通道,可设六个标准托盘位"},
  431. {id:5,w:1.2,h:1.2,grid:1,layer:4,color:"RGB(255,255,0)",describe:"半组货架,可设四层高四个标准托盘位"},
  432. {id:6,w:1.2,h:2.4,grid:2,layer:1,color:"RGB(189,215,238)",describe:"叉车通道,顶上两个托盘位"},
  433. {id:7,w:1.2,h:1.2,grid:1,layer:5,color:"RGB(255,255,5)",describe:"半组货架,可设五层高五个标准托盘位"},
  434. {id:8,w:1.2,h:3.3,grid:3,layer:4,color:"RGB(146,208,80)",describe:"4层高位货架,可设十二个标准托盘位"},
  435. {id:9,w:1.2,h:2.4,grid:2,layer:2,color:"RGB(228,243,211)",describe:"叉车通道,可设四个标准托盘位"},
  436. {id:10,w:1,h:2,grid:1,layer:4,color:"RGB(211,160,160)",describe:"小型货架"},
  437. * */
  438. let equipments = [];
  439. if (res.data.length > 0) {
  440. res.data.forEach(category => {
  441. let info = JSON.parse(category.info);
  442. equipments.push({
  443. "id":category.id,
  444. "w":category.depth,
  445. "h":category.width,
  446. "grid":info.grid,
  447. "layer":category.layer,
  448. "color":info.color,
  449. "describe":category.name,
  450. });
  451. });
  452. }
  453. this.equipments = equipments;
  454. resolve();
  455. },
  456. error : (err,status)=>{
  457. window.tempTip.show("设备种类加载失败");
  458. },
  459. timeout:3000,
  460. })
  461. });
  462. },
  463. //仓库切换
  464. selectedWarehouse(warehouse){
  465. this.isLoad = false;
  466. setTimeout(()=>{
  467. this.selected = warehouse.id;
  468. this.name = warehouse.name;
  469. this.ratio = warehouse.ratio;
  470. this.container = {width:warehouse.length*this.ratio,height:warehouse.width*this.ratio};
  471. localStorage.setItem("equipment:warehouse", warehouse.id);
  472. $.ajax({
  473. url : this.baseUrl+"api/warehouse/detail/getCoordsInfo",
  474. type : "post",
  475. dataType : "JSON",
  476. data : {id:warehouse.id},
  477. success : (res,status)=>{
  478. this.elements = res.data[0] ? JSON.parse(res.data[0]) : [];
  479. if(res.data[1] && res.data[1].length>0){
  480. let equipmentElements = [];
  481. res.data[1].forEach(eq=>{
  482. let coords = JSON.parse(eq.info);
  483. let selfInfo = this.equipments[coords.id-1];
  484. equipmentElements.push(Object.assign({
  485. eqId:eq.id,
  486. exist:eq.exist,
  487. code:eq.code,
  488. repository:eq.repositoryId,
  489. x:coords.x,
  490. y:coords.y,
  491. turn:!!coords.turn,
  492. },selfInfo));
  493. });
  494. this.equipmentElements = equipmentElements;
  495. }else this.equipmentElements = [];
  496. this.repositories = res.data[2];
  497. this.isNotEdit = true;
  498. this.isLoad = true;
  499. },
  500. error : (err,status)=>{
  501. window.tempTip.show("坐标信息加载失败");
  502. },
  503. timeout:8000,
  504. })
  505. },200);
  506. },
  507. /**
  508. * 初始页加载
  509. */
  510. initPage(){
  511. $.ajax({
  512. url : this.baseUrl+"api/warehouse/detail",
  513. type : "GET",
  514. success : (res,status)=>{
  515. this.warehouses = res.data;
  516. //这里获取warehouses
  517. let id = localStorage.getItem("equipment:warehouse");
  518. if (!id || !this.warehouses.some(warehouse=>{
  519. if (warehouse.id == id){
  520. this.selectedWarehouse(warehouse);
  521. return true;
  522. }
  523. })
  524. ){
  525. if (this.warehouses.length>0)this.selectedWarehouse(this.warehouses[0]);
  526. }
  527. $("#loading").hide();
  528. },
  529. error : (err,status)=>{
  530. window.tempTip.show("加载失败");
  531. },
  532. timeout:3000,
  533. })
  534. },
  535. flipArr(arr){
  536. let flip = [];
  537. for (let i=arr.length-1;i>=0;i--){
  538. flip.push(arr[i]);
  539. }
  540. return flip;
  541. },
  542. loadElement(){
  543. if (this.isShowRatio===undefined){
  544. this.isShowRatio = true;
  545. this.equipmentElements.forEach(eq=>{
  546. if (eq.exist){
  547. this.getChildren(eq);
  548. }else if(!eq.children){
  549. eq.children = [];
  550. }
  551. });
  552. }else{
  553. this.isShowRatio = !this.isShowRatio;
  554. }
  555. },
  556. //获取库位的可选择属性
  557. _getLocationAttr(){
  558. if (this.locationAttr!==null){
  559. return;
  560. }
  561. $.ajax({
  562. url : this.baseUrl+"api/location/getAttr",
  563. type : "post",
  564. dataType : "JSON",
  565. success : (res,status)=>{
  566. if (res.code===200){
  567. this.locationAttr = res.data;
  568. }else{
  569. window.toast.error(res.message);
  570. }
  571. },
  572. error : (err,status)=>{
  573. window.toast.error("库位选择属性加载失败");
  574. },
  575. timeout:3000,
  576. })
  577. },
  578. /**
  579. * 显示设备编码列表
  580. */
  581. showEquipmentCode(arr){
  582. event.stopPropagation();
  583. let obj = {};
  584. arr.forEach(index=>{
  585. obj[this.equipmentElements[index].code] = "";
  586. });
  587. this.failTipList = obj;
  588. $("#failTipList").modal("show");
  589. },
  590. //检索所有元素,获取在指定范围内的元素
  591. searchingSelectEq(){
  592. afterExt = function (){
  593. new Promise(function(resolve, reject) {
  594. let result = [];
  595. let els = $(".equipment");
  596. for (let i=0;i<els.length;i++){
  597. let client = els[i].getBoundingClientRect();
  598. if (client.x<0 || client.y<0){
  599. continue;
  600. }
  601. //四个角全部包含在此区域内 将元素下标加入结果数组
  602. if (client.x>=clipInfo.x && client.y>=clipInfo.y && client.x<=(clipInfo.x+clipInfo.w) && client.y<=(clipInfo.y+clipInfo.h)
  603. && (client.x+client.width)<=(clipInfo.x+clipInfo.w) && (client.y+client.height)<=(clipInfo.y+clipInfo.h)){
  604. result.push(els[i].id.split('-')[1]);
  605. }
  606. }
  607. resolve(result);
  608. }).then(indexArr=>{
  609. if (indexArr.length===0){
  610. toast.error("未选中任何设备");
  611. return;
  612. }
  613. vue.batchOperationEquipment(indexArr);
  614. });
  615. }
  616. clipScreenshots();
  617. },
  618. /**
  619. * 批量选中设备后唤起构建器
  620. */
  621. batchOperationEquipment(indexArr){
  622. this.current = {};
  623. let obj = {};
  624. indexArr.forEach(index=>{
  625. let eq = this.equipmentElements[index];
  626. let eqTypeIndex = this._getEqTypeIndex(eq.id);
  627. if (!obj[eqTypeIndex])obj[eqTypeIndex] = [];
  628. obj[eqTypeIndex].push(index);
  629. });
  630. this.batchEquipment = obj;
  631. $("#locationAttr").modal('show');
  632. },
  633. /**
  634. * 根据库位类型ID获取库位类型下标
  635. */
  636. _getEqTypeIndex(id){
  637. //当前是ID为下标+1,所以直接ID-1获取下标
  638. return id-1;
  639. for (let i=0;i<this.equipments.length;i++){
  640. if (this.equipments[i].id==id){
  641. return i;
  642. }
  643. }
  644. return null;
  645. },
  646. buildComponent(eq){
  647. let component = {
  648. "x":eq.x,"y":eq.y,"width":eq.turn ? eq.w : eq.h,"height":eq.turn ? eq.h : eq.w,"name":"","color":eq.color,
  649. "coords":"居中","border":["left","top","right","bottom"],"index":2
  650. };
  651. this.elements.push(component);
  652. },
  653. buildEquipment(eq){
  654. let children = [];
  655. let lastHeight = 1;
  656. for (let i=0;i<eq.layer;i++){
  657. let obj = this.currentEl.children[i];
  658. if (obj)lastHeight = obj.height;
  659. children.push({
  660. "height" : lastHeight,
  661. "row" : 0,
  662. "column" : 0,
  663. });
  664. }
  665. eq.children = children;
  666. this.equipmentElements.push(eq);
  667. this.exeSave(this.equipmentElements[this.equipmentElements.length-1]);
  668. },
  669. buildEquipmentGroup(){
  670. let x = this.currentEl.turn ? this.currentEl.x : Number(this.currentEl.x)+(Number(this.currentEl.w)*this.ratio);
  671. let y = this.currentEl.turn ? Number(this.currentEl.y)+(Number(this.currentEl.h)*this.ratio) : this.currentEl.y;
  672. this.buildEqInfo.list.forEach(eq=>{
  673. eq.x = x;
  674. eq.y = y;
  675. if (eq.id<0)this.buildComponent(eq); //构建组件
  676. else this.buildEquipment(eq); //构建设备
  677. if (this.currentEl.turn){
  678. y += eq.h*this.ratio+0.5;
  679. }else{
  680. x += eq.h*this.ratio+0.5;
  681. }
  682. });
  683. window.toast.success("构建完毕");
  684. this.buildEqInfo = {};
  685. $("#buildGroup").modal("hide");
  686. },
  687. getLastChar(str){
  688. let lastChar = str.substr(-1,1);
  689. if (lastChar.search(/[A-Z]/g)===0){
  690. let index = this.charArr.indexOf(lastChar);
  691. let residualCount = this.charArr.length-(index+1);
  692. if (residualCount<this.buildEqInfo.count)return null;
  693. return {type:"CHAR",val:index};
  694. }
  695. if (lastChar.search(/[\d]/g)===0){
  696. let strs = str.replace(/[^\d]/g,'*');
  697. let strsArr = strs.split('*');
  698. return {type:"NUMBER",val:strsArr[strsArr.length-1]};
  699. }
  700. return null;
  701. },
  702. buildGroup(){
  703. let count = this.buildEqInfo.count;
  704. if (!count)return;
  705. let result = this.getLastChar(this.currentEl.code);
  706. if(!result){
  707. window.toast.error("此设备编码不符合组规则");
  708. return;
  709. }
  710. let codeTran = (index)=>{
  711. let size = result.val.toString().length;
  712. let val;
  713. if(result.type==="CHAR"){
  714. if (this.increment){
  715. val=this.charArr[result.val+index];
  716. }else{
  717. val=this.charArr[result.val-index];
  718. }
  719. }else{
  720. if (this.increment){
  721. val=Number(result.val)+index;
  722. }else{
  723. val=Number(result.val)-index;
  724. }
  725. if (val.toString().length<size){
  726. val = (Array(size).join('0') + val).slice(-size);
  727. }
  728. }
  729. return this.currentEl.code.substr(0,this.currentEl.code.length-size)+val;
  730. };
  731. let list = [];
  732. for (let i=1;i<=count;i++){
  733. let obj = Object.assign({},this.currentEl);
  734. obj.eqId = undefined;
  735. obj.updateCoords = undefined;
  736. obj.code = codeTran(i);
  737. list.push(obj);
  738. }
  739. this.$set(this.buildEqInfo,"list",list);
  740. },
  741. pitchEq(el,index){
  742. this.$set(this.buildEqInfo,"current",index);
  743. this.$set(this.buildEqInfo,"currentEqId",el.id);
  744. },
  745. switchEq(el){
  746. if (this.buildEqInfo.currentEqId===el.id)return;
  747. let obj = this.buildEqInfo.list[this.buildEqInfo.current];
  748. obj.id = el.id;
  749. obj.w = el.w;
  750. obj.h = el.h;
  751. obj.describe = el.describe;
  752. obj.grid = el.grid;
  753. obj.layer = el.layer;
  754. obj.color = el.color;
  755. obj.width = el.w;
  756. obj.depth = el.h;
  757. this.$set(this.buildEqInfo,"currentEqId",el.id);
  758. },
  759. openBuildEquipmentGroup(){
  760. if (this.isNotEdit || !this.currentEl.eqId){
  761. window.toast.error("未开启编辑或未选中设备");
  762. return;
  763. }
  764. setTimeout(()=>{
  765. this.getChildren(this.currentEl);
  766. $("#buildGroup").modal("show");
  767. },100);
  768. },
  769. delCoords(){
  770. this.elements.some((el,index)=>{
  771. if (this.currentEl.name === el.name &&
  772. this.currentEl.x === el.x && this.currentEl.y === el.y){
  773. this.$set(this.elements[index],"removeSign",true);
  774. return true;
  775. }
  776. })
  777. },
  778. copyEle(){
  779. if (this.currentEl!=null && JSON.stringify(this.currentEl)!=="{}"){
  780. $('#clipboardDiv').text(JSON.stringify(this.currentEl));
  781. }
  782. },
  783. delEquipment(){
  784. this.equipmentElements.some((el,index)=>{
  785. if (this.currentEl.eqId === el.eqId){
  786. this.$set(this.equipmentElements[index],"removeSign",true);
  787. return true;
  788. }
  789. })
  790. },
  791. delElement(){
  792. if (this.currentEl.eqId)this.delEquipment();
  793. else this.delCoords();
  794. },
  795. addCoords(){
  796. if (this.isNotEdit)return;
  797. this.elements.push({"x":200,"y":200,"width":2,"height":2,"name":"","coords":"居中","border":["left","top","right","bottom"],"color":"white","index":1})
  798. },
  799. clickEditOrSave(){
  800. if(this.isNotEdit){this.isNotEdit = false;return;}
  801. let equipments = [];
  802. let delEquipments = [];
  803. let elements = [];
  804. this.equipmentElements.forEach(equipment=>{
  805. if (equipment.removeSign){
  806. delEquipments.push(equipment.eqId);
  807. }else if (equipment.updateCoords){
  808. equipments.push({
  809. id:equipment.eqId,
  810. info:JSON.stringify({x:equipment.x,y:equipment.y,id:equipment.id,turn:equipment.turn})
  811. });
  812. }
  813. });
  814. this.elements.forEach(el=>{
  815. if (!el.removeSign){
  816. elements.push(el);
  817. }
  818. });
  819. $.ajax({
  820. url : this.baseUrl+"api/warehouse/saveScene",
  821. type : "POST",
  822. headers:{'Content-Type':'application/json;charset=utf8'},
  823. data:JSON.stringify({id:this.selected,warehouse:JSON.stringify(elements),equipment:equipments,delEquipments:delEquipments}),
  824. success : (res,status)=>{
  825. if (res.code===200){
  826. this.isNotEdit = true;
  827. window.toast.success("场景更改保存成功");
  828. }else window.toast.error(res.message);
  829. },
  830. error : (err,status)=>{
  831. window.tempTip.show("加载失败");
  832. },
  833. complete:(req,status)=>{
  834. if (status==='timeout'){
  835. window.toast.error("服务器响应超时");
  836. }
  837. },
  838. timeout:10000,
  839. })
  840. },
  841. //备选设备拖拽按下事件
  842. eqDown(equipment){
  843. if (this.isNotEdit)return;
  844. if (this.currentEq.obj!==null)return;
  845. let wid = (this.turn ? equipment.w : equipment.h)*this.ratio;
  846. let hei = (this.turn ? equipment.h : equipment.w)*this.ratio;
  847. let div = document.createElement("div");
  848. div.style.width = wid+'px';
  849. div.style.height = hei+'px';
  850. div.style.backgroundColor = equipment.color;
  851. div.style.zIndex = '999';
  852. div.style.position = 'fixed';
  853. div.style.left = event.clientX+'px';
  854. div.style.top = event.clientY+'px';
  855. div.style.border = '1px #0070C0 solid';
  856. div.style.opacity = '0.5';
  857. document.getElementById("container").append(div);
  858. this.currentEq.el = div;
  859. this.currentEq.obj = equipment;
  860. },
  861. //备选设备拖拽移动事件
  862. eqMove(){
  863. if (this.isNotEdit)return;
  864. if (this.currentEq.obj===null)return;
  865. let x = event.clientX;
  866. let y = event.clientY;
  867. setTimeout(()=>{
  868. this.currentEq.el.style.left = x+'px';
  869. this.currentEq.el.style.top = y+'px';
  870. },10);
  871. },
  872. //备选设备拖拽松开事件
  873. eqUp(){
  874. if (this.isNotEdit)return;
  875. if (this.currentEq.obj===null)return;
  876. this.currentEq.el.remove();
  877. setTimeout(()=>{
  878. this.currentEq.el.remove();
  879. this.currentEq.el = null;
  880. },20);
  881. let content = document.getElementById("canvasApp");
  882. let toolWid = document.getElementById("tool").offsetWidth;
  883. let x = event.clientX-toolWid+content.scrollLeft;
  884. let y = event.clientY+content.scrollTop;
  885. if (x>=0 && y>=0){
  886. let children = [];
  887. for (let i=0;i<this.currentEq.obj.layer;i++)children.push({});
  888. let newEquipment = Object.assign({children:children,x:x,y:y}, this.currentEq.obj);
  889. newEquipment.turn = this.turn;
  890. newEquipment.width = newEquipment.w;
  891. newEquipment.depth = newEquipment.h;
  892. this.showAddModal(newEquipment);
  893. }
  894. this.currentEq.obj = null;
  895. },
  896. showAddModal(equipment){
  897. this.equipmentElements.push(equipment);
  898. this.current = this.equipmentElements[this.equipmentElements.length-1];
  899. setTimeout(()=>{
  900. $("#detailInfo").modal("show");
  901. },20);
  902. },
  903. //场景拖拽按下事件
  904. contentOnmousedown(event){
  905. if (!this.isNotEdit || this.clientCoords.x!==undefined)return;
  906. this.clientCoords = {
  907. x:event.clientX,
  908. y:event.clientY
  909. };
  910. },
  911. //场景拖拽移动事件
  912. contentOnmousemove(event){
  913. if (this.clientCoords.x===undefined)return;
  914. let diffX = event.clientX-this.clientCoords.x-2;
  915. let diffY = event.clientY-this.clientCoords.y-2;
  916. let content = document.getElementById("canvasApp");
  917. setTimeout(()=>{
  918. content.scrollTo(content.scrollLeft+diffX,content.scrollTop+diffY);
  919. },10);
  920. },
  921. //场景拖拽松开事件
  922. contentOnmouseup(){
  923. this.clientCoords = {};
  924. },
  925. onActivated(element){
  926. if (this.isNotEdit)return;
  927. this.currentEl = element;
  928. },
  929. //场景大小调整事件
  930. onResizing(newRect){
  931. if (this.isNotEdit)return;
  932. this.currentEl.width=this.accDiv(newRect.width,this.ratio);
  933. this.currentEl.height=this.accDiv(newRect.height,this.ratio);
  934. },
  935. accDiv(arg1,arg2){
  936. let t1=0,t2=0,r1,r2;
  937. try{t1=arg1.toString().split(".")[1].length}catch(e){}
  938. try{t2=arg2.toString().split(".")[1].length}catch(e){}
  939. with(Math){
  940. r1=Number(arg1.toString().replace(".",""))
  941. r2=Number(arg2.toString().replace(".",""))
  942. return this.accMul((r1/r2),pow(10,t2-t1));
  943. }
  944. },
  945. accMul(arg1,arg2){
  946. let m=0,s1=arg1.toString(),s2=arg2.toString();
  947. try{m+=s1.split(".")[1].length}catch(e){}
  948. try{m+=s2.split(".")[1].length}catch(e){}
  949. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
  950. },
  951. //场景拖拽事件
  952. onDragging(newRect){
  953. if (this.isNotEdit)return;
  954. this.currentEl.x=newRect.left;
  955. this.currentEl.y=newRect.top;
  956. $("#canvas").focus();
  957. },
  958. equipmentDrag(newRect){
  959. if (this.isNotEdit)return;
  960. this.currentEl.x=newRect.left;
  961. this.currentEl.y=newRect.top;
  962. this.currentEl.updateCoords = true;
  963. $("#canvas").focus();
  964. },
  965. //文本类属性改变
  966. changeText(key){
  967. this.currentEl[key] = event.target.value;
  968. },
  969. //数值类属性改变
  970. changeNumber(key){
  971. let val = event.target.value;
  972. this.currentEl[key] = val ? parseFloat(val) : 0;
  973. },
  974. _getObjFirstKey(obj){
  975. for(let key in obj){
  976. return key;
  977. }
  978. return null;
  979. },
  980. /**
  981. * 构建库位的默认值信息
  982. * */
  983. _locationAttrDefault(){
  984. this.buildPool.usage = this._getObjFirstKey(this.locationAttr.usage);
  985. this.buildPool.handling = this._getObjFirstKey(this.locationAttr.handling);
  986. this.buildPool.attribute = this._getObjFirstKey(this.locationAttr.attribute);
  987. this.buildPool.category = this._getObjFirstKey(this.locationAttr.category);
  988. this.buildPool.demand = this._getObjFirstKey(this.locationAttr.demand);
  989. this.buildPool.mixFlag = true;
  990. this.buildPool.mixLotFlag = false;
  991. this.buildPool.loseIdFlag = true;
  992. },
  993. /**
  994. * 批量构建库位时的操作
  995. * */
  996. nextDetailBatch(index){
  997. if (!this.current.children || this.current.children.length===0){
  998. window.toast.error("设备信息尚未加载完毕,请稍后重试!");
  999. return;
  1000. }
  1001. this.batchSign = true;
  1002. this.currentEqChildIndex = index-1;
  1003. setTimeout(function (){
  1004. let parentDom = document.getElementById("locationAttr").firstChild.firstChild;
  1005. let childDom = document.getElementById("locationModal").firstChild.firstChild;
  1006. childDom.style.minWidth = parentDom.offsetWidth+'px';
  1007. childDom.style.minHeight = parentDom.offsetHeight+'px';
  1008. $("#locationModal").modal("show");
  1009. },20);
  1010. this._locationAttrDefault();
  1011. },
  1012. //子设备选定时的库位加载
  1013. nextDetail(index){
  1014. let children = this.current.children[index-1];
  1015. if (!this.current.eqId) {
  1016. window.tempTip.index = 1050;
  1017. window.tempTip.inputVal("子设备编码", (val)=> {
  1018. this.$set(this.current.children[index-1], 'code', val);
  1019. })
  1020. return;
  1021. }
  1022. this.batchSign = false;
  1023. this.currentEqChildIndex = index-1;
  1024. this.isLoadLocation = true;
  1025. this._locationAttrDefault();
  1026. setTimeout(function (){
  1027. let parentDom = document.getElementById("detailInfo").firstChild.firstChild;
  1028. let childDom = document.getElementById("locationModal").firstChild.firstChild;
  1029. childDom.style.minWidth = (parentDom.offsetWidth+200)+'px';
  1030. childDom.style.minHeight = parentDom.offsetHeight+'px';
  1031. $("#locationModal").modal("show");
  1032. },20);
  1033. this.current.children.forEach(item=>{
  1034. item.row = Number(item.row);
  1035. item.column = Number(item.column);
  1036. });
  1037. $.ajax({
  1038. url : this.baseUrl+"api/location/get",
  1039. type : "post",
  1040. dataType : "JSON",
  1041. data : {id:children.id},
  1042. success : (res)=>{
  1043. switch (res.code){
  1044. case 200:
  1045. this.locations = res.data[0];
  1046. this.locationMapping = res.data[1] ? res.data[1] : {};
  1047. this.isLoadLocation = false;
  1048. break;
  1049. default:
  1050. window.toast.error(res.message);
  1051. }
  1052. },
  1053. error : (err)=>{
  1054. window.tempTip.setIndex(999);
  1055. window.tempTip.show("网络错误");
  1056. },
  1057. timeout:3000,
  1058. })
  1059. },
  1060. showDetail(equipment){
  1061. this._getLocationAttr();
  1062. if (!this.isNotEdit)return;
  1063. this.current = equipment;
  1064. setTimeout(()=>{
  1065. $("#detailInfo").modal("show");
  1066. this.contentOnmouseup();
  1067. },20);
  1068. this.getChildren(this.current);
  1069. },
  1070. getChildren(equipment){
  1071. if (equipment.children && equipment.children.length>0){
  1072. return;
  1073. }
  1074. $.ajax({
  1075. url : this.baseUrl+"api/equipment/getChildren",
  1076. type : "post",
  1077. dataType : "JSON",
  1078. data : {id:equipment.eqId},
  1079. success : (res)=>{
  1080. switch (res.code){
  1081. case 200:
  1082. res.data.forEach(eq=>{
  1083. let tab = eq.location_tab.split("-");
  1084. eq.row = Number(tab[0]);
  1085. eq.column = Number(tab[1]);
  1086. });
  1087. this.$set(equipment,"children",res.data);
  1088. break;
  1089. default:
  1090. window.toast.error("服务器错误");
  1091. }
  1092. },
  1093. error : (err)=>{
  1094. window.tempTip.setIndex(999);
  1095. window.tempTip.show("网络错误");
  1096. },
  1097. timeout:3000,
  1098. })
  1099. },
  1100. saveOrUpdate(){
  1101. this.error = {};
  1102. let error = this._checkEquipmentData(this.current);
  1103. if (JSON.stringify(error)!=="{}"){
  1104. console.log(error)
  1105. this.error = error;return;
  1106. }
  1107. this.exeSave(this.current);
  1108. },
  1109. exeSave(equipment){
  1110. let params = this._formatEquipmentData(equipment);
  1111. params.warehouseDetailId = this.selected;
  1112. $.ajax({
  1113. url : this.baseUrl+"api/equipment/saveOrUpdate",
  1114. type : "post",
  1115. dataType : "JSON",
  1116. headers:{'Content-Type':'application/json;charset=utf8'},
  1117. data : JSON.stringify(params),
  1118. success : (res)=>{
  1119. switch (res.code){
  1120. case 200:
  1121. equipment.eqId = res.data[0];
  1122. let locCount = 0;
  1123. equipment.children.forEach((item,index)=>{
  1124. item.id = res.data[1][index];
  1125. if (item.row && Number(item.row) > 0){
  1126. locCount += Number(item.row) * Number(item.column)
  1127. }
  1128. });
  1129. equipment.exist = locCount;
  1130. this.$forceUpdate();
  1131. $("#detailInfo").modal("hide");
  1132. window.toast.success("保存成功");
  1133. break;
  1134. case 701:
  1135. this.error = res.data;
  1136. break;
  1137. case 414:
  1138. this.error = {code:"设备编码重复"};
  1139. window.toast.error(this.error.code);
  1140. break;
  1141. default:
  1142. window.toast.error("服务器错误:"+res.message);
  1143. }
  1144. },
  1145. error : (err)=>{
  1146. console.error(err);
  1147. window.tempTip.setIndex(999);
  1148. window.tempTip.show("网络错误");
  1149. },
  1150. timeout:3000,
  1151. })
  1152. },
  1153. _checkEquipmentData(equipment){
  1154. let error = {};
  1155. if (!equipment.code)error.code = "设备编号未填写";
  1156. if (equipment.layer !== equipment.children.length)error.children = "设备绑定错误";
  1157. for (let i=0;i<equipment.layer;i++){
  1158. console.log(equipment.children[i])
  1159. if (!equipment.children[i].height)error["children["+i+"].height"] = "设备高度不得为空"
  1160. if (!equipment.children[i].area)error["children["+i+"].area"] = "设备折算面积不得为空"
  1161. if (!equipment.children[i].column && equipment.children[i].column!=0)error["children["+i+"].column"] = "库位列数不得为空"
  1162. if (!equipment.children[i].row && equipment.children[i].row!=0)error["children["+i+"].row"] = "库位行数不得为空"
  1163. }
  1164. return error;
  1165. },
  1166. _formatEquipmentData(equipment){
  1167. let eq = {};
  1168. eq.id = equipment.eqId;
  1169. eq.code = equipment.code;
  1170. eq.repositoryId = equipment.repository;
  1171. eq.info = JSON.stringify({'x':equipment.x,'y':equipment.y,'id':equipment.id,'turn':!!equipment.turn});
  1172. eq.depth = equipment.depth;
  1173. eq.width = equipment.width;
  1174. eq.children = equipment.children;
  1175. return eq;
  1176. },
  1177. removeLocationBind(){
  1178. if (this.isLoadLocation)return;
  1179. this.isLoadLocation = true;
  1180. $.ajax({
  1181. url : this.baseUrl+"api/location/removeLocationBind",
  1182. type : "post",
  1183. dataType : "JSON",
  1184. data : {id:this.current.children[this.currentEqChildIndex].id},
  1185. success : (res)=>{
  1186. switch (res.code){
  1187. case 200:
  1188. this.current.children[this.currentEqChildIndex].row = 0;
  1189. this.current.children[this.currentEqChildIndex].column = 0;
  1190. this.locations = [];
  1191. window.toast.success("解除成功!");
  1192. break;
  1193. default:
  1194. window.toast.error("库位无法释放,解除失败");
  1195. }
  1196. },
  1197. error : (err)=>{
  1198. window.tempTip.setIndex(999);
  1199. window.tempTip.show("网络错误");
  1200. },
  1201. complete:()=>{
  1202. this.isLoadLocation = false;
  1203. },
  1204. timeout:3000,
  1205. })
  1206. },
  1207. locationBatchBind(){
  1208. $("#loading").show();
  1209. let arr = this.batchEquipment[this.batchEquipmentSign];
  1210. let request = [];
  1211. let failTipList = {};
  1212. arr.forEach(index=>{
  1213. let eq = this.equipmentElements[index];
  1214. if (!eq){
  1215. window.toast.error("异常设备选择");
  1216. }else if (!eq.children || eq.children.length===0 || !eq.children[this.currentEqChildIndex]){
  1217. failTipList[eq.code]="详情尚未加载完毕";
  1218. }else{
  1219. let item = eq.children[this.currentEqChildIndex];
  1220. let code = eq.code+'-'+(this.currentEqChildIndex+1);
  1221. request.push(Object.assign({id:item.id,code:code},
  1222. this.buildPool))
  1223. }
  1224. });
  1225. $.ajax({
  1226. url : this.baseUrl+"api/location/locationBatchBound",
  1227. type : "post",
  1228. dataType : "JSON",
  1229. data : JSON.stringify(request),
  1230. headers:{'Content-Type':'application/json;charset=utf8'},
  1231. success : (res)=>{
  1232. switch (res.code){
  1233. case 200:
  1234. $("#locationModal").modal('hide');
  1235. window.toast.success("构建完毕!");
  1236. this.failTipList = Object.assign(failTipList,res.data);
  1237. if (JSON.stringify(this.failTipList)!=="{}"){
  1238. $("#failTipList").modal("show");
  1239. }
  1240. let ele = document.querySelectorAll("#locationAttr span.el-center")[this.current.layer-1-this.currentEqChildIndex];
  1241. ele.className += " bg-success";
  1242. break;
  1243. default:
  1244. window.toast.error(res.message);
  1245. }
  1246. },
  1247. error : (err)=>{
  1248. window.tempTip.setIndex(999);
  1249. window.tempTip.show("网络错误");
  1250. },
  1251. complete:(req,status)=>{
  1252. $("#loading").hide();
  1253. if (status==='timeout'){
  1254. window.toast.error("库位批量构建失败,响应超时");
  1255. }
  1256. },
  1257. timeout:3000,
  1258. });
  1259. },
  1260. locationBind(){
  1261. if (this.batchSign){
  1262. this.locationBatchBind();
  1263. return;
  1264. }
  1265. if (this.isLoadLocation)return;
  1266. let eq = this.current.children[this.currentEqChildIndex];
  1267. let code = this.current.code+'-'+(this.currentEqChildIndex+1);
  1268. this.isLoadLocation = true;
  1269. $.ajax({
  1270. url : this.baseUrl+"api/location/locationBind",
  1271. type : "post",
  1272. dataType : "JSON",
  1273. headers:{'Content-Type':'application/json;charset=utf8'},
  1274. data : JSON.stringify(Object.assign({id:eq.id,code:code},this.buildPool)),
  1275. success : (res)=>{
  1276. switch (res.code){
  1277. case 200:
  1278. this.locations = res.data;
  1279. window.toast.success("构建成功!");
  1280. this.current.children[this.currentEqChildIndex].row = Number(this.buildPool.row);
  1281. this.current.children[this.currentEqChildIndex].column = Number(this.buildPool.column);
  1282. this._locationAttrDefault();
  1283. $("#locationModal").modal("hide");
  1284. this.$forceUpdate();
  1285. break;
  1286. default:
  1287. window.toast.error(res.message);
  1288. }
  1289. },
  1290. error : (err)=>{
  1291. window.tempTip.setIndex(999);
  1292. window.tempTip.show("网络错误");
  1293. },
  1294. complete:(req,status)=>{
  1295. this.isLoadLocation = false;
  1296. if (status==='timeout'){
  1297. window.toast.error("库位建立失败,响应超时");
  1298. }
  1299. },
  1300. timeout:3000,
  1301. })
  1302. },
  1303. showAddWarehouseDetail(){
  1304. if (this.ws.length>0){
  1305. $("#warehouseDetail").modal("show");
  1306. return;
  1307. }
  1308. $.ajax({
  1309. url : this.baseUrl+"api/warehouse/getList",
  1310. type : "get",
  1311. dataType : "JSON",
  1312. success : (res)=>{
  1313. switch (res.code){
  1314. case 200:
  1315. this.ws = res.data;
  1316. $("#warehouseDetail").modal("show");
  1317. break;
  1318. default:
  1319. window.toast.error("仓库获取失败");
  1320. }
  1321. },
  1322. error : (err)=>{
  1323. window.tempTip.setIndex(999);
  1324. window.tempTip.show("网络错误");
  1325. },
  1326. complete:(req,status)=>{
  1327. this.isLoadLocation = false;
  1328. if (status==='timeout'){
  1329. window.toast.error("获取仓库超时");
  1330. }
  1331. },
  1332. timeout:3000,
  1333. })
  1334. },
  1335. addWarehouseDetail(){
  1336. $.ajax({
  1337. url : this.baseUrl+"api/warehouse/detail",
  1338. type : "post",
  1339. dataType : "JSON",
  1340. headers:{'Content-Type':'application/json;charset=utf8'},
  1341. data : JSON.stringify(this.warehouseDetail),
  1342. success : (res)=>{
  1343. switch (res.code){
  1344. case 200:
  1345. window.toast.success("仓库新建成功");
  1346. this.warehouses = res.data;
  1347. $("#warehouseDetail").modal("hide");
  1348. break;
  1349. default:
  1350. window.toast.error(res.message);
  1351. }
  1352. },
  1353. error : (err)=>{
  1354. window.tempTip.setIndex(999);
  1355. window.tempTip.show("网络错误");
  1356. },
  1357. timeout:3000,
  1358. })
  1359. },
  1360. openRepository(){
  1361. $.ajax({
  1362. url : this.baseUrl+"api/repository/group",
  1363. type : "get",
  1364. dataType : "JSON",
  1365. data:{id:this.selected},
  1366. success : (res)=>{
  1367. switch (res.code){
  1368. case 200:
  1369. this.group = res.data;
  1370. $("#repository").modal("show");
  1371. break;
  1372. default:
  1373. window.toast.error("获取区域失败");
  1374. }
  1375. },
  1376. error : (err)=>{
  1377. window.tempTip.setIndex(999);
  1378. window.tempTip.show("网络错误");
  1379. },
  1380. complete:(req,status)=>{
  1381. this.isLoadLocation = false;
  1382. if (status==='timeout'){
  1383. window.toast.error("获取区域超时");
  1384. }
  1385. },
  1386. timeout:3000,
  1387. })
  1388. },
  1389. addRepository(){
  1390. this.repository.warehouseDetailId = this.selected;
  1391. $.ajax({
  1392. url : this.baseUrl+"api/repository/addRepository",
  1393. type : "post",
  1394. dataType : "JSON",
  1395. headers:{'Content-Type':'application/json;charset=utf8'},
  1396. data:JSON.stringify(this.repository),
  1397. success : (res)=>{
  1398. switch (res.code){
  1399. case 200:
  1400. this.repositories.push(res.data);
  1401. $("#repository").modal("hide");
  1402. this.repository = {};
  1403. break;
  1404. default:
  1405. window.toast.error("库区建立失败");
  1406. }
  1407. },
  1408. error : (err)=>{
  1409. window.tempTip.setIndex(999);
  1410. window.tempTip.show("网络错误");
  1411. },
  1412. complete:(req,status)=>{
  1413. this.isLoadLocation = false;
  1414. if (status==='timeout'){
  1415. window.toast.error("建立库区超时");
  1416. }
  1417. },
  1418. timeout:3000,
  1419. })
  1420. },
  1421. /**
  1422. * 批量构建设备库位时的选中操作
  1423. * */
  1424. batchEquipmentSelected(arr,index){
  1425. this.current = this.equipmentElements[arr[0]];
  1426. this.batchEquipmentSign = index;
  1427. arr.forEach(i=>{
  1428. this.getChildren(this.equipmentElements[i]);
  1429. })
  1430. this._getLocationAttr();
  1431. },
  1432. },
  1433. filters:{
  1434. qty(code){
  1435. let inv = vue.locationMapping[code];
  1436. if(!inv)return 0;
  1437. return inv.QTY;
  1438. },
  1439. qtyOver(code){
  1440. let inv = vue.locationMapping[code];
  1441. if(!inv)return 0;
  1442. return inv.QTYALLOCATED + inv.QTYMVIN + inv.QTYMVOUT + inv.QTYONHOLD + inv.QTYPA + inv.QTYRPIN + inv.QTYRPOUT;
  1443. },
  1444. childStyle(code){
  1445. let inv = vue.locationMapping[code];
  1446. if (!inv)return '';
  1447. let qty = inv.QTY;
  1448. let other = inv.QTYALLOCATED + inv.QTYMVIN + inv.QTYMVOUT + inv.QTYONHOLD + inv.QTYPA + inv.QTYRPIN + inv.QTYRPOUT;
  1449. return (qty>0 || other>0) ?
  1450. 'color: #fff;background-color: #38c172;border-color: #38c172;' : '';
  1451. },
  1452. formatCount(tab){
  1453. let arr = tab.split("-");
  1454. return arr[0]*arr[1];
  1455. }
  1456. }
  1457. });
  1458. </script>
  1459. </html>