| | |
| | | </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 |
| | |
| | | currentRouting: {}, // 当前选择的工艺 |
| | | operations: [], // 当前选择工艺对应的工序 |
| | | operationIndex: 10, |
| | | operationSortable: null, |
| | | currentBom: {}, // 当前选择的产品结构 |
| | | components: [], // 当前选择产品结构对应的结构组件 |
| | | factoryOptions: [], |
| | |
| | | }, |
| | | false |
| | | ) |
| | | }, |
| | | beforeDestroy() { |
| | | if (this.operationSortable) { |
| | | this.operationSortable.destroy() |
| | | this.operationSortable = null |
| | | } |
| | | }, |
| | | created() { |
| | | this.dataForm.id = Number(this.$route.query.id) |
| | |
| | | dataType: '生产要求', |
| | | routingOperationId: newValue |
| | | }) |
| | | }, |
| | | operationIndex() { |
| | | this.rowDrop() |
| | | } |
| | | }, |
| | | computed: { |
| | |
| | | }, |
| | | 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) { |