From a3c7a21828653c2c74c20b1f69baf6a9fbfb8e1c Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期三, 18 三月 2026 11:01:51 +0800
Subject: [PATCH] 车间订单处理工艺文件工序排序错误问题
---
src/views/plan/manufacturingorder/productorder-form.vue | 125 +++++++++++++++++++++++++----------------
1 files changed, 76 insertions(+), 49 deletions(-)
diff --git a/src/views/plan/manufacturingorder/productorder-form.vue b/src/views/plan/manufacturingorder/productorder-form.vue
index 5968318..7b49f3d 100644
--- a/src/views/plan/manufacturingorder/productorder-form.vue
+++ b/src/views/plan/manufacturingorder/productorder-form.vue
@@ -311,10 +311,12 @@
</el-row> -->
<el-table
:key="operationIndex"
+ :data-operation-index="operationIndex"
id="operationTable"
ref="operationTable"
class="basic-template-table"
:data="operations"
+ row-key="id"
height="593px"
border
highlight-current-row
@@ -1278,6 +1280,7 @@
currentRouting: {}, // 褰撳墠閫夋嫨鐨勫伐鑹�
operations: [], // 褰撳墠閫夋嫨宸ヨ壓瀵瑰簲鐨勫伐搴�
operationIndex: 10,
+ operationSortable: null,
currentBom: {}, // 褰撳墠閫夋嫨鐨勪骇鍝佺粨鏋�
components: [], // 褰撳墠閫夋嫨浜у搧缁撴瀯瀵瑰簲鐨勭粨鏋勭粍浠�
factoryOptions: [],
@@ -1334,6 +1337,12 @@
},
false
)
+ },
+ beforeDestroy() {
+ if (this.operationSortable) {
+ this.operationSortable.destroy()
+ this.operationSortable = null
+ }
},
created() {
this.dataForm.id = Number(this.$route.query.id)
@@ -1457,6 +1466,9 @@
dataType: '鐢熶骇瑕佹眰',
routingOperationId: newValue
})
+ },
+ operationIndex() {
+ this.rowDrop()
}
},
computed: {
@@ -1483,57 +1495,72 @@
},
methods: {
rowDrop() {
- const that = this
- const tbody = document.querySelector(
- '#operationTable .el-table__body-wrapper tbody'
- )
- Sortable.create(tbody, {
- // 缁撴潫鎷栨嫿
- onEnd({ newIndex, oldIndex }) {
- if (newIndex > oldIndex) {
- // 涓嬬Щ
- that.operations
- .filter((e) => e.operationOrder == oldIndex + 1)
- .forEach((e) => (e.operationOrder = 'x'))
- that.operations
- .filter(
- (e) =>
- e.operationOrder > oldIndex + 1 &&
- e.operationOrder <= newIndex + 1
- )
- .forEach((e) => (e.operationOrder = e.operationOrder - 1))
- that.operations
- .filter((e) => e.operationOrder == 'x')
- .forEach((e) => (e.operationOrder = newIndex + 1))
- } else if (oldIndex > newIndex) {
- // 涓婄Щ
- that.operations
- .filter((e) => e.operationOrder == oldIndex + 1)
- .forEach((e) => (e.operationOrder = 'x'))
- that.operations
- .filter(
- (e) =>
- e.operationOrder < oldIndex + 1 &&
- e.operationOrder >= newIndex + 1
- )
- .forEach((e) => (e.operationOrder = e.operationOrder + 1))
- that.operations
- .filter((e) => e.operationOrder == 'x')
- .forEach((e) => (e.operationOrder = newIndex + 1))
- }
- // 鎷栨嫿缁撴潫鍚庯紝淇濆瓨鏂扮殑鎺掑簭
- const data = that.operations.map((el) => {
- return {
- id: el.id,
- operationOrder: el.operationOrder
+ if (this.operationSortable) {
+ this.operationSortable.destroy()
+ this.operationSortable = null
+ }
+
+ this.$nextTick(() => {
+ requestAnimationFrame(() => {
+ const that = this
+ const root =
+ this.$el.querySelector(
+ `#operationTable[data-operation-index="${this.operationIndex}"]`
+ ) || this.$el.querySelector('#operationTable')
+ const tbody = root
+ ? root.querySelector('.el-table__body-wrapper tbody')
+ : null
+ if (!tbody) return
+
+ this.operationSortable = Sortable.create(tbody, {
+ // 缁撴潫鎷栨嫿
+ onEnd({ newIndex, oldIndex }) {
+ if (newIndex > oldIndex) {
+ // 涓嬬Щ
+ that.operations
+ .filter((e) => e.operationOrder == oldIndex + 1)
+ .forEach((e) => (e.operationOrder = 'x'))
+ that.operations
+ .filter(
+ (e) =>
+ e.operationOrder > oldIndex + 1 &&
+ e.operationOrder <= newIndex + 1
+ )
+ .forEach((e) => (e.operationOrder = e.operationOrder - 1))
+ that.operations
+ .filter((e) => e.operationOrder == 'x')
+ .forEach((e) => (e.operationOrder = newIndex + 1))
+ } else if (oldIndex > newIndex) {
+ // 涓婄Щ
+ that.operations
+ .filter((e) => e.operationOrder == oldIndex + 1)
+ .forEach((e) => (e.operationOrder = 'x'))
+ that.operations
+ .filter(
+ (e) =>
+ e.operationOrder < oldIndex + 1 &&
+ e.operationOrder >= newIndex + 1
+ )
+ .forEach((e) => (e.operationOrder = e.operationOrder + 1))
+ that.operations
+ .filter((e) => e.operationOrder == 'x')
+ .forEach((e) => (e.operationOrder = newIndex + 1))
+ }
+ // 鎷栨嫿缁撴潫鍚庯紝淇濆瓨鏂扮殑鎺掑簭
+ const data = that.operations.map((el) => {
+ return {
+ id: el.id,
+ operationOrder: el.operationOrder
+ }
+ })
+ changeOrder(data)
+ .then()
+ .catch((error) => {
+ console.error(error)
+ })
}
})
- changeOrder(data)
- .then()
- .catch((error) => {
- console.error(error)
- })
- }
+ })
})
},
dragEnd(e) {
--
Gitblit v1.9.3