BlessingBag.ts 9.3 KB

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