WalletCashOut.ts 11 KB

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