<template>
    <a-form-model-item :label="attr.name" :prop="attr.alias">
        <a-input-number :value="modelVal"
                       :disabled="disabled"
                       :placeholder="placeholder"
                       :min="min"
                       :max="max"
                       :precision="precision"
                        @change="change">

        </a-input-number>
    </a-form-model-item>
</template>

<script>
export default {
    name: "mix-number",
    model: {
        prop: "modelVal",
        event: 'change'
    },
    props: {
        modelVal: "",
        attr: {
            type: Object,
            default: () => {
            }
        }
    },
    data() {
        return {
            setting: {
                is_allow_null: true,
                tip: "",
                min_value: 0,
                max_value: 0,
                decimal_number: 0
            },
            disabled: false,
            placeholder: "请输入",
            min: -Infinity,
            max: Infinity,
            precision: 0
        }
    },
    created() {
        this.setting = this.attr.setting
        this.setDisable(this.attr.display)
        this.setPlaceholder(this.attr.tip);
        if (!isNaN(this.setting.min_value)) {
            this.min = this.setting.min_value
        }
        if (!isNaN(this.setting.max_value)) {
            this.max = this.setting.max_value
        }
        if (!isNaN(this.setting.decimal_number)) {
            this.precision = this.setting.decimal_number
        }
    },
    methods: {
        setDisable(display) {
            if (display === 'r' || display === 'v') {
                this.disabled = true;
            } else if (display === 'h') {
                this.textType = 'hidden';
            } else if (display === 'w') {
                this.disabled = false;
            }
        },
        setPlaceholder(tip) {
            this.placeholder = tip ? tip : "请输入"
        },
        change(value) {
            this.$emit('change', value);
        }
    }
}
</script>

<style scoped>

</style>
