KLDailyDiamondRechargePanel.lua 17 KB

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