|
|
- GetGoodsItem = GetGoodsItem or BaseClass(BaseItem)
-
- function GetGoodsItem:__init()
- self.base_file = "common"
- self.layout_file = "GetGoodsItem"
- self.is_delay_callback = true
- self.can_buy = false
- self.model = BagModel:getInstance()
- self.need_refresh = false
-
- self.is_default_get_way = false
- self.show_type = false
- self.get_des_id = 0
-
- self:Load()
- end
-
- function GetGoodsItem:Load_callback()
- local nodes = {
- "buy_group/goods_name:tmp",
- "item_con:obj",
- "go_group/way_name:tmp",
- "bg", "go_group/go:obj",
- "buy_group/price_type:img",
- "buy_group/buy:obj:imgex",
- "buy_group:obj",
- "buy_group/price_num:tmp",
- "buy_group/goods_from:tmp",
- "icon:img:obj",
- "go_group:obj",
- "is_special:obj",
- "buy_group/buy/buy_text:tmp",
- "go_group/get_des:tmp",
- }
-
- self:GetChildren(nodes)
-
- self:InitEvent()
-
- if self.need_refresh then
- self:SetData(self.data, self.type_id, self.callback)
- end
- end
-
- function GetGoodsItem:InitEvent()
- local function onBtnClickHandler(target)
- if target == self.go_obj then
- self:GoFunc()
- elseif target == self.buy_obj then
- if self.shop_config and self.can_buy and self.total_cost then
- if self.show_type == "shop" then
- if self.shop_config.money_type == 1 or self.shop_config.money_type == 2 then
- local function ok_callback( ... )
- ShopModel:getInstance():Fire(ShopModel.BUY_GOODS, self.shop_config.key_id, 1)
- end
- local function toggle_function( flag )
- self.model.bag_quick_buy_toggle = flag
- end
- local function use_function( toggle_tip_data,call_fun_sum )
- print('Cat:GetGoodsItem.lua[54] self.model.bag_quick_buy_toggle', self.model.bag_quick_buy_toggle)
- if not self.model.bag_quick_buy_toggle then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- call_fun_sum()
- end
- end
- local function recharge_open_call_back()
- self.model:Fire(BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS)
- end
- local buy_tip_data = {
- gold_type = self.shop_config.money_type,--货币类型
- cost_price = self.total_cost,--消耗金额
- ok_callback = ok_callback,--成功
- toggle_function = toggle_function,--多选
- togglePriceStr = string.format("<color=#fdffc2>%s</color> 购买商品",self.total_cost),--提示语
- use_function = use_function,--最终调用
- recharge_open_call_back = recharge_open_call_back,
- }
- CustomActivityModel:getInstance():BuyTips(buy_tip_data)
- else
- ShopModel:getInstance():Fire(ShopModel.BUY_GOODS, self.shop_config.key_id, 1)
- end
- else
- self.model:Fire(BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS)
- local temp_cfg = Config.Shop[self.shop_config.key_id]
- GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, temp_cfg.shop_type, temp_cfg.sub_type, temp_cfg.goods_id, nil, true)
- end
- else
- Message.show("当前商品已售空,请耐心等待补货")
- end
- end
- end
- AddClickEvent(self.go_obj, onBtnClickHandler)
- AddClickEvent(self.buy_obj, onBtnClickHandler)
-
- local function buy_suceess()
- self.shop_config = self:GetShopData(self.type_id, self.data)
- self:CheckCanBuy(self.shop_config)
- end
- self:BindEvent(ShopModel:getInstance(),ShopModel.UPDATE_GOODS_LIST, buy_suceess)
- end
-
- function GetGoodsItem:GoFunc()
- if self.is_default_get_way then
- Message.show("请前往运营活动")
- return
- end
- GlobalEventSystem:Fire(EventName.GOODS_TOOLS_TIPS_GO_TO_EVENT)
- if self.callback then
- self.callback()
- end
- if self.data[1] == "153" then --商城 ,是商城有可能有s第三个页签的处理
- OpenFun.Open(self.data[1], self.data[2], self.data[4])
- elseif self.data[1] == "151" then
- ComposeModel:getInstance():TryComposeJump(self.type_id)
- elseif self.data[1] == "610" and self.data[2] == "2" then -- 经验副本需要特殊处理,关闭所有的上层打开界面
- DailyModel:getInstance():Fire(DailyModel.OPEN_DAILY_COMMON_TIP_VIEW, false)
- OpenFun.Open(self.data[1], self.data[2])
- else
- OpenFun.Open(self.data[1], self.data[2])
- end
- end
-
- function GetGoodsItem:SetData(data, type_id, callback)
- self.data = data
- self.type_id = type_id
- self.callback = callback
- self.show_type = false
- if not self.data then return end
- if self.is_loaded then
- local cfg = OpenFun.GetFunCfg(self.data[1], self.data[2])
- self.get_des_id = self.data[6] and tonumber(self.data[6]) or 0
- self.is_default_get_way = false
- if cfg then
- local show_type = self.data[3] or "normal"
- local is_special = self.data[5] or "0"
- self.show_type = show_type
-
- self.shop_config = self:GetShopData(self.type_id, self.data)
- if self.shop_config then
- self.go_group_obj:SetActive(false)
- self.buy_group_obj:SetActive(true)
- self.item_con_obj:SetActive(true)
- self.icon_obj:SetActive(false)
- if not self.icon_item then
- self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
- self.icon_item:SetItemSize(62, 62)
- self.icon_item:ChangeCountVisible(false)
- --self.icon_item:SetEnableClick(false)
- end
- local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
- self.icon_item:SetData(self.type_id)
- self.goods_name_tmp.text = Language.substitute("<color={0}>{1}</color>", WordManager.GetGoodsColor(basic.color, false), Trim(basic.goods_name))
- self.price_num_tmp.text = tostring(round(self.shop_config.price * self.shop_config.discount/ 100))
- self:CheckCanBuy(self.shop_config)
- local asset, source = WordManager:GetCommonMoneyIcon(self.shop_config.money_type)
- lua_resM:setImageSprite(self, self.price_type_img, asset, source,false)
- if show_type == "shop" then
- -- SetAnchoredPosition(self.price_num, -83, -14)
- -- SetAnchoredPosition(self.price_type, -47, -14)
- -- SetAnchoredPosition(self.buy, 70, 19)
- self.goods_from_tmp.text = ""
- self.price_num_tmp.color = ColorUtil:ConvertHexToRGBColor("#ffffff")
- else --"show_two"
-
- local mid = 112
- local w = self.price_num_tmp.preferredWidth + 36
- -- SetAnchoredPosition(self.price_num, mid - w / 2 + 34, 22)
- -- SetAnchoredPosition(self.price_type, mid - w / 2, 22)
- -- SetAnchoredPosition(self.buy, 70, 0)
- self.goods_from_tmp.text = ""
- self.price_num_tmp.color = ColorUtil:ConvertHexToRGBColor("#ffffff")
- end
-
- else
- self.go_group_obj:SetActive(true)
- self.buy_group_obj:SetActive(false)
- if self.data[8] then -- 存在传入剩余次数的数据时,显示剩余次数
- self.way_name_tmp.text = self.data[8] == -1 and "次数不限"
- or string.format("剩余 <color=%s>%s</color> 次", self.data[8] > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, self.data[8])
- else
- self.way_name_tmp.text = cfg.name
- end
- local show_cfg = self.data[3] or ""
- local show_type_id = 0
- if show_cfg and show_cfg ~= "" then
- local str_list = Split(show_cfg, "_")
- if #str_list >= 2 then
- if str_list[1] == "goods" then
- show_type_id = tonumber(str_list[2])
- end
- end
- end
- if show_type == "normal" then
- self.item_con_obj:SetActive(false)
- self.icon_obj:SetActive(true)
- lua_resM:setImageSprite(self,self.icon_img,"activityIcon_asset",cfg.icon_res, false)
- SetSizeDelta(self.icon,62,62)
- else --"goods"
- self.item_con_obj:SetActive(true)
- self.icon_obj:SetActive(false)
- if not self.icon_item then
- self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
- self.icon_item:SetItemSize(62, 62)
- self.icon_item:ChangeCountVisible(false)
- --self.icon_item:SetEnableClick(false)
- end
- self.icon_item:SetData(show_type_id == 0 and self.type_id or show_type_id)
- end
- self:SetGoodGetDes()
- end
- if self.icon_item then
- if is_special == "1" then
- self.icon_item:SetNumLimitVisible(true, 16)
- else
- self.icon_item:SetNumLimitVisible(false)
- end
- end
- else
- self.is_default_get_way = true
- self.go_group_obj:SetActive(true)
- self.buy_group_obj:SetActive(false)
- self.way_name_tmp.text = "运营活动"
- lua_resM:setImageSprite(self,self.icon_img,"activityIcon_asset","icon_99_1", false)
- self:SetGoodGetDes()
- end
- else
- self.need_refresh = true
- end
- end
-
- function GetGoodsItem:__delete()
- if self.icon_item then
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.icon_item)
- self.icon_item = nil
- end
- end
-
- function GetGoodsItem:SetGoodGetDes()
- if self.get_des_id then
- local cfg = GoodsConst.GetWayDes[self.get_des_id]
- if cfg then
- SetAnchoredPositionY(self.way_name, 15)
- local str = ChuanWenManager:getInstance():FormatColorTag2(cfg.des, false)
- self.get_des_tmp.text = str
- else
- SetAnchoredPositionY(self.way_name, 3)
- end
- else
- SetAnchoredPositionY(self.way_name, 3)
- end
- end
-
- function GetGoodsItem:GetShopData(type_id, data)
- local shop_config = nil
- if type_id and data and data[1] and data[2] and data[3] and (data[3] == "shop" or data[3] == "shoptwo") then
- local list = ShopModel:getInstance():GetGoodsListInfo(tonumber(data[2]))
- for k,v in pairs(list) do
- for kk,vv in pairs(v) do
- if self.type_id == vv.goods_id then
- shop_config = vv
- break
- end
- end
- if shop_config then
- break
- end
- end
- end
- return shop_config
- end
-
- function GetGoodsItem:CheckCanBuy(shop_data)
- self.can_buy = false
- self.sold_out = false
- if shop_data then
- local limit_left_num = nil
- if shop_data.quota_type > 0 then
- local left_num = shop_data.quota_num - shop_data.sold_out
- left_num = left_num > 0 and left_num or 0
- limit_left_num = left_num
- else
- limit_left_num = nil
- end
-
- price = round(shop_data.price * shop_data.discount / 100)
- local money_num = GoodsModel:getInstance():GetGoodsNumFromType(shop_data.money_type)
- local limit_num = money_num / price
- limit_num = math.floor(limit_num)
- if limit_left_num then--如果是限购 先对比
- limit_num = limit_num > limit_left_num and limit_left_num or limit_num
- end
- limit_num = limit_num > 0 and limit_num or 1
- self.can_buy = limit_num > 0
- self.sold_out = limit_left_num ~= nil and limit_left_num == 0
- self.buy_imgex.gray = self.sold_out
- if self.sold_out then
- self.buy_text_tmp.text =HtmlColorTxt("已售完", "#ffffff")
- SetTMPSharedMaterial(self.buy_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
- else
- self.total_cost = price
- self.buy_text_tmp.text = HtmlColorTxt(self.show_type == "shop" and "购买" or "前往购买", "#ffffff")
- SetTMPSharedMaterial(self.buy_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
- end
- end
- end
-
|