KLWeekDailyPackRechargePanel.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. ---@class KLWeekDailyPackRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLWeekDailyPackRechargePanelView
  3. local KLWeekDailyPackRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLWeekDailyPackRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.itemInfoList = {}
  10. GUI:DataListInitData(self.view.DailyPackItemList, function()
  11. return table.count(self.itemInfoList)
  12. end,function()
  13. end,function()
  14. end,function(realIndex)
  15. local discountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountImage') --左上角返利
  16. local discountTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountText') --返利数值
  17. local ItemNameShowText = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemNameShowText') --限制次数
  18. local limitBuyCountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'limitBuyCount') --限制次数
  19. local ItemInfoListControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemInfoList') --奖励列表
  20. local BuyBtnControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'daliyPackItemBuyBtn') --购买按钮
  21. local redpoint = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'redpoint') --红点
  22. local info = self.itemInfoList[realIndex+1]
  23. local buycount = 0 --剩余次数
  24. local totalcount = 0
  25. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey)
  26. if info.Packagename and info.Packagename~=""then
  27. GUI:Text_setString(ItemNameShowText, info.Packagename)
  28. else
  29. GUI:Text_setString(ItemNameShowText, "免费礼包")
  30. end
  31. --返利
  32. if info.rebate and info.rebate>0 then
  33. GUI:setVisible(discountControl, true)
  34. GUI:Text_setString(discountTextControl, info.rebate.."%")
  35. else
  36. GUI:setVisible(discountControl, false)
  37. end
  38. GUI:setVisible(redpoint, false)
  39. GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info})
  40. if info.canBuy then
  41. if info.Price == 0 then
  42. GUI:Button_setTitleText(BuyBtnControl, "领取")
  43. GUI:setVisible(redpoint, true)
  44. else
  45. GUI:Button_setTitleText(BuyBtnControl, tostring(info.Price).."元")
  46. end
  47. else
  48. GUI:Button_setTitleText(BuyBtnControl, "已购买")
  49. end
  50. GUI:Text_setString(limitBuyCountControl, "每周限购次数:"..(totalcount-buycount).."/"..totalcount)
  51. self:ItemUpdateFun(ItemInfoListControl,realIndex)
  52. end)
  53. end
  54. function this:ItemUpdateFun(ItemInfoListControl,Index)
  55. local data = self.itemInfoList[Index + 1]
  56. local showRewards={}
  57. for k,v in ipairs(data.Rewards) do
  58. table.insert(showRewards,v)
  59. end
  60. GUI:DataListInitData(ItemInfoListControl, function()
  61. return table.count(showRewards)
  62. end,function()
  63. end,function()
  64. end,function(realIndex)
  65. local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型
  66. local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量
  67. local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips
  68. local itemdata = showRewards[realIndex+1]
  69. GUI:setVisible(ItemInfoSlotModel, true)
  70. GUI:setVisible(itemInfoTips, true)
  71. GUI:setVisible(ItemInfoSlotCount, true)
  72. GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1])
  73. if itemdata[1] == 10040001 or itemdata[1] == 10050001 then
  74. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  75. end
  76. GUI:AddOnClickEvent(itemInfoTips,self,function()
  77. SL:OpenTips(nil, itemdata[1])
  78. end)
  79. GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2]))
  80. end)
  81. GUI:DataListUpdateData(ItemInfoListControl)
  82. end
  83. ---注册UI事件和服务器消息
  84. function this:RegistEvents()
  85. SL:RegisterLUAEvent(LUA_EVENT_WEEKPACK_RECHARGE_CHANGE, this.LUA_EVENT_WEEKPACK_RECHARGE_CHANGE, self)
  86. end
  87. --服务器发送礼包组消息后刷新礼包组的数据
  88. function this:LUA_EVENT_WEEKPACK_RECHARGE_CHANGE()
  89. self:RefreshPanel()
  90. end
  91. ---列表的购买按钮
  92. function this:ItemBuyBtn(control, data)
  93. if data[1].canBuy then
  94. local tab = SL:GetConfig("cfg_recharge", tonumber(data[1].RechargeId))
  95. GUIUtil.SDKPay(tab,1)
  96. else
  97. SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
  98. end
  99. end
  100. ---界面显示时调用一次
  101. function this:Show()
  102. end
  103. ---创建或者刷新界面数据时调用
  104. function this:Refresh()
  105. self:RefreshPanel()
  106. end
  107. function this:RefreshPanel()
  108. self.itemInfoList = {}
  109. local giftData = InfoManager.weekPackRechargeInfo.WeekPackData
  110. if not table.isNullOrEmpty(giftData) then
  111. for k,v in ipairs(giftData) do
  112. local buycount = 0 --剩余次数
  113. local totalcount = 0
  114. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  115. if buycount < 1 then
  116. v.canBuy = false
  117. else
  118. v.canBuy = true
  119. end
  120. table.insert(self.itemInfoList, v)
  121. end
  122. end
  123. table.sort(self.itemInfoList,function (a,b)
  124. if a.canBuy == b.canBuy then
  125. return a.Price<b.Price
  126. elseif a.canBuy then
  127. return true
  128. else
  129. return false
  130. end
  131. end)
  132. GUI:DataListUpdateData(self.view.DailyPackItemList)
  133. self:ShowDJHFunc()
  134. end
  135. function this:ClearDJHFunc()
  136. if self.sectimer then
  137. SL:UnSchedule(self.sectimer)
  138. self.sectimer = nil
  139. end
  140. end
  141. function this:ShowDJHFunc()
  142. self:ClearDJHFunc()
  143. local countdown = self.getControlTime()
  144. self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
  145. countdown = countdown - 1
  146. if countdown > 0 then
  147. GUI:SetActive(self.view.txt_showTime,true)
  148. GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
  149. else
  150. GUI:SetActive(self.view.txt_showTime,false)
  151. self:ClearDJHFunc()
  152. --GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  153. end
  154. end)
  155. end
  156. function this:getControlTime()
  157. local remainder = 7
  158. --当前是星期几
  159. local t = math.floor(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)/1000)
  160. local TimeData = os.date("*t", t)
  161. local weekNum = TimeData.wday - 1
  162. if weekNum == 0 then
  163. weekNum = 7
  164. end
  165. local remainderDay = remainder - weekNum
  166. --客户端结束时无法主动请求,倒计时时间固定5s
  167. local Week7Time = remainderDay * 24 * 60 * 60+(23-TimeData.hour)*(60*60)+(59-TimeData.min)*60+(60-TimeData.sec)+5
  168. return Week7Time
  169. end
  170. function this:Close()
  171. self:ClearDJHFunc()
  172. end
  173. return this