<template>
    <qg-input maxlength="11" :placeholder="placeholder" v-model.trim="val" @change="change" :after="icon">
    </qg-input>
</template>

<script>
export default {
    name: "qg-phone-input",
    props: {
        value: {
            type: [String, Number],
            default: "",
        },
        placeholder: {
            type: String,
            default: "手机号码",
        },
    },
    data() {
        return {
            icon: "",
        };
    },
    computed: {
        val: {
            get() {
                return this.value;
            },
            set(val) {
                this.$emit("input", val);
            },
        },
    },
    methods: {
        change() {
            if (!this.val.length) return (this.icon = "");
            if (/[1][3-9][0-9]{9,9}/.test(this.val)) {
                this.icon = "pitch";
            } else {
                this.icon = "close";
            }
        },
    },
};
</script>

<style scoped>

.pitch {
    border: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pitch::before {
    content: "";
    display: inline-block;
    transform: translateY(-100%);
    width: 9rem;
    height: 3rem;
    border-left: 3rem solid green;
    border-bottom: 3rem solid green;
    transform: rotate(-45deg);
}
.close {
    width: 9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.close:before {
    content: "";
    width: 2rem;
    height: 15rem;
    margin-left: -1rem;
    background: red;
    transform: rotate(45deg);
}
.close:after {
    content: "";
    width: 2rem;
    height: 15rem;
    margin-left: -1rem;
    background: red;
    transform: rotate(-45deg);
}
</style>
