Files
18xchat/assets/Scripts/chat18x/ui/panels/PopupGirlDetailPanel.ts
T
2025-09-11 00:03:22 +08:00

112 lines
3.7 KiB
TypeScript

import { _decorator, Component, Node, Label } from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView";
import { GButton } from "../../../Main/Common/GButton";
import Utils from "../../../Main/Common/Utils";
import { DetailImageItem } from "../../uiitems/DetailImageItem";
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";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { ImagePopup } from "../components/ImagePopup";
import { TipsPanel } from "./TipsPanel";
const { ccclass, property } = _decorator;
@ccclass("PopupGirlDetailPanel")
export class PopupGirlDetailPanel extends li_BaseView {
private _nodeTab: any = {};
private priceLabel: Label;
private category: number;
private girlId: number;
private resId: number;
private type: proto.cs.EnmResType;
private base: DetailImageItem | ImagePopup;
private desc: Label;
openUIDataCT(data) {
this.category = data.category;
this.resId = data.resId;
this.girlId = data.girlId;
this.base = data.base;
this.type = data.type;
}
onLoadCT() {
Utils.parseNode(this.node, this._nodeTab);
this.desc = this._nodeTab.content.getComponent(Label);
let descText = LanguageUtils.getText("popupgirldetailpanel.content");
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 价格
this.priceLabel = this._nodeTab.Price.getComponent(Label);
if (this.type === proto.cs.EnmResType.ERT_Image) {
// 图片
this.priceLabel.string = girlData
.getGrilPhotoOriginalPrice(
this.category.toString(),
this.girlId,
this.resId
)
.toString();
} else if (this.type === proto.cs.EnmResType.ERT_Video) {
// 视频
this.priceLabel.string = girlData
.getGrilVideoOriginalPrice(
this.category.toString(),
this.girlId,
this.resId
)
.toString();
}
this.desc.string = descText.replace("{price}", this.priceLabel.string);
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 + "---" + this.resId);
// 请求解锁
const reqData = {
girlId: this.girlId,
resId: this.resId,
type: this.type,
};
let res = await GirlService.I.reqUnlockGirlRes(reqData);
console.log("请求解锁资源响应数据:", res);
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
const resData = res.data;
// 保存数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
if (this.type === proto.cs.EnmResType.ERT_Image) {
// 图片
girlData.unlockImage(this.category.toString(), this.girlId, this.resId);
} else if (this.type === proto.cs.EnmResType.ERT_Video) {
// 视频
girlData.unlockVideo(this.category.toString(), this.girlId, this.resId);
}
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
walletData.balance = Number(resData.balance);
walletData.vipExpire = Number(resData.vipExpire);
// 刷新界面
if (this.base instanceof DetailImageItem) {
this.base.refreshVideoBuy(true);
} else {
this.base.refreshSelf();
}
this.close();
} else {
TipsPanel.show("Insufficient balance, need to purchase");
}
}
}