/**
         * 上、下移动
         * @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
            })
        },

Hoh_Xil
40 声望6 粉丝