// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.zhao = UtilsNode.getNode("zhao",this.node);
        this.waittimeText = UtilsNode.getNode("waittimeText",this.node);
        this.waittime = UtilsNode.getNode("waittime",this.node);
        this.chenggong = UtilsNode.getNode("chenggong",this.node);


    },
    //开始倒计时
    startCountDownTime: function () {
        // this.stopCountDownTime()
        this.chenggong.active = false;
        this.waittime.active = true;
        this.waittimeText.active = true;
        this.zhao.active = true;

        this.timeData = {
            branch: "00",
            second: "00"
        }

        this.waittime.getComponent(cc.Label).string = this.timeData.branch + ":" + this.timeData.second


        this.time_count = 0;
        this.time_branch = 0;
        this.time_second = 0;


        this.callbackCountDownTime = function () {
            this.time_second++;
            if (this.time_second > 60) {
                this.time_second = 0;
                this.time_branch++;
            }

            this.time_count++;

            //设置秒
            var second;
            if (this.time_second < 10) {
                second = '0' + this.time_second;
            } else {
                second = this.time_second;
            }
            this.timeData.second = second + "";

            var branch;
            if (this.time_branch < 10) {
                branch = '0' + this.time_branch;
            } else {
                branch = this.time_branch;
            }
            this.timeData.branch = branch + "";


            // console.log("我们的时间", this.timeData);

            this.updetaTime(this.timeData);
        }


        this.schedule(this.callbackCountDownTime, 1);
    },

    updetaTime: function (timeData) {
        this.waittime.getComponent(cc.Label).string = timeData.branch + ":" + timeData.second

    },
    //停止倒计时
    stopCountDownTime: function () {
        this.unschedule(this.callbackCountDownTime);
        this.chenggong.active = false;
        this.waittime.active = false;
        this.zhao.active = false;
        this.waittimeText.active = false;
    },
    succeed(){
        this.chenggong.active = true;
        this.waittime.active = false;
        this.zhao.active = false;
        this.waittimeText.active = false;
    }
    // update (dt) {},
});
