WalletCashOut.ts 11 KB

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