---@class KLNoobPlayerPackPanel:UIKmlLuaPanelBase ---@field view KLNoobPlayerPackPanelView local KLNoobPlayerPackPanel = class(UIKmlLuaPanelBase) local this =KLNoobPlayerPackPanel function this:AsyncLoadUI() end ---创建时调用一次 function this:Init() self.itemInfoList = {} GUI:DataListInitData(self.view.PackItemList, function() return table.count(self.itemInfoList) end,function() end,function() end,function(realIndex) local discountControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'discountImage') --左上角返利 local discountTextControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'discountText') --返利数值 local ItemNameShowText = GUI:GetChildControl(self.view.PackItemList,realIndex,'ItemNameShowText') --礼包名称 local limitBuyCountControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'limitBuyCount') --限制次数 local ItemInfoListControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'ItemInfoList') --奖励列表 local BuyBtnControl = GUI:GetChildControl(self.view.PackItemList,realIndex,'PackItemBuyBtn') --购买按钮 local redpoint = GUI:GetChildControl(self.view.PackItemList,realIndex,'redpoint') --红点 local info = self.itemInfoList[realIndex+1] local buycount = 0 --剩余次数 local totalcount = 0 buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey) if info.Packagename and info.Packagename~=""then GUI:Text_setString(ItemNameShowText, info.Packagename) else GUI:Text_setString(ItemNameShowText, "免费礼包") end --返利 if info.rebate and info.rebate>0 then GUI:setVisible(discountControl, true) GUI:Text_setString(discountTextControl, info.rebate.."%") else GUI:setVisible(discountControl, false) end GUI:setVisible(redpoint, false) GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info}) if info.canBuy then if info.Price == 0 then GUI:Button_setTitleText(BuyBtnControl, "领取") GUI:setVisible(redpoint, true) else GUI:Button_setTitleText(BuyBtnControl, tostring(info.Price).."元") end else GUI:Button_setTitleText(BuyBtnControl, "已购买") end GUI:Text_setString(limitBuyCountControl, "限购次数:"..(totalcount-buycount).."/"..totalcount) self:ItemUpdateFun(ItemInfoListControl,realIndex) end) end function this:ItemUpdateFun(ItemInfoListControl,Index) local data = self.itemInfoList[Index + 1] local showRewards={} for k,v in ipairs(data.Rewards) do table.insert(showRewards,v) end GUI:DataListInitData(ItemInfoListControl, function() return table.count(showRewards) end,function() end,function() end,function(realIndex) local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型 local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量 local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips local itemdata = showRewards[realIndex+1] GUI:setVisible(ItemInfoSlotModel, true) GUI:setVisible(itemInfoTips, true) GUI:setVisible(ItemInfoSlotCount, true) GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1]) if itemdata[1] == 10040001 or itemdata[1] == 10050001 then GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24") end GUI:AddOnClickEvent(itemInfoTips,self,function() SL:OpenTips(nil, itemdata[1]) end) GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2])) end) GUI:DataListUpdateData(ItemInfoListControl) end ---注册UI事件和服务器消息 function this:RegistEvents() SL:RegisterLUAEvent(LUA_EVENT_NOOBPACK_RECHARGE_CHANGE, this.LUA_EVENT_NOOBPACK_RECHARGE_CHANGE, self) end --服务器发送礼包组消息后刷新礼包组的数据 function this:LUA_EVENT_NOOBPACK_RECHARGE_CHANGE() self:RefreshPanel() end ---列表的购买按钮 function this:ItemBuyBtn(control, data) if data[1].canBuy then local tab = SL:GetConfig("cfg_recharge", tonumber(data[1].RechargeId)) GUIUtil.SDKPay(tab,1) end end ---界面显示时调用一次 function this:Show() end ---创建或者刷新界面数据时调用 function this:Refresh() self:RefreshPanel() end function this:RefreshPanel() self.itemInfoList = {} local giftData = InfoManager.noobPackRechargeInfo.NoobPlayerPackData if not table.isNullOrEmpty(giftData) then for k,v in ipairs(giftData) do local buycount = 0 --剩余次数 local totalcount = 0 buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey) if buycount < 1 then v.canBuy = false else v.canBuy = true end table.insert(self.itemInfoList, v) end end table.sort(self.itemInfoList,function (a,b) if a.canBuy == b.canBuy then return a.Price 0 then GUI:SetActive(self.view.txt_showTime,true) GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown)) else GUI:SetActive(self.view.txt_showTime,false) self:ClearDJHFunc() GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel") end end) end function this:Close() self:ClearDJHFunc() end return this