locationStatus.vue 20.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
<template>
  <a-card :bordered="false">
      <form id="container-form">
        <div class="select-list">
          <ul id="select_info">
            <li>
              <a-select
                show-search
                placeholder="请选择库区"
                option-filter-prop="children"
                v-model="zoneCode"
                @change="refresh"
                style="width: 200px">
                <a-select-option selected="0" id="zoneCode" v-for="item in zoneList" :key="item.name" :value="item.code">{{ item.name }}
                </a-select-option>
              </a-select>
            </li>
            <li>第
              <a-select
                show-search
                option-filter-prop="children"
                v-model="num"
                style="width: 70px">
                <a-select-option id="num" v-for="num in nums" :key="num" :value="num">{{ num }}
                </a-select-option>
              </a-select>
            </li>
            <li>
              <a-select
                show-search
                option-filter-prop="children"
                v-model="col"
                @change="refresh"
                style="width: 70px">
                <a-select-option id="col" v-for="item in colList" :key="item.name" :value="item.code">{{ item.name }}
                </a-select-option>
              </a-select>
            </li>
            <li>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="search()" icon="search" style="margin-left: 8px;">查询</a-button>
                <a-button @click='expressDelivery()' type='primary' v-if="expressDeliveryVisible" style="margin-left: 8px;">平库出库</a-button>
                <a-button @click="expressStorage()" type="primary" v-if="expressStorageVisible" style="margin-left: 8px;">平库入库</a-button>
              </span>
            </li>
          </ul>
        </div>
      </form>
    <div class="col-sm-12 select-info">
      <form id="receiptHeader-form">
        <div class="select-list">
          <ul id="img_list">
            <li style="font-size: 12px">空柜空闲:<img src="~@/assets/icon/grid_rest.png"></li>
            <li style="font-size: 12px">空盘空闲:<img src="~@/assets/icon/grid_empty.png" alt=""></li>
            <li style="font-size: 12px">整盘空闲:<img src="~@/assets/icon/grid_all.png"></li>
            <li style="font-size: 12px">空柜锁定:<img src="~@/assets/icon/grid_emp_lock.png"></li>
            <li style="font-size: 12px">空盘锁定:<img src="~@/assets/icon/grid_empty_lock.png"></li>
            <li style="font-size: 12px">整盘锁定:<img src="~@/assets/icon/grid_all_lock.png"></li>
          </ul>
          <ul id="info_list">
            <li>
              <span style="font-size: 12px">库位统计情况:</span>
              <input style="width: 600px; font-size: 12px; border: none;" type="text" id="zone" disabled/>
            </li><br><br>
            <li><span>库位:</span><input type="text" style="width: 100px; font-size: 12px; border: none;" id="code" disabled/></li><br><br>
            <li><span>容器:</span><input type="text" style="width: 200px; font-size: 12px; border: none;" id="containerCode" disabled/></li><br><br>
            <li style="width: 100%;">
              <span style="height: 32px; line-height:26px;">物项:</span>
              <a-textarea v-model="materialInfo" auto-size style="padding: 4px 5px; width: 80%; font-size: 12px; resize: none; vertical-align:top; border: none;  box-shadow: none; outline:none;" readonly />
            </li>
          </ul>
        </div>
      </form>
    </div>
    <div class="col-sm-12 select-info">
      <div id="borderCol" style="overflow-y: auto;white-space:nowrap" v-show="showPrise">
        <div class="location" id="location"></div>
      </div>
      <a-spin tip="库位视图生成中..." :spinning="spinning">
        <a-skeleton active :loading="loading" :paragraph="{ rows: 5 }"/>
      </a-spin>
    </div>
    <ExpressStorageModal ref="ExpressStorageModal" @ok="search"></ExpressStorageModal>
    <ExpressDeliveryModal ref="ExpressDeliveryModal" @ok="search"></ExpressDeliveryModal>
  </a-card>
</template>

<script>

