Files
18xchat/assets/Scripts/chat18x/ui/panels/GirlListPopupPanel.ts
T
2025-09-10 10:18:34 +08:00

65 lines
2.3 KiB
TypeScript

import { _decorator, Button, Component, Node, Label } from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView";
import Utils from "../../../Main/Common/Utils";
import { GButton } from "../../../Main/Common/GButton";
import { PopupGirlDetailPanel } from "./PopupGirlDetailPanel";
import { GirlListItem } from "../../uiitems/GirlListItem";
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
import { DataManager, DataId } from "../../data/DataManager";
import { GirlData } from "../../data/GirlData";
import { WalletData } from "../../data/WalletData";
import proto from "db://assets/Scripts/proto/proto.pb.js";
const { ccclass, property } = _decorator;
@ccclass("GirlListPopupPanel")
export class GirlListPopupPanel extends li_BaseView {
private _nodeTab: any = {};
private priceLabel: Label;
private category: number;
private girlId: number;
base: GirlListItem;
openUIDataCT(data) {
this.category = data.category;
this.girlId = data.id;
this.base = data.base;
}
onLoadCT() {
Utils.parseNode(this.node, this._nodeTab);
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 价格
this.priceLabel = this._nodeTab.Price.getComponent(Label);
this.priceLabel.string = girlData.getGrilOriginalPrice(this.category.toString(), this.girlId).toString();
this.registerListener();
}
registerListener() {
GButton.BandClick(this._nodeTab.BuyBtn, this.buyCharacter, this);
GButton.BandClick(this._nodeTab.CloseBtn, this.Close, this);
}
Close() {
this.close();
}
async buyCharacter() {
// 购买id为girlId的女生
console.log(this.girlId);
// 请求解锁
const reqData = {
id: this.girlId,
};
let res = await GirlService.I.reqUnlockGirl(reqData);
console.log("请求解锁技师响应数据:", res);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
const resData = res.data;
// 保存数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
girlData.setIsRelease(this.category.toString(), this.girlId, true);
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
walletData.balance = Number(resData.balance);
walletData.vipExpire = Number(resData.vipExpire);
// 刷新界面
this.base.refreshBuy(true);
this.close();
}
}
}