BlessingBag.ts 10.0 KB

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