import huahengUI from '@/assets/css/huahengUI.css'
import $ from '../../../assets/js/jquery-1.11.1.min'
import grid_rest from '@/assets/icon/grid_rest.png'
import grid_empty from '@/assets/icon/grid_empty.png'
import grid_half from '@/assets/icon/grid_half.png'
import grid_all from '@/assets/icon/grid_all.png'
import grid_emp_waing from '@/assets/icon/grid_emp_waing.png'
import grid_empty_waring from '@/assets/icon/grid_empty_waring.png'
import grid_half_waring from '@/assets/icon/grid_half_waring.png'
import grid_all_waring from '@/assets/icon/ContainerDisabled.png'
import grid_emp_lock from '@/assets/icon/grid_emp_lock.png'
import grid_empty_lock from '@/assets/icon/grid_empty_lock.png'
import grid_half_lock from '@/assets/icon/grid_half_lock.png'
import grid_all_lock from '@/assets/icon/grid_all_lock.png'
import rel_empty from '@/assets/icon/rel_empty.png'
import {getInventoryDetailByLocationCode, getZoneList} from '@/api/api'
import ExpressDeliveryModal from "@views/system/monitor/modules/ExpressDeliveryModal";
import ExpressStorageModal from "@views/system/monitor/modules/ExpressStorageModal";
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {getAction, postAction} from "@api/manage";


