OrderDrawPanel.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /** 订单抽奖界面 */
  2. import { AdFun } from "../../../game/data/AdData";
  3. import { GameProp, VideoAdType } from "../../../game/data/GameData";
  4. import Util from "../../util/Util";
  5. import OrderDrawItem from "../uiItem/OrderDrawItem";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class OrderDrawPanel extends cc.Component {
  9. @property({ type: OrderDrawItem, displayName: '抽奖item' })
  10. itemsArr: OrderDrawItem[] = [];
  11. private dis = 8;
  12. private endIndex = 0;
  13. private maxNum: number = 0;
  14. private curSelItem: OrderDrawItem;
  15. private lastSelItem: OrderDrawItem;
  16. private changeA: any = {};
  17. private go = 0;
  18. private listData = null;
  19. private cashData = null;
  20. private clickCool = false;
  21. async onLoad() {
  22. let data = {};
  23. let response = await mk.http.sendData('orderTaskTree/getOrderLuckyReward', data);
  24. if (response.errcode != 0) {
  25. return null;
  26. }
  27. this.listData = response.data;
  28. let len = this.listData.length;
  29. mk.console.logSingle('listData ', this.listData);
  30. this.go = 0;
  31. for (var i = 0; i < len; i++) {
  32. this.itemsArr[i].init(this.listData[i]);
  33. }
  34. }
  35. clickDraw() {
  36. if (this.clickCool) {
  37. return;
  38. }
  39. console.log('aaaaaaaa 111 ');
  40. this.clickCool = true;
  41. mk.ad.videoAdType = VideoAdType.video_init_22;
  42. mk.ad.watchAd((success: boolean) => {
  43. if (success) {
  44. gData.gameData.isOrderVideo = true;
  45. gData.adData.watchVideo(AdFun.harvest, async () => {
  46. console.log('aaaaaaaa 222 ');
  47. let data = {};
  48. let response = await mk.http.sendData('orderTaskTree/receiveRewardNewCash', data);
  49. console.log('aaaaaaaa ', response.errcode);
  50. mk.console.logSingle('receiveRewardNewCash ', response);
  51. gData.gameData.isOrderVideo = false;
  52. if (response.errcode != 0) {
  53. this.clickCool = false;
  54. return null;
  55. }
  56. //当前订单种植数据清空
  57. gData.gameData.setProp(GameProp.orderPlantTimes, {});
  58. this.cashData = response.data;
  59. mk.data.sendDataEvent('Orderreward', this.cashData.orderLuckyRedMoney);
  60. mk.console.logSingle('receiveRewardNewCash cashData ', response);
  61. this.endIndex = 0;
  62. for (var i = 0; i < this.listData.length; i++) {
  63. if (this.listData[i].amount == this.cashData.orderLuckyRedMoney) {
  64. this.endIndex = i;
  65. break;
  66. }
  67. }
  68. this.dis = 8;
  69. let startIndex = Util.rnd(0, this.dis - 1);
  70. this.maxNum = this.dis * 3 + this.endIndex;
  71. this.changeA.startIndex = startIndex;
  72. cc.tween(this.changeA).to(5, { startIndex: this.maxNum }, cc.easeOut(3)).call(() => {
  73. this.go = 2;
  74. }).start();
  75. if (this.lastSelItem) {
  76. this.lastSelItem.setSelect(false);
  77. }
  78. this.curSelItem = this.itemsArr[startIndex];
  79. this.curSelItem.setSelect(true);
  80. this.go = 1;
  81. });
  82. }
  83. else {
  84. this.clickCool = false;
  85. console.log('aaaaaaaa fail ');
  86. }
  87. })
  88. }
  89. protected update(dt: number): void {
  90. if (this.go == 1) {
  91. this.lastSelItem = this.curSelItem;
  92. this.lastSelItem.setSelect(false);
  93. console.log(Math.round(this.changeA.startIndex) % this.dis)
  94. this.curSelItem = this.itemsArr[Math.round(this.changeA.startIndex) % this.dis];
  95. this.curSelItem.setSelect(true);
  96. }
  97. else if (this.go == 2) {
  98. this.go = 0;
  99. this.scheduleOnce(() => {
  100. //奖品类型(1:红包币 2:现金)
  101. if (this.cashData.orderLuckyType == 1) {
  102. // gData.gameData.playerProp.redMoney += this.cashData.orderLuckyRedMoney;
  103. let rewardData = [{ rewardType: 1, rewardNum: this.cashData.orderLuckyRedMoney }];
  104. gData.reward.data = rewardData;
  105. mk.ui.openPanel("module/reward/reward");
  106. gData.gameData.playerProp.orderData = this.cashData.userOrderTaskInfo;
  107. gData.reward.closeUICallBack = gData.gameData.gameStyle.getRewardCallBack.bind(gData.gameData.gameStyle);
  108. gData.gameData.gameStyle.showRefreshLogic();
  109. }
  110. else if (this.cashData.orderLuckyType == 2) {
  111. gData.receiptNotice.receip_rmb = this.cashData.orderLuckyRedMoney;
  112. mk.ui.openPanel('module/newNotice/newNotice');
  113. gData.gameData.playerProp.orderData = this.cashData.userOrderTaskInfo;
  114. gData.safeDepositBoxData.setCashRecordDataLength();
  115. //处理提现逻辑
  116. gData.cashPro.isOrderCashOut = true;
  117. gData.cashPro.callBack = gData.gameData.gameStyle.getRewardCallBack.bind(gData.gameData.gameStyle);
  118. gData.gameData.gameStyle.showRefreshLogic();
  119. }
  120. mk.ui.closePanel(this.node.name);
  121. }, 1);
  122. }
  123. }
  124. }