/** * 上、下挪动 * @param {number} code 下标 * @param {number} dir 1上移 0下移 */ onMove(code, dir) { let moveComm = (curIndex, nextIndex) => { let arr = this.commodityInfo arr[curIndex] = arr.splice(nextIndex, 1, arr[curIndex])[0] return arr } this.commodityInfo.some((val, index) => { if (index === code) { if(val.primarySku) { // 判断是否为主样式 this.$message.warning('主样式不能够挪动!') } else { if (dir === 1 && index === 1) { this.$message.warning('已在顶部!') } else if (dir === 0 && index === this.commodityInfo.length - 1) { this.$message.warning('已在底部!') } else { let nextIndex = dir === 1 ? index - 1 : index + 1 this.commodityInfo = moveComm(index, nextIndex) this.$message.success('已挪动!') } } return true } return false }) },