WalletCashOut.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import SetGray from "../../component/SetGray";
  2. import TweenCast from "../../component/tween/TweenCast";
  3. import { AdFun } from "../../data/AdData";
  4. import { DataEventId, 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. let cashTimes = gData.gameData.getProp(GameProp.cashTimes);
  95. if(!cashTimes){
  96. cashTimes = 0;
  97. }
  98. this.node_addCash.active = cashTimes >= parseInt(gData.gameData.configs.ServerConfig.CashIncrease);
  99. }else{
  100. this.node_addCash.active = false;
  101. }
  102. if (gData.gameData.configs.CashCfg) {
  103. let arr = [];
  104. let data = gData.gameData.configs.CashCfg
  105. for (let i = 0; i != this.check_button.length; ++i) {
  106. if (i < data.length) {
  107. let isRemainTimes = this.check_button[i].setShowUI(data[i]);
  108. arr.push(data[i].money / 100);
  109. if (isRemainTimes && this.curChooseIndex == -1) {
  110. this.curChooseIndex = i;
  111. }
  112. } else {
  113. this.check_button[i].setShowUI(null);
  114. }
  115. }
  116. this.tc.setMoneyArr(arr);
  117. this.initTip();
  118. }
  119. }
  120. private initTip() {
  121. this.lbl_redMoney.string = (gData.gameData.playerProp.redMoney/100).toString();
  122. this.lbl_value.string = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3);
  123. if (this.curChooseIndex != -1) {
  124. let data = gData.gameData.configs.CashCfg[this.curChooseIndex];
  125. let isEnough = gData.gameData.playerProp.redMoney - data.redMoney;
  126. if (isEnough >= 0) {
  127. if (this.curChooseIndex != -1) {
  128. this.isCanCash = true;
  129. this.btn_cashOut.setGray(false, true);
  130. } else {
  131. this.isCanCash = false;
  132. this.btn_cashOut.setGray(true, true);
  133. }
  134. let needV = data.money / 100;
  135. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  136. this.lbl_tip.string = `需要${needV}元,当前有` + haveV;
  137. } else {
  138. this.isCanCash = false;
  139. this.btn_cashOut.setGray(true, true);
  140. let needV = data.money / 100;
  141. let haveV = (gData.gameData.playerProp.redMoney / 1000000).toFixed(3) + '元';
  142. this.lbl_tip.string = `需要${needV}元,当前只有` + haveV;
  143. }
  144. } else {
  145. this.isCanCash = false;
  146. this.btn_cashOut.setGray(true, true);
  147. this.lbl_tip.string = '';
  148. }
  149. }
  150. update(dt) {
  151. if (gData.walletCashOutData.init_novice) {
  152. this.initNoviceUI();
  153. gData.walletCashOutData.init_novice = false;
  154. }
  155. if (gData.walletCashOutData.adData) {
  156. gData.reward.data = gData.walletCashOutData.adData.videoRedMoney.videoRewardList;
  157. mk.ui.openPanel("module/reward/reward");
  158. gData.walletCashOutData.adData = null;
  159. }
  160. if (gData.gameData.init_wallet_redMoney) {
  161. this.initTip();
  162. gData.gameData.init_wallet_redMoney = false;
  163. }
  164. if (gData.walletCashOutData.init_cashOut) {
  165. let isRemainTimes = this.check_button[this.curChooseIndex].setRemaineTimes();
  166. if (isRemainTimes) {
  167. this.curChooseIndex = -1;
  168. this.isCanCash = false;
  169. this.btn_cashOut.setGray(true, true);
  170. this.lbl_tip.string = '';
  171. }
  172. gData.walletCashOutData.init_cashOut = false;
  173. }
  174. }
  175. private clickChooseBtn(event, customEvenData) {
  176. mk.audio.playEffect('button');
  177. let id = parseInt(customEvenData);
  178. if (id == this.curChooseIndex) {
  179. return;
  180. }
  181. if (this.check_button[id].getIsCanNotChoose()) {
  182. return;
  183. }
  184. this.check_button[id].setIsChoose(true);
  185. this.check_button[this.curChooseIndex].setIsChoose(false);
  186. this.curChooseIndex = id;
  187. this.initTip();
  188. // for (let i = 0; i != this.check_button.length; ++i) {
  189. // if (i == this.curChooseIndex) {
  190. // this.check_button[i].setIsChoose(true);
  191. // } else {
  192. // this.check_button[i].setIsChoose(false);
  193. // }
  194. // }
  195. }
  196. private clickCashOutBtn() {
  197. mk.audio.playEffect("button");
  198. if (this.isCanCash) {
  199. // if (this.checkShowTip()) {
  200. // mk.tip.pop('请先提现完前一档次数');
  201. // } else
  202. {
  203. if (cc.sys.isNative) {
  204. if (!gData.loginData.isAuth) {
  205. // JsbSystem.WxAuth();
  206. gData.gameData.authUIType = 0;
  207. mk.ui.openPanel('module/authUI/authUI');
  208. return;
  209. }
  210. }
  211. gData.adData.checkShowFullInter(1);
  212. //this.check_button[this.curChooseIndex].setIsCanNotChoose();
  213. gData.walletCashOutData.HttpCashOut2(this.curChooseIndex + 1);
  214. }
  215. }else{
  216. mk.tip.pop('收获农作物可获得红包币');
  217. }
  218. }
  219. private checkShowTip() {
  220. if (this.curChooseIndex >= 1) {
  221. let data = gData.gameData.configs.CashCfg[this.curChooseIndex - 1];
  222. let haveTimes = gData.gameData.playerProp.getRedMoneyCashOutTimesByIndex(data.index);
  223. if (data.cashFrequency > haveTimes) {
  224. return true;
  225. }
  226. return false;
  227. }
  228. return false;
  229. }
  230. private clickAddProgressBtn() {
  231. mk.audio.playEffect("button");
  232. mk.ad.videoAdType = VideoAdType.video_init_2;
  233. // 看广告
  234. mk.ad.watchAd((success: boolean) => {
  235. mk.console.log("watchAD:" + success);
  236. if (success) {
  237. gData.adData.watchVideo(null);
  238. gData.walletCashOutData.addProgress();
  239. }
  240. });
  241. }
  242. private clickAddCashBtn() {
  243. mk.audio.playEffect("button");
  244. mk.ad.videoAdType = VideoAdType.video_init_3;
  245. // 看广告
  246. mk.ad.watchAd((success: boolean) => {
  247. mk.console.log("watchAD:" + success);
  248. if (success) {
  249. gData.adData.watchVideo(AdFun.cashOutAddCash);
  250. // mk.ad.destroyNativeAd();
  251. }
  252. });
  253. }
  254. private clickEnoughCashOutBtn() {
  255. mk.audio.playEffect("button");
  256. let data = gData.gameData.playerProp.userNoviceWeFareInfo;
  257. if (data) {
  258. if (data.progressRate >= 1) {
  259. let v = Math.round(this.intV * 100);
  260. gData.walletCashOutData.HttpCashOut(v);
  261. } else {
  262. mk.tip.pop(`满${this.intV}元提现`);
  263. }
  264. }
  265. }
  266. private clickCloseBtn() {
  267. mk.audio.playEffect("button");
  268. }
  269. onDisable() {
  270. let pop = gData.adData.checkShowFullInter(4);
  271. if(pop){
  272. gData.moreGame.openType = 1;
  273. mk.data.sendDataEvent(DataEventId.htRedBag_scene, "关闭提现界面");
  274. }
  275. }
  276. }