/**
 * @author uu
 * @file 开始页面控制
 */
cc.Class({
  extends: cc.Component,
  properties: {
    bannerNode: cc.Node,
    labelNode: cc.Node,

    redBagBtnSpriteFrame: [cc.SpriteFrame],
    moneyLabel: cc.Label,
  },

  start() {

    // 红包
    this.redBagBtnSprite = this.moneyLabel.node.parent.getComponent(cc.Sprite);
    this.showRedBtn();
  },

  showRedBtn() {
    if (Utils.hadRedPacket()) {
      this.redBagBtnSprite.spriteFrame = this.redBagBtnSpriteFrame[0];
      this.moneyLabel.node.active = false
    } else {
      this.redBagBtnSprite.spriteFrame = this.redBagBtnSpriteFrame[1];
      this.moneyLabel.node.active = true;
      let moneyNum = Utils.getRedPacketNum();
      if (moneyNum == 0) moneyNum = "0.00";
      this.moneyLabel.string = moneyNum + "元";
    }
  },

  onTouched() {

  },

  showAnimation() {
    return new Promise((resolve, rejects) => {
      let action1 = cc.scaleTo(0.5, 0, 0).easing(cc.easeBackIn())
      let action2 = cc.blink(0.5, 3)
      this.bannerNode.runAction(action1)
      let action = cc.sequence(action2, cc.callFunc(() => {
        resolve()
      }))
      this.labelNode.runAction(action)
    })
  },



});