WechatWithdrawalViewComp.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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-24 11:14:32
  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 = smc.game.GameModel.wechat_tx_info.money;
  61. const info = smc.game.GameModel.wechat_tx_info.handingChargeProgress;
  62. //判断替换
  63. if (info) {
  64. this.lab_cost.node.active = true;
  65. this.richText_tips.string = this.str_list[1];
  66. this.data.cost = smc.game.GameModel.wechat_tx_info.handingChargeProgress.handingCharge;
  67. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${info.handingCharge}`);
  68. this.richText_tips.string = this.richText_tips.string.replace(/\$y/g, `${info.hasNum}`);
  69. this.richText_tips.string = this.richText_tips.string.replace(/\$n/g, `${info.gapNum}`);
  70. } else {
  71. this.lab_cost.node.active = false;
  72. this.richText_tips.string = this.str_list[0];
  73. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${smc.game.GameModel.wechat_tx_info.gapGoldNum}`);
  74. }
  75. }
  76. /** 视图对象通过 ecs.Entity.remove(WechatWithdrawalViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  77. reset() {
  78. this.node.destroy();
  79. }
  80. private btn_auto() {
  81. //判断能否提现
  82. const num = smc.game.GameModel.wechat_tx_info.gapGoldNum;
  83. if (num) {
  84. oops.gui.toast(`还需凑齐${num}金块即可微信打款`);
  85. } else {
  86. //展示提现界面//向服务器申请提现信息
  87. ServerHandler.inst.getWechatTxInfo();
  88. }
  89. }
  90. private btn_back() {
  91. oops.gui.remove(UIID.WechatWithdraw);
  92. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  93. DCHandler.inst.reportData(3000801);
  94. }
  95. private btn_record() {
  96. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  97. ServerHandler.inst.getRecordList();
  98. DCHandler.inst.reportData(3000802);
  99. } else {
  100. oops.gui.open(UIID.WithdrawRecord);
  101. }
  102. }
  103. //更新滚动公告
  104. updateNotice() {
  105. this.node_notice.active = true;
  106. const num = oops.random.getRandomInt(1, 20)
  107. //随机1-500的数,有小数保留两位
  108. const randomNum = Math.random() * 500;
  109. const numStr = randomNum.toFixed(2);
  110. let name = this.getRandomChineseName();
  111. let str = "恭喜$y收集$n金砖,到账<color=#FFF07C>$m元</color>";
  112. //正则替换str里边的$y,$n,$m
  113. let str1 = str.replace(/\$y/g, name);
  114. str1 = str1.replace(/\$n/g, num + "块");
  115. str1 = str1.replace(/\$m/g, numStr);
  116. this.richText.string = str1;
  117. this.node_notice.setPosition(new Vec3(0, -40, 0));
  118. tween(this.node_notice)
  119. .to(4, { position: new Vec3(0, 40, 0) })
  120. .call(() => {
  121. this.updateNotice();
  122. })
  123. .start();
  124. }
  125. getRandomChineseName(): string {
  126. const surnames = ["王", "李", "张", "刘", "陈", "杨", "黄", "赵", "周", "吴", "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"];
  127. const characters = "的一是了不在人有我他这中大来上国个到说们时用地为子就那和要出也得于里后自以会着对生能而多小学同见天去好她所然家前开";
  128. // 随机获取姓
  129. const surname = surnames[Math.floor(Math.random() * surnames.length)];
  130. // 生成 1 到 3 个字的名字
  131. const nameLength = Math.floor(Math.random() * 3) + 1;
  132. let givenName = "";
  133. for (let i = 0; i < nameLength; i++) {
  134. givenName += characters[Math.floor(Math.random() * characters.length)];
  135. }
  136. return surname + givenName;
  137. }
  138. private updateHead() {
  139. let url = smc.account.AccountModel.headUrl;
  140. let spriteNode = this.node.getChildByPath("Scene/Center/nameNode/Mask/sp_head");
  141. if (spriteNode) {
  142. const uiTransform = spriteNode.getComponent(UITransform);
  143. uiTransform?.setContentSize(new Size(34, 34))
  144. let sprite = spriteNode.getComponent(Sprite);
  145. if (sprite) {
  146. console.log("更新头像啦")
  147. var opt: IRemoteOptions = { ext: ".png" };
  148. var onComplete = (err: Error | null, data: ImageAsset) => {
  149. const texture = new Texture2D();
  150. texture.image = data;
  151. const spriteFrame = new SpriteFrame();
  152. spriteFrame.texture = texture;
  153. sprite.spriteFrame = spriteFrame;
  154. }
  155. resLoader.loadRemote<ImageAsset>(url, opt, onComplete);
  156. }
  157. }
  158. }
  159. formatNumber(num: number) {
  160. return Math.round(num * 100) / 100;
  161. }
  162. }