Files
18xchat/assets/Scripts/chat18x/ui/panels/PopupGirlDetailPanel.ts
T

82 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-09-09 20:57:37 +08:00
import { _decorator, Component, Node, Label } from "cc";
2025-09-09 15:33:44 +08:00
import li_BaseView from "../../../Main/Common/li_BaseView";
import { GButton } from "../../../Main/Common/GButton";
2025-09-09 16:09:10 +08:00
import Utils from "../../../Main/Common/Utils";
2025-09-09 19:21:05 +08:00
import { DetailImageItem } from "../../uiitems/DetailImageItem";
2025-09-09 20:57:37 +08:00
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";
2025-09-09 15:33:44 +08:00
const { ccclass, property } = _decorator;
2025-09-09 16:09:10 +08:00
@ccclass("PopupGirlDetailPanel")
export class PopupGirlDetailPanel extends li_BaseView {
2025-09-09 15:33:44 +08:00
private _nodeTab: any = {};
2025-09-09 20:57:37 +08:00
private priceLabel: Label;
2025-09-09 20:33:43 +08:00
private category: number;
2025-09-09 15:33:44 +08:00
private girlId: number;
2025-09-09 16:09:10 +08:00
private resId: number;
2025-09-10 10:18:27 +08:00
private type: proto.cs.EnmResType;
2025-09-09 19:21:05 +08:00
private base: DetailImageItem;
2025-09-09 15:33:44 +08:00
openUIDataCT(data) {
2025-09-09 20:33:43 +08:00
this.category = data.category;
2025-09-09 16:09:10 +08:00
this.resId = data.resId;
this.girlId = data.girlId;
2025-09-09 19:21:05 +08:00
this.base = data.base;
2025-09-10 01:00:27 +08:00
this.type = data.type;
2025-09-09 15:33:44 +08:00
}
onLoadCT() {
Utils.parseNode(this.node, this._nodeTab);
2025-09-09 20:57:37 +08:00
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 价格
this.priceLabel = this._nodeTab.Price.getComponent(Label);
2025-09-10 10:18:27 +08:00
if (this.type === proto.cs.EnmResType.ERT_Image) {
2025-09-10 01:00:27 +08:00
// 图片
this.priceLabel.string = girlData.getGrilPhotoOriginalPrice(this.category.toString(), this.girlId, this.resId).toString();
2025-09-10 10:18:27 +08:00
} else if (this.type === proto.cs.EnmResType.ERT_Video) {
2025-09-10 01:00:27 +08:00
// 视频
this.priceLabel.string = girlData.getGrilVideoOriginalPrice(this.category.toString(), this.girlId, this.resId).toString();
}
2025-09-09 15:45:50 +08:00
this.registerListener();
2025-09-09 15:33:44 +08:00
}
registerListener() {
GButton.BandClick(this._nodeTab.BuyBtn, this.buyCharacter, this);
2025-09-09 15:45:50 +08:00
GButton.BandClick(this._nodeTab.CloseBtn, this.Close, this);
}
Close() {
this.close();
2025-09-09 15:33:44 +08:00
}
2025-09-10 10:18:27 +08:00
async buyCharacter() {
2025-09-09 15:33:44 +08:00
// 购买id为girlId的女生
2025-09-09 16:09:10 +08:00
console.log(this.girlId + "---" + this.resId);
2025-09-09 19:21:05 +08:00
2025-09-10 10:18:27 +08:00
// 请求解锁
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);
// 刷新界面
2025-09-09 19:21:05 +08:00
this.base.refreshVideoBuy(true);
2025-09-10 10:18:27 +08:00
this.close();
2025-09-09 19:21:05 +08:00
}
2025-09-09 15:33:44 +08:00
}
}