KLUIRechargeDirectGiftItem.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ---@class KLUIRechargeDirectGiftItem:UIKmlLuaPanelBase
  2. ---@field view KLUIRechargeDirectGiftItemView
  3. local KLUIRechargeDirectGiftItem = class(UIKmlLuaPanelBase)
  4. local this =KLUIRechargeDirectGiftItem
  5. --直购礼包-礼包
  6. ---创建时调用一次
  7. function this:Init()
  8. self.itemDatas = {}
  9. self.allItem = {}
  10. GUI:DataListInitData(self.view.itemsDataList,function()
  11. return table.count(self.itemDatas)
  12. end,function(realIndex)
  13. local itemId = self.itemDatas[realIndex + 1].itemId
  14. local itemCount = self.itemDatas[realIndex + 1].itemNum
  15. local item = GUI:Item_Create(self.view.itemsDataList,{
  16. width = 60,
  17. height = 60,
  18. itemid = itemId,
  19. --mfixsize = "80,80",
  20. tips = "1",
  21. itemcustomcount = itemCount,
  22. })
  23. GUI:AddOnClickEvent(item,self,function()
  24. SL:OpenTips(nil,itemId)
  25. end)
  26. self.allItem[realIndex + 1] = item
  27. return item.kmlControl
  28. end,function(realIndex, kmlcontrol)
  29. end,function(realIndex, kmlcontrol)
  30. local itemId = self.itemDatas[realIndex + 1].itemId
  31. local itemCount = self.itemDatas[realIndex + 1].itemNum
  32. local item = self.allItem[realIndex + 1]
  33. GUI:Item_setItemId(item,itemId)
  34. GUI:Item_setItemCount(item,itemCount)
  35. GUI:AddOnClickEvent(item,self,function()
  36. SL:OpenTips(nil,itemId)
  37. end)
  38. end)
  39. end
  40. function this:ConfirmBuy()
  41. if self.rechargeCfg then
  42. local count,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(self.rechargeCfg.Countkey)
  43. if count > 0 then
  44. GUIUtil.SDKPay(self.rechargeCfg,1)
  45. else
  46. SL:TipMessage("已达购买次数上限",1,NoticeType.NoticeMid)
  47. end
  48. end
  49. end
  50. ---注册UI事件和服务器消息
  51. function this:RegistEvents()
  52. GUI:AddOnClickEvent(self.view.buyBtn,self,self.ConfirmBuy)
  53. SL:RegisterLUAEvent(LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self.LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self)
  54. end
  55. function this:LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE()
  56. if self.rechargeCfg and self.rechargeCfg.Countkey then
  57. local count,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(self.rechargeCfg.Countkey)
  58. local color = "#00FF00"
  59. if count <= 0 then
  60. color = "#FF0000"
  61. GUI:SetActive(self.view.redDot,false)
  62. GUI:Text_setString(self.view.priceText,"已购买")
  63. end
  64. GUI:Text_setString(self.view.countText,string.format("<color=%s>限购次数:%d</color>",color,count))
  65. end
  66. end
  67. --- @param self.args cfg_OperateActivity_CDM_column
  68. ---创建或者刷新界面数据时调用
  69. function this:Refresh()
  70. if self.args then
  71. --道具列表
  72. self.itemDatas = {}
  73. if self.args.itemCount and table.count(self.args.itemCount) > 0 then
  74. for k,v in ipairs(self.args.itemCount) do
  75. table.insert(self.itemDatas,{itemId=v[1],itemNum=v[2]})
  76. end
  77. end
  78. GUI:DataListUpdateData(self.view.itemsDataList)
  79. --礼包名、价格
  80. self.rechargeCfg = SL:GetConfigTwoKeys("cfg_recharge",self.args.id,self.args.rechargeType,"parameter","type")
  81. if self.rechargeCfg then
  82. local costStr
  83. if self.rechargeCfg.amount > 0 then
  84. costStr = string.format("%d元",self.rechargeCfg.amount)
  85. GUI:SetActive(self.view.redDot,false)
  86. else
  87. costStr = "免费"
  88. GUI:SetActive(self.view.redDot,true)
  89. end
  90. GUI:Text_setString(self.view.priceText,costStr)
  91. GUI:Text_setString(self.view.nameText,self.rechargeCfg.name)
  92. end
  93. if not self.args.index or self.args.index < 1 then
  94. self.args.index = 1
  95. elseif self.args.index > 4 then
  96. self.args.index = 4
  97. end
  98. GUI:Image_loadTexture(self.view.bg,string.format("giftBg_%d",self.args.index),"Atlas/UIRunActive_Direct.spriteatlas")
  99. end
  100. --限购次数
  101. self:LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE()
  102. end
  103. function this:RefreshItem(args)
  104. self.args = args
  105. self:Refresh()
  106. end
  107. function this:Close()
  108. SL:UnRegisterLUAEvent(LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self.LUA_EVENT_RUNACTIVE_DIRECT_COUNT_CHANGE, self)
  109. end
  110. return this