123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- ---@class KLDailyPackRechargePanel:UIKmlLuaPanelBase
- ---@field view KLDailyPackRechargePanelView
- local KLDailyPackRechargePanel = class(UIKmlLuaPanelBase)
- local this =KLDailyPackRechargePanel
- function this:AsyncLoadUI()
- end
- ---创建时调用一次
- function this:Init()
- self.selectItemInfoData = {} --选中数据保存
- self.selectItemInfoObj = {} --选中勾选框保存
- self.openSelectGIftId = 0 --打开giftId的自选框
- self.selectItemInfoRewardIndex =0 --选中的具体道具
- self.itemInfoList = {}
- GUI:DataListInitData(self.view.DailyPackItemList, function()
- return table.count(self.itemInfoList)
- end,function()
- end,function()
- end,function(realIndex)
- local discountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountImage') --左上角返利
- local discountTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountText') --返利数值
- local ItemPriceShowTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemPriceShowText') --价格标题
- local limitBuyCountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'limitBuyCount') --限制次数
- local ItemInfoListControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemInfoList') --奖励列表
- local BuyBtnControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'daliyPackItemBuyBtn') --购买按钮
- local redpoint = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'redpoint') --红点
- local info = self.itemInfoList[realIndex+1]
- local buycount = 0 --剩余次数
- local totalcount = 0
- buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey)
- --返利
- 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, "购买")
- end
- else
- GUI:Button_setTitleText(BuyBtnControl, "已购买")
- end
- GUI:Text_setString(ItemPriceShowTextControl, tostring(info.Price).."元")
- GUI:Text_setString(limitBuyCountControl, "每日限购次数:"..(totalcount-buycount).."/"..totalcount)
- self:ItemUpdateFun(ItemInfoListControl,realIndex)
- end)
- self.selectRewardList = {}
- GUI:DataListInitData(self.view.selectItemInfoDataList, function()
- return table.count(self.selectRewardList)
- end,function()
- end,function()
- end,function(realIndex)
- local selectItem = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItem') --奖励模型
- local selectItemTips = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemTips') --奖励模型
- local selectItemNum = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemNum') --奖励数量
- local iteminfogouImg = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'iteminfogouImg') --勾选
- local selectItemInfoBtn = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemInfoBtn') --勾选按钮
- local info = self.selectRewardList[realIndex+1]
- local ItemInfoTab={}
- if iteminfogouImg then
- ItemInfoTab ={
- Index = realIndex+1,
- Obj = iteminfogouImg,
- }
- table.insert(self.selectItemInfoObj,ItemInfoTab)
- end
- GUI:setVisible(iteminfogouImg, false)
- GUI:Item_setItemId(selectItem, tostring(info.rewardId))
- GUI:AddOnClickEvent(selectItemTips,self,function()
- SL:OpenTips(nil, info.rewardId)
- end)
- GUI:Text_setString(selectItemNum, tostring(info.rewarcount))
- GUI:AddOnClickEvent(selectItemInfoBtn,self,self.selectItemIndexBtn,{ Index = info.rewardIndex})
- end)
- GUI:setVisible(self.view.selectItemPanel, false)
- 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
- local showRewardsCount = table.count(showRewards)
- if not table.isNullOrEmpty(data.Optionalreward) then
- showRewardsCount = showRewardsCount +1
- end
- GUI:DataListInitData(ItemInfoListControl, function()
- return showRewardsCount
- end,function()
- end,function()
- end,function(realIndex)
- local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型
- local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量
- local selectItemBtn = GUI:GetChildControl(ItemInfoListControl,realIndex,'selectItemBtn') --模型
- local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips
- GUI:setVisible(selectItemBtn, false)
- GUI:setVisible(ItemInfoSlotModel, false)
- GUI:setVisible(ItemInfoSlotCount, false)
- GUI:setVisible(itemInfoTips, false)
- if showRewards[realIndex+1] then
- 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]))
- else
- if data.canBuy then
- if self.selectItemInfoData[data.id] and self.selectItemInfoData[data.id]~=0 then --有选中的道具
- GUI:setVisible(ItemInfoSlotModel, true)
- GUI:setVisible(itemInfoTips, true)
- GUI:setVisible(ItemInfoSlotCount, true)
- local selectInfo = InfoManager.dailyPackRechargeInfo:GetSelectRewardItem(data.id,self.selectItemInfoData[data.id])[1]
- GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId)
- if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then
- GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
- end
- GUI:AddOnClickEvent(itemInfoTips,self,self.selectItemOpenBtn,{ data})
- --[[
- GUI:AddOnClickEvent(itemInfoTips,self,function()
- SL:OpenTips(nil, selectInfo.rewardId)
- end)
- ]]--
- GUI:Text_setString(ItemInfoSlotCount,tostring(selectInfo.rewarcount))
- else
- GUI:setVisible(selectItemBtn, true)
- end
- else
- if data.buyIndex >0 then --获取购买时的自选道具
- GUI:setVisible(ItemInfoSlotModel, true)
- GUI:setVisible(itemInfoTips, true)
- GUI:setVisible(ItemInfoSlotCount, true)
- local selectInfo = InfoManager.dailyPackRechargeInfo:GetSelectRewardItem(data.id,data.buyIndex)[1]
- GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId)
- if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then
- GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
- end
- GUI:AddOnClickEvent(itemInfoTips,self,function()
- SL:OpenTips(nil, selectInfo.rewardId)
- end)
- GUI:Text_setString(ItemInfoSlotCount, tostring(selectInfo.rewarcount))
- end
- end
- end
- GUI:AddOnClickEvent(selectItemBtn,self,self.selectItemOpenBtn,{ data})
- end)
- GUI:DataListUpdateData(ItemInfoListControl)
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- GUI:AddOnClickEvent(self.view.buyAllGift_btn, self, self.buyAllGift_btn)
- GUI:AddOnClickEvent(self.view.selectItemOkBtn, self, self.selectItemOkBtn)
- GUI:AddOnClickEvent(self.view.selectItemCloseBtn, self, self.selectItemCloseBtn)
- SL:RegisterLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE, this.LUA_EVENT_DAILYPACK_RECHARGE_CHANGE, self)
- end
- --服务器发送礼包组消息后刷新礼包组的数据
- function this:LUA_EVENT_DAILYPACK_RECHARGE_CHANGE()
- self:RefreshPanel()
- end
- --打开自选框
- function this:selectItemOpenBtn(control, giftdata)
- self.openSelectGIftId = giftdata[1].id
- self.selectRewardList = InfoManager.dailyPackRechargeInfo:GetSelectRewardInfo(self.openSelectGIftId)
- if not table.isNullOrEmpty(self.selectRewardList) then
- self.selectItemInfoObj = {}
- GUI:setVisible(self.view.selectItemPanel, true)
- GUI:DataListUpdateData(self.view.selectItemInfoDataList)
- end
- end
- --关闭自选框
- function this:selectItemCloseBtn()
- self.openSelectGIftId = 0
- self.selectItemInfoRewardIndex = 0
- GUI:setVisible(self.view.selectItemPanel, false)
- self:RefreshPanel()
- end
- --选中的自选框中的具体道具
- function this:selectItemIndexBtn(control, data)
- for k,v in ipairs(self.selectItemInfoObj) do
- GUI:setVisible(v.Obj, false)
- end
- for k,v in ipairs(self.selectItemInfoObj) do
- if v.Index == data.Index then
- GUI:setVisible(v.Obj, true)
- self.selectItemInfoRewardIndex =data.Index
- end
- end
- end
- --确认选中的自选框中的具体道具
- function this:selectItemOkBtn()
- GUI:setVisible(self.view.selectItemPanel, false)
- if self.selectItemInfoRewardIndex ~= 0 and self.openSelectGIftId ~=0 then
- self.selectItemInfoData[self.openSelectGIftId] = self.selectItemInfoRewardIndex
- end
- self:RefreshPanel()
- end
- ---列表的购买按钮
- function this:ItemBuyBtn(control, data)
- local id = data[1].id
- local rechargeid = data[1].RechargeId
- if data[1].canBuy then
- if table.isNullOrEmpty(data[1].Optionalreward) then
- elseif self.selectItemInfoData[id] ==nil or self.selectItemInfoData[id] == 0 then
- SL:TipMessage( "请选中一个自选道具", 1, NoticeType.NoticeMid )
- return
- end
- local tab = {}
- tab[id] = self.selectItemInfoData[id]
- local table = SL:GetConfig("cfg_recharge", tonumber(rechargeid))
- GUIUtil.SDKPay(table,1,tab)
- else
- SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
- end
- end
- ---一键购买
- function this:buyAllGift_btn()
- local allbuyData = InfoManager.dailyPackRechargeInfo.DailyPackAllGiftData[1]
- if not allbuyData.canBuy then
- SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
- return
- end
- local tab = {}
- for k,v in pairs(self.itemInfoList) do
- if v.Price~= 0 then
- if (table.isNullOrEmpty(v.Optionalreward)) then
- elseif self.selectItemInfoData[v.id] and self.selectItemInfoData[v.id]~=0 then
- tab[v.id] = self.selectItemInfoData[v.id]
- else
- SL:TipMessage( "还有礼包没有自选,无法一键购买", 1, NoticeType.NoticeMid )
- return
- end
- end
- end
- if not InfoManager.dailyPackRechargeInfo:IsCanBuyAllGift() then
- SL:TipMessage( "已购买,无法购买", 1, NoticeType.NoticeMid )
- return
- end
- local table = SL:GetConfig("cfg_recharge", tonumber(allbuyData.RechargeId))
- GUIUtil.SDKPay(table,1,tab)
- end
- ---界面显示时调用一次
- function this:Show()
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- self:RefreshPanel()
- end
- function this:RefreshPanel()
- self.itemInfoList = {}
- local giftData = InfoManager.dailyPackRechargeInfo.DailyPackData
- 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<b.Price
- elseif a.canBuy then
- return true
- else
- return false
- end
- end)
- GUI:DataListUpdateData(self.view.DailyPackItemList)
- local allbuyData = InfoManager.dailyPackRechargeInfo.DailyPackAllGiftData[1]
- if table.isNullOrEmpty(allbuyData) then
- GUI:setVisible(self.view.buyAllGift_btn, false)
- elseif (not allbuyData.canBuy) then --已购买,该礼包无法购买
- GUI:setVisible(self.view.buyAllGift_btn, true)
- GUI:Text_setString(self.view.originalPriceNum, tostring(InfoManager.dailyPackRechargeInfo:GetAllBuyOriginPrice()))
- GUI:Button_setTitleText(self.view.buyAllGift_btn, "已购买")
- else
- GUI:setVisible(self.view.buyAllGift_btn, true)
- GUI:Text_setString(self.view.originalPriceNum, tostring(InfoManager.dailyPackRechargeInfo:GetAllBuyOriginPrice()))
- GUI:Button_setTitleText(self.view.buyAllGift_btn, tostring(allbuyData.Price).."元")
- end
- end
- function this:Close()
- end
- return this
|