|
|
- WardrobeShopView = WardrobeShopView or BaseClass(BaseItem)
- local WardrobeShopView = WardrobeShopView
- WardrobeShopView.SHOP_TYPE = {
- SINGLE = 1,
- DOUBLE = 2,
- }
- local table_insert = table.insert
- function WardrobeShopView:__init()
- self.base_file = "wardrobe"
- self.layout_file = "WardrobeShopView"
- self.model = WardrobeModel:GetInstance()
- self.cur_tab_index = 1
- self.tab_item_list = {}--左边tab
- self.top_goods_item_list = {}--主打商品表
- self.shop_bg_position = {
- [1] = {x = 30.5, y = 7.5},
- [2] = {x = 140.5, y = 90.5},
- }
- self.ani_left = -200
- self.ani_right = 400
- self.adjust_mid = {left = 50, right = 640}
- self:Load()
- end
-
- function WardrobeShopView:Load_callback()
- self.nodes = {
- "right/help_btn:obj", "right/bg:raw",
- "right/item_scroll/Viewport/item_con", "right/item_scroll:obj",
- "left/tab_con",
- "right/shop_scroll/Viewport/shop_item", "right/shop_scroll:obj",
- --中间总览
- "mid/total_mid_con/icon_image:obj:img", "mid/icon_small_image:obj:img",
- "mid/total_mid_con/wardrobe_text:txt", "mid/total_mid_con:obj",
- --中间商城
- "mid/shop_mid_con/shop_bg2:obj:img", "mid/shop_mid_con/shop_bg1:obj:img", "mid/shop_mid_con:obj",
- "mid/shop_mid_con/tip_bg:obj", "mid/shop_mid_con/tip_text:tmp",
- "mid/shop_mid_con/shop_bg2/shop_item_con2", "mid/shop_mid_con/shop_bg1/shop_item_con1",
- }
- self:GetChildren(self.nodes)
- lua_resM:setOutsideImageSprite(self, self.shop_bg1_img, GameResPath.GetWardrobeImage("wardrobe_shop_mid_bg"))
- lua_resM:setOutsideImageSprite(self, self.shop_bg2_img, GameResPath.GetWardrobeImage("wardrobe_shop_mid_bg"))
- self:AddEvents()
- if self.need_refreshData then
- self:UpdateView()
- end
- end
-
- function WardrobeShopView:AddEvents( )
- local function on_click( target )
- if self.help_btn_obj == target then
- GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 42200)
- end
- end
- AddClickEvent(self.help_btn_obj, on_click)
-
- local function on_update_total( )
- self:UpdateTabItem()
- self:UpdateTotalList()
- end
- self.on_update_total_id = self.model:BindOne("wardrobe_total_info", on_update_total)
-
- local function on_update_shop( )
- self:UpdateShopList()
- end
- self.on_update_shop_id = self.model:BindOne("wardrobe_shop_info", on_update_shop)
- end
-
- function WardrobeShopView:UpdateView( )
- self:UpdateTabItem()
- self:SwitchTab(self.cur_tab_index)
- end
-
- function WardrobeShopView:SetData( index, sub_index )
- self.cur_tab_index = sub_index or self.cur_tab_index
- if sub_index then
- self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, sub_index - 1)
- end
- if self.is_loaded then
- self.need_refreshData = false
- self:UpdateView()
- else
- self.need_refreshData = true
- end
- end
-
- function WardrobeShopView:SwitchTab( index )
- if self.cur_tab_index ~= index and index ~= 1 then
- self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, index - 1)
- end
- self.cur_tab_index = index
- self.icon_small_image_obj:SetActive(self.cur_tab_index ~= 1)
- self.item_scroll_obj:SetActive(self.cur_tab_index == 1)
- self.shop_scroll_obj:SetActive(self.cur_tab_index ~= 1)
- self.total_mid_con_obj:SetActive(self.cur_tab_index == 1)
- self.shop_mid_con_obj:SetActive(self.cur_tab_index ~= 1)
- if self.cur_tab_index == 1 then--选中总览了
- self:UpdateTotalList()
- else
- self:UpdateShopList()
- end
- for i,v in ipairs(self.tab_item_list) do
- v:SetItemSelect(self.cur_tab_index)
- end
- end
-
- function WardrobeShopView:UpdateTabItem( )
- local data = DeepCopy(Config.Wardrobeopen)
- table_insert(data, 1, {store_name = "风采总览",condition = 0, icon = 0})
- local height = 56
- local y_offset = 10
- local function call_back_func( index)
- self:SwitchTab(index)
- end
- if not self.tab_data then
- self.tab_data = data
- end
- for i,v in ipairs(data) do
- local item = self.tab_item_list[i]
- if not item then
- item = WardrobeVerTabItem.New(self.tab_con)
- item:SetPosition(0, -(i - 1) * (height + y_offset))
- self.tab_item_list[i] = item
- end
- item:SetData(v,i, call_back_func, self.cur_tab_index)
- end
- end
-
- function WardrobeShopView:UpdateShopList( )
- local cfg_data = Config.Wardrobeopen
- if cfg_data and cfg_data[self.cur_tab_index - 1] then
- local cur_stage = self.model:GetMyWardrobeStage()
- if cur_stage < cfg_data[self.cur_tab_index - 1].condition then
- self.tip_bg_obj:SetActive(true)
- if Config.Wardrobestage[cfg_data[self.cur_tab_index - 1].condition] then
- self.tip_text_tmp.text = string.format("风采值达到 %s 解锁本货柜", HtmlColorTxt(Config.Wardrobestage[cfg_data[self.cur_tab_index - 1].condition].low_value, "#FDFFC2"))
- end
- else
- self.tip_bg_obj:SetActive(false)
- self.tip_text_tmp.text = ""
- end
- else
- self.tip_bg_obj:SetActive(false)
- self.tip_text_tmp.text = ""
- end
- if not self.tab_data or self.cur_tab_index == 1 then--没有构造好数据的时候不让进来
- return
- end
- local cfg_data = self.model:GetWardrobeShopCFGByID(self.tab_data[self.cur_tab_index].store_id)
- local server_data = self.model:GeteWardrobeShopInfo(self.tab_data[self.cur_tab_index].store_id)
- local data = {}
- local top_data = {}
- for i,v in pairsByKeys(cfg_data) do
- if v.is_top == 1 then--是主打
- if TableSize(top_data) < 2 and server_data[v.pos] then--有服务端数据才插进去
- table_insert(top_data, v)
- elseif server_data[v.pos] then--有服务端数据才插进去
- table_insert(data, v)
- end
- elseif server_data[v.pos] then--有服务端数据才插进去
- table_insert(data, v)
- end
- end
- self:UpdateTopGoods(top_data, server_data)
- if not self.shop_item_list_com then
- self.shop_item_list_com = self:AddUIComponent(UI.ItemListCreator)
- end
- self.shop_item_list_com:Reset()
- local info = {
- data_list = data,
- item_con = self.shop_item,
- item_class = WardrobeShopItem,
- item_height = 157,
- item_width = 126,
- start_x = 0,
- space_x = 2,
- start_y = 0,
- scroll_view = self.shop_scroll.transform,
- create_frequency = 0.05,
- is_scroll_back_on_update = false,
- child_names = child_names,
- on_update_item = function(item, i, v)
- item:SetData(v,i)
- item:SetServerData(server_data[v.pos])
- end,
- }
- self.shop_item_list_com:UpdateItems(info)
- end
-
- --更新主打商品
- function WardrobeShopView:UpdateTopGoods( data, server_data)
- local len = TableSize(data)
- for i,v in ipairs(self.top_goods_item_list) do
- v:SetVisible(false)
- end
- if len == 0 then
- self.shop_bg1_obj:SetActive(false)
- self.shop_bg2_obj:SetActive(false)
- elseif len == 1 then
- self.shop_bg1_obj:SetActive(true)
- self.shop_bg2_obj:SetActive(false)
- SetAnchoredPosition(self.shop_bg1,self.shop_bg_position[len].x, self.shop_bg_position[len].y)
- else
- self.shop_bg1_obj:SetActive(true)
- self.shop_bg2_obj:SetActive(true)
- SetAnchoredPosition(self.shop_bg1,self.shop_bg_position[len].x, self.shop_bg_position[len].y)
- end
- for i,v in ipairs(data) do
- local item = self.top_goods_item_list[i]
- if not item then
- item = WardrobeShopItem.New(self["shop_item_con"..i])
- self.top_goods_item_list[i] = item
- end
- item:SetData(v,i)
- item:SetServerData(server_data[v.pos])
- end
- end
-
- function WardrobeShopView:UpdateTotalList( )
- local total_data = self.model:GetWardrobeTotalInfo()
- local total_list = total_data.wardrobe_list or {}
- self.wardrobe_text_txt.text = total_data.sum_wardrobe_value
- local res_name = string.format("wardrobe_level%s", total_data.stage or 1)
- lua_resM:setOutsideImageSprite(self, self.icon_image_img, GameResPath.GetWardrobeImage(res_name), true)
- lua_resM:setOutsideImageSprite(self, self.icon_small_image_img, GameResPath.GetWardrobeImage(res_name), true)
- if not self.total_item_list_com then
- self.total_item_list_com = self:AddUIComponent(UI.ItemListCreator)
- end
- local info = {
- data_list = total_list,
- item_con = self.item_con,
- item_class = WardrobeTotalItem,
- item_height = 107,
- start_x = 11,
- start_y = -8,
- scroll_view = self.item_scroll.transform,
- create_frequency = 0.05,
- is_scroll_back_on_update = false,
- child_names = child_names,
- on_update_item = function(item, i, v)
- item:SetData(v,i)
- end,
- }
- self.total_item_list_com:UpdateItems(info)
- end
-
- function WardrobeShopView:UpdateMidInfo( )
- end
-
- function WardrobeShopView:__delete( )
- for i,v in ipairs(self.tab_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.tab_item_list = {}
-
- if self.on_update_total_id then
- self.model:UnBind(self.on_update_total_id)
- self.on_update_total_id = nil
- end
-
- if self.on_update_shop_id then
- self.model:UnBind(self.on_update_shop_id)
- self.on_update_shop_id = nil
- end
-
- for i,v in ipairs(self.top_goods_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.top_goods_item_list = {}
- end
|