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