<template>
    <go-input elType="password"
              v-model="curDate"
              :labelAlign="labelAlign"
              :labelWidth="labelWidth"
              @blur="blur"
              @change="changePwd"
              :width="this.width"
              :errorFlag="errorFlag"
              :rightSlot="rightSlot"
              :validMsg="validMsg"
              :clearValue="clearValue"
              :item="this.inputItem">

            <span slot="rightIcon">
                <slot name="rightIcon"></slot>
            </span>

            <span slot="rightIconRemark">
                 <slot name="rightIconRemark"></slot>
            </span>
    </go-input>
</template>

<script>
    import GoClearInputIcon from "./commponents/go-clear-input-icon";
    import GoErrorIcon from "./commponents/go-error-icon";
    import formMixin from "../../mixins/formMixins";
    import GoLabel from "./commponents/go-label";

    export default {
        name: "go-pwd",
        mixins: [formMixin],
        data() {
            return {
                setData:false,
                curDate: this.value,
            };
        },
        props: {},
        computed: {},
        methods: {
            //校验密码的最大长度
            changePwd(val) {
                this.setData=true;
                //设置最大值
                if ((val + "").length > this.inputItem["maxLength"]) {
                    this.value = (val + "").slice(0, this.inputItem["maxLength"]);
                }
                this.curDate = (val + "").slice(0, this.inputItem["maxLength"]);
                //限制最大长度
                this.$emit("input", this.curDate);
            },
            //失去焦点 进行值校验
            blur(val) {
                this.$emit("blurFun", val);
            }
        },
        mounted() {
        },
        watch: {
            //监听值变化
            value(newVal){
                //如果是通过设置触发该方法 则不需要执行赋值操作了
                if(this.setData){
                    this.setData=false;
                }else{
                    this.curDate=newVal;
                }
            },
            errorMsg: function (newVal) {
                this.cusValidMsg = newVal;
            }
        },
        components: {
            GoErrorIcon: GoErrorIcon,
            GoLabel,
            GoClearInputIcon: GoClearInputIcon
        }
    };
</script>
