MarketFocusView = MarketFocusView or BaseClass(BaseItem)
|
|
local MarketFocusView = MarketFocusView
|
|
|
|
function MarketFocusView:__init()
|
|
self.base_file = "market"
|
|
self.layout_file = "MarketFocusView"
|
|
self.model = MarketModel:GetInstance()
|
|
self.sort_id = 1
|
|
self.sort_order = 0--0:表示顺序(从大到小) 1:表示倒序(从小到大)
|
|
self.sort_data = {
|
|
1,1,1
|
|
}
|
|
self.tab_item_list = {}
|
|
self.cur_hor_tab_index = 1 --水平tab选择
|
|
self:Load()
|
|
end
|
|
|
|
function MarketFocusView:Load_callback()
|
|
self.nodes = {
|
|
"title/time_con/time_arrow","title/auction_con:obj","right_scroll","title/auction_con/auction_arrow",
|
|
"right_scroll/Viewport/right_con","title/price_con:obj","title/price_con/price_arrow","tab_con","title/time_con:obj",
|
|
"empty:obj","empty/empty_text:tmp","empty/girl:raw","empty/empty_talk_image:raw",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
lua_resM:setOutsideRawImage(self, self.girl_raw, GameResPath.GetRoleBg("team_empty_bg_267_589"), false)
|
|
lua_resM:setOutsideRawImage(self, self.empty_talk_image_raw, GameResPath.GetViewBigBg("com_empty_bg1"), false)
|
|
self:AddEvents()
|
|
self:SetHorTabCon()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function MarketFocusView:AddEvents( )
|
|
function on_click_sort( target )
|
|
if target == self.auction_con_obj then--拍卖排序
|
|
self:SelectSort(2)
|
|
elseif target == self.price_con_obj then--一口价排序
|
|
self:SelectSort(3)
|
|
elseif target == self.time_con_obj then--时间排序
|
|
self:SelectSort(1)
|
|
end
|
|
end
|
|
AddClickEvent(self.auction_con_obj, on_click_sort)
|
|
AddClickEvent(self.price_con_obj, on_click_sort)
|
|
AddClickEvent(self.time_con_obj, on_click_sort)
|
|
local function on_update_goods( )
|
|
self:UpdateView()
|
|
end
|
|
self.on_update_goods_id = self.model:BindOne("market_focus_list", on_update_goods)
|
|
end
|
|
|
|
function MarketFocusView:SelectSort( index )
|
|
self.sort_id = index
|
|
self.sort_order = self.sort_data[index] == 1 and 1 or 0
|
|
self.sort_data[index] = self.sort_data[index] == 1 and 0 or 1
|
|
if index == 1 then
|
|
self.time_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
|
|
elseif index == 2 then
|
|
self.auction_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
|
|
elseif index == 3 then
|
|
self.price_arrow.localRotation = self.sort_data[index] == 1 and Quaternion.Euler(0,0,0) or Quaternion.Euler(0,0,180)
|
|
end
|
|
self:UpdateView()
|
|
end
|
|
|
|
function MarketFocusView:UpdateView( )
|
|
local data = DeepCopy(self.model:GetMarketFocusList(self.cur_hor_tab_index))
|
|
if self.sort_id == 1 then--时间排序
|
|
if self.sort_data[self.sort_id] == 1 then--从小到大
|
|
local sort_func = function ( a, b )
|
|
return a.end_time < b.end_time
|
|
end
|
|
table.sort(data, sort_func)
|
|
else
|
|
local sort_func = function ( a, b )
|
|
return a.end_time > b.end_time
|
|
end
|
|
table.sort(data, sort_func)
|
|
end
|
|
elseif self.sort_id == 2 then--一口价排序
|
|
if self.sort_data[self.sort_id] == 1 then--从小到大
|
|
local sort_func = function ( a, b )
|
|
return a.price < b.price
|
|
end
|
|
table.sort(data, sort_func)
|
|
else
|
|
local sort_func = function ( a, b )
|
|
return a.price > b.price
|
|
end
|
|
table.sort(data, sort_func)
|
|
end
|
|
elseif self.sort_id == 3 then--竞拍价排序
|
|
if self.sort_data[self.sort_id] == 1 then--从小到大
|
|
local sort_func = function ( a, b )
|
|
return a.get_price < b.get_price
|
|
end
|
|
table.sort(data, sort_func)
|
|
else
|
|
local sort_func = function ( a, b )
|
|
return a.get_price > b.get_price
|
|
end
|
|
table.sort(data, sort_func)
|
|
end
|
|
end
|
|
if TableSize(data) == 0 then
|
|
self.empty_obj:SetActive(true)
|
|
if self.cur_hor_tab_index == 1 then--全部
|
|
self.empty_text_tmp.text = "您还没有竞拍或关注哦~"
|
|
elseif self.cur_hor_tab_index == 2 then--竞拍
|
|
self.empty_text_tmp.text = "您还没有竞拍哦~"
|
|
elseif self.cur_hor_tab_index == 3 then--关注
|
|
self.empty_text_tmp.text = "您还没有关注的商品哦~"
|
|
end
|
|
else
|
|
self.empty_obj:SetActive(false)
|
|
end
|
|
if not self.item_list_com then
|
|
self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
|
|
end
|
|
if self.item_list_com then
|
|
self.item_list_com:Reset()
|
|
end
|
|
local info = {
|
|
data_list = data,
|
|
item_con = self.right_con,
|
|
item_class = MarketFocusItem,
|
|
start_y = 0, start_x = 22,
|
|
item_width = 1060,
|
|
item_height = 100,
|
|
space_y = 0,
|
|
scroll_view = self.right_scroll.transform,
|
|
create_frequency = 0.01,
|
|
create_num_per_time = 3,
|
|
is_scroll_back_on_update = false,
|
|
on_update_item = function(item, i, v)
|
|
item:SetData(i, v)
|
|
end,
|
|
}
|
|
self.item_list_com:UpdateItems(info)
|
|
end
|
|
|
|
function MarketFocusView:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function MarketFocusView:SetHorTabCon( )
|
|
for i,v in ipairs(self.tab_item_list) do
|
|
v:SetVisible(false)
|
|
end
|
|
local data = {"全部", "正在竞价", "已关注"}
|
|
local function click_func( index )
|
|
self:SwitchHorTab(index)
|
|
end
|
|
local count = 0
|
|
for i,v in ipairs(data) do
|
|
local item = self.tab_item_list[count+1]
|
|
if not item then
|
|
item = MarketHorTabItem.New(self.tab_con)
|
|
item:SetPosition(count * 124, 0)
|
|
self.tab_item_list[count+1] = item
|
|
end
|
|
item:SetClickFunc(click_func)
|
|
count = count + 1
|
|
item:SetData(count, v)
|
|
item:SetVisible(true)
|
|
end
|
|
self:SwitchHorTab(self.cur_hor_tab_index)
|
|
end
|
|
|
|
function MarketFocusView:SwitchHorTab( index )
|
|
for i,v in pairs(self.tab_item_list) do
|
|
v:SetSelect(i==index)
|
|
end
|
|
self.cur_hor_tab_index = index--当前选的tab
|
|
self:UpdateView()
|
|
end
|
|
|
|
function MarketFocusView:__delete( )
|
|
if self.on_update_goods_id then
|
|
self.model:UnBind(self.on_update_goods_id)
|
|
self.on_update_goods_id = nil
|
|
end
|
|
|
|
for _, v in pairs(self.tab_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.tab_item_list = {}
|
|
end
|