119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import {
|
|
_decorator,
|
|
Component,
|
|
Label,
|
|
Node,
|
|
Sprite,
|
|
tween,
|
|
UIOpacity,
|
|
} from "cc";
|
|
import { ChatController } from "../../core/ChatController";
|
|
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";
|
|
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<PurchaseConfig>(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<ShopData>(DataId.Shop);
|
|
const chatIds = shopData.getChatIds();
|
|
console.log("聊天商品Id: ", chatIds);
|
|
if (chatIds.length > 0) {
|
|
this.reqBuyGood(chatIds[0], this.girlId);
|
|
}
|
|
}
|
|
|
|
onClick_BuyVip() {
|
|
//购买VIP
|
|
console.log("购买vip");
|
|
const shopData = DataManager.I.getDataById<ShopData>(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);
|
|
console.log("请求使用余额购买商品的响应数据:", res);
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
const resData = res.data;
|
|
// 保存数据
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
girlData.setChatRemainCount(
|
|
this.categoryId.toString(),
|
|
girlId,
|
|
resData.chatRemainCount
|
|
);
|
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
|
walletData.balance = Number(resData.balance);
|
|
walletData.vipExpire = Number(resData.vipExpire);
|
|
// 刷新界面
|
|
this.hide();
|
|
}
|
|
}
|
|
}
|