BlessingBag.ts 9.6 KB

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