import verification, {VerificationType} from '$utils/verification';

import popup from "$utils/tool/popup";

export default <LibMixins>{

    data(){
      return{
          moneyValue:'',
          disabled:false
      }
    },


    methods:{

        allExChange(){

            if (this.disabled) return;

            let intMoney = parseInt(this.$store.getters.money);

            if (this.moneyValue !== intMoney) {
                this.moneyValue = intMoney;
            }
        },

        submitVerify(callback){

            if (!verification.trigger[VerificationType.empty](this.moneyValue)) {
                return popup.$toast('请输入提现金额');
            } else if (this.moneyValue > this.$store.getters.money) {
                return popup.$toast('提现金额不能大于余额');
            }

            return callback();

        },

        submit(obj){

            let value = this.moneyValue;
            return this.$request({
                url:'user/user_withdrawal',
                data:{
                    money: value,
                    code:'9999'
                },
                next:({status})=>{
                    this.disabled = status;
                },
                token:true,
                message:true,
                failMessage:true
            }).then((data)=>{

                if (data.isSuccess) {

                    this.user = {
                        money: this.$store.getters.money - value
                    }

                    // 执行更新 补救措施
                    this.$store.dispatch('updateUserMoneyPromise');

                    return  this.close();
                }

                return obj.none();

            }).catch(obj.none);

        }

    }

}