BlessingBag.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. * @description 福袋界面类
  3. * @author kaka
  4. */
  5. import SetGray from "../../component/SetGray";
  6. import TableView from "../../component/TableView";
  7. import { DataEventId, VideoAdType } from "../../data/GameData";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class BlessingBag extends cc.Component {
  11. @property(cc.RichText)
  12. txtRemaindAdNum: cc.RichText = null;
  13. @property(cc.Prefab)
  14. blassingBagItem: cc.Prefab = null;
  15. @property(cc.Node)
  16. itemContent: cc.Node = null;
  17. @property(cc.Node)
  18. btnAd: cc.Node = null;
  19. @property(cc.Node)
  20. adIcon: cc.Node = null;
  21. @property(cc.Node)
  22. node_xiabiao: cc.Node = null;
  23. @property(TableView)
  24. tableview: TableView = null;
  25. @property(cc.Button)
  26. video_btn: cc.Button = null;
  27. private scroll_view: cc.ScrollView = null!;
  28. /**红包页面类型 1 大额 2 任务*/
  29. private rbPanelType: number = 0;
  30. private adrbArray = [];
  31. private isPlayInitAni = true;
  32. onLoad() {
  33. }
  34. onEnable() {
  35. this.isPlayAni = false;
  36. this.isPlayInitAni = true;
  37. gData.blessingBag.isPlayAniUpdate = false;
  38. gData.blessingBag.init_videoRbData = true;
  39. }
  40. update(dt) {
  41. this.PlayMoneyAniUpdate(dt);
  42. if (gData.blessingBag.init_videoRbData) {
  43. this.UpdateInfo();
  44. }
  45. if (gData.blessingBag.init_openRb) {
  46. //this.OpenRbPanel(gData.blessingBag.taskRbId, gData.blessingBag.rbNum);
  47. if (cc.sys.isNative && !gData.loginData.isAuth) {
  48. // JsbSystem.WxAuth();
  49. mk.ui.openPanel('module/authUI/authUI');
  50. return;
  51. }
  52. gData.blessingBag.HttpCashTask();
  53. }
  54. }
  55. lateUpdate() {
  56. gData.blessingBag.init_videoRbData = false;
  57. gData.blessingBag.init_openRb = false;
  58. }
  59. UpdateInfo() {
  60. let data = gData.blessingBag.videoRbData;
  61. if (!data) {
  62. return
  63. }
  64. let isAllComplete = true;
  65. for (let i = 0; i != data.welFareTaskList.length; ++i) {
  66. if (data.welFareTaskList[i].progressRate < 1) {
  67. isAllComplete = false;
  68. break;
  69. }
  70. }
  71. //if(isAllComplete || data.leftVideoTimes <= 0)
  72. if (isAllComplete) {
  73. this.video_btn.interactable = false;
  74. let cmp = this.video_btn.getComponent(SetGray);
  75. if (cmp) {
  76. cmp.setGray(true);
  77. }
  78. }
  79. {
  80. if (!isAllComplete && !this.video_btn.interactable) {
  81. this.video_btn.interactable = true;
  82. let cmp = this.video_btn.getComponent(SetGray);
  83. if (cmp) {
  84. cmp.setGray(false);
  85. }
  86. }
  87. }
  88. this.txtRemaindAdNum.string = "<color=#FDFCF5>今日剩余次数:</c><color=#FFE533>" + data.leftVideoTimes + "</color>";
  89. //this.adIcon.active = data.isVideo != 1;
  90. if (this.adrbArray.length < 4) {
  91. this.adrbArray = [];
  92. for (let i = 0; i < data.welFareTaskList.length; i++) {
  93. let obj = {
  94. data: data.welFareTaskList[i],
  95. isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate,
  96. isPlayInitAni: this.isPlayInitAni
  97. }
  98. this.adrbArray.push(obj);
  99. }
  100. this.itemContent.emit('srollview-init', this.adrbArray);
  101. this.scroll_view = this.itemContent.getComponent(cc.ScrollView);
  102. this.scroll_view.vertical = false;
  103. cc.tween(this.node).delay(0.1).call(() => {
  104. let allItem = this.tableview.getFrontPositionItemByCount(5);
  105. for (let i = 0; i != allItem.length; ++i) {
  106. //allItem[i].active = true;
  107. let posY = allItem[i].position.y
  108. allItem[i].y = posY - 600;
  109. cc.tween(allItem[i]).delay(i * 0.1).to(0.3, { y: posY }, cc.easeSineOut()).start();
  110. }
  111. }).start();
  112. } else {
  113. this.adrbArray = [];
  114. for (let i = 0; i < data.welFareTaskList.length; i++) {
  115. let obj = {
  116. data: data.welFareTaskList[i],
  117. isPlayAniUpdate: gData.blessingBag.isPlayAniUpdate,
  118. isPlayInitAni: this.isPlayInitAni
  119. }
  120. this.adrbArray.push(obj);
  121. }
  122. //刷新
  123. this.itemContent.emit('srollview-update', this.adrbArray);
  124. }
  125. this.isPlayInitAni = false;
  126. gData.blessingBag.isPlayAniUpdate = false;
  127. }
  128. private isPlayAni = false;
  129. targetProgress: number = 0;
  130. delta: number = 0;
  131. curValue: number = 0;
  132. curTime: number = 0;
  133. totalTime: number = 0;
  134. lastNum: number = 0;
  135. PlayMoneyAni(time) {
  136. this.totalTime = time;
  137. this.delta = (this.targetProgress - this.lastNum) / time;
  138. this.curValue = this.lastNum;
  139. this.curTime = 0;
  140. this.isPlayAni = true;
  141. }
  142. PlayMoneyAniUpdate(dt) {
  143. if (this.isPlayAni) {
  144. if (this.curTime < this.totalTime) {
  145. this.curTime += dt;
  146. this.curValue += this.delta * dt;
  147. if (this.curValue >= this.targetProgress) {
  148. this.isPlayAni = false;
  149. this.curValue = this.targetProgress;
  150. this.lastNum = this.targetProgress;
  151. }
  152. } else {
  153. this.isPlayAni = false;
  154. this.curTime = this.totalTime;
  155. this.curValue = this.targetProgress;
  156. this.lastNum = this.targetProgress;
  157. }
  158. }
  159. }
  160. Click_AdProgressBtn() {
  161. mk.audio.playEffect("button");
  162. // if (gData.blessingBag.videoRbData.isVideo == 1) {
  163. // //免费加进度
  164. // gData.blessingBag.addProgress();
  165. // } else
  166. {
  167. // if (cc.sys.isNative && !gData.loginData.isAuth) {
  168. // // JsbSystem.WxAuth();
  169. // mk.ui.openPanel('module/authUI/authUI');
  170. // return;
  171. // }
  172. if (gData.blessingBag.videoRbData.leftVideoTimes > 0) {
  173. mk.ad.videoAdType = VideoAdType.video_init_15;
  174. mk.ad.watchAd(async (success: boolean) => {
  175. mk.console.log("watchAD:" + success);
  176. if (success) {
  177. await gData.adData.watchVideo(null);
  178. gData.blessingBag.addProgress();
  179. }
  180. });
  181. } else {
  182. mk.tip.pop('今日观看次数已用完');
  183. }
  184. }
  185. }
  186. /**
  187. * 打开红包页面
  188. * @param type 打开红包类型 1 大额红包 2 任务红包
  189. * @param num 红包金额
  190. */
  191. OpenRbPanel(type: number, num: number) {
  192. //this.rbPanelType = type;
  193. // this.txtRbNum.string = num + "元";
  194. // this.nodeRb.active = true;
  195. // this.rbOpenBtn.active = true;
  196. //把打开原来的红包界面操作取消掉,直接提现
  197. gData.blessingBag.HttpCashTask();
  198. }
  199. CheckCashRedCode() {
  200. let data = gData.blessingBag.videoRbData;
  201. if (data.redMoneyCode.length > 0) {
  202. for (let i = 0; i < data.redMoneyCode.length; i++) {
  203. if (data.preLargeAmountCashId == data.redMoneyCode[i].RedMoneyId) {
  204. if (data.redMoneyCode[i].RedMoneyCode != "") {
  205. gData.redCodeData.openRedCode(data.redMoneyCode[i].VideoCashBig, data.redMoneyCode[i].RedMoneyCode);
  206. } else {
  207. mk.tip.pop('提现成功');
  208. }
  209. return;
  210. }
  211. }
  212. }
  213. mk.tip.pop('请先完成提现任务');
  214. }
  215. async Click_CashBtn() {
  216. mk.audio.playEffect("button");
  217. if (gData.blessingBag.videoRbData.cumulativeAmount >= gData.blessingBag.videoRbData.requestAmount) {
  218. let response = await gData.blessingBag.HttpCashBig();
  219. if (response && response.data.code == 1) {
  220. //弹红包码界面
  221. this.CheckCashRedCode();
  222. gData.cashNormal.getRecord();// 请求新的提现记录
  223. } else {
  224. mk.tip.pop('请先完成提现任务');
  225. }
  226. } else {
  227. mk.tip.pop("累计到" + gData.blessingBag.videoRbData.requestAmount + "元才可提现");
  228. }
  229. }
  230. /** 点击帮助回调 */
  231. clickHelpCallBack() {
  232. let des = "1、观看大量视频可以快速增加提现进度。\n\n2、提现进度到100%,可以提现对应档位的红包。\n\n3、余额累计满一定金额,可以申请大额提现。";
  233. gData.help.des = des;
  234. }
  235. Click_InitData() {
  236. mk.audio.playEffect("button");
  237. gData.blessingBag.HttpInitAdRbData();
  238. }
  239. /** 点击关闭 */
  240. onClickClose() {
  241. }
  242. onDisable() {
  243. let pop = gData.adData.checkShowFullInter(4);
  244. if(pop){
  245. gData.moreGame.openType = 2;
  246. mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭福利界面");
  247. }
  248. }
  249. onDestroy(){
  250. //gData.adData.checkPopInter(InterAdType.interstitial1_click_10);
  251. gData.gameData.popTableScreenADLogic(9);
  252. }
  253. }