|
|
- GoodsBatchBuyView = GoodsBatchBuyView or BaseClass(BaseView)
- local GoodsBatchBuyView = GoodsBatchBuyView
- -- 批量购买界面
- function GoodsBatchBuyView:__init(parent)
- self.base_file = "bag"
- self.layout_file = "GoodsBatchBuyView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = true
- self.change_scene_close = true
- self.is_set_zdepth = true
-
- --回调方法
- self.load_callback = function()
- self:LoadSuccess()
- self:InitEvent()
- end
-
- self.open_callback = function()
- self:SetData()
- end
-
- self.close_callback = function()
- local vo = ItemUseModel:getInstance():GetItemShowVo()
- if vo then
- GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
- end
- end
-
- self.destroy_callback = function()
- self:Clear()
- end
- end
-
- function GoodsBatchBuyView:LoadSuccess()
- self.cancelBtn = self:GetChild("cancelBtn").gameObject
- self.okBtn = self:GetChild("okBtn").gameObject
-
- self.nameText = self:GetChild("nameText"):GetComponent("Text")
- self.itemCon = self:GetChild("itemCon")
- self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.itemCon)
- self.awardItem:SetItemSize(108,108)
- self.addNumComponent = AddNumberComponent.New(self:GetChild("addNumCon"))
- self.addNumComponent:SetComponentWidth(422)
- local function onChangeCountHandler(count)
- self:ChangeCount(count)
- end
- self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT, onChangeCountHandler)
- self.addNumComponent:SetVisibleCalcBtn(false)
- self.addNumComponent:InitData(1, 99, 1, 1, 6)
-
- local nodes = {
- "Window:raw",
- }
- self:GetChildren(nodes)
- lua_resM:setOutsideRawImage(self, self.Window_raw, GameResPath.GetViewBigBg("tips_comm_bg6"), false)
- end
-
- function GoodsBatchBuyView:InitEvent()
- local function onClickHandler(target)
- if target == self.cancelBtn then
- self:Close()
- elseif target == self.okBtn then
- self:BtnCall()
- end
- end
- AddClickEvent(self.cancelBtn,onClickHandler)
- AddClickEvent(self.okBtn,onClickHandler)
-
- -- local function onChangeCountHandler(count)
- -- self:ChangeCount(count)
- -- end
- -- self.change_count_id = self.addNumComponent:Bind(ComponentEvent.AddNumberComponent.CHANGE_COUNT,onChangeCountHandler)
- end
-
- function GoodsBatchBuyView:Open(goods_id, cur_count, max_count)
- self.goods_id = goods_id
- self.cur_count = cur_count
- self.max_count = max_count
- self.vo = GoodsModel:getInstance():GetBagGoodsInfoById(goods_id)
-
- BaseView.Open(self)
- end
-
- function GoodsBatchBuyView:SetData( )
- if not self.vo or not self.vo.type_id then return end
- local bagGoods = GoodsModel:getInstance():GetBagGoodsInfoById(self.goods_id)
- local has_num = bagGoods.goods_num --单独数量,不是绑定+非绑定数量
- if self.max_count and has_num >= self.max_count then
- has_num = self.max_count
- end
- self.awardItem:SetData(self.vo.type_id, has_num, nil, nil, nil, nil, nil, nil, nil, true)
-
-
- self.nameText.text = "<color="..WordManager.GetGoodsColor(self.vo.color)..">" .. Trim(self.vo.goods_name).."</color>"
-
- if self.vo.type==38 and self.vo.subtype==7 then
- local max = OffLineModel:getInstance():GetNumMax(self.vo.type_id)
- if has_num < max then
- max = has_num
- end
- self.addNumComponent:InitData(1,has_num,1, max)
- elseif self.vo.type == 37 and self.vo.subtype == 2 then--经验药水
- self.addNumComponent:InitData(1,has_num,1,1)
- elseif self.vo.type == 38 and (self.vo.subtype == 35 or self.vo.subtype == 34) then--副本扫荡卷
- self.addNumComponent:InitData(1,has_num,1,1)
- else
- local num = self.cur_count or has_num
- self.addNumComponent:InitData(1,has_num,1,num)
- end
- end
-
- function GoodsBatchBuyView:ChangeCount(count)
- if self.vo and self.vo.type_id then
- self.awardItem:SetData(self.vo.type_id, count, nil, nil, nil, nil, nil, nil, nil, true)
- end
- end
-
- function GoodsBatchBuyView:Clear( )
- if self.awardItem then
- self.awardItem:ReleaseObj()
- 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
-
- function GoodsBatchBuyView:BtnCall( )
- if not self.vo or not self.goods_id then return end
-
- local cur_num = self.addNumComponent:GetCurrCount()--self.buy_slider.value
- if cur_num==0 then
- Message.show("使用数量不能为0")
- return
- else
- if self.vo.type==38 and self.vo.subtype==7 then
- --离线挂机卡特殊判断
- OffLineModel:getInstance():OnBuy(self.goods_id, cur_num)
- elseif self.vo.type==37 and self.vo.subtype==3 then
- FishModel:getInstance():OnBuy(self.goods_id, cur_num)
- else
- GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_id, self.vo.type_id, cur_num)
- end
- if self.vo.type == 16 and self.vo.subtype == 7 then -- 坐骑幻形
- HorseModel:getInstance():UseItem(self.vo.type_id)
- end
- if self.vo.type == 20 and self.vo.subtype == 5 then -- 坐骑幻形
- WingModel:getInstance():UseItem(self.vo.type_id)
- end
- end
- self:Close()
- end
|