diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index b990122e63..f19ec6cad1 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -29,16 +29,21 @@
-
-
+
  • -
    +
    +
    -
  • -
    + +
    @@ -102,24 +107,21 @@ export default { }, methods: { dropCondition(e) { - const newCondIndex = Number(e.dataTransfer.getData('conditionIndex')); - const oldCondIndex = Number(e.target.id.slice(4)); + const moveIndex = Number(e.dataTransfer.getData('conditionIndex')); + const targetIndex = Number(e.target.id.slice(4)); - let reorderPlan = []; + function moveArrIndex(arr, from, to) { + arr.splice(to, 0, arr.splice(from, 1)[0]); + return arr; + } - this.conditionCollection.forEach((condition, index) => { - const reorderObj = {}; - reorderObj.oldIndex = index; - if (index === oldCondIndex) { - reorderObj.newIndex = newCondIndex; - } else if (index === newCondIndex) { - reorderObj.newIndex = oldCondIndex; - } else { - reorderObj.newIndex = index; - } - reorderPlan.push(reorderObj); - }); + const oldIndexArr = Object.keys(this.conditionCollection); + const newIndexArr = moveArrIndex(Object.keys(this.conditionCollection), moveIndex, targetIndex); + const reorderPlan = []; + for (let i = 0; i < oldIndexArr.length; i++) { + reorderPlan.push({oldIndex: i, newIndex: newIndexArr[i]}); + } this.reorder(reorderPlan); }, handleConditionResult(args) {