BlessingBag.ts 12 KB

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