BlessingBag.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /**
  2. * @description 福袋界面类
  3. * @author kaka
  4. */
  5. import JsbSystem from "../../../mk/system/JsbSystem";
  6. import { AdFun } from "../../data/AdData";
  7. import { DataEventId, VideoAdType } from "../../data/GameData";
  8. import { cashProType } from "../../data/module/CashProData";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class BlessingBag extends cc.Component {
  12. @property(cc.Label)
  13. txtBigNum: cc.Label = null;
  14. @property(cc.Label)
  15. txtAddEft: cc.Label = null;
  16. @property(cc.RichText)
  17. txtTipAd: cc.RichText = null;
  18. @property(cc.RichText)
  19. txtBigDelta: cc.RichText = null;
  20. @property(cc.RichText)
  21. txtBigTask: cc.RichText = null;
  22. @property(cc.RichText)
  23. txtRemaindAdNum: cc.RichText = null;
  24. @property(cc.Prefab)
  25. blassingBagItem: cc.Prefab = null;
  26. @property(cc.Node)
  27. itemContent: cc.Node = null;
  28. @property(cc.Node)
  29. btnCash: cc.Node = null;
  30. @property(cc.Node)
  31. btnAd: cc.Node = null;
  32. @property(cc.Animation)
  33. aniBigAdBtn: cc.Animation = null;
  34. @property(cc.Node)
  35. adIcon: cc.Node = null;
  36. @property(cc.Animation)
  37. aniBtnAd: cc.Animation = null;
  38. @property(cc.Node)
  39. rbOpenBtn: cc.Node = null;
  40. @property(cc.Node)
  41. nodeRb: cc.Node = null;
  42. @property(cc.Label)
  43. txtRbNum: cc.Label = null;
  44. @property(cc.Node)
  45. testNode: cc.Node = null;
  46. @property(cc.EditBox)
  47. inputBox: cc.EditBox = null;
  48. /**红包页面类型 1 大额 2 任务*/
  49. private rbPanelType: number = 0;
  50. private adrbArray = [];
  51. private isPlayInitAni = true;
  52. private isSuccess = false;
  53. onLoad() {
  54. this.testNode.active = gData.gameData.configs.ServerConfig.VideoRedBagEmpty == 1;
  55. }
  56. onEnable() {
  57. this.isPlayAni = false;
  58. this.isPlayInitAni = true;
  59. gData.blessingBag.isPlayAniUpdate = false;
  60. gData.blessingBag.init_videoRbData = true;
  61. }
  62. update(dt) {
  63. this.PlayMoneyAniUpdate(dt);
  64. if (gData.blessingBag.init_videoRbData) {
  65. this.UpdateInfo();
  66. }
  67. if (gData.blessingBag.init_openRb) {
  68. this.OpenRbPanel(gData.blessingBag.rbType, gData.blessingBag.rbNum);
  69. }
  70. }
  71. lateUpdate() {
  72. gData.blessingBag.init_videoRbData = false;
  73. gData.blessingBag.init_openRb = false;
  74. }
  75. UpdateInfo() {
  76. let data = gData.blessingBag.videoRbData;
  77. if (!data) {
  78. return
  79. }
  80. this.targetProgress = data.cumulativeAmount;
  81. this.txtBigDelta.node.active = data.showTask != 1;
  82. this.txtBigTask.node.active = data.showTask == 1;
  83. this.txtTipAd.string = data.showTask == 1 ? "提现中..." : "<b>满<color=#FFE00C>" + data.requestAmount + "元</color>可提现</b>";
  84. this.txtBigDelta.string = "<outline color=#8C1010 width=4><b>每次视频额外奖励<color=#FFE00C>" + data.videoAmountPerTime + "元</color></b></outline>";
  85. this.txtBigTask.string = "<outline color=#8C1010 width=4>金额已达标,完成<color=#4EB7FF>观看视频</color>任务可到账"
  86. + "\n观看视频次数:<color=#FFE00C>" + data.taskVideoWatchTime + "/" + data.taskVideoTime + "</color>,连续观看天数:<color=#FFE00C>" + data.taskVideoWatchDay + "/" + data.taskVideoDay + "</color></outline>"
  87. this.txtRemaindAdNum.string = "<b>今日剩余次数:<color=#B02D29>" + data.videoTime + "</color></b>";
  88. this.adIcon.active = data.needToWatchTheVideo == 1;
  89. if (gData.blessingBag.isPlayAniUpdate) {
  90. if (this.lastNum < data.cumulativeAmount) {
  91. let world_pos = this.btnCash.parent.convertToWorldSpaceAR(this.btnCash.getPosition());
  92. mk.fly.PlayCoinAnim(1, 10, this.btnAd.getPosition(), world_pos, () => {
  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. mk.audio.playEffect("button");
  185. if (!gData.loginData.isAuth) {
  186. JsbSystem.WxAuth();
  187. return;
  188. }
  189. if (gData.blessingBag.videoRbData.needToWatchTheVideo != 1) {
  190. //免费加进度
  191. gData.blessingBag.HttpNoAdProgress();
  192. } else {
  193. if (gData.blessingBag.videoRbData.videoTime > 0) {
  194. mk.ad.videoAdType = VideoAdType.Fudai;
  195. mk.ad.watchAd((success: boolean,request_id: string) => {
  196. mk.console.log("watchAD:" + success);
  197. if (success) {
  198. gData.adData.watchVideo(AdFun.bigCash,request_id)
  199. }
  200. });
  201. } else {
  202. mk.tip.pop('今日观看次数已用完');
  203. }
  204. }
  205. mk.audio.playEffect('button');
  206. console.log("--->You Click AdProgressBtn ", gData.blessingBag.videoRbData);
  207. }
  208. /**
  209. * 打开红包页面
  210. * @param type 打开红包类型 1 大额红包 2 任务红包
  211. * @param num 红包金额
  212. */
  213. OpenRbPanel(type: number, num: number) {
  214. this.rbPanelType = type;
  215. this.txtRbNum.string = num + "元";
  216. this.nodeRb.active = true;
  217. this.rbOpenBtn.active = true;
  218. }
  219. CheckCashRedCode() {
  220. let data = gData.blessingBag.videoRbData;
  221. if (data.redMoneyCode.length > 0) {
  222. for (let i = 0; i < data.redMoneyCode.length; i++) {
  223. if (data.preLargeAmountCashId == data.redMoneyCode[i].RedMoneyId) {
  224. if (data.redMoneyCode[i].RedMoneyCode != "") {
  225. gData.redCodeData.openRedCode(data.redMoneyCode[i].VideoCashBig, data.redMoneyCode[i].RedMoneyCode);
  226. } else {
  227. mk.tip.pop('提现成功');
  228. }
  229. return;
  230. }
  231. }
  232. }
  233. mk.tip.pop('请先完成提现任务');
  234. }
  235. async Click_CashBtn() {
  236. console.log("--->You Click CashBtn");
  237. mk.audio.playEffect("button");
  238. if (gData.blessingBag.videoRbData.cumulativeAmount >= gData.blessingBag.videoRbData.requestAmount) {
  239. let response = await gData.blessingBag.HttpCashBig();
  240. if (response && response.data.code == 1) {
  241. //弹红包码界面
  242. this.CheckCashRedCode();
  243. gData.cashNormal.getRecord();// 请求新的提现记录
  244. this.isSuccess = true;
  245. } else {
  246. mk.tip.pop('请先完成提现任务');
  247. }
  248. } else {
  249. mk.tip.pop("累计到" + gData.blessingBag.videoRbData.requestAmount + "元才可提现");
  250. }
  251. }
  252. canOpen: boolean = true;
  253. /**红包界面开按钮*/
  254. async Click_CashOpenBtn() {
  255. mk.audio.playEffect("button");
  256. if (!this.canOpen) return;
  257. this.canOpen = false;
  258. if (this.rbPanelType == 1) {
  259. gData.cashPro.openCashPro(cashProType.blessing_bigCash, gData.blessingBag.bigRbNum)
  260. } else {
  261. //弹确认提现界面
  262. this.rbOpenBtn.active = false;
  263. this.aniBtnAd.node.active = true;
  264. this.aniBtnAd.setCurrentTime(0);
  265. this.aniBtnAd.play();
  266. setTimeout(async () => {
  267. this.aniBtnAd.stop();
  268. this.aniBtnAd.node.active = false;
  269. this.rbOpenBtn.active = true;
  270. this.nodeRb.active = false;
  271. let response = await gData.blessingBag.HttpCashTask();
  272. if (response && response.errcode != 0) {
  273. this.isSuccess = true;
  274. }
  275. this.canOpen = true;
  276. }, 1000);
  277. }
  278. }
  279. /** 点击帮助回调 */
  280. clickHelpCallBack() {
  281. let des = "1、观看大量视频可以快速增加提现进度。\n\n2、提现进度到100%,可以提现对应档位的红包。\n\n3、余额累计满一定金额,可以申请大额提现。";
  282. gData.help.des = des;
  283. }
  284. Click_InitData() {
  285. mk.audio.playEffect("button");
  286. gData.blessingBag.HttpInitAdRbData();
  287. }
  288. EditBox_End() {
  289. console.log("-->Input:", this.inputBox.string);
  290. gData.blessingBag.adsource_id_value = this.inputBox.string;
  291. }
  292. /** 点击关闭 */
  293. onClickClose() {
  294. mk.ad.checkShowInterByChance();
  295. }
  296. }