KLMainOperateAddRechargePanel.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ---@class KLMainOperateAddRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLMainOperateAddRechargePanelView
  3. local KLMainOperateAddRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLMainOperateAddRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.showList = {}
  10. GUI:DataListInitData(self.view.showItemInfoList, function()
  11. return self:GetAllShowItems()
  12. end,function()
  13. end,function()
  14. end, function(realIndex)
  15. self:ItemUpdateFun(realIndex)
  16. end)
  17. end
  18. function this:GetAllShowItems()
  19. return table.count(self.showList)
  20. end
  21. function this:ItemUpdateFun(realIndex)
  22. local data = self.showList[realIndex+1]
  23. local txt_taskDes = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_taskDes')
  24. local txt_process = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_process')
  25. local showItems = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'showItems')
  26. local btn_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_get')
  27. local btn_nav = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_nav')
  28. local txt_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_get')
  29. --任务描述
  30. GUI:Text_setString(txt_taskDes, data.taskDes)
  31. --任务进度
  32. local todayMoney = data.money
  33. local color = todayMoney >= data.goal and EColor[EGradColor.green] or EColor[EGradColor.red]
  34. local str = string.format("<color=%s>%s/%s</color>", color, todayMoney, data.goal)
  35. GUI:Text_setString(txt_process, str)
  36. --展示奖励
  37. local showRewards = data.reward
  38. GUI:HideAllChilds(showItems)
  39. for i = 1, table.count(showRewards) do
  40. local itemId = showRewards[i][1]
  41. local item = GUI:Item_Create(showItems, {
  42. width = "70",
  43. height = "70",
  44. itemid = itemId,
  45. mfixsize = "80,80",
  46. tips = "1",
  47. itemcustomcount = showRewards[i][2]
  48. })
  49. GUI:AddOnClickEvent(item, self, function()
  50. SL:OpenTips(nil, itemId)
  51. end)
  52. end
  53. --任务状态
  54. GUI:SetActive(btn_get,false)
  55. GUI:SetActive(btn_nav,false)
  56. GUI:SetActive(txt_get,false)
  57. if data.giftState == E_RechargeState.CanGet then
  58. GUI:SetActive(btn_get,true)
  59. GUI:AddOnClickEvent(btn_get,self,self.GetOnClick,{cfgId = data.id})
  60. elseif data.giftState == E_RechargeState.NotComplete then
  61. GUI:SetActive(btn_nav,true)
  62. GUI:AddOnClickEvent(btn_nav,self,self.GoOnClick)
  63. elseif data.giftState == E_RechargeState.AlreadyGet then
  64. GUI:SetActive(txt_get,true)
  65. end
  66. end
  67. function this:GetOnClick(_,data)
  68. if data.cfgId then
  69. --请求领奖
  70. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, {type = 17, action = "reward" ,id = data.cfgId})
  71. end
  72. end
  73. function this:GoOnClick()
  74. GUI:UIPanel_Close("dev/outui/MainOperateActivity/Panel/KLMainOperateActivity/KLMainOperateActivityPanel")
  75. --跳转到充值界面
  76. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel",nil,nil,{2})
  77. end
  78. ---注册UI事件和服务器消息
  79. function this:RegistEvents()
  80. SL:RegisterLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self.RefreshPanelData, self)
  81. --SL:RegisterLUAEvent(LUA_EVENT_OPERATE_ADD_RECHARGE_CHANGE, self.RefreshPanelData, self)
  82. end
  83. ---界面显示时调用一次
  84. function this:Show()
  85. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_MAIN_ACTIVE_INFO, { subType =EOperateActivityActivityType.OperateAddRecharge})
  86. end
  87. ---创建或者刷新界面数据时调用
  88. function this:Refresh()
  89. --self:RefreshPanelData()
  90. end
  91. function this:ShowDJHFunc(time)
  92. self:ClearDJHFunc()
  93. local countdown = 1
  94. if time and time>0 then
  95. countdown = time
  96. end
  97. self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
  98. countdown = countdown - 1
  99. if countdown > 0 then
  100. GUI:SetActive(self.view.txt_showTime,true)
  101. GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
  102. else
  103. GUI:SetActive(self.view.txt_showTime,false)
  104. self:ClearDJHFunc()
  105. end
  106. end)
  107. end
  108. function this:ClearDJHFunc()
  109. if self.sectimer then
  110. SL:UnSchedule(self.sectimer)
  111. self.sectimer = nil
  112. end
  113. end
  114. function this:RefreshPanelData()
  115. --倒计时
  116. self.showList = {}
  117. local data = InfoManager.mainOperateActivityInfo
  118. self:ShowDJHFunc(data:GetOADJSTimeBySubType(EOperateActivityActivityType.OperateAddRecharge))
  119. for k, v in ipairs(data.addRechargeInfo) do
  120. if v.showCount > 0 and v.money< v.showCount then
  121. -----策划需求,达到一定充值金额才显示部分礼包
  122. else
  123. table.insert(self.showList,v)
  124. end
  125. end
  126. table.sort(self.showList,function(a,b)
  127. if a.giftState == b.giftState then
  128. return a.id < b.id
  129. else
  130. return a.giftState < b.giftState
  131. end
  132. end)
  133. GUI:DataListUpdateData(self.view.showItemInfoList)
  134. end
  135. function this:Close()
  136. self:ClearDJHFunc()
  137. end
  138. return this