BlessingBag.ts 11 KB

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