WalletCashOut.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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(true);
  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(isInit = false) {
  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. if(!isInit)
  64. {
  65. cc.tween(this.lbl_noviceValue.node).to(0.1, {scale: 1.2}).to(0.1, {scale: 1}).start();
  66. }
  67. this.intV = Math.round(value);
  68. this.lbl_tipUp.string = `进度加满后必得${this.intV}元现金`;
  69. this.lbl_cashOut.string = `满${this.intV}元提现`;
  70. if (data.progressRate >= 1) {
  71. this.btn_addProgress.setGray(true, true);
  72. } else {
  73. this.btn_addProgress.setGray(false, true);
  74. }
  75. }
  76. }
  77. private multiply(num1, num2) {
  78. const num1Changed = Number(num1.toString().replace('.', ''));
  79. const num2Changed = Number(num2.toString().replace('.', ''));
  80. const baseNum = this.digitLength(num1) + this.digitLength(num2);
  81. return num1Changed * num2Changed / Math.pow(10, baseNum);
  82. }
  83. private digitLength(num) {
  84. const eSplit = num.toString().split(/[eE]/);
  85. const len = (eSplit[0].split('.')[1] || '').length - (+(eSplit[1] || 0));
  86. return len > 0 ? len : 0;
  87. }
  88. private initCashOutUI() {
  89. if (gData.gameData.configs.CashCfg) {
  90. let arr = [];
  91. let data = gData.gameData.configs.CashCfg
  92. for (let i = 0; i != this.check_button.length; ++i) {
  93. if (i < data.length) {
  94. let isRemainTimes = this.check_button[i].setShowUI(data[i]);
  95. arr.push(data[i].money / 100);
  96. if (isRemainTimes && this.curChooseIndex == -1) {
  97. this.curChooseIndex = i;
  98. }
  99. } else {
  100. this.check_button[i].setShowUI(null);
  101. }
  102. }
  103. this.tc.setMoneyArr(arr);
  104. this.initTip();
  105. }
  106. }
  107. private initTip() {
  108. this.lbl_redMoney.string = (gData.gameData.playerProp.redMoney/100).toString();
  109. this.lbl_value.string = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3);
  110. if (this.curChooseIndex != -1) {
  111. let data = gData.gameData.configs.CashCfg[this.curChooseIndex];
  112. let isEnough = gData.gameData.playerProp.redMoney - data.redMoney;
  113. if (isEnough >= 0) {
  114. if (this.curChooseIndex != -1) {
  115. this.isCanCash = true;
  116. this.btn_cashOut.setGray(false, true);
  117. } else {
  118. this.isCanCash = false;
  119. this.btn_cashOut.setGray(true, true);
  120. }
  121. let needV = data.money / 100;
  122. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  123. this.lbl_tip.string = `需要${needV}元,当前有` + haveV;
  124. } else {
  125. this.isCanCash = false;
  126. this.btn_cashOut.setGray(true, true);
  127. let needV = data.money / 100;
  128. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  129. this.lbl_tip.string = `需要${needV}元,当前只有` + haveV;
  130. }
  131. } else {
  132. this.isCanCash = false;
  133. this.btn_cashOut.setGray(true, true);
  134. this.lbl_tip.string = '';
  135. }
  136. }
  137. update(dt) {
  138. if (gData.walletCashOutData.init_novice) {
  139. this.initNoviceUI();
  140. gData.walletCashOutData.init_novice = false;
  141. }
  142. if (gData.walletCashOutData.adData) {
  143. gData.reward.data = gData.walletCashOutData.adData.videoRedMoney.videoRewardList;
  144. mk.ui.openPanel("module/reward/reward");
  145. gData.walletCashOutData.adData = null;
  146. }
  147. if (gData.gameData.init_wallet_redMoney) {
  148. this.initTip();
  149. gData.gameData.init_wallet_redMoney = false;
  150. }
  151. if (gData.walletCashOutData.init_cashOut) {
  152. let isRemainTimes = this.check_button[this.curChooseIndex].setRemaineTimes();
  153. if (isRemainTimes) {
  154. this.curChooseIndex = -1;
  155. this.isCanCash = false;
  156. this.btn_cashOut.setGray(true, true);
  157. this.lbl_tip.string = '';
  158. }
  159. gData.walletCashOutData.init_cashOut = false;
  160. }
  161. }
  162. private clickChooseBtn(event, customEvenData) {
  163. mk.audio.playEffect('button');
  164. let id = parseInt(customEvenData);
  165. if (id == this.curChooseIndex) {
  166. return;
  167. }
  168. if (this.check_button[id].getIsCanNotChoose()) {
  169. return;
  170. }
  171. this.check_button[id].setIsChoose(true);
  172. this.check_button[this.curChooseIndex].setIsChoose(false);
  173. this.curChooseIndex = id;
  174. this.initTip();
  175. // for (let i = 0; i != this.check_button.length; ++i) {
  176. // if (i == this.curChooseIndex) {
  177. // this.check_button[i].setIsChoose(true);
  178. // } else {
  179. // this.check_button[i].setIsChoose(false);
  180. // }
  181. // }
  182. }
  183. private clickCashOutBtn() {
  184. mk.audio.playEffect("button");
  185. console.log('=========>', this.isCanCash);
  186. if (this.isCanCash) {
  187. if (this.checkShowTip()) {
  188. mk.tip.pop('请先提现完前一档次数');
  189. } else {
  190. gData.adData.checkPopCashFull();
  191. //this.check_button[this.curChooseIndex].setIsCanNotChoose();
  192. gData.walletCashOutData.HttpCashOut2(this.curChooseIndex + 1);
  193. }
  194. }else{
  195. mk.tip.pop('红包币不足');
  196. }
  197. }
  198. private checkShowTip() {
  199. if (this.curChooseIndex >= 1) {
  200. let data = gData.gameData.configs.CashCfg[this.curChooseIndex - 1];
  201. let haveTimes = gData.gameData.playerProp.getRedMoneyCashOutTimesByIndex(data.index);
  202. if (data.cashFrequency > haveTimes) {
  203. return true;
  204. }
  205. return false;
  206. }
  207. return false;
  208. }
  209. private clickAddProgressBtn() {
  210. mk.audio.playEffect("button");
  211. mk.ad.videoAdType = VideoAdType.video_init_2;
  212. // 看广告
  213. mk.ad.watchAd((success: boolean) => {
  214. mk.console.log("watchAD:" + success);
  215. if (success) {
  216. gData.adData.watchVideo(null);
  217. gData.walletCashOutData.addProgress();
  218. }
  219. });
  220. }
  221. private clickAddCashBtn() {
  222. mk.audio.playEffect("button");
  223. mk.ad.videoAdType = VideoAdType.video_init_3;
  224. // 看广告
  225. mk.ad.watchAd((success: boolean) => {
  226. mk.console.log("watchAD:" + success);
  227. if (success) {
  228. gData.adData.watchVideo(AdFun.cashOutAddCash);
  229. // mk.ad.destroyNativeAd();
  230. }
  231. });
  232. }
  233. private clickEnoughCashOutBtn() {
  234. mk.audio.playEffect("button");
  235. let data = gData.gameData.playerProp.userNoviceWeFareInfo;
  236. if (data) {
  237. if (data.progressRate >= 1) {
  238. let v = Math.round(this.intV * 100);
  239. gData.walletCashOutData.HttpCashOut(v);
  240. } else {
  241. mk.tip.pop(`满${this.intV}元提现`);
  242. }
  243. }
  244. }
  245. private clickCloseBtn() {
  246. mk.audio.playEffect("button");
  247. }
  248. onDisable() {
  249. gData.adData.checkShowFullInter(4);
  250. }
  251. }