KLUIRechargeDirectPanel.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ---@class KLUIRechargeDirectPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIRechargeDirectPanelView
  3. local KLUIRechargeDirectPanel = class(UIKmlLuaPanelBase)
  4. local this =KLUIRechargeDirectPanel
  5. --运营活动-直购礼包面板
  6. ---创建时调用一次
  7. function this:Init()
  8. self.giftDatas = {}
  9. self.allGifts = {}
  10. GUI:DataListInitData(self.view.giftDataList, function()
  11. return table.count(self.giftDatas)
  12. end, function(realIndex)
  13. local data = self.giftDatas[realIndex + 1]
  14. local item = GUI:UIPanel_Open("dev/outui/RunActive_RechargeDirect/Item/KLUIRechargeDirectGift/KLUIRechargeDirectGiftItem",self.view.giftDataList,self,data,true)
  15. self.allGifts[realIndex + 1] = item
  16. return item.view.root.kmlControl
  17. end, function(realIndex, kmlcontrol)
  18. end, function(realIndex, kmlcontrol)
  19. local data = self.giftDatas[realIndex + 1]
  20. self.allGifts[realIndex + 1]:RefreshItem(data)
  21. end)
  22. end
  23. function this:RefreshGifts()
  24. local currentGroup = InfoManager.mainOperateActivityInfo.NowOperateActivityMainGroup
  25. local cfg = SL:GetConfigTable("cfg_OperateActivity_CDM")
  26. self.giftDatas = {}
  27. for k,v in ipairs(cfg) do
  28. if v.mainGroup == currentGroup and (v.bugType == 1 or v.bugType == 3) then
  29. table.insert(self.giftDatas,v)
  30. end
  31. end
  32. for i,v in ipairs(self.giftDatas) do
  33. v.index = i
  34. end
  35. GUI:DataListUpdateData(self.view.giftDataList)
  36. end
  37. function this:buyAllBtn()
  38. if self.buyAllRechargeCfg then
  39. for k,cfg in ipairs(self.giftDatas) do
  40. local rechargeCfg = SL:GetConfigTwoKeys("cfg_recharge",cfg.id,cfg.rechargeType,"parameter","type")
  41. if not rechargeCfg then
  42. return
  43. end
  44. if rechargeCfg.amount > 0 then
  45. local count,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(rechargeCfg.Countkey)
  46. if count < totalcount then
  47. SL:TipMessage("有已购买的礼包,无法购买",1,NoticeType.NoticeMid)
  48. return
  49. end
  50. end
  51. end
  52. GUIUtil.SDKPay(self.buyAllRechargeCfg,1)
  53. end
  54. end
  55. ---注册UI事件和服务器消息
  56. function this:RegistEvents()
  57. GUI:AddOnClickEvent(self.view.buyAllBtn,self,self.buyAllBtn)
  58. SL:RegisterLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self.LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self)
  59. end
  60. function this:LUA_EVENT_MAINOPERATEACTIVITY_CHANGE()
  61. self:Refresh()
  62. end
  63. ---创建或者刷新界面数据时调用
  64. function this:Refresh()
  65. local leftTime = InfoManager.mainOperateActivityInfo:GetOADJSTimeBySubType(EOperateActivityActivityType.RechargeDirect)
  66. GUI:SetControl_time(self.view.refreshTime, leftTime)
  67. local group = InfoManager.mainOperateActivityInfo.NowOperateActivityMainGroup
  68. local tempTbl = SL:GetConfig("cfg_OperateActivity_CDM",group,"mainGroup")
  69. if tempTbl and tempTbl.img and not string.isNullOrEmpty(tempTbl.img) then
  70. GUI:Image_loadTexture(self.view.bg,string.format("Texture/%s.png",tempTbl.img))
  71. end
  72. self:RefreshGifts()
  73. --一键购买
  74. local buyAllActivityCfg = SL:GetConfigMultiKeys("cfg_OperateActivity_CDM",group,2,"mainGroup","bugType")
  75. if buyAllActivityCfg then
  76. self.buyAllRechargeCfg = SL:GetConfigTwoKeys("cfg_recharge",buyAllActivityCfg.id,buyAllActivityCfg.rechargeType,"parameter","type")
  77. if self.buyAllRechargeCfg then
  78. GUI:setVisible(self.view.buyAllBtn,true)
  79. --原价现价
  80. GUI:Text_setString(self.view.oldText,string.format("原价: <color=red>%d</color>",buyAllActivityCfg.parameter))
  81. GUI:Text_setString(self.view.priceText,string.format("%d元",self.buyAllRechargeCfg.amount))
  82. else
  83. GUI:setVisible(self.view.buyAllBtn,false)
  84. end
  85. else
  86. GUI:setVisible(self.view.buyAllBtn,false)
  87. end
  88. end
  89. function this:Close()
  90. SL:UnRegisterLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self.LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self)
  91. end
  92. return this