|
|
- MarketFocusItem = MarketFocusItem or BaseClass(BaseItem)
- local MarketFocusItem = MarketFocusItem
-
- function MarketFocusItem:__init()
- self.base_file = "market"
- self.layout_file = "MarketFocusItem"
- self.model = MarketModel:GetInstance()
-
- self:Load()
- end
-
- function MarketFocusItem:Load_callback()
- self.nodes = {
- "time_text:tmp","one_price_text:tmp","auction_price_text:tmp","focus_btn:obj:img","my_price_text:tmp",
- "buy_btn:obj:imgex","auction_btn/auction_btn_text:tmp","auction_btn:obj:imgex","name_text:tmp","item_con",
- "show_image:obj","my_icon:obj","my_image:obj","one_image:obj","auction_image:obj","my_text:tmp:obj",
- "focus_text:tmp", "buy_btn/buy_btn_text:tmp",
- }
- self:GetChildren(self.nodes)
-
- self.awardItem = UIObjPool:PopItem(UIObjPool.UIType.AwardItem,self.item_con)
- self.awardItem:SetEnableClick(false)
- self.awardItem:SetItemSize(78, 78)
- self:AddEvents()
- if self.need_refreshData then
- self:UpdateView()
- end
- end
-
- function MarketFocusItem:AddEvents( )
- function on_click( target )
- if target == self.focus_btn_obj then
- if self.is_like then
- self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15511, self.data.id)
- else
- self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15510, self.data.id)
- end
- elseif target == self.auction_btn_obj then
- if self.is_my_sales then
- Message.show("不能购买自己的商品哦~")
- return
- end
- if self.no_auction_price then
- Message.show("该商品不能竞拍购买哦~")
- else
- self.model:Fire(MarketModel.OPEN_MARKET_BUY_VIEW, self.data, MarketModel.AUCTION_PRICE_TYPE)
- end
- elseif target == self.buy_btn_obj then
- if self.is_my_sales then
- Message.show("不能购买自己的商品哦~")
- return
- end
- if self.no_one_price then
- Message.show("该商品不能一口价购买哦~")
- else
- self.model:Fire(MarketModel.OPEN_MARKET_BUY_VIEW, self.data, MarketModel.ONE_PRICE_TYPE)
- end
- end
- end
- AddClickEvent(self.buy_btn_obj, on_click)
- AddClickEvent(self.focus_btn_obj, on_click)
- AddClickEvent(self.auction_btn_obj, on_click)
- local function onBtnClickHandler(target, x, y)
- if target == self.gameObject then
- local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.type_id)
- if goods_vo.type == GoodsModel.TYPE.EQUIP then
- UIToolTipMgr:getInstance():AppendEquipTips(self.data.type_id, x, y, self.data, nil, nil, {"buyBtn"},"market_buy")
- else
- local can_auction = self.model:IsGoodsCanAuction(self.data.type_id) and self.can_auction
- local can_buy_one = self.model:IsGoodsCanBuyOnePrice(self.data.type_id)
- if can_auction and can_buy_one then
- UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketBuyBtn","marketActionBtn"}, nil, true)
- elseif can_auction and not can_buy_one then
- UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketActionBtn"}, nil, true)
- elseif can_buy_one and not can_auction then
- UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketBuyBtn"}, nil, true)
- end
- end
- end
- end
- AddClickEvent(self.gameObject, onBtnClickHandler)
-
- local function on_price_up( id, price )
- if self.data.id == id then
- self.data.price = price
- self:UpdateView()
- end
- end
- self:BindEvent(self.model, MarketModel.UPDATE_ONE_GOODS_BY_PRICE_UP, on_price_up)
- end
-
- function MarketFocusItem:UpdateView( )
- self.name_text_tmp.text = GoodsModel:getInstance():getGoodsName(self.data.type_id,true)
- local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.type_id)
- self.is_my_sales = self.data.role_id == RoleManager.Instance.mainRoleInfo.role_id
- if goods_vo.buyout_price == 0 then
- self.one_price_text_tmp.text = "无"
- self.no_one_price = true
- else
- self.one_price_text_tmp.text = self.data.get_price
- self.no_one_price = false
- end
-
- if goods_vo.trade_price == 0 then
- self.auction_price_text_tmp.text = "无"
- self.no_auction_price = true
- else
- if self.data.aution_num > 0 then--出过价的要变色
- self.auction_price_text_tmp.text = HtmlColorTxt(self.data.price, ColorUtil.YELLOW_DARK)
- self.my_text_tmp.text = "该商品正在竞价中"
- else
- self.auction_price_text_tmp.text = self.data.price
- end
- self.no_auction_price = false
- end
- local market_show_time = goods_vo.market_show_time
- local equip_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.data)
- equip_data.equip_key = "EquipView"
- GoodsModel:getInstance():SetBaseInfo(equip_data.goods_vo)
- equip_data.goods_vo.is_market = true
- self.awardItem:SetData(self.data.type_id, self.data.goods_num, nil, equip_data)
- local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(equip_data.goods_vo)
- self.awardItem:ChangeEquipState(flag)
- if self.data.up_time + market_show_time > TimeUtil:getServerTime( ) then
- self.rest_time = self.data.up_time + market_show_time - TimeUtil:getServerTime( )
- self.is_show_time = true
- else
- self.rest_time = self.data.end_time - TimeUtil:getServerTime( )
- self.is_show_time = false
- end
- self.is_like = self.data.is_like == 1 and true or false
- if self.is_like then
- lua_resM:setImageSprite(self, self.focus_btn_img, "market_asset", "market_icon1",true)
- self.focus_text_tmp.text = "已关注"
- else
- lua_resM:setImageSprite(self, self.focus_btn_img, "market_asset", "market_icon2",true)
- self.focus_text_tmp.text = "关注"
- end
-
- self.focus_btn_obj:SetActive(goods_vo.market_show_time > 0)
- SetAnchoredPositionY(self.name_text, goods_vo.market_show_time > 0 and 20 or 0)
- if self.is_show_time then
- self.focus_text_tmp.text = "开拍提醒"
- else
- if goods_vo.market_show_time > 0 then
- self.focus_text_tmp.text = (self.is_like) and "取消关注" or "关注"
- else
- self.focus_text_tmp.text = ""
- end
- end
-
- self.can_auction = true
- if self.data.role_id > 655 and self.data.sell_type == 2 and not self.no_one_price then --公会拍卖玩家上架且有一口价的不能竞拍
- self.can_auction = false
- end
- self.show_image_obj:SetActive(self.is_show_time)
- if self.no_one_price or self.is_my_sales then
- self.buy_btn_imgex.gray = true
- SetTMPSharedMaterial(self.buy_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
- else
- self.buy_btn_imgex.gray = self.is_show_time
- if self.is_show_time then
- SetTMPSharedMaterial(self.buy_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
- else
- SetTMPSharedMaterial(self.buy_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
- end
- end
- if self.no_auction_price then
- self.auction_btn_imgex.gray = true
- SetTMPSharedMaterial(self.auction_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
- else
- self.auction_btn_imgex.gray = self.is_show_time or not self.can_auction
- if self.is_show_time or not self.can_auction then
- SetTMPSharedMaterial(self.auction_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
- else
- SetTMPSharedMaterial(self.auction_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
- end
- end
- -- self.my_price_text_tmp.text = self.data.my_price > 0 and self.data.my_price or ""
- -- if self.data.my_price == self.data.price and self.data.price > 0 then
- -- self.auction_btn_text_tmp.text = "出价最高"
- -- self.my_text_tmp.text = "您的出价"
- -- self:SetMyPriceConVisible(true)
- -- lua_resM:setImageSprite(self, self.my_image_img, "market_asset", "market_item5", true)
- -- else
- -- self.my_text_tmp.text = "您的出价"
- -- self:SetMyPriceConVisible(self.data.my_price > 0)
- -- lua_resM:setImageSprite(self, self.my_image_img, "market_asset", "market_item15", true)
- -- end
- self.auction_btn_text_tmp.text = "竞价"
- if self.data.my_price == self.data.price and self.data.price > 0 then
- self.my_text_tmp.text = "亲,目前您的出价最高"
- elseif self.data.my_bid == 1 then
- self.my_text_tmp.text = HtmlColorTxt("您的出价已被超过", ColorUtil.RED_DARK)
- end
- self:SetMyPriceConVisible(self.data.my_price > 0 or self.data.aution_num > 0)
- if not self.time_str then
- self:UpdateTime()
- end
- end
-
- function MarketFocusItem:UpdateTime( )
- self.time_str = "MarketFocusItem"..self.index
- if self.rest_time>0 then
- local function time_callback( ... )
- self.rest_time = self.rest_time - 1
- if self.rest_time>=0 then
- self.time_text_tmp.text = TimeUtil:convertTime(self.rest_time)
- else
- if self.is_show_time then--如果是公示期到了,就刷新一下时间
- self:UpdateView()
- else
- self.time_text_tmp.text = HtmlColorTxt("已到期", ColorUtil.RED_DARK)
- self.model:DeleteFuncCallBack(self.time_str)
- self.time_str = nil
- end
- end
- end
- self.model:SetFuncCallBack(time_callback, self.time_str)
- else
- if self.is_show_time then--如果是公示期到了,就刷新一下时间
- self:UpdateView()
- else
- self.time_text_tmp.text = HtmlColorTxt("已到期", ColorUtil.RED_DARK)
- self.model:DeleteFuncCallBack(self.time_str)
- self.time_str = nil
- end
- end
- end
-
- function MarketFocusItem:SetData(index, data )
- self.index = index
- self.data = data
- if self.is_loaded then
- self.need_refreshData = false
- self:UpdateView()
- else
- self.need_refreshData = true
- end
- end
-
- function MarketFocusItem:SetMyPriceConVisible( bool )
- -- self.my_image_obj:SetActive(bool)
- -- self.my_icon_obj:SetActive(bool)
- -- self.my_text_obj:SetActive(bool)
- self.my_image_obj:SetActive(bool)
- self.my_text_obj:SetActive(bool)
- self.my_icon_obj:SetActive(false)
- end
-
- function MarketFocusItem:__delete( )
- if self.time_str then
- self.model:DeleteFuncCallBack(self.time_str)
- end
- if self.awardItem then
- UIObjPool:PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
- self.awardItem = nil
- end
- if self.on_update_view_id then
- self.model:UnBind(self.on_update_view_id)
- self.on_update_view_id = nil
- end
- end
|