local UIWalletShopGoldBuyTipsView = require("UIRuneShop/UIRuneShopGoldBuyTipsView_Generate") function UIWalletShopGoldBuyTipsView:OnAwake(data) self.controller = require("UIRuneShop/UIWalletShopGoldBuyTipsCtr"):new() self.controller:Init(self) self.controller:SetData(data) end function UIWalletShopGoldBuyTipsView:AddEventListener() ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name) end function UIWalletShopGoldBuyTipsView:FillContent(data, uiBase) self.uiBase = uiBase local gameObject = self.uiBase:GetRoot() if gameObject ~= nil then self.gameObject = gameObject self.transform = gameObject.transform end self:InitGenerate(self.transform, data) self:Init() end function UIWalletShopGoldBuyTipsView:Init() self.controller:InitData() local goodsData = self.controller:GetCurGoodsData() self.presentPrice.currency:SetActive(false) if not goodsData then self.textTitle.text.text = '' self.buyLimitTxt.text.text = '' self.presentPrice.number.text.text = '' self.image.image.enabled = false self.image.image.sprite = nil return end local price = goodsData.price if price <= 0 then self.presentPrice.number.text.text = string.formatbykey('Free') else self.presentPrice.number.text.text = string.formatbykey('WalletGold',price)--tostring(price) end local cfgData = goodsData.cfgData if cfgData then CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite) if sprite then self.image.image.sprite = sprite self.image.image.enabled = true end end) local rewards = cfgData.Reward local reward local goldNum = 0 if rewards then for i = 1, #rewards do reward = rewards[i] if reward[1] == Enum.ItemType.Diamond then if reward[2] then goldNum = goldNum + reward[2] end end end end local extraGoldNum = 0 local isFirstBuy = goodsData.first_buy if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and isFirstBuy then self.textTitle.text.text = tostring(cfgData.Name) .. string.formatbykey('RuneShopGoldTitle1') rewards = cfgData.FirstBuyReward for i = 1, #rewards do reward = rewards[i] if reward[1] == Enum.ItemType.Diamond then if reward[2] then extraGoldNum = extraGoldNum + reward[2] end end end elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then self.textTitle.text.text = tostring(cfgData.Name) .. string.formatbykey('RuneShopGoldTitle2') rewards = cfgData.ExtraBuyReward for i = 1, #rewards do reward = rewards[i] if reward[1] == Enum.ItemType.Diamond then if reward[2] then extraGoldNum = extraGoldNum + reward[2] end end end else self.textTitle.text.text = tostring(cfgData.Name) end local contentStr = '+' .. tostring((goldNum + extraGoldNum)) local itemCfgData = ManagerContainer.CfgMgr:GetItemById(Enum.ItemType.Diamond) if itemCfgData then contentStr = contentStr .. tostring(itemCfgData.Name) end self.buyLimitTxt.text.text = string.formatbykey('RuneShopGoldDsc2', tostring(price)) self.goldText.text.text = string.formatbykey('RuneShopGoldDsc3', tostring((goldNum + extraGoldNum)),tostring(goldNum), tostring(extraGoldNum)) else self.image.image.enabled = false self.image.image.sprite = nil self.textTitle.text.text = '' self.goldText.text.text = '' self.buyLimitTxt.text.text = '' end end function UIWalletShopGoldBuyTipsView:RemoveEventListener() ManagerContainer.LuaEventMgr:Unregister(self.uiData.name) end function UIWalletShopGoldBuyTipsView:AddUIEventListener() self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn) self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn) self.uiBase:AddButtonUniqueEventListener(self.btnBuy.button, self, self.OnClickBuyBtn) end function UIWalletShopGoldBuyTipsView:OnHide() end function UIWalletShopGoldBuyTipsView:OnShow(data) self.controller:SetData(data) end function UIWalletShopGoldBuyTipsView:OnClose() end function UIWalletShopGoldBuyTipsView:OnDispose() self.controller:OnDispose() end function UIWalletShopGoldBuyTipsView:OnClickCloseBtn() self:UIClose() end function UIWalletShopGoldBuyTipsView:OnClickBuyBtn() --钱包儲值 local count = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.WalletNum) local goodsData = self.controller:GetCurGoodsData() if not goodsData then self:UIClose() return end local cfgData = goodsData.cfgData if cfgData then if count >= cfgData.RMB then local creditLimit = ManagerContainer.DataMgr.WalletShopData:GetCreditLimit() if creditLimit then ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id) else local max_credit = ManagerContainer.DataMgr.WalletShopData:GetMaxUseCredit() local use_credit = ManagerContainer.DataMgr.WalletShopData:GetCurUseCredit() local credit = max_credit - use_credit if credit >= cfgData.RMB then ManagerContainer.DataMgr.WalletShopData:SendWalletShopItemBuyReq(cfgData.Id) else ManagerContainer.LuaUIMgr:ShowMessageBox("Insufficient",nil,nil,self,self.OnClickGetCredit) --ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("InsufficientLimit") end end else CommonUtil.ItemNotEnoughHandle(Enum.ItemType.WalletNum) end end self:UIClose() end function UIWalletShopGoldBuyTipsView:OnClickGetCredit() ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, nil) end return UIWalletShopGoldBuyTipsView