BlessingBag.ts 12 KB

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