BlessingBag.ts 11 KB

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