import {RoomGiftType} from "@/pages/talking/const/roomGiftType";
import userIntegral from "$utils/control/integral";
import popup from "$utils/tool/popup";
import {nextTick} from "vue";

export default {

    [RoomGiftType.default]:{
        fetch:'fetchDefault',

        methods:{
            // 校验是否有资格使用
            check({integral}){
                return userIntegral.checkBalance(integral,true);
            },
            // 减余额
            reduce({integral}){
                userIntegral.reduceBalance(integral,false);
            },
            // 增加余额
            plus({integral}){
                userIntegral.plusBalance(integral,false);
            },
            checkUpdate(data,vm,unique){
                return vm.checkUpdateUserIntegral(unique);
            }
        }

    },

    [RoomGiftType.knapsack]:{
        fetch:'fetchKnapsack',
        empty:'背包空空如也',

        methods:{
            check({gift,number}){
                let result= gift.num >= number;
                if (!result) {
                    popup.$toast('数量不足');
                }
                return result;
            },
            // 锁定数量
            reduce({item,number,giveUserId},vm){
                item.num -= (giveUserId.length * number);

                if (item.num <= 0) {
                    vm.updateBanner();
                }

            },
            // 恢复数量
            plus({item,number,giveUserId},vm){

                let num = item.num;

                item.num += (giveUserId.length * number);

                if (num <= 0) {
                    vm.updateBanner();
                }
            },

        }
    }

}
