WalletCashOut.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import SetGray from "../../component/SetGray";
  2. import TweenCast from "../../component/tween/TweenCast";
  3. import { AdFun } from "../../data/AdData";
  4. import { VideoAdType } from "../../data/GameData";
  5. import CheckButton from "./CheckButton";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class WalletCashOut extends cc.Component {
  9. @property({ displayName: '公告组件', type: TweenCast })
  10. private tc: TweenCast = null;
  11. @property({ displayName: '进度条', type: cc.Sprite })
  12. private sp_progress: cc.Sprite = null;
  13. @property({ displayName: '红包币', type: cc.Label })
  14. private lbl_redMoney: cc.Label = null;
  15. @property({ displayName: '金额', type: cc.Label })
  16. private lbl_value: cc.Label = null;
  17. @property({ displayName: '下提示', type: cc.Label })
  18. private lbl_tip: cc.Label = null;
  19. @property({ displayName: '提现按钮文本', type: cc.Label })
  20. private lbl_cashOut: cc.Label = null;
  21. @property({ displayName: '新手描述', type: cc.Label })
  22. private lbl_noviceTitle: cc.Label = null;
  23. @property({ displayName: '新手金额', type: cc.Label })
  24. private lbl_noviceValue: cc.Label = null;
  25. @property({ displayName: '上提示', type: cc.Label })
  26. private lbl_tipUp: cc.Label = null;
  27. @property(SetGray)
  28. btn_cashOut: SetGray = null;
  29. @property(SetGray)
  30. btn_addProgress: SetGray = null;
  31. @property({ displayName: '6个选择按钮', type: CheckButton })
  32. private check_button: CheckButton[] = [];
  33. private curChooseIndex: number = -1;
  34. private intV: number = 0;
  35. private isCanCash = false;
  36. start() {
  37. // mk.ad.showNative(4);
  38. this.initNoviceUI();
  39. this.initCashOutUI();
  40. // let data = [{}, {}, {}, {}, {}, {}];
  41. // for (let i = 0; i != this.check_button.length; ++i) {
  42. // if (i < data.length) {
  43. // this.check_button[i].setShowUI(data[i]);
  44. // } else {
  45. // this.check_button[i].setShowUI(null);
  46. // }
  47. // }
  48. }
  49. private initNoviceUI() {
  50. let data = gData.gameData.playerProp.userNoviceWeFareInfo;
  51. if (data) {
  52. this.lbl_noviceTitle.string = data.name + ':';
  53. this.sp_progress.fillRange = data.progressRate;
  54. let value = data.cashmoney / 100;
  55. let v = this.multiply(value, data.progressRate);
  56. mk.console.logSingle('initNoviceUI=>', v);
  57. let str = v.toString().split('.');
  58. if (str.length >= 2 && str[1].length > 4) {
  59. this.lbl_noviceValue.string = v.toFixed(4) + '元';
  60. } else {
  61. this.lbl_noviceValue.string = v.toString() + '元';
  62. }
  63. this.intV = Math.round(value);
  64. this.lbl_tipUp.string = `进度加满后必得${this.intV}元现金`;
  65. this.lbl_cashOut.string = `满${this.intV}元提现`;
  66. if (data.progressRate >= 1) {
  67. this.btn_addProgress.setGray(true, true);
  68. } else {
  69. this.btn_addProgress.setGray(false, true);
  70. }
  71. }
  72. }
  73. private multiply(num1, num2) {
  74. const num1Changed = Number(num1.toString().replace('.', ''));
  75. const num2Changed = Number(num2.toString().replace('.', ''));
  76. const baseNum = this.digitLength(num1) + this.digitLength(num2);
  77. return num1Changed * num2Changed / Math.pow(10, baseNum);
  78. }
  79. private digitLength(num) {
  80. const eSplit = num.toString().split(/[eE]/);
  81. const len = (eSplit[0].split('.')[1] || '').length - (+(eSplit[1] || 0));
  82. return len > 0 ? len : 0;
  83. }
  84. private initCashOutUI() {
  85. if (gData.gameData.configs.CashCfg) {
  86. let arr = [];
  87. let data = gData.gameData.configs.CashCfg
  88. for (let i = 0; i != this.check_button.length; ++i) {
  89. if (i < data.length) {
  90. let isRemainTimes = this.check_button[i].setShowUI(data[i]);
  91. arr.push(data[i].money / 100);
  92. if (isRemainTimes && this.curChooseIndex == -1) {
  93. this.curChooseIndex = i;
  94. }
  95. } else {
  96. this.check_button[i].setShowUI(null);
  97. }
  98. }
  99. this.tc.setMoneyArr(arr);
  100. this.initTip();
  101. }
  102. }
  103. private initTip() {
  104. this.lbl_redMoney.string = (gData.gameData.playerProp.redMoney/100).toString();
  105. this.lbl_value.string = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  106. if (this.curChooseIndex != -1) {
  107. let data = gData.gameData.configs.CashCfg[this.curChooseIndex];
  108. let isEnough = gData.gameData.playerProp.redMoney - data.redMoney;
  109. if (isEnough >= 0) {
  110. if (this.curChooseIndex != -1) {
  111. this.isCanCash = true;
  112. this.btn_cashOut.setGray(false, true);
  113. } else {
  114. this.isCanCash = false;
  115. this.btn_cashOut.setGray(true, true);
  116. }
  117. let needV = data.money / 100;
  118. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  119. this.lbl_tip.string = `需要${needV}元,当前有` + haveV;
  120. } else {
  121. this.isCanCash = false;
  122. this.btn_cashOut.setGray(true, true);
  123. let needV = data.money / 100;
  124. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  125. this.lbl_tip.string = `需要${needV}元,当前只有` + haveV;
  126. }
  127. } else {
  128. this.isCanCash = false;
  129. this.btn_cashOut.setGray(true, true);
  130. this.lbl_tip.string = '';
  131. }
  132. }
  133. update(dt) {
  134. if (gData.walletCashOutData.init_novice) {
  135. this.initNoviceUI();
  136. gData.walletCashOutData.init_novice = false;
  137. }
  138. if (gData.walletCashOutData.adData) {
  139. gData.reward.data = gData.walletCashOutData.adData.videoRedMoney.videoRewardList;
  140. mk.ui.openPanel("module/reward/reward");
  141. gData.walletCashOutData.adData = null;
  142. }
  143. if (gData.gameData.init_wallet_redMoney) {
  144. this.initTip();
  145. gData.gameData.init_wallet_redMoney = false;
  146. }
  147. if (gData.walletCashOutData.init_cashOut) {
  148. let isRemainTimes = this.check_button[this.curChooseIndex].setRemaineTimes();
  149. if (isRemainTimes) {
  150. this.curChooseIndex = -1;
  151. this.isCanCash = false;
  152. this.btn_cashOut.setGray(true, true);
  153. this.lbl_tip.string = '';
  154. }
  155. gData.walletCashOutData.init_cashOut = false;
  156. }
  157. }
  158. private clickChooseBtn(event, customEvenData) {
  159. mk.audio.playEffect('button');
  160. let id = parseInt(customEvenData);
  161. if (id == this.curChooseIndex) {
  162. return;
  163. }
  164. if (this.check_button[id].getIsCanNotChoose()) {
  165. return;
  166. }
  167. this.check_button[id].setIsChoose(true);
  168. this.check_button[this.curChooseIndex].setIsChoose(false);
  169. this.curChooseIndex = id;
  170. this.initTip();
  171. // for (let i = 0; i != this.check_button.length; ++i) {
  172. // if (i == this.curChooseIndex) {
  173. // this.check_button[i].setIsChoose(true);
  174. // } else {
  175. // this.check_button[i].setIsChoose(false);
  176. // }
  177. // }
  178. }
  179. private clickCashOutBtn() {
  180. mk.audio.playEffect("button");
  181. console.log('=========>', this.isCanCash);
  182. if (this.isCanCash) {
  183. if (this.checkShowTip()) {
  184. mk.tip.pop('请先提现完前一档次数');
  185. } else {
  186. gData.adData.checkPopCashFull();
  187. //this.check_button[this.curChooseIndex].setIsCanNotChoose();
  188. gData.walletCashOutData.HttpCashOut2(this.curChooseIndex + 1);
  189. }
  190. }else{
  191. mk.tip.pop('红包币不足');
  192. }
  193. }
  194. private checkShowTip() {
  195. if (this.curChooseIndex >= 1) {
  196. let data = gData.gameData.configs.CashCfg[this.curChooseIndex - 1];
  197. let haveTimes = gData.gameData.playerProp.getRedMoneyCashOutTimesByIndex(data.index);
  198. if (data.cashFrequency > haveTimes) {
  199. return true;
  200. }
  201. return false;
  202. }
  203. return false;
  204. }
  205. private clickAddProgressBtn() {
  206. mk.audio.playEffect("button");
  207. mk.ad.videoAdType = VideoAdType.video_init_2;
  208. // 看广告
  209. mk.ad.watchAd((success: boolean) => {
  210. mk.console.log("watchAD:" + success);
  211. if (success) {
  212. gData.adData.watchVideo(null);
  213. gData.walletCashOutData.addProgress();
  214. }
  215. });
  216. }
  217. private clickAddCashBtn() {
  218. mk.audio.playEffect("button");
  219. mk.ad.videoAdType = VideoAdType.video_init_3;
  220. // 看广告
  221. mk.ad.watchAd((success: boolean) => {
  222. mk.console.log("watchAD:" + success);
  223. if (success) {
  224. gData.adData.watchVideo(AdFun.cashOutAddCash);
  225. // mk.ad.destroyNativeAd();
  226. }
  227. });
  228. }
  229. private clickEnoughCashOutBtn() {
  230. mk.audio.playEffect("button");
  231. let data = gData.gameData.playerProp.userNoviceWeFareInfo;
  232. if (data) {
  233. if (data.progressRate >= 1) {
  234. let v = Math.round(this.intV * 100);
  235. gData.walletCashOutData.HttpCashOut(v);
  236. } else {
  237. mk.tip.pop(`满${this.intV}元提现`);
  238. }
  239. }
  240. }
  241. private clickCloseBtn() {
  242. mk.audio.playEffect("button");
  243. }
  244. onDisable() {
  245. gData.adData.checkShowFullInter(4);
  246. }
  247. }