export default {
  name: "locationStatus",
  mixins: [JeecgListMixin],
  components: {
    ExpressStorageModal,
    ExpressDeliveryModal
  },
  data() {
    return {
      spinning: true,
      loading: true,
      showPrise: false,
      expressDeliveryVisible: false,
      expressStorageVisible: false,
      col: "row",
      materialInfo: "",
      colList: [
        {code: "row", name: "行"},
        {code: "line", name: "列"},
        {code: "layer", name: "层"}
      ],
      zoneCode: '',
      zoneList: [],
      num: 1,
      nums: [],
      model: {},
      url: {
        getStatus: "/location/locationMonitor/getStatus",
        getLocationInfo: "/location/locationMonitor/getLocationInfo",
        getAllLocation: "/location/locationMonitor/getAllLocation"
      },
      grid_row: null,
      grid_line: null,
      grid_layer: null,
      list_info: null,
      currentLocationCode: 0,
    }
  },
  created() {
    this.loadFrom()
    window.gridMsg = this.gridMsg
    window.mClose = this.mClose
    window.lays = this.lays
  },
  mounted() {
    // 方法一:确保 .location 元素存在且已渲染
    const locationElement = document.querySelector('.location');
    if (locationElement) {
      const resizeObserver = new ResizeObserver(entries => {
        for (let entry of entries) {
          this.changeMargin();
        }
      });
      resizeObserver.observe(locationElement);
      setTimeout(() => {
        this.refresh(); // 使用箭头函数,this 指向 Vue 组件实例
      }, 1000);
    }
  },
  methods: {
    loadData() {
      // 空方法,为了覆盖混入文件中的方法,解决报错
    },
    loadFrom() {
      getZoneList().then((res) => {
        if (res.success) {
          this.zoneList = res.result;
          if (this.zoneList.length > 0) {
            this.zoneCode = this.zoneList[0].code;
          }
        }
      })
    },
    handleNumsSelect() {
      let col = this.col;
      if (col === "row") {
        this.nums = this.grid_row;
      } else if (col === "line") {
        this.nums = this.grid_line;
      } else if (col === "layer") {
        this.nums = this.grid_layer;
      } else {
        this.$message.warning("错误");
      }
    },
    refresh() {
      let url = this.url.getAllLocation
      getAction(url, {zoneCode: this.zoneCode}).then(res => {
        if (res.success) {
          this.grid_row = res.result.maxRow;
          this.grid_line = res.result.maxLine;
          this.grid_layer = res.result.maxLayer;
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.handleNumsSelect();
        this.search();
      })
      this.locationStatistics();
    },
    //格子宽度
    changeMargin() {
      let box_width = 0;
      if (document.getElementById("location") != null) {
        box_width = document.getElementById("location").offsetWidth;
      }
      box_width = box_width - 80;
      let num = this.col;
      let grid_width;
      if (num === "layer" || num === "row") {
        grid_width = box_width / this.grid_line;
      } else if (num === "line") {
        grid_width = box_width / this.grid_row;
      }
      if (grid_width >= 50) {
        $(".grid").css({"width": "50px", "height": "50px"});
      } else if (grid_width <= 20) {
        $(".grid").css({"width": "20px", "height": "20px"});
      } else {
        $(".grid").css({"width": grid_width, "height": grid_width});
      }
    },
    //tips信息
    lays(x) {
      let $j = $(x);
      let row = $j.attr("data-i");
      let line = $j.attr("data-j");
      let layers = $j.attr("data-k");
      row = parseInt(row);
      line = parseInt(line);
      layers = parseInt(layers);
      if (this.list_info) {
        for (const element of this.list_info) {
          if (element.row === row && element.icolumn === line && element.layer === layers) {
            let str_info = '';
            let container_code = '';
            if (element.containerCode) {
              container_code = "\n容器编码:" + element.containerCode + "";
              if (element.materialName) {
                for (let j = 0; j < element.materialName.length; j++) {
                  let list_batch = element.batch[j].length == 0 ? "无" : element.batch[j];
                  let list_qty = element.qty[j];
                  str_info += "\n物项信息:批次->" + list_batch + ",物项名称->" + element.materialName[j] + ",物项编码->" + element.materialCode[j] + ",数量->" + list_qty + ""
                }
              }
            }
            let code = element.code === null ? "无" : element.code;
            $("[data-i='" + row + "']" + "[data-j='" + line + "']" + "[data-k='" + layers + "']").attr({"title": "第" + row + "行,第" + line + "列,第" + layers + "层\n库位:" + code + container_code + str_info});
          }
        }
      } else {
        return ""
      }
    },
    // 快速入库
    expressStorage() {
      let json = {
        "containerCode": this.currentContainerCode,
        "locationCode": this.currentLocationCode
      }
      this.$refs.ExpressStorageModal.edit(json);
    },
    // 获取库存信息
    getInventory(locationCode) {
      let params = {
        locationCode: locationCode
      }
      getInventoryDetailByLocationCode(params).then((res) => {
        if (res.success) {
          let parameter = [];
          let newArr = res.result.records;
          for (let i of newArr) {
            let param = {
              materialCode: i.materialCode,
              qty:i.qty,
              shipQty: 0,
              inventoryDetailId: i.id,
              containerCode: i.containerCode
            }
            parameter.push(param);
          }
          this.$refs.ExpressDeliveryModal.edit(parameter);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //快速出库
    expressDelivery() {
      this.getInventory(this.currentLocationCode);
    },
    // 显示快速出库
    revealExpressDelivery(code, materialCode) {
      this.expressDeliveryVisible = !!materialCode;
      if (this.zoneCode != 'P') {
        this.expressDeliveryVisible = false;
      }
    },
    // 显示快速入库
    revealExpressStorage(code) {
      this.expressStorageVisible = !!code;
      if (this.zoneCode != 'P') {
        this.expressStorageVisible = false;
      }
    },
    //关闭tips
    mClose(x) {
      //关闭
      // Vue.prototype.$Jnotification.error({message: '系统提示', description: "鼠标拿走了", duration: 4})
    },
    //库位信息请求和状态显示
    ajaxGrid(x, info) {
      let _this = this
      let url = this.url.getLocationInfo;
      postAction(url, info).then(res => {
        if (res.success) {
          if (x === "row") {
            for (let i = 0; i < res.result.length; i++) {
              let index = res.result[i].icolumn + ((res.result[i].layer - 1) * this.grid_line);
              index = index - 1;
              _this.resShow(res, index, i);
            }
            _this.clearLocation(this.grid_line, this.grid_layer);
          } else if (x === "line") {
            for (let i = 0; i < res.result.length; i++) {
              let index = res.result[i].row + ((res.result[i].layer - 1) * this.grid_row);
              index = index - 1;
              _this.resShow(res, index, i);
            }
            _this.clearLocation(this.grid_row, this.grid_layer);
          } else if (x === "layer") {
            for (let i = 0; i < res.result.length; i++) {
              let index = res.result[i].icolumn + ((res.result[i].row - 1) * this.grid_line);
              index = index - 1;
              _this.resShow(res, index, i);
            }
            _this.clearLocation(this.grid_line, this.grid_row);
          }
        } else {
          this.$message.error(res.message);
        }
        this.list_info = res.result;
      }).finally(() => {

      })
    },
    //库位请求的结果显示
    resShow(res, index, i) {
      let row = res.result[i].row;
      let jColumn = res.result[i].icolumn;
      let kLayer = res.result[i].layer;
      if (res.result[i].locationAttribute === "1") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_rest,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "2") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_empty,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "3") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_half,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "4") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_all,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "5") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_emp_lock,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "6") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_empty_lock,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "7") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_half_lock,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "8") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_all_lock,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "9") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_emp_waing,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "10") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_empty_waring,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "11") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_half_waring,
          "isTrue": 1
        });
      } else if (res.result[i].locationAttribute === "12") {
        $("[data-i='" + row + "']" + "[data-j='" + jColumn + "']" + "[data-k='" + kLayer + "']").attr({
          "src": grid_all_waring,
          "isTrue": 1
        });
      }
    },
    //清除将数据库中没有的库位
    clearLocation(x, y) {
      for (let j = 0; j < x * y; j++) {
        let $grid = $(".grid");
        let sta = $grid.eq(j).attr("isTrue");
        if (sta !== "1") {
          $grid.eq(j).attr({"src": rel_empty, "onmouseover": "", "onclick": ""});
        }
      }
      this.spinning = false;
      this.showPrise = true;
      this.loading = false;
    },
    //点击显示当前库位信息
    gridMsg(msg) {
      let $j = $(msg);
      let row = $j.attr("data-i");
      let line = $j.attr("data-j");
      let layers = $j.attr("data-k");
      row = parseInt(row);
      line = parseInt(line);
      layers = parseInt(layers);
      if (this.list_info) {
        for (const element of this.list_info) {
          if (element.row === row && element.icolumn === line && element.layer === layers) {
            let materialCode = '';
            //let $material = $("#material");
            if (element.materialName) {
              //$material.children().remove();
              let str_info = '';
              for (let j = 0; j < element.materialName.length; j++) {
                let list_batch = element.batch[j].length === 0 ? "无" : element.batch[j];
                let list_qty = element.qty[j];
                str_info += "批次->" + list_batch + ",物项名称->" + element.materialName[j] + ",物项编码->" + element.materialCode[j] + ",数量->" + list_qty;
                materialCode = element.materialCode[j];
                if (j !== element.materialName.length -1) {
                  str_info += "\r\n"
                }
              }
              this.materialInfo = str_info
            } else {
              this.materialInfo = "无"
            }
            let $code = $("#code");
            $code.val(element.code);
            $("#containerCode").val(element.containerCode === "" ? "无" : element.containerCode);
            this.currentContainerCode = element.containerCode;
            this.currentLocationCode = $code.val()
            this.revealExpressDelivery(element.code, materialCode);
            this.revealExpressStorage(element.code);
            break;
          }
        }
      } else {
        return ""
      }
    },
    //搜索平面库位
    search() {
      this.spinning = true;
      this.showPrise = false;
      this.loading = true;
      let col = this.col;
      let num = this.num;
      let data;

      $("#location").children().remove();
      let $location = $(".location");
      if (col === "row") {
        data = {zoneCode: this.zoneCode, row: num};
        for (let i = this.grid_layer; i > 0; i--) {
          if (i != this.grid_layer) {
            $location.append("<br>")
          }
          $location.append("<span style='display: inline-block;text-align: right;width: 50px; margin-right: 10px;'>第" + i + "层</span>");
          for (let j = 1; j <= this.grid_line; j++) {
            $location.append("<img data-i=" + num + " data-j=" + j + " data-k=" + i + " class='grid' onmouseover='lays(this)' onmouseout='mClose(this)' onclick='gridMsg(this)'>");
          }
        }
      } else if (col === "line") {
        data = {zoneCode: this.zoneCode, line: num};
        for (let k = this.grid_layer; k > 0; k--) {
          if (k != this.grid_layer) {
            $location.append("<br>")
          }
          $location.append("<span style='display: inline-block;text-align: right;width: 50px; margin-right: 10px;'>第" + k + "层</span>");
          for (let l = 1; l <= this.grid_row; l++) {
            $location.append("<img data-i=" + l + " data-j=" + num + " data-k=" + k + " class='grid' onmouseover='lays(this)' onmouseout='mClose(this)' onclick='gridMsg(this)'>");
          }
        }
      } else if (col === "layer") {
        data = {zoneCode: this.zoneCode, layer: num};
        for (let m = 1; m <= this.grid_row; m++) {
          if (m != 1) {
            $location.append("<br>")
          }
          $location.append("<span style='display: inline-block;text-align: right;width: 50px; margin-right: 10px;'>第" + m + "行</span>");
          for (let n = 1; n <= this.grid_line; n++) {
            $location.append("<img data-i=" + m + " data-j=" + n + " data-k=" + num + " class='grid' onmouseover='lays(this)' onmouseout='mClose(this)' onclick='gridMsg(this)'>");
          }
        }
      }
      this.ajaxGrid(col, data);
    },
    locationStatistics() {
      let url = this.url.getStatus;
      getAction(url, {zoneCode: this.zoneCode}).then(res => {
        if (res.success) {
          $("#zone").val("库位总数:" + res.result.location + ",空库位:" + res.result.emptyLocation +
            ",空托盘库位:" + res.result.haveContainLocation + ",有货库位:" + res.result.haveInventoryLocation)
        } else {
          this.$message.warning(res.message)
        }
      }).finally()
    }
  }
}
</script>