diff --git a/assets/Scripts/chat18x/data/ShopData.ts b/assets/Scripts/chat18x/data/ShopData.ts index a87e170c..7085ed87 100644 --- a/assets/Scripts/chat18x/data/ShopData.ts +++ b/assets/Scripts/chat18x/data/ShopData.ts @@ -93,6 +93,22 @@ export class ShopData extends BaseData { return resultId; } + /** 获取7天会员的 id */ + public get7DayMemberId(): number { + const ids = this.getMemberIds(); + const length = ids.length; + if (length <= 0) return 0; + return ids[0]; + } + + /** 获取30天会员的 id */ + public get30DayMemberId(): number { + const ids = this.getMemberIds(); + const length = ids.length; + if (length <= 1) return 0; + return ids[1]; + } + /** 是否是聊天商品,首位数字为 3 */ public isChatId(id: number): boolean { const firstDigit = id.toString()[0]; // 取首位字符 diff --git a/assets/Scripts/chat18x/network/services/ShopService.ts b/assets/Scripts/chat18x/network/services/ShopService.ts index 9d65e3ed..e0d04471 100644 --- a/assets/Scripts/chat18x/network/services/ShopService.ts +++ b/assets/Scripts/chat18x/network/services/ShopService.ts @@ -5,7 +5,7 @@ import { HttpShopService } from "./HttpShopService"; import { MockShopService } from "./MockShopService"; // 模拟开关 -const USE_MOCK = true; +const USE_MOCK = false; export class ShopService implements IShopService { private static _I: ShopService | null = null; diff --git a/assets/Scripts/chat18x/ui/panels/PurchasePanel.ts b/assets/Scripts/chat18x/ui/panels/PurchasePanel.ts index cdc39ee2..564f046f 100644 --- a/assets/Scripts/chat18x/ui/panels/PurchasePanel.ts +++ b/assets/Scripts/chat18x/ui/panels/PurchasePanel.ts @@ -11,8 +11,10 @@ import { InnerEventCode, InnerMsgCode } from "../../../Main/Config/InnerMsgCode" import { DataManager, DataId } from "../../data/DataManager"; import { WalletData } from "../../data/WalletData"; import { ShopData } from "../../data/ShopData"; +import { GirlData } from "../../data/GirlData"; import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService"; import proto from 'db://assets/Scripts/proto/proto.pb.js'; +import GameRootUI from "../../../Main/Common/GameRootUI"; const { ccclass, property } = _decorator; @@ -25,7 +27,6 @@ export class PurchasePanel extends li_BaseView { private vipTime7: Label; private vipPrice30: Label; private vipTime30: Label; - private tryBuyId: number; @property([PurchasePanelItem]) public items: PurchasePanelItem[] = []; @@ -53,26 +54,32 @@ export class PurchasePanel extends li_BaseView { bandBtn() { GButton.BandClick( - this._nodeTab.BuyVipBtn, + this._nodeTab.Buy7DayVipBt, () => { //TODO:购买vip - console.log("购买Vip"); + console.log("购买Vip 7"); + const shopData = DataManager.I.getDataById(DataId.Shop); + const memberId = shopData.get7DayMemberId(); + this.reqBuyGood(memberId); }, this ); GButton.BandClick( - this._nodeTab.BuyDiamondBtn, + this._nodeTab.Buy30DayVipBtn, () => { - //TODO:购买钻石 - console.log("购买钻石,商品id:" + this.tryBuyId); + //TODO:购买vip + console.log("购买Vip 30"); + const shopData = DataManager.I.getDataById(DataId.Shop); + const memberId = shopData.get30DayMemberId(); + this.reqBuyGood(memberId); }, this - ); + ); GButton.BandClick( - this._nodeTab.QUIT, + this._nodeTab.ReturnBtn, () => { - //TODO:购买钻石 - ViewManager.I.closeView(this.node); + this.onClose(); + GameRootUI.I.showDefaultView(); }, this ); @@ -98,16 +105,12 @@ export class PurchasePanel extends li_BaseView { const shopData = DataManager.I.getDataById(DataId.Shop); // VIP会员 - const memberIds = shopData.getMemberIds(); - for (let i = 0; i < memberIds.length; i++) { - const id = memberIds[i]; - const price = shopData.getOriginalPriceById(id); - if (i === 0) { - this.vipPrice7.string = `$ ${price}`; - } else if (i === 1) { - this.vipPrice30.string = `$ ${price}`; - } - } + const memberId7 = shopData.get7DayMemberId(); + const price7 = shopData.getOriginalPriceById(memberId7); + this.vipPrice7.string = `$ ${price7}`; + const memberId30 = shopData.get30DayMemberId(); + const price30 = shopData.getOriginalPriceById(memberId30); + this.vipPrice30.string = `$ ${price30}`; // 充值商品 const rechargeIds = shopData.getRechargeIds(); for (let index = 0; index < this.items.length; index++) { @@ -118,7 +121,7 @@ export class PurchasePanel extends li_BaseView { } setDiamondTag(id: number) { - this.tryBuyId = id; + this.reqBuyGood(id); } getPlayerMerData() { @@ -152,6 +155,27 @@ export class PurchasePanel extends li_BaseView { ).replace("${leftTime}", leftTime); } + // 使用余额购买商品 + async reqBuyGood(goodId: number) { + // 请求购买商品 + const reqData = { + goodId: goodId, + girlId: 0, + }; + 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(DataId.Girl); + const walletData = DataManager.I.getDataById(DataId.Wallet); + walletData.balance = Number(resData.balance); + walletData.vipExpire = Number(resData.vipExpire); + // 刷新界面 + + } + } + onDestroy() { Utils.removeInnerEL(InnerMsgCode.BalanceChange, this, () => { diff --git a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts index 41a0e3f8..3ea129e9 100644 --- a/assets/Scripts/chat18x/ui/panels/ThemePanel.ts +++ b/assets/Scripts/chat18x/ui/panels/ThemePanel.ts @@ -36,7 +36,7 @@ export class ThemePanel extends li_BaseView { uid: Label; itemInst: GirlListItem; content: Node; - + private vipLeftTime: Label; recId: number; recName: Label; recSprite: Sprite; @@ -50,6 +50,7 @@ export class ThemePanel extends li_BaseView { this.uid = this._nodeTab.uid.getComponent(Label); this.recName = this._nodeTab.characterNameText.getComponent(Label); this.recSprite = this._nodeTab.recPicSlot.getComponent(Sprite); + this.vipLeftTime = this._nodeTab.vipText.getComponent(Label); this.registerListener(); this.itemInst = this._nodeTab.ThemeItem.getComponent(ThemeItem); @@ -63,6 +64,7 @@ export class ThemePanel extends li_BaseView { async Show() { //some temp data this.refreshCoinNum(); + this.refreshVipExpire(); const accountData = DataManager.I.getDataById(DataId.Account); this.uid.string = "uid: " + accountData.accId; this.recId = 1; @@ -167,8 +169,10 @@ export class ThemePanel extends li_BaseView { private refreshVipExpire() { const walletData = DataManager.I.getDataById(DataId.Wallet); const vipExpire = walletData.vipExpire; - // TODO - + const leftTime = Utils.formatVipLeftTime(vipExpire); + this.vipLeftTime.string = LanguageUtils.getText( + "purchasepanel.vip_left" + ).replace("${leftTime}", leftTime); } onDestroy(): void { diff --git a/assets/Scripts/chat18x/uiitems/PurchasePanelItem.ts b/assets/Scripts/chat18x/uiitems/PurchasePanelItem.ts index 544d5972..5ab0d526 100644 --- a/assets/Scripts/chat18x/uiitems/PurchasePanelItem.ts +++ b/assets/Scripts/chat18x/uiitems/PurchasePanelItem.ts @@ -3,6 +3,8 @@ import { PurchasePanel } from "../ui/panels/PurchasePanel"; import { PurchaseConfig } from "../../schema/schema"; import { DataManager, DataId } from "../data/DataManager"; import { ShopData } from "../data/ShopData"; +import { GButton } from "db://assets/Scripts/Main/Common/GButton"; + const { ccclass, property } = _decorator; @ccclass("PurchasePanelItem") @@ -17,6 +19,8 @@ export class PurchasePanelItem extends Component { public init(base: PurchasePanel, goodId: number) { this.baseView = base; this.goodId = goodId; + + GButton.BandClick(this.node, this.onClickThis, this); } public show() { @@ -27,8 +31,7 @@ export class PurchasePanelItem extends Component { this.price.string = price.toString(); } - onClickThis() { + async onClickThis() { this.baseView.setDiamondTag(this.goodId); - console.log("点击了"); } } diff --git a/assets/bundles/Chat18x/ThemePanel.prefab b/assets/bundles/Chat18x/ThemePanel.prefab index e980aa7c..a3e8addd 100644 --- a/assets/bundles/Chat18x/ThemePanel.prefab +++ b/assets/bundles/Chat18x/ThemePanel.prefab @@ -1746,7 +1746,7 @@ }, { "__type__": "cc.Node", - "_name": "text", + "_name": "vipText", "_objFlags": 0, "__editorExtras__": {}, "_parent": { diff --git a/proto_cs b/proto_cs index f055100c..9ec1d4f0 160000 --- a/proto_cs +++ b/proto_cs @@ -1 +1 @@ -Subproject commit f055100cf0f378ddd96d8e153655b5166c65e6e8 +Subproject commit 9ec1d4f07754a1c91f80bf1e3c583d42e42049b2