KLDailyPackRechargePanel.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. ---@class KLDailyPackRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLDailyPackRechargePanelView
  3. local KLDailyPackRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLDailyPackRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.selectItemInfoData = {} --选中数据保存
  10. self.selectItemInfoObj = {} --选中勾选框保存
  11. self.openSelectGIftId = 0 --打开giftId的自选框
  12. self.selectItemInfoRewardIndex =0 --选中的具体道具
  13. self.itemInfoList = {}
  14. GUI:DataListInitData(self.view.DailyPackItemList, function()
  15. return table.count(self.itemInfoList)
  16. end,function()
  17. end,function()
  18. end,function(realIndex)
  19. local discountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountImage') --左上角返利
  20. local discountTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountText') --返利数值
  21. local ItemPriceShowTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemPriceShowText') --价格标题
  22. local limitBuyCountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'limitBuyCount') --限制次数
  23. local ItemInfoListControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemInfoList') --奖励列表
  24. local BuyBtnControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'daliyPackItemBuyBtn') --购买按钮
  25. local redpoint = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'redpoint') --红点
  26. local info = self.itemInfoList[realIndex+1]
  27. local buycount = 0 --剩余次数
  28. local totalcount = 0
  29. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey)
  30. --返利
  31. if info.rebate and info.rebate>0 then
  32. GUI:setVisible(discountControl, true)
  33. GUI:Text_setString(discountTextControl, info.rebate.."%")
  34. else
  35. GUI:setVisible(discountControl, false)
  36. end
  37. GUI:setVisible(redpoint, false)
  38. GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info})
  39. if info.canBuy then
  40. if info.Price == 0 then
  41. GUI:Button_setTitleText(BuyBtnControl, "领取")
  42. GUI:setVisible(redpoint, true)
  43. else
  44. GUI:Button_setTitleText(BuyBtnControl, "购买")
  45. end
  46. else
  47. GUI:Button_setTitleText(BuyBtnControl, "已购买")
  48. end
  49. GUI:Text_setString(ItemPriceShowTextControl, tostring(info.Price).."元")
  50. GUI:Text_setString(limitBuyCountControl, "每日限购次数:"..(totalcount-buycount).."/"..totalcount)
  51. self:ItemUpdateFun(ItemInfoListControl,realIndex)
  52. end)
  53. self.selectRewardList = {}
  54. GUI:DataListInitData(self.view.selectItemInfoDataList, function()
  55. return table.count(self.selectRewardList)
  56. end,function()
  57. end,function()
  58. end,function(realIndex)
  59. local selectItem = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItem') --奖励模型
  60. local selectItemTips = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemTips') --奖励模型
  61. local selectItemNum = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemNum') --奖励数量
  62. local iteminfogouImg = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'iteminfogouImg') --勾选
  63. local selectItemInfoBtn = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemInfoBtn') --勾选按钮
  64. local info = self.selectRewardList[realIndex+1]
  65. local ItemInfoTab={}
  66. if iteminfogouImg then
  67. ItemInfoTab ={
  68. Index = realIndex+1,
  69. Obj = iteminfogouImg,
  70. }
  71. table.insert(self.selectItemInfoObj,ItemInfoTab)
  72. end
  73. GUI:setVisible(iteminfogouImg, false)
  74. GUI:Item_setItemId(selectItem, tostring(info.rewardId))
  75. GUI:AddOnClickEvent(selectItemTips,self,function()
  76. SL:OpenTips(nil, info.rewardId)
  77. end)
  78. GUI:Text_setString(selectItemNum, tostring(info.rewarcount))
  79. GUI:AddOnClickEvent(selectItemInfoBtn,self,self.selectItemIndexBtn,{ Index = info.rewardIndex})
  80. end)
  81. GUI:setVisible(self.view.selectItemPanel, false)
  82. end
  83. function this:ItemUpdateFun(ItemInfoListControl,Index)
  84. local data = self.itemInfoList[Index + 1]
  85. local showRewards={}
  86. for k,v in ipairs(data.Rewards) do
  87. table.insert(showRewards,v)
  88. end
  89. local showRewardsCount = table.count(showRewards)
  90. if not table.isNullOrEmpty(data.Optionalreward) then
  91. showRewardsCount = showRewardsCount +1
  92. end
  93. GUI:DataListInitData(ItemInfoListControl, function()
  94. return showRewardsCount
  95. end,function()
  96. end,function()
  97. end,function(realIndex)
  98. local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型
  99. local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量
  100. local selectItemBtn = GUI:GetChildControl(ItemInfoListControl,realIndex,'selectItemBtn') --模型
  101. local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips
  102. GUI:setVisible(selectItemBtn, false)
  103. GUI:setVisible(ItemInfoSlotModel, false)
  104. GUI:setVisible(ItemInfoSlotCount, false)
  105. GUI:setVisible(itemInfoTips, false)
  106. if showRewards[realIndex+1] then
  107. local itemdata = showRewards[realIndex+1]
  108. GUI:setVisible(ItemInfoSlotModel, true)
  109. GUI:setVisible(itemInfoTips, true)
  110. GUI:setVisible(ItemInfoSlotCount, true)
  111. GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1])
  112. if itemdata[1] == 10040001 or itemdata[1] == 10050001 then
  113. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  114. end
  115. GUI:AddOnClickEvent(itemInfoTips,self,function()
  116. SL:OpenTips(nil, itemdata[1])
  117. end)
  118. GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2]))
  119. else
  120. if data.canBuy then
  121. if self.selectItemInfoData[data.id] and self.selectItemInfoData[data.id]~=0 then --有选中的道具
  122. GUI:setVisible(ItemInfoSlotModel, true)
  123. GUI:setVisible(itemInfoTips, true)
  124. GUI:setVisible(ItemInfoSlotCount, true)
  125. local selectInfo = InfoManager.dailyPackRechargeInfo:GetSelectRewardItem(data.id,self.selectItemInfoData[data.id])[1]
  126. GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId)
  127. if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then
  128. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  129. end
  130. GUI:AddOnClickEvent(itemInfoTips,self,self.selectItemOpenBtn,{ data})
  131. --[[
  132. GUI:AddOnClickEvent(itemInfoTips,self,function()
  133. SL:OpenTips(nil, selectInfo.rewardId)
  134. end)
  135. ]]--
  136. GUI:Text_setString(ItemInfoSlotCount,tostring(selectInfo.rewarcount))
  137. else
  138. GUI:setVisible(selectItemBtn, true)
  139. end
  140. else
  141. if data.buyIndex >0 then --获取购买时的自选道具
  142. GUI:setVisible(ItemInfoSlotModel, true)
  143. GUI:setVisible(itemInfoTips, true)
  144. GUI:setVisible(ItemInfoSlotCount, true)
  145. local selectInfo = InfoManager.dailyPackRechargeInfo:GetSelectRewardItem(data.id,data.buyIndex)[1]
  146. GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId)
  147. if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then
  148. GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24")
  149. end
  150. GUI:AddOnClickEvent(itemInfoTips,self,function()
  151. SL:OpenTips(nil, selectInfo.rewardId)
  152. end)
  153. GUI:Text_setString(ItemInfoSlotCount, tostring(selectInfo.rewarcount))
  154. end
  155. end
  156. end
  157. GUI:AddOnClickEvent(selectItemBtn,self,self.selectItemOpenBtn,{ data})
  158. end)
  159. GUI:DataListUpdateData(ItemInfoListControl)
  160. end
  161. ---注册UI事件和服务器消息
  162. function this:RegistEvents()
  163. GUI:AddOnClickEvent(self.view.buyAllGift_btn, self, self.buyAllGift_btn)
  164. GUI:AddOnClickEvent(self.view.selectItemOkBtn, self, self.selectItemOkBtn)
  165. GUI:AddOnClickEvent(self.view.selectItemCloseBtn, self, self.selectItemCloseBtn)
  166. SL:RegisterLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE, this.LUA_EVENT_DAILYPACK_RECHARGE_CHANGE, self)
  167. end
  168. --服务器发送礼包组消息后刷新礼包组的数据
  169. function this:LUA_EVENT_DAILYPACK_RECHARGE_CHANGE()
  170. self:RefreshPanel()
  171. end
  172. --打开自选框
  173. function this:selectItemOpenBtn(control, giftdata)
  174. self.openSelectGIftId = giftdata[1].id
  175. self.selectRewardList = InfoManager.dailyPackRechargeInfo:GetSelectRewardInfo(self.openSelectGIftId)
  176. if not table.isNullOrEmpty(self.selectRewardList) then
  177. self.selectItemInfoObj = {}
  178. GUI:setVisible(self.view.selectItemPanel, true)
  179. GUI:DataListUpdateData(self.view.selectItemInfoDataList)
  180. end
  181. end
  182. --关闭自选框
  183. function this:selectItemCloseBtn()
  184. self.openSelectGIftId = 0
  185. self.selectItemInfoRewardIndex = 0
  186. GUI:setVisible(self.view.selectItemPanel, false)
  187. self:RefreshPanel()
  188. end
  189. --选中的自选框中的具体道具
  190. function this:selectItemIndexBtn(control, data)
  191. for k,v in ipairs(self.selectItemInfoObj) do
  192. GUI:setVisible(v.Obj, false)
  193. end
  194. for k,v in ipairs(self.selectItemInfoObj) do
  195. if v.Index == data.Index then
  196. GUI:setVisible(v.Obj, true)
  197. self.selectItemInfoRewardIndex =data.Index
  198. end
  199. end
  200. end
  201. --确认选中的自选框中的具体道具
  202. function this:selectItemOkBtn()
  203. GUI:setVisible(self.view.selectItemPanel, false)
  204. if self.selectItemInfoRewardIndex ~= 0 and self.openSelectGIftId ~=0 then
  205. self.selectItemInfoData[self.openSelectGIftId] = self.selectItemInfoRewardIndex
  206. end
  207. self:RefreshPanel()
  208. end
  209. ---列表的购买按钮
  210. function this:ItemBuyBtn(control, data)
  211. local id = data[1].id
  212. local rechargeid = data[1].RechargeId
  213. if data[1].canBuy then
  214. if table.isNullOrEmpty(data[1].Optionalreward) then
  215. elseif self.selectItemInfoData[id] ==nil or self.selectItemInfoData[id] == 0 then
  216. SL:TipMessage( "请选中一个自选道具", 1, NoticeType.NoticeMid )
  217. return
  218. end
  219. local tab = {}
  220. tab[id] = self.selectItemInfoData[id]
  221. local table = SL:GetConfig("cfg_recharge", tonumber(rechargeid))
  222. GUIUtil.SDKPay(table,1,tab)
  223. else
  224. SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
  225. end
  226. end
  227. ---一键购买
  228. function this:buyAllGift_btn()
  229. local allbuyData = InfoManager.dailyPackRechargeInfo.DailyPackAllGiftData[1]
  230. if not allbuyData.canBuy then
  231. SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid )
  232. return
  233. end
  234. local tab = {}
  235. for k,v in pairs(self.itemInfoList) do
  236. if v.Price~= 0 then
  237. if (table.isNullOrEmpty(v.Optionalreward)) then
  238. elseif self.selectItemInfoData[v.id] and self.selectItemInfoData[v.id]~=0 then
  239. tab[v.id] = self.selectItemInfoData[v.id]
  240. else
  241. SL:TipMessage( "还有礼包没有自选,无法一键购买", 1, NoticeType.NoticeMid )
  242. return
  243. end
  244. end
  245. end
  246. if not InfoManager.dailyPackRechargeInfo:IsCanBuyAllGift() then
  247. SL:TipMessage( "已购买,无法购买", 1, NoticeType.NoticeMid )
  248. return
  249. end
  250. local table = SL:GetConfig("cfg_recharge", tonumber(allbuyData.RechargeId))
  251. GUIUtil.SDKPay(table,1,tab)
  252. end
  253. ---界面显示时调用一次
  254. function this:Show()
  255. end
  256. ---创建或者刷新界面数据时调用
  257. function this:Refresh()
  258. self:RefreshPanel()
  259. end
  260. function this:RefreshPanel()
  261. self.itemInfoList = {}
  262. local giftData = InfoManager.dailyPackRechargeInfo.DailyPackData
  263. if not table.isNullOrEmpty(giftData) then
  264. for k,v in ipairs(giftData) do
  265. local buycount = 0 --剩余次数
  266. local totalcount = 0
  267. buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey)
  268. if buycount < 1 then
  269. v.canBuy = false
  270. else
  271. v.canBuy = true
  272. end
  273. table.insert(self.itemInfoList, v)
  274. end
  275. end
  276. table.sort(self.itemInfoList,function (a,b)
  277. if a.canBuy == b.canBuy then
  278. return a.Price<b.Price
  279. elseif a.canBuy then
  280. return true
  281. else
  282. return false
  283. end
  284. end)
  285. GUI:DataListUpdateData(self.view.DailyPackItemList)
  286. local allbuyData = InfoManager.dailyPackRechargeInfo.DailyPackAllGiftData[1]
  287. if table.isNullOrEmpty(allbuyData) then
  288. GUI:setVisible(self.view.buyAllGift_btn, false)
  289. elseif (not allbuyData.canBuy) then --已购买,该礼包无法购买
  290. GUI:setVisible(self.view.buyAllGift_btn, true)
  291. GUI:Text_setString(self.view.originalPriceNum, tostring(InfoManager.dailyPackRechargeInfo:GetAllBuyOriginPrice()))
  292. GUI:Button_setTitleText(self.view.buyAllGift_btn, "已购买")
  293. else
  294. GUI:setVisible(self.view.buyAllGift_btn, true)
  295. GUI:Text_setString(self.view.originalPriceNum, tostring(InfoManager.dailyPackRechargeInfo:GetAllBuyOriginPrice()))
  296. GUI:Button_setTitleText(self.view.buyAllGift_btn, tostring(allbuyData.Price).."元")
  297. end
  298. end
  299. function this:Close()
  300. end
  301. return this