子表单 的 切换顺序!!

598 阅读1分钟

需要让表单里面的数据,可以实现顺序的调整,因此监听了单选框的变化,判断用户点击的是 index 的 向上还是向下 来重新排序!!!

chrome-capture (1).gif image.png

toggleSort({index,row:{sortStr}}){
  console.log({index,sortStr})
  let children = this.form.dynamic
  if(sortStr==='up'){
    if(index!==0){
      children.splice(index-1,0,{...children[index],sortStr:undefined})
      children.splice(index+1,1)
    }else{
      children[index].sortStr=undefined
    }
  }else if(sortStr==='down'){
    if(index!==children.length-1){
      let item = children[index]
      let downItem = children[index+1]
      children.splice(index,1,downItem)
      children.splice(index+1,1,{...item,sortStr:undefined})
    }else{
      children[index].sortStr=undefined
    }
  }
  this.form.dynamic =  children
},