WechatWithdrawalViewComp.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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-15 14:47:44
  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. this.addEvent();
  51. }
  52. addEvent() {
  53. oops.message.on(GameEvent.openRecordView, this.openRecordView, this);
  54. }
  55. //设置数据
  56. setData() {
  57. this.data.nickName = smc.account.AccountModel.accountName;
  58. this.data.headUrl = smc.account.AccountModel.headUrl;
  59. this.data.money = smc.game.GameModel.wechat_tx_info.money;
  60. //当前关卡
  61. const curLevel = smc.account.AccountModel.curLevel;
  62. console.log(">>>>>>>>>>>>>>", curLevel)
  63. this.lab_cost.node.active = curLevel == 12;
  64. //判断替换
  65. this.richText_tips.string = this.str_list[curLevel == 12 ? 1 : 0];
  66. const info = smc.game.GameModel.wechat_tx_info.handingChargeProgress;
  67. if (curLevel > 12) {
  68. //info.handingCharge替换$m,info.hasNum替换$y,info.gapNum替换$n
  69. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${info.handingCharge}`);
  70. this.richText_tips.string = this.richText_tips.string.replace(/\$y/g, `${info.hasNum}`);
  71. this.richText_tips.string = this.richText_tips.string.replace(/\$n/g, `${info.gapNum}`);
  72. } else {
  73. this.richText_tips.string = this.richText_tips.string.replace(/\$m/g, `${smc.game.GameModel.wechat_tx_info.gapGoldNum}`);
  74. }
  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. if (num) {
  85. oops.gui.toast(`还需凑齐${num}金块即可微信打款`);
  86. } else {
  87. //展示提现界面//向服务器申请提现信息
  88. ServerHandler.inst.getWechatTxInfo();
  89. }
  90. }
  91. private btn_back() {
  92. oops.gui.remove(UIID.WechatWithdraw);
  93. }
  94. private btn_record() {
  95. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  96. ServerHandler.inst.getRecordList();
  97. } else {
  98. oops.gui.open(UIID.WithdrawRecord);
  99. }
  100. }
  101. private openRecordView() {
  102. console.log("打开提现列表");
  103. oops.gui.open(UIID.WithdrawRecord);
  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 = "恭喜<color=#bcdc36>$y</color>收集<color=#bcdc36>$n</color>金砖,到账<color=#bcdc36>$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(30, 30))
  146. let sprite = spriteNode.getComponent(Sprite);
  147. if (sprite) {
  148. console.log("更新头像啦")
  149. var opt: IRemoteOptions = { ext: ".png" };
  150. var onComplete = (err: Error | null, data: ImageAsset) => {
  151. const texture = new Texture2D();
  152. texture.image = data;
  153. const spriteFrame = new SpriteFrame();
  154. spriteFrame.texture = texture;
  155. sprite.spriteFrame = spriteFrame;
  156. }
  157. resLoader.loadRemote<ImageAsset>(url, opt, onComplete);
  158. }
  159. }
  160. }
  161. }