表格行拖动,数据中状态值不同的禁止拖拽

rowDrop () {
      const tbody = document.querySelector('.el-table__body-wrapper tbody')
      const _this = this
      let sort = Sortable.create(tbody, {
        forceFallback: false,
        onMove: (evt, originalEvent) => {
          // 出现非发布和已发布,立即还原交换
          if (_this.initTableData[evt.dragged.rowIndex].status != _this.initTableData[evt.related.rowIndex].status) {
            return false
          }
        },
        onEnd ({ newIndex, oldIndex }) {
          let newRow = _this.initTableData[newIndex]
          let oldRow = _this.initTableData[oldIndex]
          const currRow = _this.initTableData.splice(oldIndex, 1)[0]
          if (!newRow) {
            let index = _this.initTableData.length - 1
            let sort = _this.initTableData[index].sequence
            currRow.sequence = sort + 1
            _this.initTableData.splice(oldIndex, 0, currRow)
            return
          }
          let old = newRow.sequence
          let current = currRow.sequence
          currRow.sequence = old   //交换顺序
          newRow.sequence = current
          _this.initTableData.splice(newIndex, 0, currRow)
          _this.temp.push(currRow)
          _this.temp.push(newRow)
          _this.$emit('update:initTableData', _this.initTableData)
        }
      })
    },

  

posted on 2019-09-27 17:17  ihuangqing  阅读(975)  评论(0编辑  收藏  举报