InboundManagement.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <template>
  2. <el-card shadow="always" :body-style="{ padding: '10px' }">
  3. <div class="app-container">
  4. <div class="main-wrap">
  5. <div class="left">
  6. <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
  7. <el-form-item prop="machineTool" label="机台" style="width: 500px">
  8. <el-select
  9. v-model="form.machineTool"
  10. filterable
  11. @change="machineToolChange"
  12. >
  13. <el-option
  14. v-for="(item, index) in lineOptions"
  15. :key="index"
  16. :label="item.productionLineName"
  17. :value="item.id"
  18. >
  19. <span class="discribe" style="float: left">{{item.productionLineName }}</span>
  20. <span
  21. style="float: right; color: #8492a6; font-size: 13px"
  22. >{{ item.productionLineDepartment }}</span
  23. >
  24. </el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item prop="scid" label="丝车">
  28. <el-select
  29. v-model="form.scid"
  30. filterable
  31. >
  32. <el-option
  33. v-for="(item, index) in silkcartList"
  34. :key="index"
  35. :label="item.scname"
  36. :value="item.id"
  37. >
  38. <span class="discribe" style="float: left">{{item.scname }}</span>
  39. <span
  40. style="float: right; color: #8492a6; font-size: 13px"
  41. >{{ item.scWeight }}</span
  42. >
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="卷数" prop="js" style="width: 278px">
  47. <el-input v-model="form.js" placeholder="请输入卷数"/>
  48. </el-form-item>
  49. <el-form-item label="毛重" prop="standby" style="width: 278px">
  50. <el-input v-model="form.standby" placeholder="请输入毛重" />
  51. </el-form-item>
  52. </el-form>
  53. <div slot="footer" class="dialog-footer">
  54. <el-button type="primary" @click="submitForm">确 定</el-button>
  55. <el-button @click="cancel">取 消</el-button>
  56. </div>
  57. </div>
  58. <div class="right">
  59. <div class="table-wrap">
  60. <el-table
  61. ref="proTableRef"
  62. :data="batchTableData"
  63. border
  64. stripe
  65. width="100%"
  66. max-height="260"
  67. highlight-current-row
  68. :row-class-name="tableRowClassName"
  69. @row-click="handleCurrentChange"
  70. >
  71. <!-- <el-table-column
  72. type="index"
  73. label="序号"
  74. width="50"
  75. ></el-table-column> -->
  76. <el-table-column
  77. v-for="col in columns"
  78. :prop="col.id"
  79. :key="col.id"
  80. :label="col.label"
  81. >
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. </div>
  86. </div>
  87. <!-- <pagination-->
  88. <!-- v-show="total>0"-->
  89. <!-- :total="total"-->
  90. <!-- :page.sync="queryParams.pageNum"-->
  91. <!-- :limit.sync="queryParams.pageSize"-->
  92. <!-- @pagination="getList"-->
  93. <!-- />-->
  94. <!-- 添加或修改线边舱库存对话框 -->
  95. </div>
  96. </el-card>
  97. </template>
  98. <script>
  99. import { listLineSideCabin, getLineSideCabin, delLineSideCabin, addLineSideCabin, updateLineSideCabin, getLineOptionLsit, finishedProductList, listSilkcart,} from "@/api/lineSideCabin/lineSideCabin";
  100. import {getSilkcart} from "@/api/silkcart/silkcart";
  101. export default {
  102. name: "LineSideCabin",
  103. data() {
  104. return {
  105. // 遮罩层
  106. loading: true,
  107. // 选中数组
  108. ids: [],
  109. // 非单个禁用
  110. single: true,
  111. // 非多个禁用
  112. multiple: true,
  113. // 显示搜索条件
  114. showSearch: true,
  115. // 总条数
  116. total: 0,
  117. // 线边舱库存表格数据
  118. lineSideCabinList: [],
  119. // 弹出层标题
  120. title: "",
  121. // 是否显示弹出层
  122. open: false,
  123. // 查询参数
  124. queryParams: {
  125. pageNum: 1,
  126. pageSize: 10,
  127. productNo: null,
  128. productName: null,
  129. productSpecifications: null,
  130. productId: null,
  131. batchNumber: null,
  132. colours: null,
  133. machineTool: null,
  134. js: null,
  135. status: null,
  136. standby: null,
  137. standby1: null,
  138. standby2: null,
  139. standby3: null,
  140. workshop: null,
  141. recipient: null,
  142. collectTime: null,
  143. confirm: null,
  144. confirmTime: null,
  145. scid:null
  146. },
  147. // 表单参数
  148. form: {
  149. id: null,
  150. productNo: null,
  151. productName: null,
  152. productSpecifications: null,
  153. productId: null,
  154. batchNumber: null,
  155. colours: null,
  156. machineTool: null,//机台号
  157. js: null,
  158. status: null,
  159. standby: '', // 确保初始化为空字符串
  160. standby1: null,
  161. standby2: null,
  162. standby3: null,
  163. workshop: null,
  164. recipient: null,
  165. collectTime: null,
  166. confirm: null,
  167. confirmTime: null,
  168. scid: null
  169. },
  170. // 表单校验
  171. rules: {
  172. },
  173. batchData: [], //所有批号数据
  174. batchTableData: [], //批号表格数据
  175. lineOptions: [], //机台选项数据
  176. silkcartList: [], //丝车列表
  177. xzbatchTableData: [], //选中的批号表格数据
  178. currentRow: null, // 添加当前选中行
  179. columns: [
  180. {
  181. id: "productNo",
  182. label: this.$t('printIndex.columns.productNo'),
  183. },
  184. {
  185. id: "productName",
  186. label: this.$t('printIndex.columns.productName'),
  187. },
  188. {
  189. id: "productSpecifications",
  190. label: this.$t('printIndex.columns.productSpecifications'),
  191. },
  192. {
  193. id: "lotNum",
  194. label: this.$t('printIndex.columns.lotNum'),
  195. },
  196. {
  197. id: "productColor",
  198. label: this.$t('printIndex.columns.productColor'),
  199. },
  200. // {
  201. // id: "productName",
  202. // label: "订单号",
  203. // },
  204. ],
  205. websocket: null,
  206. wsUrl: 'ws://localhost:8721/DBCc',
  207. };
  208. },
  209. created() {
  210. // 确保在创建新连接前关闭旧连接
  211. if (this.websocket) {
  212. this.closeWebSocket();
  213. }
  214. this.getList();
  215. this.initWebSocket();
  216. },
  217. mounted() {
  218. this.getLineOptionLsit();
  219. },
  220. beforeDestroy() {
  221. this.closeWebSocket();
  222. },
  223. beforeRouteLeave(to, from, next) {
  224. // 路由离开时关闭连接
  225. this.closeWebSocket();
  226. next();
  227. },
  228. methods: {
  229. /** 查询线边舱库存列表 */
  230. getList() {
  231. this.loading = true;
  232. listLineSideCabin(this.queryParams).then(response => {
  233. this.lineSideCabinList = response.rows;
  234. this.total = response.total;
  235. this.loading = false;
  236. });
  237. },
  238. // 取消按钮
  239. cancel() {
  240. this.open = false;
  241. this.reset();
  242. },
  243. // 表单重置
  244. reset() {
  245. this.form = {
  246. id: null,
  247. productNo: null,
  248. productName: null,
  249. productSpecifications: null,
  250. productId: null,
  251. batchNumber: null,
  252. colours: null,
  253. machineTool: null,
  254. js: null,
  255. status: null,
  256. standby: '', // 确保重置时也初始化为空字符串
  257. standby1: null,
  258. standby2: null,
  259. standby3: null,
  260. workshop: null,
  261. recipient: null,
  262. collectTime: null,
  263. confirm: null,
  264. confirmTime: null,
  265. scid: null
  266. };
  267. this.resetForm("form");
  268. },
  269. /** 机台相关 */
  270. // 机台改变回调
  271. machineToolChange(id) {
  272. console.log("================选中机台")
  273. if (id) {
  274. this.form.machineToolNo = this.lineOptions.find(
  275. (item) => item.id == id
  276. ).productionLineNo;
  277. }
  278. this.getAllBatchData(id);
  279. },
  280. // 获取机台选项数据
  281. async getLineOptionLsit() {
  282. let payLoad = {
  283. isEnablePaging: false,
  284. };
  285. try {
  286. let res = await getLineOptionLsit(payLoad);
  287. let scres = await listSilkcart(payLoad);
  288. if (res.code == 200) {
  289. this.lineOptions = res.rows;
  290. this.silkcartList = scres.rows;
  291. if (this.lineOptions.length > 0 && this.excuteType == 1) {
  292. this.form.machineTool = this.lineOptions[0].id;
  293. this.machineToolChange(this.form.machineTool);
  294. }
  295. } else {
  296. }
  297. } catch (error) {}
  298. console.log("------------------",this.silkcartList)
  299. },
  300. // 获取所有批次数据
  301. async getAllBatchData(id) {
  302. try {
  303. console.log('===================获取批次数据')
  304. let payload = { machineTool: id };
  305. let res = await finishedProductList(payload);
  306. if (res.code == 200) {
  307. this.batchData = res.data;
  308. this.batchTableData = res.data;
  309. } else {
  310. }
  311. } catch (error) {}
  312. },
  313. // 表格点击回调
  314. async handleCurrentChange(val) {
  315. if (!val) return;
  316. // 设置当前选中行的高亮
  317. this.$refs.proTableRef.setCurrentRow(val);
  318. this.xzbatchTableData = val;
  319. console.log("表格点击回调",this.xzbatchTableData)
  320. //判断是否为纺丝部如果是则不做处理
  321. if(val?.productionlinedepartment && val.productionlinedepartment !== undefined && val.productionlinedepartment !== "纺丝部" && val.productionlinedepartment !== ""){
  322. this.form.tubeColor = val.tubeColor;//管色
  323. this.form.boxWeight = val.boxWeight;//箱重
  324. this.form.canisterWeight = val.canisterWeight;//筒重
  325. }
  326. if (this.isStartReadNum || this.excuteType != 1) {
  327. return;
  328. }
  329. if (!this.currentRow || val.id != this.currentRow.id) {
  330. this.tableData = [];
  331. this.nowWeight = 0;
  332. this.getQrCodeHandle();
  333. this.summertId = new Date().getTime(); //总码单id重新生成
  334. }
  335. this.currentRow = val;
  336. },
  337. /** 机台相关 */
  338. /** 搜索按钮操作 */
  339. handleQuery() {
  340. this.queryParams.pageNum = 1;
  341. this.getList();
  342. },
  343. /** 重置按钮操作 */
  344. resetQuery() {
  345. this.resetForm("queryForm");
  346. this.handleQuery();
  347. },
  348. // 多选框选中数据
  349. handleSelectionChange(selection) {
  350. this.ids = selection.map(item => item.id)
  351. this.single = selection.length!==1
  352. this.multiple = !selection.length
  353. },
  354. /** 新增按钮操作 */
  355. handleAdd() {
  356. this.reset();
  357. this.open = true;
  358. this.title = "添加线边舱库存";
  359. },
  360. /** 修改按钮操作 */
  361. handleUpdate(row) {
  362. this.reset();
  363. const id = row.id || this.ids
  364. getLineSideCabin(id).then(response => {
  365. this.form = response.data;
  366. this.open = true;
  367. this.title = "修改线边舱库存";
  368. });
  369. },
  370. /** 提交按钮 */
  371. submitForm() {
  372. this.$refs["form"].validate(valid => {
  373. this.form.productNo = this.xzbatchTableData.productNo;
  374. this.form.productName = this.xzbatchTableData.productName;
  375. this.form.productSpecifications = this.xzbatchTableData.productSpecifications;
  376. this.form.productId = this.xzbatchTableData.productId;//类型字段变更为存储产品id
  377. this.form.batchNumber = this.xzbatchTableData.lotNum;
  378. this.form.colours = this.xzbatchTableData.productColor;
  379. this.form.standby3 = this.xzbatchTableData.id;//任务id
  380. if (valid) {
  381. if (this.form.id != null) {
  382. updateLineSideCabin(this.form).then(response => {
  383. this.$modal.msgSuccess("修改成功");
  384. this.open = false;
  385. this.getList();
  386. });
  387. } else {
  388. addLineSideCabin(this.form).then(response => {
  389. this.$modal.msgSuccess("新增成功");
  390. this.open = false;
  391. this.getList();
  392. });
  393. }
  394. }
  395. });
  396. },
  397. /** 删除按钮操作 */
  398. handleDelete(row) {
  399. const ids = row.id || this.ids;
  400. this.$modal.confirm('是否确认删除线边舱库存编号为"' + ids + '"的数据项?').then(function() {
  401. return delLineSideCabin(ids);
  402. }).then(() => {
  403. this.getList();
  404. this.$modal.msgSuccess("删除成功");
  405. }).catch(() => {});
  406. },
  407. /** 导出按钮操作 */
  408. handleExport() {
  409. this.download('lineSideCabin/lineSideCabin/export', {
  410. ...this.queryParams
  411. }, `lineSideCabin_${new Date().getTime()}.xlsx`)
  412. },
  413. /** 初始化 WebSocket 连接 */
  414. initWebSocket() {
  415. this.closeWebSocket();
  416. try {
  417. console.log('开始连接WebSocket:', this.wsUrl);
  418. this.websocket = new WebSocket(this.wsUrl);
  419. this.websocket.onopen = () => {
  420. console.log('WebSocket 连接成功');
  421. };
  422. this.websocket.onmessage = this.handleWebSocketMessage;
  423. this.websocket.onerror = () => {
  424. console.log('WebSocket 连接错误');
  425. this.closeWebSocket();
  426. };
  427. this.websocket.onclose = () => {
  428. console.log('WebSocket 连接关闭');
  429. this.websocket = null;
  430. };
  431. } catch (e) {
  432. console.error('WebSocket 连接错误:', e);
  433. this.closeWebSocket();
  434. }
  435. },
  436. /** 关闭 WebSocket 连接 */
  437. closeWebSocket() {
  438. if (this.websocket) {
  439. try {
  440. this.websocket.close();
  441. this.websocket = null;
  442. console.log('WebSocket 连接已关闭');
  443. } catch (error) {
  444. console.error('关闭 WebSocket 连接失败:', error);
  445. }
  446. }
  447. },
  448. /** 处理WebSocket消息 */
  449. handleWebSocketMessage(e) {
  450. try {
  451. const data = JSON.parse(e.data);
  452. // 处理权重数据
  453. if (data.weight !== undefined) {
  454. const weight = parseFloat(data.weight);
  455. if (!isNaN(weight)) {
  456. this.$set(this.form, 'standby', weight.toFixed(2));
  457. console.log('更新重量数据:', weight.toFixed(2), '是否稳定:', data.isStable);
  458. // 如果重量稳定,显示提示
  459. if (data.isStable) {
  460. this.$message({
  461. type: 'success',
  462. message: `重量已稳定: ${weight.toFixed(2)}kg`,
  463. duration: 2000
  464. });
  465. }
  466. }
  467. }
  468. } catch (error) {
  469. console.error('处理WebSocket消息失败:', error);
  470. }
  471. },
  472. // 表格行的类名
  473. tableRowClassName({row, rowIndex}) {
  474. if (this.currentRow && row.id === this.currentRow.id) {
  475. return 'current-row';
  476. }
  477. return '';
  478. },
  479. }
  480. };
  481. </script>
  482. <style lang="scss" scoped>
  483. .main-wrap {
  484. width: 100%;
  485. display: flex;
  486. justify-content: space-between;
  487. .left {
  488. width: 30%;
  489. .top-area {
  490. display: flex;
  491. justify-content: space-between;
  492. .msg {
  493. display: flex;
  494. align-items: center;
  495. font-size: 16px;
  496. font-weight: 700;
  497. }
  498. .btn-list {
  499. width: 100%;
  500. display: flex;
  501. justify-content: space-between;
  502. }
  503. }
  504. .count-area {
  505. display: flex;
  506. flex-wrap: wrap;
  507. .count-item {
  508. display: flex;
  509. margin-bottom: 10px;
  510. width: 50%;
  511. }
  512. }
  513. }
  514. .right {
  515. width: 70%;
  516. // flex: 1;
  517. .queryForm {
  518. width: 100%;
  519. padding: 0 10px;
  520. display: flex;
  521. .label {
  522. text-align: right;
  523. color: #606266;
  524. line-height: 30px;
  525. display: block;
  526. width: 100px;
  527. font-weight: 700;
  528. text-decoration: aliceblue;
  529. margin-right: 10px;
  530. }
  531. }
  532. .table-wrap {
  533. margin-top: 5px;
  534. width: 100%;
  535. overflow-x: scroll;
  536. }
  537. }
  538. }
  539. ::v-deep .el-date-editor.el-input {
  540. width: 100%;
  541. }
  542. ::v-deep .el-input-number--mini {
  543. width: 99%;
  544. }
  545. ::v-deep .el-table__body tr.current-row > td.el-table__cell {
  546. background-color: #55e905 !important;
  547. }
  548. ::v-deep .el-table__body tr.hover-row.current-row > td.el-table__cell {
  549. background-color: #55e905 !important;
  550. }
  551. ::v-deep .el-table__body tr.hover-row > td.el-table__cell {
  552. background-color: #55e905 !important;
  553. }
  554. </style>