WechatWithdrawalViewComp.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-20 17:00:12
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-23 15:54:40
  6. * @Description: 微信提现页面
  7. */
  8. import { _decorator, ImageAsset, Label, Node, RichText, Size, Sprite, SpriteFrame, Texture2D, tween, UITransform, Vec3 } from "cc";
  9. import { IRemoteOptions, resLoader } from "db://oops-framework/core/common/loader/ResLoader";
  10. import { oops } from "db://oops-framework/core/Oops";
  11. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  12. import { ecs } from "db://oops-framework/libs/ecs/ECS";
  13. import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp";
  14. import { GameEvent } from "../common/config/GameEvent";
  15. import { UIID } from "../common/config/GameUIConfig";
  16. import { ServerHandler } from "../common/manager/ServerHandler";
  17. import { smc } from "../common/SingletonModuleComp";
  18. import { Format } from "../utils/Format";
  19. import { DCHandler } from "../common/manager/DCHandler";
  20. const { ccclass, property } = _decorator;
  21. /** 视图层对象 */
  22. @ccclass('WechatWithdrawalViewComp')
  23. @ecs.register('WechatWithdrawalView', false)
  24. export class WechatWithdrawalViewComp extends CCVMParentComp {
  25. data: any = {
  26. nickName: "",
  27. money: 0,
  28. channel: "微信零钱",
  29. headUrl: "",
  30. cost: 0,
  31. }
  32. str_list: string[] = [
  33. `再收集<color =#C13935>$m块</color>金砖,<color =#C13935>现金</color>全部自动到账`,
  34. `微信大额提现需要<color =#C13935>$m元</color>手续费
  35. 已赚$y元,仅差<color =#C13935>$n元</color>`
  36. ]
  37. @property(RichText)
  38. private richText: RichText = null!;
  39. @property(Node)
  40. private node_notice: Node = null!;
  41. @property(Label)
  42. private lab_cost: Label = null!; //手续费
  43. @property(RichText)
  44. private richText_tips: RichText = null!; //提示
  45. /** 视图层逻辑代码分离演示 */
  46. start() {
  47. // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
  48. DCHandler.inst.reportData(3000800);
  49. this.setButton();
  50. this.updateNotice();
  51. this.setData();
  52. this.updateHead();
  53. }
  54. //设置数据
  55. setData() {
  56. const curLevel = smc.account.AccountModel.curLevel;
  57. this.data.nickName = smc.account.AccountModel.accountName;
  58. this.data.headUrl = smc.account.AccountModel.headUrl;
  59. this.richText_tips.string = this.str_list[curLevel > 12 ? 1 : 0];
  60. this.data.money = Format.formatWxCoin(smc.game.GameModel.wechat_tx_info.money);
  61. const info = smc.game.GameModel.wechat_tx_info.handingChargeProgress;
  62. //当前关卡
  63. console.log(">>>>>>>>>>>>>>", curLevel)
  64. this.lab_cost.node.active = curLevel > 12;
  65. //判断替换
  66. if (curLevel > 12 && info) {
  67. this.data.cost = smc.game.GameModel.wechat_tx_info.handingChargeProgress.handingCharge;
  68. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${info.handingCharge}`);
  69. this.richText_tips.string = this.richText_tips.string.replace(/\$y/g, `${info.hasNum}`);
  70. this.richText_tips.string = this.richText_tips.string.replace(/\$n/g, `${info.gapNum}`);
  71. } else {
  72. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${smc.game.GameModel.wechat_tx_info.gapGoldNum}`);
  73. }
  74. }
  75. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  76. reset() {
  77. this.node.destroy();
  78. }
  79. private btn_auto() {
  80. //判断能否提现
  81. const num = smc.game.GameModel.wechat_tx_info.gapGoldNum;
  82. if (num) {
  83. oops.gui.toast(`还需凑齐${num}金块即可微信打款`);
  84. } else {
  85. //展示提现界面//向服务器申请提现信息
  86. ServerHandler.inst.getWechatTxInfo();
  87. }
  88. }
  89. private btn_back() {
  90. oops.gui.remove(UIID.WechatWithdraw);
  91. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  92. DCHandler.inst.reportData(3000801);
  93. }
  94. private btn_record() {
  95. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  96. ServerHandler.inst.getRecordList();
  97. DCHandler.inst.reportData(3000802);
  98. } else {
  99. oops.gui.open(UIID.WithdrawRecord);
  100. }
  101. }
  102. //更新滚动公告
  103. updateNotice() {
  104. this.node_notice.active = true;
  105. const num = oops.random.getRandomInt(1, 20)
  106. //随机1-500的数,有小数保留两位
  107. const randomNum = Math.random() * 500;
  108. const numStr = randomNum.toFixed(2);
  109. let name = this.getRandomChineseName();
  110. let str = "恭喜$y收集$n金砖,到账<color=#FFF07C>$m元</color>";
  111. //正则替换str里边的$y,$n,$m
  112. let str1 = str.replace(/\$y/g, name);
  113. str1 = str1.replace(/\$n/g, num + "块");
  114. str1 = str1.replace(/\$m/g, numStr);
  115. this.richText.string = str1;
  116. this.node_notice.setPosition(new Vec3(0, -40, 0));
  117. tween(this.node_notice)
  118. .to(4, { position: new Vec3(0, 40, 0) })
  119. .call(() => {
  120. this.updateNotice();
  121. })
  122. .start();
  123. }
  124. getRandomChineseName(): string {
  125. const surnames = ["王", "李", "张", "刘", "陈", "杨", "黄", "赵", "周", "吴", "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"];
  126. const characters = "的一是了不在人有我他这中大来上国个到说们时用地为子就那和要出也得于里后自以会着对生能而多小学同见天去好她所然家前开";
  127. // 随机获取姓
  128. const surname = surnames[Math.floor(Math.random() * surnames.length)];
  129. // 生成 1 到 3 个字的名字
  130. const nameLength = Math.floor(Math.random() * 3) + 1;
  131. let givenName = "";
  132. for (let i = 0; i < nameLength; i++) {
  133. givenName += characters[Math.floor(Math.random() * characters.length)];
  134. }
  135. return surname + givenName;
  136. }
  137. private updateHead() {
  138. let url = smc.account.AccountModel.headUrl;
  139. let spriteNode = this.node.getChildByPath("Scene/Center/nameNode/Mask/sp_head");
  140. if (spriteNode) {
  141. const uiTransform = spriteNode.getComponent(UITransform);
  142. uiTransform?.setContentSize(new Size(34, 34))
  143. let sprite = spriteNode.getComponent(Sprite);
  144. if (sprite) {
  145. console.log("更新头像啦")
  146. var opt: IRemoteOptions = { ext: ".png" };
  147. var onComplete = (err: Error | null, data: ImageAsset) => {
  148. const texture = new Texture2D();
  149. texture.image = data;
  150. const spriteFrame = new SpriteFrame();
  151. spriteFrame.texture = texture;
  152. sprite.spriteFrame = spriteFrame;
  153. }
  154. resLoader.loadRemote<ImageAsset>(url, opt, onComplete);
  155. }
  156. }
  157. }
  158. formatNumber(num: number) {
  159. return Math.round(num * 100) / 100;
  160. }
  161. }