cc.Class({
    extends: cc.Component,

    properties: {
    
    },
    onLoad () {
        this.TimeLabel = this.node.getComponent(cc.Label);
        //init
        this.Init();
    },
    Init()
    {
        this.curtTime = {'second':0,'millisecond':0,'secondBase':60,'millisecondBase':60};
    },
    CountDown(time,callback)
    {
        this.curtTime.second  = time.second;
        this.curtTime.millisecond  = time.millisecond;
        let times = this.curtTime.second*this.curtTime.millisecondBase + this.curtTime.millisecond;
        times--;
        
        this.schedule(function(){
            this.TimeMinus();
            this.TimeLabel.string = this.ShowTime(this.curtTime);
            if(this.curtTime.second*this.curtTime.millisecondBase + this.curtTime.millisecond == 0)
            {
                callback();
            }
        }.bind(this),0.01,times);
    },
    TimeMinus()
    {
        if((this.curtTime.millisecond-1) < 0)
        {
            this.curtTime.millisecond = this.curtTime.millisecondBase-1;
            this.curtTime.second--;

            return;
        }

        this.curtTime.millisecond--;
    },
    ShowTime(time)
    {
        if(time.millisecond<10)
        {
            return '0'+this.curtTime.second + ':0' + this.curtTime.millisecond;
        }
        else
        {
            return '0'+this.curtTime.second + ':' + this.curtTime.millisecond;
        }
    }
});
