chenhj
14 小时以前 a3c7a21828653c2c74c20b1f69baf6a9fbfb8e1c
车间订单处理工艺文件工序排序错误问题
已修改1个文件
125 ■■■■■ 文件已修改
src/views/plan/manufacturingorder/productorder-form.vue 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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) {