index.blade.php 69 KB

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