|
|
- AddTimeView = AddTimeView or BaseClass(BaseView)
- local AddTimeView = AddTimeView
- AddTimeView.Type = {
- DESIGNATION = 1,
- FASHION = 2,
- }
- --通用续时界面
- function AddTimeView:__init()
- self.base_file = "uiComponent"
- self.layout_file = "AddTimeView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = true --全屏界面默认使用这个参数
- self.change_scene_close = true
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = false --是否要显示顶部的金钱栏
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.switch_callback = function(index)
- self:SwitchTab(index)
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function AddTimeView:Open( data)
- self.data = data
- BaseView.Open(self)
- end
-
- function AddTimeView:LoadSuccess()
- local nodes = {
- "num_text:txt","name_text:txt","add_num_con","bg:raw","close_btn:obj",
- "rest_time_text:txt","btn:obj","add_time_text:txt","title_text:txt",
- "item_con","goods_name_text:txt",
- }
- self:GetChildren(nodes)
- lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("add_time_bg"),false)
- self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
- self.awardItem:SetItemSize(59, 59)
- self.addNumComponent = AddNumberComponent.New(self.add_num_con)
- self.addNumComponent:SetComponentWidth(380)
- self.addNumComponent:SetVisibleCalcBtn(false)
- end
-
- function AddTimeView:AddEvent()
- local function on_click( target )
- if target == self.btn_obj then
- if self.data.type == AddTimeView.Type.DESIGNATION then
- if self.count > 0 then
- DesignationModel:GetInstance():Fire(DesignationModel.REQUEST_DESIGNATION, 41106, self.data.goods_id, self.data.id, self.count)
- else
- Message.show("您没有该物品哦~")
- end
- elseif self.data.type == AddTimeView.Type.FASHION then
- if self.count > 0 then
- FashionModel:GetInstance():Fire(FashionEvent.REQUEST_FASHION_PROTOCOL, 41304, self.data.goods_id, self.data.id, self.count)
- else
- Message.show("您没有该物品哦~")
- end
- end
- self:Close()
- elseif target == self.close_btn_obj then
- self:Close()
- end
- end
- AddClickEvent(self.btn_obj, on_click)
- AddClickEvent(self.close_btn_obj, on_click)
-
- local function onChangeCountHandler(count)
- self:SetCountNum(count)
- end
- self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT, onChangeCountHandler)
- end
-
- function AddTimeView:OpenSuccess()
- self:UpdateView()
- end
-
- function AddTimeView:UpdateView()
- local rest_time = 0
- if self.data.type == AddTimeView.Type.DESIGNATION then
- rest_time = DesignationModel:GetInstance():GetDesignationRestTimeById(self.data.id)
- rest_time = rest_time > 0 and rest_time or 0
- self.rest_time_text_txt.text = string.format("剩余时间:%s", TimeUtil:timeConvert10(rest_time, true))
- self.title_text_txt.text = "称号续费"
- self.goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.goods_id)
- local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, true)
- self.num_text_txt.text = HtmlColorTxt(self.goods_num, ColorUtil.GREEN_DARK)
- self.goods_name_text_txt.text = goods_name
- self.name_text_txt.text = DesignationModel:GetInstance():GetDesignationNameById(self.data.id)
- self.awardItem:SetData(self.data.goods_id, 1, nil, nil, nil, nil, nil, self.mask_id)
- self.addNumComponent:InitData(1, self.goods_num, 1, 1, 12)
- self:SetCountNum(self.goods_num > 0 and 1 or 0)
- elseif self.data.type == AddTimeView.Type.FASHION then
- rest_time = FashionModel:GetInstance():GetFashionRestTimeById(self.data.id)
- rest_time = rest_time > 0 and rest_time or 0
- self.rest_time_text_txt.text = string.format("剩余时间:%s", TimeUtil:timeConvert10(rest_time, true))
- self.title_text_txt.text = "时装续费"
- self.goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.data.goods_id)
- local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, true)
- local fashion_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, false)
- self.num_text_txt.text = HtmlColorTxt(self.goods_num, ColorUtil.GREEN_DARK)
- self.goods_name_text_txt.text = goods_name
- self.name_text_txt.text = fashion_name
- self.awardItem:SetData(self.data.goods_id, 1, nil, nil, nil, nil, nil, self.mask_id)
- self.addNumComponent:InitData(1, self.goods_num, 1, 1, 12)
- self:SetCountNum(self.goods_num > 0 and 1 or 0)
- end
- end
-
- function AddTimeView:SetCountNum( count )
- self.count = count
- if self.data.type == AddTimeView.Type.DESIGNATION then
- local expire_time = 0
- local cfg = Config.Dsgt[self.data.id]
- if cfg then
- expire_time = cfg.expire_time
- end
- self.add_time_text_txt.text = TimeUtil:timeConvert10(expire_time * self.count, true)
- elseif self.data.type == AddTimeView.Type.FASHION then
- local career = RoleManager.Instance.mainRoleInfo.career
- local cfg = Config.Fashionmodel[self.data.id.."@"..career]
- local expire_time = 0
- if cfg then
- expire_time = cfg.expire_time
- end
- self.add_time_text_txt.text = TimeUtil:timeConvert10(expire_time * self.count, true)
- end
- end
-
- function AddTimeView:DestroySuccess( )
- if self.awardItem then
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
- self.awardItem = nil
- end
-
- if self.addNumComponent then
- if self.change_count_id then
- self.addNumComponent:UnBind(self.change_count_id)
- self.change_count_id = nil
- end
- self.addNumComponent:DeleteMe()
- self.addNumComponent = nil
- end
- end
|