WechatWithdrawalViewComp.ts 6.9 KB

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