计数器按照,商品起订量和最小包装量,选择步数和校验

eg:商品起订量:1,最小包装量:20

根据最小包装量选择步数    :step="goodSkuList.miniPachingQuantity"

根据起订量默认最小值        :min="goodSkuList.miniOrderQuantity"

goodSkuList 为父组件传过来的值
<template>
    <div class="product_detail_head w-100">
        <el-input-number @blur="inputinp" @change="changeinpunum" v-model="goodSkuList.inputModelNum" :step="goodSkuList.miniPachingQuantity" :min="goodSkuList.miniOrderQuantity" label="件" size="small"></el-input-number>
        <span v-show="isCheckFailure">请按照购买规则</span>
    </div>
</template>

<script>
export default {
    data() {
        return {
            isCheckFailure: false,
        };
    },
    methods: {
        changeinpunum(currentValue, oldValue) {
            console.log('change');
            this.$forceUpdate();
            var c = this.goodSkuList.inputModelNum; //输入多少  1
            var b = this.goodSkuList.miniPachingQuantity; //倍数   20

            var a = c / b == 0 ? 1 : c / b;
            a = Math.round(a);
            c = a * b;
            this.goodSkuList.inputModelNum = c; 
            // 提示语,如果不能取余数为0,就显示提示框
            if (this.goodSkuList.inputModelNum % b == 0 && Math.round(this.goodSkuList.inputModelNum % b) == 0) {
                console.log('隐藏');
                this.isCheckFailure = false;
            } else {
                this.isCheckFailure = true;
            }
        },
        inputinp(vval) {
            console.log(vval);
            console.log('输入');
            this.$forceUpdate();

            var c = this.goodSkuList.inputModelNum; //输入多少
            var b = this.goodSkuList.miniPachingQuantity; //倍数
            console.log(c, b);
            if (Math.round(c / b) == 0) {
                console.log(111111);
                this.isCheckFailure = false;
            } else {
                console.log(222222);
                this.goodSkuList.inputModelNum = this.goodSkuList.miniOrderQuantity;
                this.isCheckFailure = true;
            }
        },
    },
};
</script>

猜你喜欢

转载自blog.csdn.net/m0_69502730/article/details/131695740