KLOperateDiamondRechargePanel.lua 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. ---@class KLOperateDiamondRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLOperateDiamondRechargePanelView
  3. local KLOperateDiamondRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLOperateDiamondRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.costItem = { 10040001, 10050001 }
  10. self.itemInfoList = {}
  11. GUI:DataListInitData(self.view.DailyPackItemList, function()
  12. return table.count(self.itemInfoList)
  13. end,function()
  14. end,function()
  15. end,function(realIndex)
  16. local discountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountImage') --左上角返利
  17. local discountTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountText') --返利数值
  18. local ItemPriceShowTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemPriceShowText') --价格标题
  19. local limitBuyCountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'limitBuyCount') --限制次数
  20. local ItemInfoListControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemInfoList') --奖励列表
  21. local BuyBtnControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'daliyPackItemBuyBtn') --购买按钮
  22. local redpoint = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'redpoint') --红点
  23. local diamondImg = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'DiamondImg') --钻石
  24. local info = self.itemInfoList[realIndex + 1]
  25. local buycount = 0 --剩余次数
  26. local totalcount = 0
  27. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey)
  28. if info.Diamonditem == 1 then
  29. GUI:Image_loadTexture(diamondImg, "10040001", "Atlas/TS_Common.spriteatlas")
  30. else
  31. GUI:Image_loadTexture(diamondImg, "10050001", "Atlas/TS_Common.spriteatlas")
  32. end
  33. --返利
  34. if info.Rebate and info.Rebate > 0 then
  35. GUI:setVisible(discountControl, true)
  36. GUI:Text_setString(discountTextControl, info.Rebate.."%")
  37. else
  38. GUI:setVisible(discountControl, false)
  39. end
  40. GUI:setVisible(redpoint, false)
  41. GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info})
  42. if info.canBuy then
  43. if info.Price == 0 then
  44. GUI:Button_setTitleText(BuyBtnControl, "领取")
  45. GUI:setVisible(redpoint, true)
  46. else
  47. GUI:Button_setTitleText(BuyBtnControl, "购买")
  48. end
  49. else
  50. GUI:Button_setTitleText(BuyBtnControl, "已购买")
  51. end
  52. if info.Price == 0 then
  53. GUI:setVisible(diamondImg, false)
  54. GUI:Text_setString(ItemPriceShowTextControl, "免费")
  55. else
  56. GUI:setVisible(diamondImg, true)
  57. GUI:Text_setString(ItemPriceShowTextControl, tostring(info.Price).."钻石")
  58. end
  59. GUI:Text_setString(limitBuyCountControl, "每日限购次数:"..(totalcount-buycount).."/"..totalcount)
  60. self:ItemUpdateFun(ItemInfoListControl,realIndex)
  61. end)
  62. end
  63. function this:ItemUpdateFun(ItemInfoListControl,Index)
  64. local data = self.itemInfoList[Index + 1]
  65. local showRewards={}
  66. for k,v in ipairs(data.Rewards) do
  67. table.insert(showRewards,v)
  68. end
  69. GUI:DataListInitData(ItemInfoListControl, function()
  70. return table.count(showRewards)
  71. end,function()
  72. end,function()
  73. end,function(realIndex)
  74. local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型
  75. local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量
  76. local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips
  77. GUI:setVisible(ItemInfoSlotModel, false)
  78. GUI:setVisible(ItemInfoSlotCount, false)
  79. GUI:setVisible(itemInfoTips, false)
  80. local itemdata = showRewards[realIndex + 1]
  81. GUI:setVisible(ItemInfoSlotModel, true)
  82. GUI:setVisible(itemInfoTips, true)
  83. GUI:setVisible(ItemInfoSlotCount, true)
  84. GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1])
  85. if itemdata[1] == 10040001 or itemdata[1] == 10050001 then
  86. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  87. end
  88. GUI:AddOnClickEvent(itemInfoTips,self,function()
  89. SL:OpenTips(nil, itemdata[1])
  90. end)
  91. GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2]))
  92. end)
  93. GUI:DataListUpdateData(ItemInfoListControl)
  94. end
  95. ---注册UI事件和服务器消息
  96. function this:RegistEvents()
  97. GUI:AddOnClickEvent(self.view.buyAllGift_btn, self, self.buyAllGift_btn)
  98. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MAIN_ACTIVE_INFO, self.RES_MAIN_ACTIVE_INFO, self)
  99. end
  100. function this:RES_MAIN_ACTIVE_INFO(_, message)
  101. if message then
  102. local list = {}
  103. local count = table.count(message.diamondPackInfo)
  104. if count > 0 then
  105. for i = 1, count do
  106. local data = {}
  107. local v = message.diamondPackInfo[tostring(i)]
  108. ---@type cfg_DiamondPack_column
  109. local tbl = SL:GetConfig("cfg_DiamondPack", tonumber(v.diamondPackId))
  110. if tbl.type ~= 2 then
  111. data.Type = tbl.type
  112. data.Rewards = tbl.reward
  113. data.Price = tbl.money
  114. data.Diamonditem = tbl.diamond
  115. data.Countkey = tbl.countkey
  116. data.Rebate = tbl.rebates
  117. data.Id = tbl.id
  118. list[#list + 1] = data
  119. else
  120. self.autoBuyId = tbl.id
  121. self.totalPrice = tbl.text
  122. self.discountPrice = tbl.money
  123. end
  124. end
  125. end
  126. self:RefreshPanel(list)
  127. end
  128. end
  129. ---一键购买
  130. function this:buyAllGift_btn()
  131. if self.limitBuyAll then
  132. SL:TipMessage( "已购买,无法购买", 1, NoticeType.NoticeMid )
  133. return
  134. end
  135. ---@type cfg_DiamondPack_column
  136. local tbl = SL:GetConfig("cfg_DiamondPack", self.autoBuyId)
  137. local buy = false
  138. if tbl.diamonditem == 2 then
  139. local cost_1 = SL:GetBagItemCount(self.costItem[2])
  140. local cost_2 = SL:GetBagItemCount(self.costItem[1])
  141. if cost_1 + cost_2 >= tbl.money then
  142. buy = true
  143. end
  144. else
  145. local cost = SL:GetBagItemCount(self.costItem[1])
  146. if cost >= tbl.money then
  147. buy = true
  148. end
  149. end
  150. if buy then
  151. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, { type = "18", id = self.autoBuyId })
  152. else
  153. SL:TipMessage( SL:GetConfig('cfg_string',28003).text, 1, NoticeType.NoticeMid )
  154. end
  155. end
  156. ---列表的购买按钮
  157. function this:ItemBuyBtn(control, data)
  158. if data[1].canBuy then
  159. local buy = false
  160. if data[1].Diamonditem == 2 then
  161. local cost_1 = SL:GetBagItemCount(self.costItem[2])
  162. local cost_2 = SL:GetBagItemCount(self.costItem[1])
  163. if cost_1 + cost_2 >= data[1].Price then
  164. buy = true
  165. end
  166. else
  167. local cost = SL:GetBagItemCount(self.costItem[1])
  168. if cost >= data[1].Price then
  169. buy = true
  170. end
  171. end
  172. if buy then
  173. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, { type = "18", id = data[1].Id })
  174. else
  175. SL:TipMessage( SL:GetConfig('cfg_string',28003).text, 1, NoticeType.NoticeMid )
  176. end
  177. else
  178. SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
  179. end
  180. end
  181. ---界面显示时调用一次
  182. function this:Show()
  183. self.limitBuyAll = false
  184. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_MAIN_ACTIVE_INFO, { subType = EOperateActivityActivityType.DiamondRecharge })
  185. end
  186. ---创建或者刷新界面数据时调用
  187. function this:Refresh()
  188. local leftTime = InfoManager.mainOperateActivityInfo:GetOADJSTimeBySubType(EOperateActivityActivityType.DiamondRecharge)
  189. if leftTime then
  190. GUI:SetControl_time(self.view.refreshTime, leftTime)
  191. end
  192. end
  193. function this:RefreshPanel(giftData)
  194. self.itemInfoList = {}
  195. if not table.isNullOrEmpty(giftData) then
  196. for _, v in ipairs(giftData) do
  197. local buycount = 0 --剩余次数
  198. local totalcount = 0
  199. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  200. if buycount < 1 then
  201. v.canBuy = false
  202. else
  203. v.canBuy = true
  204. end
  205. if buycount ~= totalcount and v.Type == 1 then
  206. self.limitBuyAll = true
  207. end
  208. table.insert(self.itemInfoList, v)
  209. end
  210. end
  211. table.sort(self.itemInfoList,function (a, b)
  212. if a.canBuy == b.canBuy then
  213. return a.Price < b.Price
  214. elseif a.canBuy then
  215. return true
  216. else
  217. return false
  218. end
  219. end)
  220. GUI:DataListUpdateData(self.view.DailyPackItemList)
  221. if self.limitBuyAll then
  222. GUI:setVisible(self.view.buyAllGift_btn, false)
  223. else
  224. ---@type cfg_global_column
  225. local tbl = SL:GetConfig("cfg_global", 28003)
  226. if tbl and tbl.value == "0" then
  227. GUI:setVisible(self.view.buyAllGift_btn, false)
  228. return
  229. end
  230. GUI:setVisible(self.view.buyAllGift_btn, true)
  231. GUI:Text_setString(self.view.originalPriceNum, tostring(self.totalPrice))
  232. GUI:Text_setString(self.view.allBuyTextTips, SL:GetConfig("cfg_string", 28004).text)
  233. GUI:Button_setTitleText(self.view.buyAllGift_btn, tostring(self.discountPrice).."钻石")
  234. end
  235. end
  236. function this:Close()
  237. end
  238. return this