index.blade.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  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. {id:1,w:1.2,h:2.4,grid:2,layer:4,color:"RGB(252,228,214)",describe:"4层高位货架,可设八个标准托盘位"},
  326. {id:2,w:1.2,h:2.4,grid:2,layer:5,color:"RGB(255,255,255)",describe:"5层高位货架,可设十个标准托盘位"},
  327. {id:3,w:1.2,h:3.3,grid:3,layer:1,color:"RGB(169,208,142)",describe:"叉车通道,可设三个标准托盘位"},
  328. {id:4,w:1.2,h:3.3,grid:3,layer:2,color:"RGB(221,235,247)",describe:"叉车通道,可设六个标准托盘位"},
  329. {id:5,w:1.2,h:1.2,grid:1,layer:4,color:"RGB(255,255,0)",describe:"半组货架,可设四层高四个标准托盘位"},
  330. {id:6,w:1.2,h:2.4,grid:2,layer:1,color:"RGB(189,215,238)",describe:"叉车通道,顶上两个托盘位"},
  331. {id:7,w:1.2,h:1.2,grid:1,layer:5,color:"RGB(255,255,5)",describe:"半组货架,可设五层高五个标准托盘位"},
  332. {id:8,w:1.2,h:3.3,grid:3,layer:4,color:"RGB(146,208,80)",describe:"4层高位货架,可设十二个标准托盘位"},
  333. {id:9,w:1.2,h:2.4,grid:2,layer:2,color:"RGB(228,243,211)",describe:"叉车通道,可设四个标准托盘位"},
  334. {id:10,w:1,h:2,grid:1,layer:4,color:"RGB(211,160,160)",describe:"小型货架"},
  335. ],
  336. currentEq:{ //选中的设备
  337. el:null,
  338. obj:null,
  339. },
  340. equipmentElements:[], //设备元素池
  341. grid:false, //设备拖拽是否开启网格
  342. turn:true, //设备是否翻转
  343. isLoadLocation:false, //开启加载库位
  344. //baseUrl:"http://127.0.0.1:8112/",
  345. baseUrl:"https://swms.baoshi56.com/",
  346. current:{}, //当前操作的设备
  347. error:{},
  348. locations:[], //库位信息
  349. currentEqChildIndex:null, //当前节点下标
  350. buildPool:{}, //库位构建信息
  351. client:{}, //复制后的坐标记录
  352. buildEqInfo:{}, //设备组构建信息
  353. charArr : [...Array(26).keys()].map(i => String.fromCharCode(i + 65)), //A-Z字符
  354. elSeList:[
  355. {id:-1,w:1.2,h:2.4,grid:2,color:"RGB(255,255,0)",describe:"消防栓设施或立柱,不可设库位"},
  356. ],//场景元素预设列表
  357. locationAttr:null,//库位建立时的可选择属性
  358. batchEquipment:{
  359. },//设备类型 与设备下标的映射
  360. batchEquipmentSign:"",//当前选择的batchEquipment下标
  361. batchSign:false,//当前是否为批量构建
  362. failTipList:{},//构建失败的库位提示信息
  363. isShowRatio:undefined,//是否展示库位现存比例
  364. },
  365. mounted() {
  366. this.initPage();
  367. let content = document.getElementById("canvasApp");
  368. content.onmousemove = (event)=>{
  369. this.client = {x:event.clientX,y:event.clientY};
  370. }
  371. },
  372. computed:{
  373. flipLayer(){
  374. let layer = [];
  375. for (let i=this.current.layer;i>0;i--){
  376. layer.push(i);
  377. }
  378. return layer;
  379. },
  380. flipChildren(){
  381. if(!this.current.children){
  382. return [];
  383. }
  384. let children = [];
  385. for (let i=this.current.children.length - 1;i>=0;i--){
  386. children.push(this.current.children[i]);
  387. }
  388. return children;
  389. },
  390. },
  391. created: function() {
  392. let content = document.getElementById("canvasApp");
  393. document.onkeydown = e=> {
  394. if (this.isNotEdit || !this.current)return;
  395. let key = e.keyCode;
  396. if (key === 8) {
  397. this.delElement();
  398. }
  399. if(key===67 && e.ctrlKey){
  400. this.copyEle();
  401. }
  402. if(key===86 && e.ctrlKey){
  403. let val = $('#clipboardDiv').val();
  404. if (!val || JSON.stringify(val)==="{}")return;
  405. let toolWid = document.getElementById("tool").offsetWidth;
  406. let obj = Object.assign({},JSON.parse(val));
  407. obj.x = this.client.x-toolWid+content.scrollLeft;
  408. obj.y = this.client.y+content.scrollTop;
  409. obj.children = [];
  410. for (let i=0;i<obj.layer;i++)obj.children.push({});
  411. if (this.currentEl.eqId){
  412. obj.eqId = undefined;
  413. this.current = obj;
  414. this.currentEl = obj;
  415. this.showAddModal(obj);
  416. }else{
  417. this.elements.push(obj);
  418. }
  419. }
  420. };
  421. },
  422. methods:{
  423. //仓库切换
  424. selectedWarehouse(warehouse){
  425. this.isLoad = false;
  426. setTimeout(()=>{
  427. this.selected = warehouse.id;
  428. this.name = warehouse.name;
  429. this.ratio = warehouse.ratio;
  430. this.container = {width:warehouse.length*this.ratio,height:warehouse.width*this.ratio};
  431. localStorage.setItem("equipment:warehouse", warehouse.id);
  432. $.ajax({
  433. url : this.baseUrl+"warehouse/detail/getCoordsInfo",
  434. type : "post",
  435. dataType : "JSON",
  436. data : {id:warehouse.id},
  437. success : (res,status)=>{
  438. this.elements = res.data[0] ? JSON.parse(res.data[0]) : [];
  439. if(res.data[1] && res.data[1].length>0){
  440. let equipmentElements = [];
  441. res.data[1].forEach(eq=>{
  442. let coords = JSON.parse(eq.info);
  443. let selfInfo = this.equipments[coords.id-1];
  444. equipmentElements.push(Object.assign({
  445. eqId:eq.id,
  446. exist:eq.exist,
  447. code:eq.code,
  448. width:eq.width,
  449. depth:eq.depth,
  450. repository:eq.repositoryId,
  451. x:coords.x,
  452. y:coords.y,
  453. turn:!!coords.turn,
  454. },selfInfo));
  455. });
  456. this.equipmentElements = equipmentElements;
  457. }else this.equipmentElements = [];
  458. this.repositories = res.data[2];
  459. this.isNotEdit = true;
  460. this.isLoad = true;
  461. },
  462. error : (err,status)=>{
  463. window.tempTip.show("坐标信息加载失败");
  464. },
  465. timeout:3000,
  466. })
  467. },200);
  468. },
  469. /**
  470. * 初始页加载
  471. */
  472. initPage(){
  473. $.ajax({
  474. url : this.baseUrl+"warehouse/detail",
  475. type : "GET",
  476. success : (res,status)=>{
  477. this.warehouses = res.data;
  478. //这里获取warehouses
  479. let id = localStorage.getItem("equipment:warehouse");
  480. if (!id || !this.warehouses.some(warehouse=>{
  481. if (warehouse.id == id){
  482. this.selectedWarehouse(warehouse);
  483. return true;
  484. }
  485. })
  486. ){
  487. if (this.warehouses.length>0)this.selectedWarehouse(this.warehouses[0]);
  488. }
  489. $("#loading").hide();
  490. },
  491. error : (err,status)=>{
  492. window.tempTip.show("加载失败");
  493. },
  494. timeout:3000,
  495. })
  496. },
  497. flipArr(arr){
  498. let flip = [];
  499. for (let i=arr.length-1;i>=0;i--){
  500. flip.push(arr[i]);
  501. }
  502. return flip;
  503. },
  504. loadElement(){
  505. if (this.isShowRatio===undefined){
  506. this.isShowRatio = true;
  507. this.equipmentElements.forEach(eq=>{
  508. if (eq.exist){
  509. this.getChildren(eq);
  510. }else if(!eq.children){
  511. eq.children = [];
  512. }
  513. });
  514. }else{
  515. this.isShowRatio = !this.isShowRatio;
  516. }
  517. },
  518. //获取库位的可选择属性
  519. _getLocationAttr(){
  520. if (this.locationAttr!==null){
  521. return;
  522. }
  523. $.ajax({
  524. url : this.baseUrl+"location/getAttr",
  525. type : "post",
  526. dataType : "JSON",
  527. success : (res,status)=>{
  528. if (res.code===200){
  529. this.locationAttr = res.data;
  530. }else{
  531. window.toast.error(res.message);
  532. }
  533. },
  534. error : (err,status)=>{
  535. window.toast.error("库位选择属性加载失败");
  536. },
  537. timeout:3000,
  538. })
  539. },
  540. /**
  541. * 显示设备编码列表
  542. */
  543. showEquipmentCode(arr){
  544. event.stopPropagation();
  545. let obj = {};
  546. arr.forEach(index=>{
  547. obj[this.equipmentElements[index].code] = "";
  548. });
  549. this.failTipList = obj;
  550. $("#failTipList").modal("show");
  551. },
  552. //检索所有元素,获取在指定范围内的元素
  553. searchingSelectEq(){
  554. afterExt = function (){
  555. new Promise(function(resolve, reject) {
  556. let result = [];
  557. let els = $(".equipment");
  558. for (let i=0;i<els.length;i++){
  559. let client = els[i].getBoundingClientRect();
  560. if (client.x<0 || client.y<0){
  561. continue;
  562. }
  563. //四个角全部包含在此区域内 将元素下标加入结果数组
  564. if (client.x>=clipInfo.x && client.y>=clipInfo.y && client.x<=(clipInfo.x+clipInfo.w) && client.y<=(clipInfo.y+clipInfo.h)
  565. && (client.x+client.width)<=(clipInfo.x+clipInfo.w) && (client.y+client.height)<=(clipInfo.y+clipInfo.h)){
  566. result.push(els[i].id.split('-')[1]);
  567. }
  568. }
  569. resolve(result);
  570. }).then(indexArr=>{
  571. if (indexArr.length===0){
  572. toast.error("未选中任何设备");
  573. return;
  574. }
  575. vue.batchOperationEquipment(indexArr);
  576. });
  577. }
  578. clipScreenshots();
  579. },
  580. /**
  581. * 批量选中设备后唤起构建器
  582. */
  583. batchOperationEquipment(indexArr){
  584. this.current = {};
  585. let obj = {};
  586. indexArr.forEach(index=>{
  587. let eq = this.equipmentElements[index];
  588. let eqTypeIndex = this._getEqTypeIndex(eq.id);
  589. if (!obj[eqTypeIndex])obj[eqTypeIndex] = [];
  590. obj[eqTypeIndex].push(index);
  591. });
  592. this.batchEquipment = obj;
  593. $("#locationAttr").modal('show');
  594. },
  595. /**
  596. * 根据库位类型ID获取库位类型下标
  597. */
  598. _getEqTypeIndex(id){
  599. //当前是ID为下标+1,所以直接ID-1获取下标
  600. return id-1;
  601. for (let i=0;i<this.equipments.length;i++){
  602. if (this.equipments[i].id==id){
  603. return i;
  604. }
  605. }
  606. return null;
  607. },
  608. buildComponent(eq){
  609. let component = {
  610. "x":eq.x,"y":eq.y,"width":eq.turn ? eq.w : eq.h,"height":eq.turn ? eq.h : eq.w,"name":"","color":eq.color,
  611. "coords":"居中","border":["left","top","right","bottom"],"index":2
  612. };
  613. this.elements.push(component);
  614. },
  615. buildEquipment(eq){
  616. let children = [];
  617. let lastHeight = 1;
  618. for (let i=0;i<eq.layer;i++){
  619. let obj = this.currentEl.children[i];
  620. if (obj)lastHeight = obj.height;
  621. children.push({
  622. "height" : lastHeight,
  623. "row" : 0,
  624. "column" : 0,
  625. });
  626. }
  627. eq.children = children;
  628. this.equipmentElements.push(eq);
  629. this.exeSave(this.equipmentElements[this.equipmentElements.length-1]);
  630. },
  631. buildEquipmentGroup(){
  632. let x = this.currentEl.turn ? this.currentEl.x : Number(this.currentEl.x)+(Number(this.currentEl.w)*this.ratio);
  633. let y = this.currentEl.turn ? Number(this.currentEl.y)+(Number(this.currentEl.h)*this.ratio) : this.currentEl.y;
  634. this.buildEqInfo.list.forEach(eq=>{
  635. eq.x = x;
  636. eq.y = y;
  637. if (eq.id<0)this.buildComponent(eq); //构建组件
  638. else this.buildEquipment(eq); //构建设备
  639. if (this.currentEl.turn){
  640. y += eq.h*this.ratio+0.5;
  641. }else{
  642. x += eq.h*this.ratio+0.5;
  643. }
  644. });
  645. window.toast.success("构建完毕");
  646. this.buildEqInfo = {};
  647. $("#buildGroup").modal("hide");
  648. },
  649. getLastChar(str){
  650. let lastChar = str.substr(-1,1);
  651. if (lastChar.search(/[A-Z]/g)===0){
  652. let index = this.charArr.indexOf(lastChar);
  653. let residualCount = this.charArr.length-(index+1);
  654. if (residualCount<this.buildEqInfo.count)return null;
  655. return {type:"CHAR",val:index};
  656. }
  657. if (lastChar.search(/[\d]/g)===0){
  658. let strs = str.replace(/[^\d]/g,'*');
  659. let strsArr = strs.split('*');
  660. return {type:"NUMBER",val:strsArr[strsArr.length-1]};
  661. }
  662. return null;
  663. },
  664. buildGroup(){
  665. let count = this.buildEqInfo.count;
  666. if (!count)return;
  667. let result = this.getLastChar(this.currentEl.code);
  668. if(!result){
  669. window.toast.error("此设备编码不符合组规则");
  670. return;
  671. }
  672. let codeTran = (index)=>{
  673. let size = result.val.toString().length;
  674. let val;
  675. if(result.type==="CHAR"){
  676. if (this.increment){
  677. val=this.charArr[result.val+index];
  678. }else{
  679. val=this.charArr[result.val-index];
  680. }
  681. }else{
  682. if (this.increment){
  683. val=Number(result.val)+index;
  684. }else{
  685. val=Number(result.val)-index;
  686. }
  687. if (val.toString().length<size){
  688. val = (Array(size).join('0') + val).slice(-size);
  689. }
  690. }
  691. return this.currentEl.code.substr(0,this.currentEl.code.length-size)+val;
  692. };
  693. let list = [];
  694. for (let i=1;i<=count;i++){
  695. let obj = Object.assign({},this.currentEl);
  696. obj.eqId = undefined;
  697. obj.updateCoords = undefined;
  698. obj.code = codeTran(i);
  699. list.push(obj);
  700. }
  701. this.$set(this.buildEqInfo,"list",list);
  702. },
  703. pitchEq(el,index){
  704. this.$set(this.buildEqInfo,"current",index);
  705. this.$set(this.buildEqInfo,"currentEqId",el.id);
  706. },
  707. switchEq(el){
  708. if (this.buildEqInfo.currentEqId===el.id)return;
  709. let obj = this.buildEqInfo.list[this.buildEqInfo.current];
  710. obj.id = el.id;
  711. obj.w = el.w;
  712. obj.h = el.h;
  713. obj.describe = el.describe;
  714. obj.grid = el.grid;
  715. obj.layer = el.layer;
  716. obj.color = el.color;
  717. obj.width = el.w;
  718. obj.depth = el.h;
  719. this.$set(this.buildEqInfo,"currentEqId",el.id);
  720. },
  721. openBuildEquipmentGroup(){
  722. if (this.isNotEdit || !this.currentEl.eqId){
  723. window.toast.error("未开启编辑或未选中设备");
  724. return;
  725. }
  726. setTimeout(()=>{
  727. this.getChildren(this.currentEl);
  728. $("#buildGroup").modal("show");
  729. },100);
  730. },
  731. delCoords(){
  732. this.elements.some((el,index)=>{
  733. if (this.currentEl.name === el.name &&
  734. this.currentEl.x === el.x && this.currentEl.y === el.y){
  735. this.$set(this.elements[index],"removeSign",true);
  736. return true;
  737. }
  738. })
  739. },
  740. copyEle(){
  741. if (this.currentEl!=null && JSON.stringify(this.currentEl)!=="{}"){
  742. $('#clipboardDiv').text(JSON.stringify(this.currentEl));
  743. }
  744. },
  745. delEquipment(){
  746. this.equipmentElements.some((el,index)=>{
  747. if (this.currentEl.eqId === el.eqId){
  748. this.$set(this.equipmentElements[index],"removeSign",true);
  749. return true;
  750. }
  751. })
  752. },
  753. delElement(){
  754. if (this.currentEl.eqId)this.delEquipment();
  755. else this.delCoords();
  756. },
  757. addCoords(){
  758. if (this.isNotEdit)return;
  759. this.elements.push({"x":200,"y":200,"width":2,"height":2,"name":"","coords":"居中","border":["left","top","right","bottom"],"color":"white","index":1})
  760. },
  761. clickEditOrSave(){
  762. if(this.isNotEdit){this.isNotEdit = false;return;}
  763. let equipments = [];
  764. let delEquipments = [];
  765. let elements = [];
  766. this.equipmentElements.forEach(equipment=>{
  767. if (equipment.removeSign){
  768. delEquipments.push(equipment.eqId);
  769. }else if (equipment.updateCoords){
  770. equipments.push({
  771. id:equipment.eqId,
  772. info:JSON.stringify({x:equipment.x,y:equipment.y,id:equipment.id,turn:equipment.turn})
  773. });
  774. }
  775. });
  776. this.elements.forEach(el=>{
  777. if (!el.removeSign){
  778. elements.push(el);
  779. }
  780. });
  781. $.ajax({
  782. url : this.baseUrl+"warehouse/saveScene",
  783. type : "POST",
  784. headers:{'Content-Type':'application/json;charset=utf8'},
  785. data:JSON.stringify({id:this.selected,warehouse:JSON.stringify(elements),equipment:equipments,delEquipments:delEquipments}),
  786. success : (res,status)=>{
  787. if (res.code===200){
  788. this.isNotEdit = true;
  789. window.toast.success("场景更改保存成功");
  790. }else window.toast.error(res.message);
  791. },
  792. error : (err,status)=>{
  793. window.tempTip.show("加载失败");
  794. },
  795. complete:(req,status)=>{
  796. if (status==='timeout'){
  797. window.toast.error("服务器响应超时");
  798. }
  799. },
  800. timeout:10000,
  801. })
  802. },
  803. //备选设备拖拽按下事件
  804. eqDown(equipment){
  805. if (this.isNotEdit)return;
  806. if (this.currentEq.obj!==null)return;
  807. let wid = (this.turn ? equipment.w : equipment.h)*this.ratio;
  808. let hei = (this.turn ? equipment.h : equipment.w)*this.ratio;
  809. let div = document.createElement("div");
  810. div.style.width = wid+'px';
  811. div.style.height = hei+'px';
  812. div.style.backgroundColor = equipment.color;
  813. div.style.zIndex = '999';
  814. div.style.position = 'fixed';
  815. div.style.left = event.clientX+'px';
  816. div.style.top = event.clientY+'px';
  817. div.style.border = '1px #0070C0 solid';
  818. div.style.opacity = '0.5';
  819. document.getElementById("container").append(div);
  820. this.currentEq.el = div;
  821. this.currentEq.obj = equipment;
  822. },
  823. //备选设备拖拽移动事件
  824. eqMove(){
  825. if (this.isNotEdit)return;
  826. if (this.currentEq.obj===null)return;
  827. let x = event.clientX;
  828. let y = event.clientY;
  829. setTimeout(()=>{
  830. this.currentEq.el.style.left = x+'px';
  831. this.currentEq.el.style.top = y+'px';
  832. },10);
  833. },
  834. //备选设备拖拽松开事件
  835. eqUp(){
  836. if (this.isNotEdit)return;
  837. if (this.currentEq.obj===null)return;
  838. this.currentEq.el.remove();
  839. setTimeout(()=>{
  840. this.currentEq.el.remove();
  841. this.currentEq.el = null;
  842. },20);
  843. let content = document.getElementById("canvasApp");
  844. let toolWid = document.getElementById("tool").offsetWidth;
  845. let x = event.clientX-toolWid+content.scrollLeft;
  846. let y = event.clientY+content.scrollTop;
  847. if (x>=0 && y>=0){
  848. let children = [];
  849. for (let i=0;i<this.currentEq.obj.layer;i++)children.push({});
  850. let newEquipment = Object.assign({children:children,x:x,y:y}, this.currentEq.obj);
  851. newEquipment.turn = this.turn;
  852. newEquipment.width = newEquipment.w;
  853. newEquipment.depth = newEquipment.h;
  854. this.showAddModal(newEquipment);
  855. }
  856. this.currentEq.obj = null;
  857. },
  858. showAddModal(equipment){
  859. this.equipmentElements.push(equipment);
  860. this.current = this.equipmentElements[this.equipmentElements.length-1];
  861. setTimeout(()=>{
  862. $("#detailInfo").modal("show");
  863. },20);
  864. },
  865. //场景拖拽按下事件
  866. contentOnmousedown(event){
  867. if (!this.isNotEdit || this.clientCoords.x!==undefined)return;
  868. this.clientCoords = {
  869. x:event.clientX,
  870. y:event.clientY
  871. };
  872. },
  873. //场景拖拽移动事件
  874. contentOnmousemove(event){
  875. if (this.clientCoords.x===undefined)return;
  876. let diffX = event.clientX-this.clientCoords.x-2;
  877. let diffY = event.clientY-this.clientCoords.y-2;
  878. let content = document.getElementById("canvasApp");
  879. setTimeout(()=>{
  880. content.scrollTo(content.scrollLeft+diffX,content.scrollTop+diffY);
  881. },10);
  882. },
  883. //场景拖拽松开事件
  884. contentOnmouseup(){
  885. this.clientCoords = {};
  886. },
  887. onActivated(element){
  888. if (this.isNotEdit)return;
  889. this.currentEl = element;
  890. },
  891. //场景大小调整事件
  892. onResizing(newRect){
  893. if (this.isNotEdit)return;
  894. this.currentEl.width=this.accDiv(newRect.width,this.ratio);
  895. this.currentEl.height=this.accDiv(newRect.height,this.ratio);
  896. },
  897. accDiv(arg1,arg2){
  898. let t1=0,t2=0,r1,r2;
  899. try{t1=arg1.toString().split(".")[1].length}catch(e){}
  900. try{t2=arg2.toString().split(".")[1].length}catch(e){}
  901. with(Math){
  902. r1=Number(arg1.toString().replace(".",""))
  903. r2=Number(arg2.toString().replace(".",""))
  904. return this.accMul((r1/r2),pow(10,t2-t1));
  905. }
  906. },
  907. accMul(arg1,arg2){
  908. let m=0,s1=arg1.toString(),s2=arg2.toString();
  909. try{m+=s1.split(".")[1].length}catch(e){}
  910. try{m+=s2.split(".")[1].length}catch(e){}
  911. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
  912. },
  913. //场景拖拽事件
  914. onDragging(newRect){
  915. if (this.isNotEdit)return;
  916. this.currentEl.x=newRect.left;
  917. this.currentEl.y=newRect.top;
  918. $("#canvas").focus();
  919. },
  920. equipmentDrag(newRect){
  921. if (this.isNotEdit)return;
  922. this.currentEl.x=newRect.left;
  923. this.currentEl.y=newRect.top;
  924. this.currentEl.updateCoords = true;
  925. $("#canvas").focus();
  926. },
  927. //文本类属性改变
  928. changeText(key){
  929. this.currentEl[key] = event.target.value;
  930. },
  931. //数值类属性改变
  932. changeNumber(key){
  933. let val = event.target.value;
  934. this.currentEl[key] = val ? parseFloat(val) : 0;
  935. },
  936. _getObjFirstKey(obj){
  937. for(let key in obj){
  938. return key;
  939. }
  940. return null;
  941. },
  942. /**
  943. * 构建库位的默认值信息
  944. * */
  945. _locationAttrDefault(){
  946. this.buildPool.usage = this._getObjFirstKey(this.locationAttr.usage);
  947. this.buildPool.handling = this._getObjFirstKey(this.locationAttr.handling);
  948. this.buildPool.attribute = this._getObjFirstKey(this.locationAttr.attribute);
  949. this.buildPool.category = this._getObjFirstKey(this.locationAttr.category);
  950. this.buildPool.demand = this._getObjFirstKey(this.locationAttr.demand);
  951. this.buildPool.mixFlag = true;
  952. this.buildPool.mixLotFlag = false;
  953. this.buildPool.loseIdFlag = true;
  954. },
  955. /**
  956. * 批量构建库位时的操作
  957. * */
  958. nextDetailBatch(index){
  959. if (!this.current.children || this.current.children.length===0){
  960. window.toast.error("设备信息尚未加载完毕,请稍后重试!");
  961. return;
  962. }
  963. this.batchSign = true;
  964. this.currentEqChildIndex = index-1;
  965. setTimeout(function (){
  966. let parentDom = document.getElementById("locationAttr").firstChild.firstChild;
  967. let childDom = document.getElementById("locationModal").firstChild.firstChild;
  968. childDom.style.minWidth = parentDom.offsetWidth+'px';
  969. childDom.style.minHeight = parentDom.offsetHeight+'px';
  970. $("#locationModal").modal("show");
  971. },20);
  972. this._locationAttrDefault();
  973. },
  974. //子设备选定时的库位加载
  975. nextDetail(index){
  976. if (!this.current.eqId)return;
  977. this.batchSign = false;
  978. this.currentEqChildIndex = index-1;
  979. this.isLoadLocation = true;
  980. this._locationAttrDefault();
  981. setTimeout(function (){
  982. let parentDom = document.getElementById("detailInfo").firstChild.firstChild;
  983. let childDom = document.getElementById("locationModal").firstChild.firstChild;
  984. childDom.style.minWidth = (parentDom.offsetWidth+200)+'px';
  985. childDom.style.minHeight = parentDom.offsetHeight+'px';
  986. $("#locationModal").modal("show");
  987. },20);
  988. let children = this.current.children[this.currentEqChildIndex];
  989. this.current.children.forEach(item=>{
  990. item.row = Number(item.row);
  991. item.column = Number(item.column);
  992. });
  993. $.ajax({
  994. url : this.baseUrl+"location/get",
  995. type : "post",
  996. dataType : "JSON",
  997. data : {id:children.id},
  998. success : (res)=>{
  999. switch (res.code){
  1000. case 200:
  1001. this.locations = res.data[0];
  1002. this.locationMapping = res.data[1] ? res.data[1] : {};
  1003. this.isLoadLocation = false;
  1004. break;
  1005. default:
  1006. window.toast.error(res.message);
  1007. }
  1008. },
  1009. error : (err)=>{
  1010. window.tempTip.setIndex(999);
  1011. window.tempTip.show("网络错误");
  1012. },
  1013. timeout:3000,
  1014. })
  1015. },
  1016. showDetail(equipment){
  1017. this._getLocationAttr();
  1018. if (!this.isNotEdit)return;
  1019. this.current = equipment;
  1020. setTimeout(()=>{
  1021. $("#detailInfo").modal("show");
  1022. this.contentOnmouseup();
  1023. },20);
  1024. this.getChildren(this.current);
  1025. },
  1026. getChildren(equipment){
  1027. if (equipment.children && equipment.children.length>0){
  1028. return;
  1029. }
  1030. $.ajax({
  1031. url : this.baseUrl+"equipment/getChildren",
  1032. type : "post",
  1033. dataType : "JSON",
  1034. data : {id:equipment.eqId},
  1035. success : (res)=>{
  1036. switch (res.code){
  1037. case 200:
  1038. res.data.forEach(eq=>{
  1039. let tab = eq.location_tab.split("-");
  1040. eq.row = Number(tab[0]);
  1041. eq.column = Number(tab[1]);
  1042. });
  1043. this.$set(equipment,"children",res.data);
  1044. break;
  1045. default:
  1046. window.toast.error("服务器错误");
  1047. }
  1048. },
  1049. error : (err)=>{
  1050. window.tempTip.setIndex(999);
  1051. window.tempTip.show("网络错误");
  1052. },
  1053. timeout:3000,
  1054. })
  1055. },
  1056. saveOrUpdate(){
  1057. this.error = {};
  1058. let error = this._checkEquipmentData(this.current);
  1059. if (JSON.stringify(error)!=="{}"){
  1060. this.error = error;return;
  1061. }
  1062. this.exeSave(this.current);
  1063. },
  1064. exeSave(equipment){
  1065. let params = this._formatEquipmentData(equipment);
  1066. params.warehouseDetailId = this.selected;
  1067. $.ajax({
  1068. url : this.baseUrl+"equipment/saveOrUpdate",
  1069. type : "post",
  1070. dataType : "JSON",
  1071. headers:{'Content-Type':'application/json;charset=utf8'},
  1072. data : JSON.stringify(params),
  1073. success : (res)=>{
  1074. switch (res.code){
  1075. case 200:
  1076. equipment.eqId = res.data[0];
  1077. let locCount = 0;
  1078. equipment.children.forEach((item,index)=>{
  1079. item.id = res.data[1][index];
  1080. if (item.row && Number(item.row) > 0){
  1081. locCount += Number(item.row) * Number(item.column)
  1082. }
  1083. });
  1084. equipment.exist = locCount;
  1085. this.$forceUpdate();
  1086. $("#detailInfo").modal("hide");
  1087. window.toast.success("保存成功");
  1088. break;
  1089. case 701:
  1090. this.error = res.data;
  1091. break;
  1092. case 414:
  1093. this.error = {code:"设备编码重复"};
  1094. window.toast.error(this.error.code);
  1095. break;
  1096. default:
  1097. window.toast.error("服务器错误:"+res.message);
  1098. }
  1099. },
  1100. error : (err)=>{
  1101. console.error(err);
  1102. window.tempTip.setIndex(999);
  1103. window.tempTip.show("网络错误");
  1104. },
  1105. timeout:3000,
  1106. })
  1107. },
  1108. _checkEquipmentData(equipment){
  1109. let error = {};
  1110. if (!equipment.code)error.code = "设备编号未填写";
  1111. if (!equipment.width)error.width = "设备宽度未填写";
  1112. if (!equipment.depth)error.depth = "设备深度未填写";
  1113. if (equipment.layer !== equipment.children.length)error.children = "设备绑定错误";
  1114. for (let i=0;i<equipment.layer;i++){
  1115. if (!equipment.children[i].height)error["children["+i+"].height"] = "设备高度不得为空"
  1116. if (!equipment.children[i].column && equipment.children[i].column!=0)error["children["+i+"].column"] = "库位列数不得为空"
  1117. if (!equipment.children[i].row && equipment.children[i].row!=0)error["children["+i+"].row"] = "库位行数不得为空"
  1118. }
  1119. return error;
  1120. },
  1121. _formatEquipmentData(equipment){
  1122. let eq = {};
  1123. eq.id = equipment.eqId;
  1124. eq.code = equipment.code;
  1125. eq.repositoryId = equipment.repository;
  1126. eq.info = JSON.stringify({'x':equipment.x,'y':equipment.y,'id':equipment.id,'turn':!!equipment.turn});
  1127. eq.depth = equipment.depth;
  1128. eq.width = equipment.width;
  1129. eq.children = equipment.children;
  1130. return eq;
  1131. },
  1132. removeLocationBind(){
  1133. if (this.isLoadLocation)return;
  1134. this.isLoadLocation = true;
  1135. $.ajax({
  1136. url : this.baseUrl+"location/removeLocationBind",
  1137. type : "post",
  1138. dataType : "JSON",
  1139. data : {id:this.current.children[this.currentEqChildIndex].id},
  1140. success : (res)=>{
  1141. switch (res.code){
  1142. case 200:
  1143. this.current.children[this.currentEqChildIndex].row = 0;
  1144. this.current.children[this.currentEqChildIndex].column = 0;
  1145. this.locations = [];
  1146. window.toast.success("解除成功!");
  1147. break;
  1148. default:
  1149. window.toast.error("库位无法释放,解除失败");
  1150. }
  1151. },
  1152. error : (err)=>{
  1153. window.tempTip.setIndex(999);
  1154. window.tempTip.show("网络错误");
  1155. },
  1156. complete:()=>{
  1157. this.isLoadLocation = false;
  1158. },
  1159. timeout:3000,
  1160. })
  1161. },
  1162. locationBatchBind(){
  1163. $("#loading").show();
  1164. let arr = this.batchEquipment[this.batchEquipmentSign];
  1165. let request = [];
  1166. let failTipList = {};
  1167. arr.forEach(index=>{
  1168. let eq = this.equipmentElements[index];
  1169. if (!eq){
  1170. window.toast.error("异常设备选择");
  1171. }else if (!eq.children || eq.children.length===0 || !eq.children[this.currentEqChildIndex]){
  1172. failTipList[eq.code]="详情尚未加载完毕";
  1173. }else{
  1174. let item = eq.children[this.currentEqChildIndex];
  1175. let code = eq.code+'-'+(this.currentEqChildIndex+1);
  1176. request.push(Object.assign({id:item.id,code:code},
  1177. this.buildPool))
  1178. }
  1179. });
  1180. $.ajax({
  1181. url : this.baseUrl+"location/locationBatchBound",
  1182. type : "post",
  1183. dataType : "JSON",
  1184. data : JSON.stringify(request),
  1185. headers:{'Content-Type':'application/json;charset=utf8'},
  1186. success : (res)=>{
  1187. switch (res.code){
  1188. case 200:
  1189. $("#locationModal").modal('hide');
  1190. window.toast.success("构建完毕!");
  1191. this.failTipList = Object.assign(failTipList,res.data);
  1192. if (JSON.stringify(this.failTipList)!=="{}"){
  1193. $("#failTipList").modal("show");
  1194. }
  1195. let ele = document.querySelectorAll("#locationAttr span.el-center")[this.current.layer-1-this.currentEqChildIndex];
  1196. ele.className += " bg-success";
  1197. break;
  1198. default:
  1199. window.toast.error(res.message);
  1200. }
  1201. },
  1202. error : (err)=>{
  1203. window.tempTip.setIndex(999);
  1204. window.tempTip.show("网络错误");
  1205. },
  1206. complete:(req,status)=>{
  1207. $("#loading").hide();
  1208. if (status==='timeout'){
  1209. window.toast.error("库位批量构建失败,响应超时");
  1210. }
  1211. },
  1212. timeout:3000,
  1213. });
  1214. },
  1215. locationBind(){
  1216. if (this.batchSign){
  1217. this.locationBatchBind();
  1218. return;
  1219. }
  1220. if (this.isLoadLocation)return;
  1221. let eq = this.current.children[this.currentEqChildIndex];
  1222. let code = this.current.code+'-'+(this.currentEqChildIndex+1);
  1223. this.isLoadLocation = true;
  1224. $.ajax({
  1225. url : this.baseUrl+"location/locationBind",
  1226. type : "post",
  1227. dataType : "JSON",
  1228. headers:{'Content-Type':'application/json;charset=utf8'},
  1229. data : JSON.stringify(Object.assign({id:eq.id,code:code},this.buildPool)),
  1230. success : (res)=>{
  1231. switch (res.code){
  1232. case 200:
  1233. this.locations = res.data;
  1234. window.toast.success("构建成功!");
  1235. this.current.children[this.currentEqChildIndex].row = Number(this.buildPool.row);
  1236. this.current.children[this.currentEqChildIndex].column = Number(this.buildPool.column);
  1237. this._locationAttrDefault();
  1238. $("#locationModal").modal("hide");
  1239. this.$forceUpdate();
  1240. break;
  1241. default:
  1242. window.toast.error(res.message);
  1243. }
  1244. },
  1245. error : (err)=>{
  1246. window.tempTip.setIndex(999);
  1247. window.tempTip.show("网络错误");
  1248. },
  1249. complete:(req,status)=>{
  1250. this.isLoadLocation = false;
  1251. if (status==='timeout'){
  1252. window.toast.error("库位建立失败,响应超时");
  1253. }
  1254. },
  1255. timeout:3000,
  1256. })
  1257. },
  1258. showAddWarehouseDetail(){
  1259. if (this.ws.length>0){
  1260. $("#warehouseDetail").modal("show");
  1261. return;
  1262. }
  1263. $.ajax({
  1264. url : this.baseUrl+"warehouse/getList",
  1265. type : "get",
  1266. dataType : "JSON",
  1267. success : (res)=>{
  1268. switch (res.code){
  1269. case 200:
  1270. this.ws = res.data;
  1271. $("#warehouseDetail").modal("show");
  1272. break;
  1273. default:
  1274. window.toast.error("仓库获取失败");
  1275. }
  1276. },
  1277. error : (err)=>{
  1278. window.tempTip.setIndex(999);
  1279. window.tempTip.show("网络错误");
  1280. },
  1281. complete:(req,status)=>{
  1282. this.isLoadLocation = false;
  1283. if (status==='timeout'){
  1284. window.toast.error("获取仓库超时");
  1285. }
  1286. },
  1287. timeout:3000,
  1288. })
  1289. },
  1290. addWarehouseDetail(){
  1291. $.ajax({
  1292. url : this.baseUrl+"warehouse/detail",
  1293. type : "post",
  1294. dataType : "JSON",
  1295. headers:{'Content-Type':'application/json;charset=utf8'},
  1296. data : JSON.stringify(this.warehouseDetail),
  1297. success : (res)=>{
  1298. switch (res.code){
  1299. case 200:
  1300. window.toast.success("仓库新建成功");
  1301. this.warehouses = res.data;
  1302. $("#warehouseDetail").modal("hide");
  1303. break;
  1304. default:
  1305. window.toast.error(res.message);
  1306. }
  1307. },
  1308. error : (err)=>{
  1309. window.tempTip.setIndex(999);
  1310. window.tempTip.show("网络错误");
  1311. },
  1312. timeout:3000,
  1313. })
  1314. },
  1315. openRepository(){
  1316. $.ajax({
  1317. url : this.baseUrl+"repository/group",
  1318. type : "get",
  1319. dataType : "JSON",
  1320. data:{id:this.selected},
  1321. success : (res)=>{
  1322. switch (res.code){
  1323. case 200:
  1324. this.group = res.data;
  1325. $("#repository").modal("show");
  1326. break;
  1327. default:
  1328. window.toast.error("获取区域失败");
  1329. }
  1330. },
  1331. error : (err)=>{
  1332. window.tempTip.setIndex(999);
  1333. window.tempTip.show("网络错误");
  1334. },
  1335. complete:(req,status)=>{
  1336. this.isLoadLocation = false;
  1337. if (status==='timeout'){
  1338. window.toast.error("获取区域超时");
  1339. }
  1340. },
  1341. timeout:3000,
  1342. })
  1343. },
  1344. addRepository(){
  1345. this.repository.warehouseDetailId = this.selected;
  1346. $.ajax({
  1347. url : this.baseUrl+"repository/addRepository",
  1348. type : "post",
  1349. dataType : "JSON",
  1350. headers:{'Content-Type':'application/json;charset=utf8'},
  1351. data:JSON.stringify(this.repository),
  1352. success : (res)=>{
  1353. switch (res.code){
  1354. case 200:
  1355. this.repositories.push(res.data);
  1356. $("#repository").modal("hide");
  1357. this.repository = {};
  1358. break;
  1359. default:
  1360. window.toast.error("库区建立失败");
  1361. }
  1362. },
  1363. error : (err)=>{
  1364. window.tempTip.setIndex(999);
  1365. window.tempTip.show("网络错误");
  1366. },
  1367. complete:(req,status)=>{
  1368. this.isLoadLocation = false;
  1369. if (status==='timeout'){
  1370. window.toast.error("建立库区超时");
  1371. }
  1372. },
  1373. timeout:3000,
  1374. })
  1375. },
  1376. /**
  1377. * 批量构建设备库位时的选中操作
  1378. * */
  1379. batchEquipmentSelected(arr,index){
  1380. this.current = this.equipmentElements[arr[0]];
  1381. this.batchEquipmentSign = index;
  1382. arr.forEach(i=>{
  1383. this.getChildren(this.equipmentElements[i]);
  1384. })
  1385. this._getLocationAttr();
  1386. },
  1387. },
  1388. filters:{
  1389. qty(code){
  1390. let inv = vue.locationMapping[code];
  1391. if(!inv)return 0;
  1392. return inv.QTY;
  1393. },
  1394. qtyOver(code){
  1395. let inv = vue.locationMapping[code];
  1396. if(!inv)return 0;
  1397. return inv.QTYALLOCATED + inv.QTYMVIN + inv.QTYMVOUT + inv.QTYONHOLD + inv.QTYPA + inv.QTYRPIN + inv.QTYRPOUT;
  1398. },
  1399. childStyle(code){
  1400. let inv = vue.locationMapping[code];
  1401. if (!inv)return '';
  1402. let qty = inv.QTY;
  1403. let other = inv.QTYALLOCATED + inv.QTYMVIN + inv.QTYMVOUT + inv.QTYONHOLD + inv.QTYPA + inv.QTYRPIN + inv.QTYRPOUT;
  1404. return (qty>0 || other>0) ?
  1405. 'color: #fff;background-color: #38c172;border-color: #38c172;' : '';
  1406. },
  1407. formatCount(tab){
  1408. let arr = tab.split("-");
  1409. return arr[0]*arr[1];
  1410. }
  1411. }
  1412. });
  1413. </script>
  1414. </html>