DailyCashOutUI.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import { EVENT_TYPE } from "../../game/data/GameData";
  8. import GameConst from "../data/GameConst";
  9. import PlayerConst from "../data/PlayerConst";
  10. import EffectMgr from "../mgr/EffectMgr";
  11. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  12. import HttpMgr from "../mgr/HttpMgr";
  13. import GameLogic from "../util/GameLogic";
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class DailyCashOutUI extends cc.Component {
  17. @property(cc.Node)
  18. node_rectBg: cc.Node = null;
  19. @property(cc.Label)
  20. label_videoTaskTip: cc.Label = null;
  21. @property(cc.Label)
  22. label_videoTaskProgress: cc.Label = null;
  23. @property(cc.ProgressBar)
  24. bar_videoTaskProgress: cc.ProgressBar = null;
  25. @property(cc.Label)
  26. label_timeTaskTip: cc.Label = null;
  27. @property(cc.Label)
  28. @property(cc.Label)
  29. label_timeTaskProgress: cc.Label = null;
  30. @property(cc.ProgressBar)
  31. bar_timeTaskProgress: cc.ProgressBar = null;
  32. @property(cc.Label)
  33. label_passTaskTip: cc.Label = null;
  34. @property(cc.Label)
  35. label_passTaskProgress: cc.Label = null;
  36. @property(cc.ProgressBar)
  37. bar_passTaskProgress: cc.ProgressBar = null;
  38. @property(cc.Node)
  39. node_closeBtn: cc.Node = null;
  40. @property(cc.Node)
  41. node_cashOutBtn: cc.Node = null;
  42. @property(cc.Node)
  43. node_cashOutBtn_on: cc.Node = null;
  44. @property(cc.Node)
  45. node_cashOutBtn_off: cc.Node = null;
  46. public videoNum: number = 30;
  47. public onlineTime: number = 30;
  48. public passNum: number = 20;
  49. // LIFE-CYCLE CALLBACKS:
  50. // onLoad () {}
  51. onEnable() {
  52. GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "进入每日打卡界面");
  53. this.initView();
  54. }
  55. start() {
  56. this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
  57. this.initEvent();
  58. }
  59. initView() {
  60. this.initLabelTip();
  61. this.initWatchVideoNum();
  62. this.initOnlineTime();
  63. this.initPassNum();
  64. this.initCashOutState();
  65. }
  66. initLabelTip() {
  67. if (PlayerConst.loginDay == 1) {
  68. this.videoNum = 10;
  69. this.onlineTime = 5;
  70. this.passNum = 3;
  71. }
  72. else {
  73. this.videoNum = GameLogic.getVideoNumByEcpm();
  74. this.onlineTime = 15;
  75. this.passNum = 15;
  76. }
  77. this.label_videoTaskTip.string = `观看视频${this.videoNum}次`;
  78. this.label_timeTaskTip.string = `在线时长达到${this.onlineTime}分钟`;
  79. this.label_passTaskTip.string = `通关${this.passNum}关`;
  80. }
  81. initWatchVideoNum() {
  82. this.label_videoTaskProgress.string = `${PlayerConst.watchVideoNum}/${this.videoNum}`;
  83. let progress = PlayerConst.watchVideoNum / this.videoNum;
  84. progress = progress >= 1 ? 1 : progress;
  85. this.bar_videoTaskProgress.progress = progress;
  86. }
  87. initOnlineTime() {
  88. let onlineTime = Math.floor(PlayerConst.onlineTime / 60);
  89. this.label_timeTaskProgress.string = `${onlineTime}/${this.onlineTime}`;
  90. let progress = onlineTime / this.onlineTime;
  91. progress = progress >= 1 ? 1 : progress;
  92. this.bar_timeTaskProgress.progress = progress;
  93. }
  94. initPassNum() {
  95. this.label_passTaskProgress.string = `${PlayerConst.passNum}/${this.passNum}`;
  96. let progress = PlayerConst.passNum / this.passNum;
  97. progress = progress >= 1 ? 1 : progress;
  98. this.bar_passTaskProgress.progress = progress;
  99. }
  100. /**初始化提现状态 */
  101. initCashOutState() {
  102. if (this.bar_videoTaskProgress.progress != 1 || this.bar_timeTaskProgress.progress != 1 || this.bar_passTaskProgress.progress != 1) {
  103. this.node_cashOutBtn_off.active = true;
  104. this.node_cashOutBtn_on.active = !this.node_cashOutBtn_off.active;
  105. }
  106. else {
  107. this.node_cashOutBtn_on.active = !PlayerConst.ifDailyCashOut;
  108. this.node_cashOutBtn_off.active = PlayerConst.ifDailyCashOut;
  109. }
  110. }
  111. /**初始化事件 */
  112. initEvent() {
  113. this.node_cashOutBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  114. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  115. //如果未授权则添加监听
  116. if (!GameConst.isAuth) {
  117. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  118. }
  119. }
  120. /**点击按钮 */
  121. onClickBtn(event: cc.Event.EventTouch) {
  122. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  123. mk.audio.playEffect("ef_button_click");
  124. switch (event.currentTarget) {
  125. case this.node_cashOutBtn:
  126. this.onClickCashOutBtn();
  127. break;
  128. case this.node_closeBtn:
  129. this.onClickCloseBtn();
  130. break;
  131. }
  132. }
  133. // update (dt) {}
  134. //点击提现按钮
  135. onClickCashOutBtn() {
  136. GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "点击提现按钮");
  137. if (!GameConst.isAuth) {
  138. EffectMgr.Inst.addTip("授权才能提现哦");
  139. mk.ui.openPanel("game/prefab/uiPanel/GuideAuthUI");
  140. return;
  141. }
  142. if (!this.node_cashOutBtn_on.active) {
  143. if (PlayerConst.ifDailyCashOut) {
  144. EffectMgr.Inst.addTip(`今天已提现啦,明天再来哦~`);
  145. }
  146. else {
  147. EffectMgr.Inst.addTip(`完成任务才可提现哦`);
  148. }
  149. return;
  150. }
  151. let cashNum = 0.3;
  152. HttpMgr.Inst.cash(cashNum, 2).then(() => {
  153. PlayerConst.ifDailyCashOut = true;
  154. this.initCashOutState();
  155. EffectMgr.Inst.addTip("提现成功,请等待微信到账");
  156. GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "每日提现成功");
  157. GameMgr.Inst.sendEventCp(UI_NAME.DailyCashOutUI, "每日提现成功");
  158. //提现操作
  159. }).catch((err) => {
  160. mk.console.log("[DailyCashOut] cash err", err);
  161. EffectMgr.Inst.addTip(err.errmsg);
  162. // EffectMgr.Inst.addTip(`后台维护中,请稍后再试`)
  163. });
  164. }
  165. //点击继续按钮
  166. onClickCloseBtn() {
  167. GameMgr.Inst.sendEvent(UI_NAME.DailyCashOutUI, "点击关闭按钮");
  168. mk.ui.closePanel("DailyCashOutUI")
  169. }
  170. //自定义事件---------------------------------------------------------------------
  171. /**微信授权返回 */
  172. onWxAuthBack() {
  173. this.initView();
  174. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  175. }
  176. }