import { _decorator, Component, Label, Node, Sprite, tween, UIOpacity, } from "cc"; 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"; 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"; import { logger } from "db://assets/Scripts/Main/Common/Logger"; const { ccclass, property } = _decorator; @ccclass("PayToTalkSubpanel") export class PayToTalkSubpanel extends Component { @property(Label) timeLabel: Label = null; @property(Label) timeBtnLabel: Label = null; @property(Label) vipLabel: Label = null; @property(Label) vipBtnLabel: Label = null; base: UIOpacity; categoryId: number; girlId: number; protected onLoad(): void { this.base = this.getComponent(UIOpacity); } show(categoryId: string, girlId: number) { this.node.active = true; this.base.opacity = 0; this.categoryId = Number(categoryId); this.girlId = girlId; const cfg = ConfigManager.I.getDataById(ConfigId.Purchase); const count = cfg.getCountById(cfg.getChatIds()[0]); this.timeBtnLabel.string = count + LanguageUtils.getText("chatpanel.buy10times"); tween(this.base).to(0.3, { opacity: 255 }).start(); } hide() { tween(this.base) .to( 0.3, { opacity: 0 }, { onComplete: () => { this.base.node.active = false; }, } ) .start(); } refresh() {} onClick_BuyTime() { //购买次数 //ChatController.Instance.resetChatCount(); const shopData = DataManager.I.getDataById(DataId.Shop); const chatIds = shopData.getChatIds(); logger.log("聊天商品Id: ", chatIds); if (chatIds.length > 0) { this.reqBuyGood(chatIds[0], this.girlId); } } onClick_BuyVip() { //购买VIP logger.log("购买vip"); const shopData = DataManager.I.getDataById(DataId.Shop); const memberId = shopData.get7DayMemberId(); this.reqBuyGood(memberId, this.girlId); } // 使用余额购买商品 async reqBuyGood(goodId: number, girlId: number) { // 请求购买商品 const reqData = { goodId: goodId, girlId: girlId, }; let res = await ShopService.I.reqBuyGood(reqData); logger.log("请求使用余额购买商品的响应数据:", res); if (res && res.code === proto.cs.EnmRetCode.SUCCESS) { const resData = res.data; // 保存数据 const girlData = DataManager.I.getDataById(DataId.Girl); girlData.setChatRemainCount( this.categoryId.toString(), girlId, resData.chatRemainCount ); const walletData = DataManager.I.getDataById(DataId.Wallet); walletData.balance = Number(resData.balance); walletData.vipExpire = Number(resData.vipExpire); // 刷新界面 this.hide(); } } }