KLShowStallPanel.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ---@class KLShowStallPanel:UIKmlLuaPanelBase
  2. ---@field view KLShowStallPanelView
  3. local KLShowStallPanel = class(UIKmlLuaPanelBase)
  4. local this =KLShowStallPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.itemPanelList = {}
  10. local capacity = SL:GetConfig("cfg_global", 8001, "id").value
  11. self.is_tips = false
  12. self:CreateItem(capacity)
  13. self.tickTimer = SL:Schedule(self.tickTimer,0, 2, -1, function()
  14. self:RefreshUI()
  15. end)
  16. end
  17. ---注册UI事件和服务器消息
  18. function this:RegistEvents()
  19. end
  20. ---界面显示时调用一次
  21. function this:Show()
  22. end
  23. ---创建或者刷新界面数据时调用
  24. function this:Refresh()
  25. --self:RefreshUI()
  26. end
  27. function this:RefreshUI()
  28. for _, v in pairs(self.itemPanelList) do
  29. v:Remove()
  30. end
  31. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_STALL_GOODS,self.args.id)
  32. end
  33. function this:Close()
  34. if self.once then
  35. SL:UnSchedule(self.once)
  36. self.once = nil
  37. end
  38. if self.tickTimer then
  39. SL:UnSchedule(self.tickTimer)
  40. self.tickTimer = nil
  41. end
  42. end
  43. ---注册UI事件和服务器消息
  44. function this:RegistEvents()
  45. GUI:AddOnClickEvent(self.view.btn_close, self, self.ClosePanel)
  46. GUI:AddOnClickEvent(self.view.stop_stall, self, self.StopStall)
  47. GUI:AddOnClickEvent(self.view.add_stall, self, self.AddStall)
  48. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_STALL_GOODS, self.RES_STALL_GOODS, self)
  49. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_END_STALL, self.RES_END_STALL, self)
  50. end
  51. function this:ClosePanel()
  52. GUI:UIPanel_Close("dev/outui/Stall/Panel/KLShowStall/KLShowStallPanel")
  53. end
  54. function this:CreateItem(capacity)
  55. for i = 1, capacity do
  56. if not GUI:IsWebGLAsync() then
  57. ---@type KLTradeSalesItem
  58. local item = GUI:UIPanel_Open("dev/outui/Stall/Item/KLShowStallItem/KLShowStallItem", self.view.sales_grid, self, nil, true)
  59. table.insert(self.itemPanelList, item)
  60. else
  61. GUI:UIPanel_Open("dev/outui/Stall/Item/KLShowStallItem/KLShowStallItem", self.view.sales_grid, self, nil, true,
  62. function ( tempUI )
  63. table.insert(self.itemPanelList, tempUI)
  64. end)
  65. end
  66. end
  67. GUI:SetScrollView_scrollpos(self.view.sales_scroll,0)
  68. end
  69. ---@param message GoodsData
  70. function this:RES_STALL_GOODS(_, message)
  71. if message.title then
  72. local title_list = string.split(message.title,'#')
  73. GUI:Text_setString(self.view.title,title_list[2])
  74. end
  75. self:ShowGoodsInfo(message.allgoods)
  76. local userid = SL:GetMetaValue("USER_ID")
  77. if message.rid and tonumber(message.rid) == tonumber(userid) then
  78. GUI:setVisible(self.view.stop_stall,true)
  79. GUI:setVisible(self.view.add_stall,true)
  80. else
  81. GUI:setVisible(self.view.stop_stall,false)
  82. GUI:setVisible(self.view.add_stall,false)
  83. end
  84. if not self.is_tips then
  85. if not message.allgoods or not message.allgoods["1"] then
  86. SL:CommonTipsMessage({ showTips = "摊位物品被抢购空了" ,
  87. ui = self,
  88. sureBtnText = "确定",
  89. cancelBtnText = "取消"
  90. })
  91. self.is_tips = true
  92. return
  93. end
  94. end
  95. end
  96. function this:ShowGoodsInfo(data)
  97. if not data or not data["1"] then
  98. self:HideAll()
  99. return
  100. end
  101. for _, v in pairs(self.itemPanelList) do
  102. v.is_new = false
  103. end
  104. for i, v in pairs(data) do
  105. if self.itemPanelList and self.itemPanelList[tonumber(i)] then
  106. if not self.itemPanelList[tonumber(i)]:IsGoods() then
  107. ---@type KLTradeGoodsItemData
  108. --local goods = {}
  109. --goods["itemname"] = v.item
  110. --goods["count"] = v.count
  111. --goods.price = math.floor(v.price / v.count)
  112. --goods.time = v.time and v.time or 0
  113. --goods.itemcfgid = v.cfgid
  114. --goods.cointype = v.cointype
  115. --goods.itemid = v.itemid
  116. --goods.timename = "公示时间:"
  117. --goods.type = 1
  118. --goods["itemname"] = v.itemname
  119. --goods["count"] = v.count
  120. --goods.price = math.floor(v.totalprice / v.count)
  121. --goods.totalprice
  122. --goods.time = v.time and v.time or 0
  123. --goods.itemcfgid = v.itemcfgid
  124. --goods.cointype = v.cointype
  125. --goods.itemid = v.itemid
  126. --goods.timename = "公示时间:"
  127. --goods.type = 1
  128. self.itemPanelList[tonumber(i)]:UpdateUI(v)
  129. self.itemPanelList[tonumber(i)].is_new = true
  130. end
  131. end
  132. end
  133. for _, v in pairs(self.itemPanelList) do
  134. if not v.is_new then
  135. v:Remove()
  136. v:HideItem()
  137. end
  138. end
  139. end
  140. function this:HideAll()
  141. for _, v in pairs(self.itemPanelList) do
  142. v:HideItem()
  143. end
  144. end
  145. function this:StopStall()
  146. SL:CommonTipsMessage({ showTips = "是否取消摆摊?" ,
  147. ui = self,
  148. sureBtnText = "确定",
  149. cancelBtnText = "取消",
  150. callback = self.closeStall
  151. })
  152. end
  153. function this:closeStall()
  154. local userid = SL:GetMetaValue("USER_ID")
  155. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_END_STALL,userid)
  156. end
  157. function this:RES_END_STALL(_, message)
  158. if message then
  159. self:ClosePanel()
  160. end
  161. end
  162. function this:AddStall()
  163. self:ClosePanel()
  164. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLTradeMain/KLTradeMainPanel", nil, nil, "toggle_trade_my_up")
  165. end
  166. return this