import { _decorator, Component, Node, Prefab, instantiate, EventHandler, Label, Button, Sprite, SpriteFrame, Texture2D, ImageAsset, color } from 'cc'; import { ADHelper } from '../ad/ADHelper'; import { DataSystem } from '../core/data/DataSystem'; import { Http } from '../core/net/Http'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { WindowSystem } from '../core/ui/window/WindowSystem'; import { ISJSB } from '../data/jsb/platform'; import { UserData } from '../data/UserData'; import { ReportThinking } from '../ReportThinking'; import { WithdrawalItem } from './WithdrawalItem'; const { ccclass, property, requireComponent } = _decorator; @ccclass('MyWalletUI') @requireComponent(ResourceLoader) export class MyWalletUI extends Component { @property({ tooltip: "头像", type: Sprite }) private headIcon: Sprite; @property({ tooltip: "提现列表父级", type: Node }) private itemParent: Node; @property({ tooltip: "选中提现档次变动回调", type: EventHandler }) private chooseChangeBack: EventHandler; @property({ tooltip: "提现提示文本", type: Label }) private withdrawalTipTxt: Label; @property({ tooltip: "提现按钮", type: Node }) private withdrawlBtn: Node; @property({ tooltip: "总资产文本", type: Label }) private assetsTxt: Label; @property({ tooltip: "广告", type: ADHelper }) private adNode: ADHelper; private withdrawalID = 0;//提现id private isWithdrawal = false;//是否正在提现 private itemArray: Node[] = [];//提现档次item private itemData: any[]; private chooseID: number = -1;//选中提现档次 private withdrawalType: number = -1;//选中提现类型 start() { this.initUI(); } private async initUI() { let avator = DataSystem.getData(UserData).avator; if (ISJSB() && avator) { let img = await await this.getComponent(ResourceLoader).loadRemote(avator, { ext: ".png" }); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.headIcon.spriteFrame = spriteFrame; } this.initBonus(); //获取提现列表 let result = await this.getComponent(Http).send("/api/user/withdrawList"); if (result && result.code == 0) { this.initItemList(result.data); } } private chooseChange(chooseID: number, message: string, withdrawalType: number, withdrawalID: number) { // if (chooseID == this.chooseID) { // return; // } this.chooseID > -1 && (this.itemArray[this.chooseID].getComponent(WithdrawalItem).chooseImg.active = false); this.chooseID = chooseID; this.withdrawalID = withdrawalID; this.withdrawalType = withdrawalType; this.itemArray[this.chooseID].getComponent(WithdrawalItem).chooseImg.active = true; if (message) { this.withdrawalTipTxt.color = color(214, 51, 51, 255); this.withdrawalTipTxt.string = message; this.withdrawlBtn.getComponent(Button).interactable = false; this.withdrawlBtn.getComponent(Sprite).grayscale = true; } else { this.withdrawalTipTxt.string = "当前可提现"; this.withdrawalTipTxt.color = color(71, 148, 40, 255); this.withdrawlBtn.getComponent(Button).interactable = true; this.withdrawlBtn.getComponent(Sprite).grayscale = false; } } public async withdrawal() { if (this.isWithdrawal) { return; } this.isWithdrawal = true; let result = await this.getComponent(Http).send("/api/user/withdraw", { id: this.withdrawalID, type: this.withdrawalType }); if (result && result.data) {//提现成功 WindowSystem.showTips(result.data.message); let userData = DataSystem.getData(UserData); ReportThinking.currency_decrease('bonus', userData.bonus, result.data.bonus, userData.bonus - result.data.bonus, 'withdraw'); result.data.bonus && (DataSystem.getData(UserData).bonus -= result.data.bonus); result.data.bonus && this.initBonus(); // result.data.list && this.initItemList(result.data.list); let _result = await this.getComponent(Http).send("/api/user/withdrawList"); if (_result && _result.code == 0) { this.initItemList(_result.data); } (Math.random() * 100) <= 35 && this.adNode.show(); } this.isWithdrawal = false; } //更新item public async initItemList(list: Array) { //#region 只显示一个0.3 let isDelete = false; for (let k = 0; k < list.length; k++) { if (list[k].type == WithDrawType.Frist) { isDelete = true; break; } } if (isDelete) { for (let k = 0; k < list.length; k++) { if (list[k].type != WithDrawType.Frist && list[k].money == 0.3) { list.splice(k, 1); break; } } } this.itemData = list; //#endregion let indexMax = 0; for (let i = 0; i < list.length; i++) { if (i > 7) { break;//最多显示八个档次 } indexMax = i; if (i >= this.itemArray.length) { let prefab = await this.node.getComponent(ResourceLoader).load("prefabs/ui/myWallet/withdrawalItem", Prefab); let item = instantiate(prefab); item.parent = this.itemParent; this.itemArray.push(item); item.getComponent(WithdrawalItem).chooseChangeBack = this.chooseChangeBack; item.getComponent(WithdrawalItem).setData(list[i], i); } else { this.itemArray[i].getComponent(WithdrawalItem).setData(list[i], i); } } if ((indexMax + 1) < this.itemArray.length) {//删除多余的item for (let j = 0; j < this.itemArray.length - indexMax - 1; j++) { this.itemArray[indexMax + 1].destroy(); this.itemArray.splice(indexMax + 1, 1); } } let index = this.chooseID == -1 ? 0 : this.chooseID; index = (index + 1) > this.itemArray.length ? (this.itemArray.length - 1) : index; this.chooseChange(index, this.itemData[index].message, this.itemData[index].type, this.itemData[index].id); } //更新红包币显示 public initBonus() { let bonus = DataSystem.getData(UserData).bonus; if (bonus >= 1000) { this.assetsTxt.string = bonus + "≈" + (Math.round(bonus / 10000 * 100) / 100) + "元"; } else { this.assetsTxt.string = bonus + "≈" + (bonus / 10000) + "元"; } } } export enum WithDrawType { /** * 裂变提现 */ Share = 1, /** * 看视频提现 */ Video, /** * 红包兑换提现 */ Bonus, /** * 首次提现 */ Frist, /** * 彩票提现 */ Lottery }