index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <div>
  3. <el-row :gutter="20">
  4. <el-col :span="6">
  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. />
  13. <el-scrollbar class="boxes-container base-container">
  14. <div
  15. v-for="(item, index) in boxesList"
  16. :key="index"
  17. :class="{ 'box-selected': index === currentBoxIndex }"
  18. class="box-item"
  19. @click="clickBox(item, index)"
  20. >
  21. <div class="box-name">{{ item.vehicleName }}</div>
  22. <div
  23. v-for="(material, index) in item.list"
  24. :key="index"
  25. class="box-info"
  26. >
  27. <div>{{ material.materialName }}</div>
  28. <div>{{ material.num }}</div>
  29. </div>
  30. </div>
  31. </el-scrollbar>
  32. <el-button class="sureBtn" type="primary" @click="sureToOut"
  33. >出库
  34. </el-button>
  35. </el-col>
  36. <el-col :span="6">
  37. <div class="type-title">捡料位</div>
  38. <el-scrollbar class="outing-container">
  39. <div class="boxHeader">载具名称:{{ outingBox?.vehicleName }}</div>
  40. <div class="boxHeader">载具编码:{{ outingBox?.vehicleCode }}</div>
  41. <div
  42. v-for="(material, index) in outingMaterials"
  43. :key="index"
  44. class="outing-box"
  45. >
  46. <div class="material-title">
  47. {{ material.materialName }} | {{ material.materialNo }}
  48. </div>
  49. <!-- <div class="material-info">-->
  50. <!-- <div>批次号</div>-->
  51. <!-- <el-tooltip :content="material.batchCode" placement="top">-->
  52. <!-- <div class="batchCode">{{ material.batchCode }}</div>-->
  53. <!-- </el-tooltip>-->
  54. <!-- </div>-->
  55. <!-- <div class="material-info">-->
  56. <!-- <div>位置</div>-->
  57. <!-- <div>{{ material.locationNo }}</div>-->
  58. <!-- </div>-->
  59. <div class="material-info">
  60. <div>数量</div>
  61. <div>{{ material.num }}</div>
  62. </div>
  63. </div>
  64. </el-scrollbar>
  65. <el-button class="sureBtn" type="info" @click="backToStorage"
  66. >入库
  67. </el-button>
  68. </el-col>
  69. <el-col :span="6">
  70. <ScanCodeInput
  71. v-model="boxInputValue"
  72. :clearable="true"
  73. placeholder="请扫描或输入载具编号"
  74. @keyup.enter="enterBoxInput"
  75. />
  76. <div class="boxHeader">载具名称:{{ toSendBoxInfo?.vehicleName }}</div>
  77. <div class="boxHeader">载具编码:{{ toSendBoxInfo?.vehicleCode }}</div>
  78. <div class="type-title">请扫码物料</div>
  79. <ScanCodeInput
  80. v-model="scanCodeInput"
  81. placeholder="请扫描或输入物料编码"
  82. @keyup.enter="handleScanCodeInput"
  83. />
  84. <el-scrollbar style="height: calc(100vh - 535px); margin-top: 10px">
  85. <div class="list-container">
  86. <div
  87. v-for="(item, index) in materialList"
  88. :key="index"
  89. class="list-box"
  90. >
  91. <div>
  92. <div class="name">{{ item.materialName }}</div>
  93. <div class="spec">{{ item.spec }}</div>
  94. </div>
  95. <div class="bottom">
  96. <NumberInput v-model="item.num" />
  97. <span class="unit">{{ item.unitDictLabel }}</span>
  98. </div>
  99. <i-ep-delete
  100. class="delete-btn"
  101. color="#ff4d4f"
  102. size="20px"
  103. @click="deleteMaterial(index)"
  104. />
  105. </div>
  106. </div>
  107. </el-scrollbar>
  108. <el-button class="sureBtn" type="primary" @click="sureToAdd"
  109. >确认添加
  110. </el-button>
  111. </el-col>
  112. <el-col :span="6">
  113. <div class="type-title">流转终点</div>
  114. <div class="destination">
  115. <el-scrollbar>
  116. <div
  117. v-for="(item, index) in destinationList"
  118. :key="index"
  119. :class="{ selected: index === currentDestinationIndex }"
  120. class="end-box"
  121. @click="onEndBoxClick(index, item)"
  122. >
  123. <div class="name">{{ item.name }}</div>
  124. </div>
  125. </el-scrollbar>
  126. </div>
  127. <el-button class="sureBtn" type="primary" @click="createTask"
  128. >派发
  129. </el-button>
  130. </el-col>
  131. </el-row>
  132. </div>
  133. </template>
  134. <script lang="ts" setup>
  135. //料箱
  136. import {
  137. addMaterialFlow,
  138. getBoxDetailByLabel,
  139. getDestinationList,
  140. getMaterialInfoByLabel,
  141. } from "@/api/process/materialFlow";
  142. import {
  143. backToStorageAPI,
  144. getStorageBoxesList,
  145. getStorageOrderInfo,
  146. toOutBox,
  147. } from "@/api/storage/out";
  148. import { useCommonStoreHook } from "@/store";
  149. const commonS = useCommonStoreHook();
  150. const boxSearch = ref("");
  151. const boxesList = ref<any[]>([]);
  152. const currentBox = ref<any>({});
  153. const currentBoxIndex = ref(-1);
  154. const enterBox = () => {
  155. boxSearch.value = boxSearch.value.trim();
  156. getStorageBoxesList({}).then((res: any) => {
  157. boxesList.value = res.data;
  158. });
  159. };
  160. const clickBox = (box: any, index: number) => {
  161. currentBox.value = box;
  162. currentBoxIndex.value = index;
  163. };
  164. const sureToOut = async () => {
  165. let res: any = await toOutBox({
  166. vehicleNo: currentBox.value.vehicleNo,
  167. houseNo: currentBox.value.houseNo,
  168. });
  169. commonS.orderId = res.data.orderId;
  170. commonS.changeBoxType = 2; // 2出库
  171. ElMessage.success("出库成功,等待料箱到达捡料位置");
  172. checkHasOuting();
  173. };
  174. //捡料位
  175. let outingRawBoxList: any[] = []; //确认添加的时候会对比捡料位和扫描的数量,多次点击会导致捡料位的数字一直改变,所以用一个变量来保存原始的捡料位数据
  176. const outingBox = ref<any>({});
  177. const outingMaterials = ref<any[]>([]);
  178. let outInterval: number = -1;
  179. const checkHasOuting = () => {
  180. // 点击出库之后,需要在其他地方(机器)确实已经到达检料位置,才能进行捡料
  181. // 接口需要传入出库outBox接口返回的orderId转为id传上去, 如果有这个orderId就开始轮询
  182. // 如果没有数据则停止轮询。数据返回的state是1处理中2启用3处理异常4已完成, 当为3或者4的时候停止轮询,并且在派发后清空oderid。
  183. if (commonS.orderId != -1) {
  184. outInterval = setInterval(() => {
  185. getStorageOrderInfo({ id: commonS.orderId })
  186. .then((res: any) => {
  187. if (res.data) {
  188. if (res.data.state === 3 || res.data.state === 4) {
  189. clearInterval(outInterval);
  190. commonS.orderId = -1;
  191. // 同时也刷新左侧列表数据
  192. getStorageBoxesList({}).then((res: any) => {
  193. boxesList.value = res.data;
  194. });
  195. if (commonS.changeBoxType === 2) {
  196. outingBox.value = { ...res.data };
  197. toSendBoxInfo.value = { ...outingBox.value }; //默认派发出库的盒子,如果返库了,扫码物料上方的载具信息则需要重新获取
  198. if (res.data.detailsList.length > 0) {
  199. outingMaterials.value = outingBox.value.detailsList;
  200. outingRawBoxList = JSON.parse(
  201. JSON.stringify(outingBox.value.detailsList)
  202. );
  203. materialList.value = JSON.parse(
  204. JSON.stringify(outingBox.value.detailsList)
  205. );
  206. } else {
  207. outingRawBoxList = [];
  208. outingMaterials.value = [];
  209. }
  210. }
  211. }
  212. } else {
  213. clearInterval(outInterval);
  214. }
  215. })
  216. .catch(() => {
  217. clearInterval(outInterval);
  218. commonS.orderId = -1;
  219. });
  220. }, 5000);
  221. }
  222. };
  223. const backToStorage = async () => {
  224. console.log("back to storage");
  225. let res: any = await backToStorageAPI({
  226. vehicleCode: outingBox.value.vehicleCode,
  227. houseNo: outingBox.value.houseNo,
  228. detailsList: outingMaterials.value,
  229. });
  230. commonS.orderId = res.data.orderId;
  231. commonS.changeBoxType = 1; // 2出库
  232. ElMessage.success("返库成功,等待料箱到达");
  233. checkHasOuting();
  234. outingBox.value = {};
  235. toSendBoxInfo.value = {};
  236. outingMaterials.value = [];
  237. currentBox.value = {};
  238. currentBoxIndex.value = -1;
  239. boxSearch.value = "";
  240. // getStorageBoxesList({}).then((res: any) => {
  241. // boxesList.value = res.data;
  242. // });
  243. };
  244. // 物料
  245. const toSendBoxInfo = ref<any>({}); //扫码物料上方的载具信息,默认是出库的减料位的盒子,也可以通过扫码获取新的盒子
  246. const scanCodeInput = ref("");
  247. const materialList = ref<any[]>([]);
  248. const boxInputValue = ref("");
  249. const enterBoxInput = () => {
  250. boxInputValue.value = boxInputValue.value.trim();
  251. getBoxDetailByLabel(boxInputValue.value).then((res: any) => {
  252. toSendBoxInfo.value = {
  253. vehicleName: res.data.name,
  254. vehicleCode: res.data.code,
  255. vehicleId: res.data.id,
  256. };
  257. boxInputValue.value = "";
  258. });
  259. };
  260. const handleScanCodeInput = () => {
  261. getMaterialInfoByLabel(scanCodeInput.value).then((res: any) => {
  262. // 扫描之后要先查看数组中是否有这个物料,有的话就数量相加,没有的话就添加到数组中
  263. let hasMaterial = false;
  264. for (let i = 0; i < materialList.value.length; i++) {
  265. let currentMaterial = materialList.value[i];
  266. if (currentMaterial.materialCode === res.data.materialCode) {
  267. hasMaterial = true;
  268. // SEQ/BATCH 如果是流转卡号数量只能唯1,序列号相加
  269. if (currentMaterial.codeType === "BATCH") {
  270. materialList.value[i].num += res.data.num;
  271. break;
  272. }
  273. }
  274. }
  275. !hasMaterial && materialList.value.push(res.data);
  276. scanCodeInput.value = "";
  277. });
  278. };
  279. const sureToAdd = () => {
  280. // 循环物料列表,在循环捡料位的列表,进行数量相减,最大数量判断
  281. // 每次判断之前,先重置数据
  282. outingMaterials.value = JSON.parse(JSON.stringify(outingRawBoxList));
  283. for (let i = 0; i < materialList.value.length; i++) {
  284. let currentMaterial = materialList.value[i];
  285. for (let j = 0; j < outingMaterials.value.length; j++) {
  286. let currentOutingMaterial = outingMaterials.value[j];
  287. if (currentMaterial.materialCode === currentOutingMaterial.materialNo) {
  288. if (currentMaterial.num > currentOutingMaterial.num) {
  289. currentMaterial.num = currentOutingMaterial.num;
  290. currentOutingMaterial.num = 0;
  291. } else {
  292. currentOutingMaterial.num -= currentMaterial.num;
  293. }
  294. break;
  295. }
  296. }
  297. }
  298. };
  299. const deleteMaterial = (index: number) => {
  300. materialList.value.splice(index, 1);
  301. };
  302. // 出库终点
  303. const destinationList = ref<any>();
  304. const currentDestination = ref<any>({});
  305. const currentDestinationIndex = ref(-1);
  306. const onEndBoxClick = (index: number, item: any) => {
  307. currentDestination.value = item;
  308. currentDestinationIndex.value = index;
  309. };
  310. onMounted(() => {
  311. let wm = new WeakMap();
  312. getDestinationList(0).then((res: any) => {
  313. destinationList.value = res.data;
  314. });
  315. getStorageBoxesList({}).then((res: any) => {
  316. boxesList.value = res.data;
  317. });
  318. checkHasOuting();
  319. });
  320. const createTask = () => {
  321. const params = {
  322. circulationDetail: [...materialList.value],
  323. // coordinate: "",
  324. // houseNo: outingBox.value.houseNo,
  325. // locationNo: "",
  326. stationId: currentDestination.value.id,
  327. targetType: currentDestination.value.targetType,
  328. vehicleCode: toSendBoxInfo.value.vehicleCode,
  329. vehicleId: toSendBoxInfo.value.vehicleId,
  330. vehicleName: toSendBoxInfo.value.vehicleName,
  331. };
  332. addMaterialFlow(params).then((res: any) => {
  333. ElMessage.success(res.msg ?? "派发成功");
  334. currentBox.value = {};
  335. currentBoxIndex.value = -1;
  336. boxSearch.value = "";
  337. outingBox.value = {};
  338. outingMaterials.value = [];
  339. toSendBoxInfo.value = {};
  340. materialList.value = [];
  341. currentDestination.value = {};
  342. currentDestinationIndex.value = -1;
  343. });
  344. };
  345. onBeforeUnmount(() => {
  346. clearInterval(outInterval);
  347. });
  348. </script>
  349. <style lang="scss" scoped>
  350. .type-title {
  351. font-weight: 500;
  352. font-size: 30px;
  353. color: rgba(0, 0, 0, 0.9);
  354. text-align: left;
  355. margin-bottom: 15px;
  356. }
  357. .base-container {
  358. width: 100%;
  359. margin-top: 15px;
  360. height: calc(100vh - 420px);
  361. }
  362. .boxes-container {
  363. .box-item {
  364. background: #fff;
  365. border-radius: 16px;
  366. margin-bottom: 15px;
  367. padding: 10px 8px;
  368. }
  369. .box-selected {
  370. border: 2px solid #0a59f7;
  371. }
  372. .box-name {
  373. font-size: 20px;
  374. line-height: 40px;
  375. }
  376. .box-info {
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: center;
  380. font-weight: bolder;
  381. font-size: 24px;
  382. }
  383. }
  384. .boxHeader {
  385. font-weight: bolder;
  386. font-size: 24px;
  387. text-align: left;
  388. }
  389. .outing-container {
  390. height: calc(100vh - 354px);
  391. .outing-box {
  392. background: #fff;
  393. border-radius: 16px;
  394. margin-bottom: 15px;
  395. padding: 10px 8px;
  396. position: relative;
  397. }
  398. .material-title {
  399. font-weight: bolder;
  400. font-size: 24px;
  401. text-align: left;
  402. }
  403. .material-info {
  404. font-size: 20px;
  405. display: flex;
  406. justify-content: space-between;
  407. align-items: center;
  408. }
  409. .batchCode {
  410. max-width: 60%;
  411. flex-shrink: 0;
  412. overflow: hidden;
  413. text-overflow: ellipsis;
  414. }
  415. }
  416. .list-container {
  417. width: 100%;
  418. display: grid;
  419. /*行间距*/
  420. grid-row-gap: 24px;
  421. /*列间距*/
  422. //grid-column-gap: 24px;
  423. grid-template-columns: 1fr;
  424. .list-box {
  425. height: 210px;
  426. background: #fff;
  427. border-radius: 16px 16px 16px 16px;
  428. display: flex;
  429. flex-direction: column;
  430. justify-content: space-between;
  431. align-items: start;
  432. padding: 30px 30px;
  433. position: relative;
  434. .delete-btn {
  435. position: absolute;
  436. top: 15px;
  437. right: 15px;
  438. }
  439. .name {
  440. font-weight: 500;
  441. font-size: 24px;
  442. color: rgba(0, 0, 0, 0.9);
  443. text-align: left;
  444. }
  445. .spec {
  446. font-size: 20px;
  447. color: rgba(0, 0, 0, 0.6);
  448. text-align: left;
  449. }
  450. .bottom {
  451. display: flex;
  452. justify-content: start;
  453. align-items: end;
  454. }
  455. .unit {
  456. font-weight: 500;
  457. font-size: 24px;
  458. color: rgba(0, 0, 0, 0.6);
  459. text-align: left;
  460. margin-left: 5px;
  461. }
  462. }
  463. }
  464. .destination {
  465. height: calc(100vh - 353px);
  466. margin-top: 15px;
  467. .end-box {
  468. height: 80px;
  469. background: #ffffff;
  470. border-radius: 40px;
  471. display: flex;
  472. justify-content: center;
  473. align-items: center;
  474. font-weight: 500;
  475. font-size: 24px;
  476. color: rgba(0, 0, 0, 0.9);
  477. display: flex;
  478. justify-content: space-evenly;
  479. align-items: center;
  480. }
  481. .end-box:not(:last-child) {
  482. margin-bottom: 15px;
  483. }
  484. .selected {
  485. border-radius: 40px;
  486. border: 2px solid rgba(10, 89, 247, 1);
  487. }
  488. .name {
  489. font-weight: 500;
  490. font-size: 24px;
  491. color: rgba(0, 0, 0, 0.9);
  492. }
  493. }
  494. .sureBtn {
  495. height: 80px;
  496. font-size: 24px;
  497. //background: #0a59f7;
  498. border-radius: 76px 76px 76px 76px;
  499. width: 100%;
  500. margin-top: 10px;
  501. }
  502. </style>