import Status from '$mixins/status/const/status';

export default <LibMixins>{

    data(){
      return {
          status_fetch_key:'submit',
          exit:false
      }
    },

    computed:{

        buttonStatus(){
            // 如果不允许进入加载状态设置为无状态
            if (this.status === Status.loading && !this.intoLoading || this.status === Status.success && !this.success) {
                return Status.none
            } else {
                return this.status;
            }
        }

    },

    methods:{

        trigger(){
            if (this.disabled || this._status === Status.success || this._status === Status.loading) return;

            if (this.$attrs.onPress) {
                return this.$emit('press');
            }

            if (this.$attrs.onSubmitVerify) {
                return this.$emit('submit-verify',(data:any)=> this.statusFetch(false,data));
            }

            if (this.$attrs.onSubmit) {
                return this.statusFetch();
            }

        },

        triggerChangeStatus(status:Status){
            clearTimeout(this._timeChangeStats);
            if (this.success && status === Status.success) {

                setTimeout(()=>{
                    this.$emit('change-success');
                },this.changeSuccessTime);

                this._timeChangeStats = setTimeout(()=> {
                    if (this._status === Status.success) {
                        this.exit = true;
                        setTimeout(()=>{
                            this.exit = false;
                            this.setStatus(Status.none);
                        },600);
                    }
                },this.asyncSuccess);
            }
        }

    },

    onUnmounted(){
        clearTimeout(this._timeChangeStats);
    }

}