|
|
- GoodsDestroyView = GoodsDestroyView or BaseClass(BaseView)
- local GoodsDestroyView = GoodsDestroyView
-
- function GoodsDestroyView:__init()
- self.base_file = "bag"
- self.layout_file = "GoodsDestroyView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = true
- self.change_scene_close = true
- self.is_set_zdepth = true
- self.is_delay_callback = false
-
- self.fix_item_list = {}
- --self.use_local_view = true
-
- self.model = GoodsModel:getInstance()
- self.load_callback = function ()
- self:LoadSuccess()
- self:InitEvent()
- end
- self.open_callback = function ()
- self:InitView()
- end
- self.close_callback = function ()
- self:Remove()
- end
- end
-
- function GoodsDestroyView:Remove()
- for i,item in pairs(self.fix_item_list) do
- item:ReleaseObj()
- end
- self.fix_item_list = {}
- end
-
- function GoodsDestroyView:InitView()
- self.destroy_list = {}
- local data = nil
- local goods_dic = self.model:GetBagGoodsDic()
- for index,good_vo in pairs(goods_dic) do
- if self.model:CheckIsExpireTime(good_vo) then
- if #self.destroy_list < 20 then --一次性最多20个
- data = {
- style = 0,
- typeId = good_vo.type_id,
- goods_id = good_vo.goods_id,
- count = good_vo.goods_num
- }
- table.insert(self.destroy_list,data)
- end
- end
- end
-
-
- local total_list = self.destroy_list
-
- if #total_list < 5 then
- self.item_parent.anchoredPosition = Vector2(240 - ((#total_list - 1) * 98 + 84 )/ 2,-17)
- else
- self.item_parent.anchoredPosition = Vector2(6,-17)
- end
-
- for i,v in ipairs(total_list) do
- local item = self.fix_item_list[i]
- if item == nil then
- item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_parent)
- self.fix_item_list[i] = item
- end
-
-
- local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
- item:SetData(goods_Id,v.count,nil,nil,lock,nil,nil,nil,self.layer_name)
- item:SetVisible(true)
- item:SetItemSize(90, 90)
- item:SetAnchoredPosition(98 * (i - 1),0)
- end
-
- self.mContent.sizeDelta = Vector2(#total_list * 98,200)
-
- for i=#total_list + 1,#self.fix_item_list do
- self.fix_item_list[i]:SetVisible(false)
- end
- end
-
- function GoodsDestroyView:LoadSuccess()
-
- self.confirmBtn,
- self.cancelBtn = self:GetChildGameObjects({
- "confirmBtn",
- "cancelBtn",
- })
-
- self.mContent,
- self.item_parent = self:GetChildTransforms({
- "ScrollView/Viewport/Content",
- "ScrollView/Viewport/Content/ItemParent",
- })
- end
-
- function GoodsDestroyView:Open()
- BaseView.Open(self)
- end
-
- function GoodsDestroyView:InitEvent()
- local function click_handler(target)
- if target == self.confirmBtn then
- if #self.destroy_list > 0 then
- GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15051,1, self.destroy_list)
- end
- self:Close()
- elseif target == self.cancelBtn then
- self:Close()
- end
- end
- AddClickEvent(self.confirmBtn, click_handler, 2)
- AddClickEvent(self.cancelBtn, click_handler, 2)
- end
-
|