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

123 lines
3.4 KiB
TypeScript
Raw Normal View History

2025-08-27 16:12:19 +08:00
import {
_decorator,
Component,
Label,
Node,
Sprite,
tween,
UIOpacity,
} from "cc";
2025-09-10 17:37:24 +08:00
import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService";
import { DataManager, DataId } from "../../data/DataManager";
import { WalletData } from "../../data/WalletData";
import { ShopData } from "../../data/ShopData";
import { GirlData } from "../../data/GirlData";
2025-09-20 13:47:44 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import { ConfigId, ConfigManager } from "../../manager/ConfigManager";
import { PurchaseConfig } from "../../config/PurchaseConfig";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
2025-09-21 20:18:24 +08:00
import { logger } from "db://assets/Scripts/Main/Common/Logger";
2025-10-14 11:00:49 +08:00
import li_BaseView from "../../../Main/Common/li_BaseView";
import { TipsPanel } from "./TipsPanel";
import { NavigationManager } from "../../manager/NavigationManager";
2025-09-21 20:18:24 +08:00
2025-08-25 20:15:42 +08:00
const { ccclass, property } = _decorator;
2025-10-14 11:00:49 +08:00
@ccclass("PayToTalkPanel")
export class PayToTalkPanel extends li_BaseView {
2025-08-27 16:12:19 +08:00
base: UIOpacity;
2025-08-25 20:15:42 +08:00
2025-10-14 11:00:49 +08:00
categoryId: string;
girlId: number;
openUIDataCT(data) {
this.categoryId = data.categoryId;
this.girlId = data.girlId;
}
onLoadCT(): void {
2025-08-27 16:12:19 +08:00
this.base = this.getComponent(UIOpacity);
2025-10-14 11:00:49 +08:00
this.show();
2025-08-27 16:12:19 +08:00
}
2025-08-25 20:15:42 +08:00
2025-10-14 11:00:49 +08:00
show() {
if (!this.base) this.base = this.getComponent(UIOpacity);
2025-08-27 16:12:19 +08:00
this.node.active = true;
this.base.opacity = 0;
2025-09-20 13:47:44 +08:00
const cfg = ConfigManager.I.getDataById<PurchaseConfig>(ConfigId.Purchase);
2025-08-27 16:12:19 +08:00
tween(this.base).to(0.3, { opacity: 255 }).start();
}
hide() {
tween(this.base)
.to(
0.3,
{ opacity: 0 },
{
onComplete: () => {
2025-10-14 11:00:49 +08:00
NavigationManager.Instance.closePopupPanel(this.node);
2025-08-27 16:12:19 +08:00
},
}
)
.start();
}
2025-08-25 20:15:42 +08:00
refresh() {}
onClick_BuyTime() {
//购买次数
2025-09-10 16:43:46 +08:00
//ChatController.Instance.resetChatCount();
2025-09-10 17:37:24 +08:00
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
const chatIds = shopData.getChatIds();
2025-09-21 20:18:24 +08:00
logger.log("聊天商品Id: ", chatIds);
2025-09-10 17:37:24 +08:00
if (chatIds.length > 0) {
this.reqBuyGood(chatIds[0], this.girlId);
}
2025-08-25 20:15:42 +08:00
}
onClick_BuyVip() {
//购买VIP
2025-09-21 20:18:24 +08:00
logger.log("购买vip");
2025-10-14 11:00:49 +08:00
// const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
// const memberId = shopData.get7DayMemberId();
// this.reqBuyGood(memberId, this.girlId);
NavigationManager.Instance.openPopupPanel("PurchasePanel");
}
onClickClose() {
this.hide();
2025-08-25 20:15:42 +08:00
}
2025-09-10 17:37:24 +08:00
// 使用余额购买商品
async reqBuyGood(goodId: number, girlId: number) {
// 请求购买商品
const reqData = {
goodId: goodId,
girlId: girlId,
};
let res = await ShopService.I.reqBuyGood(reqData);
2025-09-21 20:18:24 +08:00
logger.log("请求使用余额购买商品的响应数据:", res);
2025-09-10 17:37:24 +08:00
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
const resData = res.data;
// 保存数据
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
2025-09-20 13:47:44 +08:00
girlData.setChatRemainCount(
2025-10-14 11:00:49 +08:00
this.categoryId,
2025-09-20 13:47:44 +08:00
girlId,
resData.chatRemainCount
);
2025-09-10 17:37:24 +08:00
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
walletData.balance = Number(resData.balance);
walletData.vipExpire = Number(resData.vipExpire);
// 刷新界面
2025-10-14 11:00:49 +08:00
TipsPanel.show(LanguageUtils.getText("payment.succeed"));
2025-09-10 17:37:24 +08:00
this.hide();
2025-10-14 11:00:49 +08:00
} else {
if (res && res.code) {
const key = "error_code_" + res.code;
TipsPanel.show(LanguageUtils.getText(key));
}
2025-09-10 17:37:24 +08:00
}
2025-09-20 13:47:44 +08:00
}
2025-08-25 20:15:42 +08:00
}