index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <div>
  3. <el-row :gutter="20">
  4. <el-col :span="8">
  5. <div class="type-title">载具入库</div>
  6. <ScanCodeInput
  7. v-model="boxSearch"
  8. :clearable="true"
  9. :showSuffix="true"
  10. placeholder="请扫描或输入料箱编号"
  11. @keyup.enter="enterBox"
  12. :disabled="outStatus || addStatus"
  13. />
  14. <el-scrollbar class="boxes-container base-container">
  15. <div
  16. v-for="(item, index) in boxesList"
  17. :key="index"
  18. :class="{ 'box-selected': index === currentBoxIndex }"
  19. class="box-item"
  20. @click="clickBox(item, index)"
  21. >
  22. <div class="box-header">
  23. <div class="box-name">{{ item.vehicleNo }}</div>
  24. <div class="box-name">
  25. {{ item.locationNo ? item.locationNo : "-" }}
  26. </div>
  27. </div>
  28. <div
  29. v-for="(material, index) in item.list"
  30. :key="index"
  31. class="box-info"
  32. >
  33. <div>{{ material.materialName }}</div>
  34. <div>{{ material.num }}</div>
  35. </div>
  36. </div>
  37. </el-scrollbar>
  38. <el-button
  39. class="sureBtn"
  40. type="primary"
  41. :disabled="outStatus || addStatus || Machinery"
  42. @click="sureToOut"
  43. >出库
  44. </el-button>
  45. </el-col>
  46. <el-col :span="8">
  47. <div class="type-title">原有物料</div>
  48. <el-scrollbar class="outing-container">
  49. <div style="height: 300px" v-if="Machinery">
  50. <MachineryLoading />
  51. </div>
  52. <div v-if="!outStatus">
  53. <div class="addbox" v-if="addSuccessStatus">
  54. 扫码的载具编码:{{ addBoxInfo.code }}
  55. </div>
  56. <ScanCodeInput
  57. v-if="addStatus && addSuccessStatus == false"
  58. v-model="addBoxSearch"
  59. :clearable="true"
  60. :showSuffix="true"
  61. placeholder="请扫描或输入载具编号"
  62. @keyup.enter="addenterBox"
  63. />
  64. <el-button
  65. class="sureBtn"
  66. :type="addStatus ? 'info' : 'primary'"
  67. @click="changeAddStatus"
  68. :disabled="Machinery"
  69. style="margin-bottom: 20px"
  70. >{{ addStatus ? "取消" : "入库新载具" }}
  71. </el-button>
  72. </div>
  73. <div class="addbox" v-if="outStatus && !Machinery">
  74. 当前载具编码:{{ currentBox.vehicleNo }}
  75. </div>
  76. <div
  77. v-for="(material, index) in outingMaterials"
  78. :key="index"
  79. class="outing-box"
  80. >
  81. <div class="outing-box-header">
  82. <div class="material-title">
  83. {{ material.materialName }} | {{ material.materialNo }}
  84. </div>
  85. <!-- <div
  86. @click=""
  87. class="material-title deleteSty"
  88. >
  89. 删除
  90. </div> -->
  91. <i-ep-delete
  92. class="delete-btn"
  93. color="#ff4d4f"
  94. size="20px"
  95. @click="deleteIndexOld(index)"
  96. />
  97. </div>
  98. <div class="material-info">
  99. <div>批次号/序列号</div>
  100. <el-tooltip :content="material.batchCode" placement="top">
  101. <div class="batchCode">{{ material.batchCode }}</div>
  102. </el-tooltip>
  103. </div>
  104. <div class="material-info">
  105. <div>位置</div>
  106. <div>{{ material.locationNo }}</div>
  107. </div>
  108. <div class="material-info">
  109. <div>量值</div>
  110. <!-- <div>{{ material.num }}</div> -->
  111. <div>
  112. <NumberInput v-model="material.num" />
  113. </div>
  114. </div>
  115. </div>
  116. </el-scrollbar>
  117. <el-button
  118. class="sureBtn"
  119. type="info"
  120. @click="backToStorage"
  121. :disabled="Machinery || !boxStatus"
  122. >入库
  123. </el-button>
  124. </el-col>
  125. <el-col :span="8">
  126. <div class="type-title">请扫码物料</div>
  127. <ScanCodeInput
  128. v-model="scanCodeInput"
  129. placeholder="请扫描或输入物料编码"
  130. @keyup.enter="handleScanCodeInput"
  131. />
  132. <el-scrollbar class="base-container">
  133. <div class="list-container">
  134. <div
  135. v-for="(item, index) in materialList"
  136. :key="index"
  137. class="list-box"
  138. >
  139. <div class="list-box-header">
  140. <div>
  141. <div>
  142. <div class="name">{{ item.materialName }}</div>
  143. <div class="spec">{{ item.spec }}</div>
  144. </div>
  145. <div class="bottom">
  146. <NumberInput v-model="item.num" />
  147. <span class="unit">{{ item.unitDictLabel }}</span>
  148. </div>
  149. </div>
  150. <!-- <div
  151. @click="deleteIndexScanAdd(index)"
  152. class="list-box-delete deleteSty"
  153. >
  154. 删除
  155. </div> -->
  156. <i-ep-delete
  157. class="delete-btn"
  158. color="#ff4d4f"
  159. size="20px"
  160. @click="deleteIndexScanAdd(index)"
  161. />
  162. </div>
  163. </div>
  164. </div>
  165. </el-scrollbar>
  166. <el-button
  167. class="sureBtn"
  168. type="primary"
  169. @click="sureToAdd"
  170. :disabled="Machinery || materialList.length < 1 || !boxStatus"
  171. >确认添加
  172. </el-button>
  173. </el-col>
  174. </el-row>
  175. </div>
  176. </template>
  177. <script lang="ts" setup>
  178. //料箱
  179. import {
  180. getDestinationList,
  181. getMaterialInfoByLabel,
  182. } from "@/api/process/materialFlow";
  183. import { getVehicleInfo } from "@/api/prepare";
  184. import {
  185. backToStorageAPI,
  186. getStorageBoxesList,
  187. toOutBox,
  188. inBoxAPI,
  189. } from "@/api/storage/in";
  190. import { getStorageOrderInfo } from "@/api/storage/out";
  191. import { useCommonStoreHook } from "@/store";
  192. const commonS = useCommonStoreHook();
  193. const boxSearch = ref("");
  194. const deleteIndexOld = (index: any) => {
  195. outingMaterials.value.splice(index, 1);
  196. ElMessage.success("操作成功!");
  197. };
  198. const deleteIndexScanAdd = (index: any) => {
  199. materialList.value.splice(index, 1);
  200. ElMessage.success("操作成功!");
  201. };
  202. //硬件操作期间的状态:false 表示未有操作 true表示硬件在操作中
  203. const Machinery = ref(false);
  204. //盒内原有物料data
  205. const boxesList = ref<any[]>([]);
  206. //新加载具的开起状态
  207. const addStatus = ref(false);
  208. //新加载具的成功状态
  209. const addSuccessStatus = ref(false);
  210. //新加载具的内容
  211. const addBoxInfo = ref();
  212. //库中选中的item
  213. const currentBox = ref<any>({});
  214. //绑定当前盒子的状态
  215. const boxStatus = ref(false);
  216. const currentBoxIndex = ref(-1);
  217. //库中选中的状态
  218. const outStatus = ref(false);
  219. //新扫时候的input值
  220. const addBoxSearch = ref("");
  221. const resetData = () => {
  222. addSuccessStatus.value = false;
  223. addBoxInfo.value = null;
  224. addBoxSearch.value = "";
  225. outingBox.value = {};
  226. outingRawBoxList = [];
  227. outingMaterials.value = [];
  228. materialList.value = [];
  229. currentBox.value = {};
  230. currentBoxIndex.value = -1;
  231. boxSearch.value = "";
  232. addStatus.value = false;
  233. outStatus.value = false;
  234. boxStatus.value = false;
  235. };
  236. const changeAddStatus = () => {
  237. if (addStatus.value == true) {
  238. resetData();
  239. } else {
  240. addStatus.value = !addStatus.value;
  241. }
  242. };
  243. //扫盒子
  244. const addenterBox = () => {
  245. addBoxSearch.value = addBoxSearch.value.trim();
  246. getVehicleInfo(addBoxSearch.value ? addBoxSearch.value : {}).then((res) => {
  247. addBoxInfo.value = res.data;
  248. addSuccessStatus.value = true;
  249. outingBox.value.vehicleNo = addBoxInfo.value.code;
  250. outingBox.value.vehicleId = addBoxInfo.value.id;
  251. outingBox.value.houseNo = "1";
  252. ElMessage.success("扫码成功!");
  253. boxStatus.value = true;
  254. });
  255. };
  256. //出库
  257. const enterBox = () => {
  258. boxSearch.value = boxSearch.value.trim();
  259. getStorageBoxesList(
  260. boxSearch.value ? { vehicleCode: boxSearch.value } : {}
  261. ).then((res) => {
  262. boxesList.value = res.data;
  263. commonS.orderInId = res.data.orderId;
  264. });
  265. };
  266. const clickBox = (box: any, index: number) => {
  267. currentBox.value = box;
  268. currentBoxIndex.value = index;
  269. };
  270. //出库操作
  271. const sureToOut = async () => {
  272. let res = await toOutBox({
  273. vehicleNo: currentBox.value.vehicleNo,
  274. houseNo: currentBox.value.houseNo,
  275. });
  276. ElMessage.success("出库成功,等待料箱到达捡料位置");
  277. commonS.orderInId = res.data.orderId;
  278. commonS.changeBoxType = 1;
  279. Machinery.value = true;
  280. checkHasOuting();
  281. outStatus.value = true;
  282. };
  283. //定时器任务
  284. let outInterval: number = -1;
  285. const checkHasOuting = () => {
  286. // 点击出库之后,需要在其他地方(机器)确实已经到达检料位置,才能进行捡料
  287. // 接口需要传入出库outBox接口返回的orderId转为id传上去, 如果有这个orderId就开始轮询
  288. // 如果没有数据则停止轮询。数据返回的state是1处理中2启用3处理异常4已完成, 当为3或者4的时候停止轮询,并且在派发后清空oderid。
  289. if (commonS.orderInId != -1) {
  290. outInterval = setInterval(() => {
  291. getStorageOrderInfo({ id: commonS.orderInId })
  292. .then((res: any) => {
  293. if (res.data) {
  294. if (res.data.state === 3 || res.data.state === 4) {
  295. clearInterval(outInterval);
  296. commonS.orderInId = -1;
  297. if (commonS.changeBoxType === 1) {
  298. outingBox.value = currentBox.value;
  299. if (outingBox.value.list.length > 0) {
  300. outingMaterials.value = outingBox.value.list;
  301. outingRawBoxList = JSON.parse(
  302. JSON.stringify(outingBox.value.list)
  303. );
  304. } else {
  305. outingRawBoxList = [];
  306. outingMaterials.value = [];
  307. }
  308. getStorageBoxesList({}).then((res: any) => {
  309. boxesList.value = res.data;
  310. });
  311. currentBoxIndex.value = -1;
  312. ElMessage.success("料箱已到达");
  313. Machinery.value = false;
  314. boxStatus.value = true;
  315. } else {
  316. resetData();
  317. getStorageBoxesList({}).then((res) => {
  318. boxesList.value = res.data;
  319. });
  320. ElMessage.success("料箱入库成功");
  321. Machinery.value = false;
  322. }
  323. } else {
  324. outStatus.value = false;
  325. ElMessage.error(res.msg);
  326. }
  327. } else {
  328. clearInterval(outInterval);
  329. }
  330. })
  331. .catch(() => {
  332. clearInterval(outInterval);
  333. commonS.orderInId = -1;
  334. Machinery.value = false;
  335. });
  336. }, 5000);
  337. }
  338. };
  339. let outingRawBoxList: any[] = []; //确认添加的时候会对比捡料位和扫描的数量,多次点击会导致捡料位的数字一直改变,所以用一个变量来保存原始的捡料位数据
  340. const outingBox = ref<any>({});
  341. const outingMaterials = ref<any[]>([]);
  342. const backToStorage = async () => {
  343. const { data } = await backToStorageAPI({
  344. vehicleCode: outingBox.value.vehicleNo,
  345. houseNo: outingBox.value.houseNo,
  346. detailsList: outingMaterials.value,
  347. });
  348. outingBox.value = {};
  349. outingMaterials.value = [];
  350. ElMessage.success("返库操作成功,等待料箱到达");
  351. commonS.changeBoxType = 2;
  352. commonS.orderInId = data.orderId;
  353. Machinery.value = true;
  354. checkHasOuting();
  355. };
  356. // 物料
  357. const scanCodeInput = ref("");
  358. //扫码后的array
  359. const materialList = ref<any>([]);
  360. // 扫码料码
  361. const handleScanCodeInput = () => {
  362. getMaterialInfoByLabel(scanCodeInput.value).then((res) => {
  363. //seq是序列号唯一的
  364. if (res.data.codeType == "SEQ") {
  365. res.data.seqNo = scanCodeInput.value;
  366. } else {
  367. res.data.seqNo = "";
  368. }
  369. materialList.value.push({ ...res.data });
  370. scanCodeInput.value = "";
  371. ElMessage.success("扫码成功!");
  372. });
  373. };
  374. //确认添加:只是页面静态添加 不做接口发送
  375. const sureToAdd = () => {
  376. for (let i = 0; i < materialList.value.length; i++) {
  377. let status = false;
  378. for (let b = 0; b < outingMaterials.value.length; b++) {
  379. if (materialList.value[i].seqNo != "") {
  380. outingMaterials.value.push({
  381. ...materialList.value[i],
  382. materialNo: materialList.value[i].materialCode,
  383. unit: materialList.value[i].unitDictValue,
  384. });
  385. status = true;
  386. } else {
  387. if (
  388. materialList.value[i].materialCode ==
  389. outingMaterials.value[b].materialNo &&
  390. materialList.value[i].materialName ==
  391. outingMaterials.value[b].materialName &&
  392. materialList.value[i].batchCode == outingMaterials.value[b].batchCode
  393. ) {
  394. outingMaterials.value[b].num =
  395. outingMaterials.value[b].num + materialList.value[i].num;
  396. status = true;
  397. }
  398. }
  399. }
  400. if (status == false) {
  401. outingMaterials.value.push({
  402. ...materialList.value[i],
  403. materialNo: materialList.value[i].materialCode,
  404. unit: materialList.value[i].unitDictValue,
  405. });
  406. }
  407. }
  408. materialList.value = [];
  409. ElMessage.success("添加成功!");
  410. };
  411. // 流转终点
  412. const destinationList = ref([]);
  413. onMounted(() => {
  414. getDestinationList(1).then((res) => {
  415. destinationList.value = res.data;
  416. });
  417. getStorageBoxesList({}).then((res) => {
  418. boxesList.value = res.data;
  419. });
  420. checkHasOuting();
  421. });
  422. </script>
  423. <style lang="scss" scoped>
  424. .type-title {
  425. font-weight: 500;
  426. font-size: 30px;
  427. color: rgba(0, 0, 0, 0.9);
  428. text-align: left;
  429. margin-bottom: 15px;
  430. }
  431. .base-container {
  432. width: 100%;
  433. margin-top: 15px;
  434. height: calc(100vh - 420px);
  435. }
  436. .boxes-container {
  437. .box-item {
  438. background: #fff;
  439. border-radius: 16px;
  440. margin-bottom: 15px;
  441. padding: 10px 8px;
  442. }
  443. .box-selected {
  444. border: 2px solid #0a59f7;
  445. }
  446. .box-header {
  447. display: flex;
  448. justify-content: space-between;
  449. }
  450. .box-name {
  451. font-size: 20px;
  452. line-height: 40px;
  453. }
  454. .box-info {
  455. display: flex;
  456. justify-content: space-between;
  457. align-items: center;
  458. font-weight: bolder;
  459. font-size: 24px;
  460. }
  461. }
  462. .deleteSty {
  463. color: #0a59f7;
  464. }
  465. .outing-container {
  466. height: calc(100vh - 354px);
  467. .outing-box {
  468. background: #fff;
  469. border-radius: 16px;
  470. margin-bottom: 15px;
  471. padding: 10px 8px;
  472. }
  473. .outing-box-header {
  474. display: flex;
  475. justify-content: space-between;
  476. }
  477. .material-title {
  478. font-weight: bolder;
  479. font-size: 24px;
  480. text-align: left;
  481. }
  482. .material-info {
  483. font-size: 20px;
  484. display: flex;
  485. justify-content: space-between;
  486. align-items: center;
  487. }
  488. .batchCode {
  489. max-width: 60%;
  490. flex-shrink: 0;
  491. overflow: hidden;
  492. text-overflow: ellipsis;
  493. }
  494. }
  495. .list-container {
  496. width: 100%;
  497. display: grid;
  498. /*行间距*/
  499. grid-row-gap: 24px;
  500. /*列间距*/
  501. //grid-column-gap: 24px;
  502. grid-template-columns: 1fr;
  503. .list-box {
  504. height: 210px;
  505. background: #fff;
  506. border-radius: 16px 16px 16px 16px;
  507. display: flex;
  508. flex-direction: column;
  509. justify-content: space-between;
  510. align-items: start;
  511. padding: 30px 30px;
  512. .list-box-header {
  513. width: 100%;
  514. display: flex;
  515. justify-content: space-between;
  516. }
  517. .list-box-delete {
  518. text-align: right;
  519. font-weight: bolder;
  520. font-size: 24px;
  521. }
  522. .name {
  523. font-weight: 500;
  524. font-size: 24px;
  525. color: rgba(0, 0, 0, 0.9);
  526. text-align: left;
  527. }
  528. .spec {
  529. font-size: 20px;
  530. color: rgba(0, 0, 0, 0.6);
  531. text-align: left;
  532. }
  533. .bottom {
  534. display: flex;
  535. justify-content: start;
  536. align-items: end;
  537. }
  538. .unit {
  539. font-weight: 500;
  540. font-size: 24px;
  541. color: rgba(0, 0, 0, 0.6);
  542. text-align: left;
  543. margin-left: 5px;
  544. }
  545. }
  546. }
  547. .destination {
  548. height: calc(100vh - 350px);
  549. margin-top: 15px;
  550. .end-box {
  551. height: 80px;
  552. background: #ffffff;
  553. border-radius: 40px;
  554. display: flex;
  555. justify-content: center;
  556. align-items: center;
  557. font-weight: 500;
  558. font-size: 24px;
  559. color: rgba(0, 0, 0, 0.9);
  560. display: flex;
  561. justify-content: space-evenly;
  562. align-items: center;
  563. }
  564. .end-box:not(:last-child) {
  565. margin-bottom: 15px;
  566. }
  567. .selected {
  568. border-radius: 40px;
  569. border: 2px solid rgba(10, 89, 247, 1);
  570. }
  571. .name {
  572. font-weight: 500;
  573. font-size: 24px;
  574. color: rgba(0, 0, 0, 0.9);
  575. }
  576. }
  577. .sureBtn {
  578. height: 80px;
  579. font-size: 24px;
  580. //background: #0a59f7;
  581. border-radius: 76px 76px 76px 76px;
  582. width: 100%;
  583. margin-top: 10px;
  584. }
  585. .addbox {
  586. margin-bottom: 10px;
  587. border-radius: 16px;
  588. background-color: white;
  589. text-align: center;
  590. padding: 20px 0;
  591. font-size: $f24;
  592. }
  593. </style>