BlessingBag.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /**
  2. * @description 福袋界面类
  3. * @author kaka
  4. */
  5. import { AdFun } from "../../data/AdData";
  6. import { cashProType } from "../../data/module/CashProData";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class BlessingBag extends cc.Component {
  10. @property(cc.Label)
  11. txtBigNum: cc.Label = null;
  12. @property(cc.Label)
  13. txtAddEft: cc.Label = null;
  14. @property(cc.RichText)
  15. txtTipAd: cc.RichText = null;
  16. @property(cc.RichText)
  17. txtBigDelta: cc.RichText = null;
  18. @property(cc.RichText)
  19. txtBigTask: cc.RichText = null;
  20. @property(cc.RichText)
  21. txtRemaindAdNum: cc.RichText = null;
  22. @property(cc.Prefab)
  23. blassingBagItem: cc.Prefab = null;
  24. @property(cc.Node)
  25. itemContent: cc.Node = null;
  26. @property(cc.Node)
  27. btnCash: cc.Node = null;
  28. @property(cc.Node)
  29. btnAd: cc.Node = null;
  30. @property(cc.Animation)
  31. aniBigAdBtn: cc.Animation = null;
  32. @property(cc.Node)
  33. adIcon: cc.Node = null;
  34. @property(cc.Animation)
  35. aniBtnAd: cc.Animation = null;
  36. @property(cc.Node)
  37. rbOpenBtn: cc.Node = null;
  38. @property(cc.Node)
  39. nodeRb: cc.Node = null;
  40. @property(cc.Label)
  41. txtRbNum: cc.Label = null;
  42. @property(cc.Node)
  43. testNode: cc.Node = null;
  44. @property(cc.EditBox)
  45. inputBox: cc.EditBox = null;
  46. /**红包页面类型 1 大额 2 任务*/
  47. private rbPanelType: number = 0;
  48. private adrbArray = [];
  49. private isPlayInitAni = true;
  50. onLoad() {
  51. this.testNode.active = gData.gameData.configs.ServerConfig.VideoRedBagEmpty == 1;
  52. }
  53. onEnable() {
  54. this.isPlayAni = false;
  55. this.isPlayInitAni = false;
  56. gData.blessingBag.isPlayAniUpdate = false;
  57. gData.blessingBag.init_videoRbData = true;
  58. }
  59. update(dt) {
  60. this.PlayMoneyAniUpdate(dt);
  61. if (gData.blessingBag.init_videoRbData) {
  62. this.UpdateInfo();
  63. }
  64. if (gData.blessingBag.init_openRb) {
  65. this.OpenRbPanel(gData.blessingBag.rbType, gData.blessingBag.rbNum);
  66. }
  67. }
  68. lateUpdate() {
  69. gData.blessingBag.init_videoRbData = false;
  70. gData.blessingBag.init_openRb = false;
  71. }
  72. UpdateInfo() {
  73. let data = gData.blessingBag.videoRbData;
  74. if (!data) {
  75. return
  76. }
  77. this.targetProgress = data.cumulativeAmount;
  78. this.txtBigDelta.node.active = data.showTask != 1;
  79. this.txtBigTask.node.active = data.showTask == 1;
  80. this.txtTipAd.string = data.showTask == 1 ? "提现中..." : "<b>满<color=#FFE00C>" + data.requestAmount + "元</color>可提现</b>";
  81. this.txtBigDelta.string = "<outline color=#8C1010 width=4><b>每次视频额外奖励<color=#FFE00C>" + data.videoAmountPerTime + "元</color></b></outline>";
  82. this.txtBigTask.string = "<outline color=#8C1010 width=4>金额已达标,完成<color=#4EB7FF>观看视频</color>任务可到账"
  83. + "\n观看视频次数:<color=#FFE00C>" + data.taskVideoWatchTime + "/" + data.taskVideoTime + "</color>,连续观看天数:<color=#FFE00C>" + data.taskVideoWatchDay + "/" + data.taskVideoDay + "</color></outline>"
  84. this.txtRemaindAdNum.string = "<b>今日剩余次数:<color=#B02D29>" + data.videoTime + "</color></b>";
  85. this.adIcon.active = data.needToWatchTheVideo == 1;
  86. if (gData.blessingBag.isPlayAniUpdate) {
  87. if (this.lastNum < data.cumulativeAmount) {
  88. mk.fly.PlayCoinAnim(1, 10, this.btnAd.getPosition(), this.btnCash.getPosition(), () => {
  89. this.aniBigAdBtn.setCurrentTime(0);
  90. this.aniBigAdBtn.play();
  91. });
  92. this.txtAddEft.node.setPosition(cc.v2(0, 380));
  93. this.txtAddEft.string = "+" + data.videoAmountPerTime + "元";
  94. this.txtAddEft.node.stopAllActions();
  95. this.txtAddEft.node.scale = 0;
  96. this.txtAddEft.node.opacity = 255;
  97. this.txtAddEft.node.active = true;
  98. let a0 = cc.delayTime(0.8);
  99. let a1t = cc.sequence(cc.scaleTo(0.15, 1.2), cc.scaleTo(0.15, 1));
  100. let a1a = cc.spawn(cc.moveBy(0.3, cc.v2(0, 30)), a1t);
  101. let a2 = cc.delayTime(0.5);
  102. let a3 = cc.fadeOut(0.15);
  103. let a4 = cc.callFunc(() => {
  104. //this.txtBigNum.string = data.cumulativeAmount + "元";
  105. this.PlayMoneyAni(0.2);
  106. this.txtAddEft.node.active = false;
  107. });
  108. this.txtAddEft.node.runAction(cc.sequence(a0, a1a, a2, a3, a4));
  109. } else {
  110. this.txtBigNum.string = data.cumulativeAmount.toFixed(2) + "元";
  111. this.lastNum = data.cumulativeAmount;
  112. }
  113. } else {
  114. this.txtBigNum.string = data.cumulativeAmount.toFixed(2) + "元";
  115. this.lastNum = data.cumulativeAmount;
  116. }
  117. if (this.adrbArray.length < 4) {
  118. this.adrbArray = [];
  119. for (let i = 0; i < data.redMonies.length; i++) {
  120. let obj = {
  121. data: data.redMonies[i],
  122. isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate,
  123. isPlayInitAni: this.isPlayInitAni
  124. }
  125. this.adrbArray.push(obj);
  126. }
  127. this.itemContent.emit('srollview-init', this.adrbArray);
  128. } else {
  129. this.adrbArray = [];
  130. for (let i = 0; i < data.redMonies.length; i++) {
  131. let obj = {
  132. data: data.redMonies[i],
  133. isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate,
  134. isPlayInitAni: this.isPlayInitAni
  135. }
  136. this.adrbArray.push(obj);
  137. }
  138. //刷新
  139. this.itemContent.emit('srollview-update', this.adrbArray);
  140. }
  141. this.isPlayInitAni = false;
  142. gData.blessingBag.isPlayAniUpdate = false;
  143. }
  144. private isPlayAni = false;
  145. targetProgress: number = 0;
  146. delta: number = 0;
  147. curValue: number = 0;
  148. curTime: number = 0;
  149. totalTime: number = 0;
  150. lastNum: number = 0;
  151. PlayMoneyAni(time) {
  152. this.totalTime = time;
  153. this.delta = (this.targetProgress - this.lastNum) / time;
  154. this.curValue = this.lastNum;
  155. this.curTime = 0;
  156. console.log("--->Update Time: " + time + " delta: " + this.delta + " curValue: " + this.curValue + " lastNum: " + this.lastNum);
  157. this.isPlayAni = true;
  158. }
  159. PlayMoneyAniUpdate(dt) {
  160. if (this.isPlayAni) {
  161. if (this.curTime < this.totalTime) {
  162. this.curTime += dt;
  163. this.curValue += this.delta * dt;
  164. if (this.curValue >= this.targetProgress) {
  165. this.isPlayAni = false;
  166. this.curValue = this.targetProgress;
  167. this.lastNum = this.targetProgress;
  168. }
  169. console.log("-->CurValue:" + this.curValue);
  170. } else {
  171. this.isPlayAni = false;
  172. this.curTime = this.totalTime;
  173. this.curValue = this.targetProgress;
  174. this.lastNum = this.targetProgress;
  175. }
  176. this.txtBigNum.string = this.curValue.toFixed(2) + "元";
  177. }
  178. }
  179. Click_AdProgressBtn() {
  180. mk.audio.playEffect("button");
  181. if (gData.blessingBag.videoRbData.needToWatchTheVideo != 1) {
  182. //免费加进度
  183. gData.blessingBag.HttpNoAdProgress();
  184. } else {
  185. if (gData.blessingBag.videoRbData.videoTime > 0) {
  186. mk.ad.watchAd((success: boolean) => {
  187. mk.console.log("watchAD:" + success);
  188. if (success) {
  189. gData.adData.watchVideo(AdFun.bigCash)
  190. }
  191. });
  192. } else {
  193. mk.tip.pop('今日观看次数已用完');
  194. }
  195. }
  196. mk.audio.playEffect('button');
  197. console.log("--->You Click AdProgressBtn ", gData.blessingBag.videoRbData);
  198. }
  199. /**
  200. * 打开红包页面
  201. * @param type 打开红包类型 1 大额红包 2 任务红包
  202. * @param num 红包金额
  203. */
  204. OpenRbPanel(type: number, num: number) {
  205. this.rbPanelType = type;
  206. this.txtRbNum.string = num + "元";
  207. this.nodeRb.active = true;
  208. this.rbOpenBtn.active = true;
  209. }
  210. CheckCashRedCode() {
  211. let data = gData.blessingBag.videoRbData;
  212. if (data.redMoneyCode.length > 0) {
  213. for (let i = 0; i < data.redMoneyCode.length; i++) {
  214. if (data.preLargeAmountCashId == data.redMoneyCode[i].RedMoneyId) {
  215. if (data.redMoneyCode[i].RedMoneyCode != "") {
  216. gData.redCodeData.openRedCode(data.redMoneyCode[i].VideoCashBig, data.redMoneyCode[i].RedMoneyCode);
  217. } else {
  218. mk.tip.pop('提现成功');
  219. }
  220. return;
  221. }
  222. }
  223. }
  224. mk.tip.pop('请先完成提现任务');
  225. }
  226. async Click_CashBtn() {
  227. console.log("--->You Click CashBtn");
  228. mk.audio.playEffect("button");
  229. if (gData.blessingBag.videoRbData.cumulativeAmount >= gData.blessingBag.videoRbData.requestAmount) {
  230. let response = await gData.blessingBag.HttpCashBig();
  231. if (response && response.data.code == 1) {
  232. //弹红包码界面
  233. this.CheckCashRedCode();
  234. } else {
  235. mk.tip.pop('请先完成提现任务');
  236. }
  237. } else {
  238. mk.tip.pop("累计到" + gData.blessingBag.videoRbData.requestAmount + "元才可提现");
  239. }
  240. }
  241. canOpen: boolean = true;
  242. /**红包界面开按钮*/
  243. async Click_CashOpenBtn() {
  244. mk.audio.playEffect("button");
  245. if (!this.canOpen) return;
  246. this.canOpen = false;
  247. if (this.rbPanelType == 1) {
  248. gData.cashPro.openCashPro(cashProType.blessing_bigCash, gData.blessingBag.bigRbNum)
  249. } else {
  250. //弹确认提现界面
  251. this.rbOpenBtn.active = false;
  252. this.aniBtnAd.node.active = true;
  253. this.aniBtnAd.setCurrentTime(0);
  254. this.aniBtnAd.play();
  255. setTimeout(() => {
  256. this.aniBtnAd.stop();
  257. this.aniBtnAd.node.active = false;
  258. this.rbOpenBtn.active = true;
  259. this.nodeRb.active = false;
  260. gData.cashPro.openCashPro(cashProType.blessing_taskCash, gData.blessingBag.taskRbNum)
  261. this.canOpen = true;
  262. }, 1000);
  263. }
  264. }
  265. /** 点击帮助回调 */
  266. clickHelpCallBack() {
  267. let des = "1、观看大量视频可以快速增加提现进度。\n\n2、提现进度到100%,可以提现对应档位的红包。\n\n3、余额累计满一定金额,可以申请大额提现。";
  268. gData.help.des = des;
  269. }
  270. Click_InitData() {
  271. mk.audio.playEffect("button");
  272. gData.blessingBag.HttpInitAdRbData();
  273. }
  274. EditBox_End() {
  275. console.log("-->Input:", this.inputBox.string);
  276. gData.blessingBag.adsource_id_value = this.inputBox.string;
  277. }
  278. }