import test from '@/utils/test';
export default {
    data(){
        return {
            vValue:false,
            content:''
        }
    },

    watch:{
        value(){
            this.changeValue(this.value);
        }
    },

    methods:{
        changeValue(value){
            if (this.vValue !== value) {
                this.vValue = value;
                if (this.value !== value) {
                    return this.$emit('input',value);
                }
            }
        },
        closeModal(){
            if (this.vValue) {
                return this.changeValue(false);
            }
        },

        submit(){
            if(this.loadingStatus) return;

            test.verificationPromise({
                key:'invite_no',
                value: this.content,
                rules:'请输入邀请码',
            },true).then((data)=>{

                return this.$request({
                    url:'user/bindUser',
                    data,
                    loading:'绑定中',
                    token:true,
                    message:true,
                    failMessage:true,
                    next:({status})=> this.loadingStatus = status
                }).then((data)=>{
                    if (data.isSuccess) {
                        this.content = '';

                        this.updateUserInfo({
                            ...data.data,
                        });

                        this.closeModal();
                    }
                })

            });

        }

    },
}