local WeekMonthGiftPackPage = quick_class("WeekMonthGiftPackPage") local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local sortingOrder = 0 local extra=nil--判断周、月礼包 local data = { [1]={picture = "m_meizhoulibao_banner",}, --周礼包 [2]={picture = "m_meiyuelibao_banner",}, --月礼包 [3]={picture = "z_zhenqibaoge_banner",}, --珍奇宝阁 [4]={picture = "s_shengxingyouli_banner",}, --升星有礼 [5]={picture = "l_leichong_tu",}, --累计充值 } function WeekMonthGiftPackPage:ctor(mainPanel, gameObject) self.mainPanel = mainPanel self.gameObject = gameObject self:InitComponent(gameObject) self:BindEvent() self.ItemList = {} end function WeekMonthGiftPackPage:InitComponent(gameObject) self.itemPre = Util.GetGameObject(gameObject, "rzyBg/ItemPre") self.bg = Util.GetGameObject(gameObject, "rzyBg") self.titleBg = Util.GetGameObject(gameObject, "rzyBg/bg"):GetComponent("Image") self.redPoint=Util.GetGameObject(gameObject,"rzyBg/freeBtn/redPoint") self.endTime = Util.GetGameObject(gameObject, "rzyBg/endTime"):GetComponent("Text") self.endTimeBg = Util.GetGameObject(gameObject, "rzyBg/Image") self.scrollItem = Util.GetGameObject(gameObject, "rzyBg/scrollItem") self.tip1 = Util.GetGameObject(gameObject, "rzyBg/tip1") self.tip2 = Util.GetGameObject(gameObject, "rzyBg/tip2") local rootHight = self.scrollItem.transform.rect.height local width = self.scrollItem.transform.rect.width self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform, self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35)) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 end function WeekMonthGiftPackPage:BindEvent() end function WeekMonthGiftPackPage:OnShow(_sortingOrder,extraTab) sortingOrder = _sortingOrder extra=extraTab self:RefreshData() self.gameObject:SetActive(true) end function WeekMonthGiftPackPage:RefreshData() -- 刷新商品数据 self:RefreshGiftData() -- 刷新剩余时间 self:GetRemainTime() end function WeekMonthGiftPackPage:RefreshGiftData() local shopData = {} self.titleBg.sprite = Util.LoadSprite(data[extra].picture) if extra == 1 then--周礼包 self.tip1:SetActive(true) self.tip2:SetActive(false) shopData = self:ResetShopData(OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)) elseif extra ==2 then--月礼包 self.tip1:SetActive(false) self.tip2:SetActive(true) shopData = self:ResetShopData(OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)) end --#OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift == 27 table.sort(shopData,function(a,b) if a.sortId == b.sortId then return a.data.goodsId < b.data.goodsId else return a.sortId > b.sortId end end) local callBack = function(index, item) self:RefreshShowData(item, shopData[index].data) end self.scrollView:SetData(shopData, callBack) end function WeekMonthGiftPackPage:RefreshShowData(item, data) local grid = Util.GetGameObject(item, "scrollView/grid") local btnBuy = Util.GetGameObject(item, "btnBuy") local icon = Util.GetGameObject(btnBuy, "icon") local price = Util.GetGameObject(btnBuy, "price"):GetComponent("Text") local redPoint = Util.GetGameObject(btnBuy, "redPoint") local buyInfo = Util.GetGameObject(item, "buyInfo"):GetComponent("Text") local shadow=Util.GetGameObject(item,"shadow") -- 物品Item local shows local shopItemData local boughtNum = 0 local limitNum = 0 local costId, finalNum, oriCostNum shopItemData = rechargeCommodityConfig[data.goodsId] shows = shopItemData.RewardShow --name.text = shopItemData.Name boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.goodsId) limitNum = shopItemData.Limit --limitNum = OperatingManager.GetLeftBuyTime(GoodsTypeDef.DirectPurchaseGift,data.goodsId) costId, finalNum, oriCostNum = nil,shopItemData.Price,nil --滚动条复用重设itemview if self.ItemList[item] then for i = 1, 4 do self.ItemList[item][i].gameObject:SetActive(false) end for i = 1, #shows do if self.ItemList[item][i] then self.ItemList[item][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder) self.ItemList[item][i].gameObject:SetActive(true) end end else self.ItemList[item]={} for i = 1, 4 do self.ItemList[item][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform) self.ItemList[item][i].gameObject:SetActive(false) local obj= newObjToParent(shadow,self.ItemList[item][i].transform) obj.transform:SetAsFirstSibling() obj.transform:DOAnchorPos(Vector3(0,-3,0),0) obj:GetComponent("RectTransform").transform.localScale=Vector3.one*1.1 obj.gameObject:SetActive(true) end for i = 1, #shows do self.ItemList[item][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,self.mainPanel.sortingOrder) self.ItemList[item][i].gameObject:SetActive(true) end end -- 设置按钮状态 local isCanBuy = limitNum - boughtNum >0 btnBuy:GetComponent("Button").interactable = isCanBuy Util.SetGray(btnBuy,not isCanBuy) icon:GetComponent("Image").enabled=isCanBuy if isCanBuy then price.text = string.format(MoneyUtil.GetMoneyUnitName(), finalNum)--..MoneyUtil.GetMoneyUnitName() buyInfo.text = Language[11454]..limitNum - boughtNum .. "/" .. limitNum..Language[11455] --limitNum == -1 and "" or limitNum - boughtNum .. "/" .. limitNum else price.alignment="MiddleCenter" price.text=Language[10526] buyInfo.text=Language[11498]..""..limitNum - boughtNum.."".. "/" .. limitNum..Language[11455] end Util.AddOnceClick(btnBuy, function() if not isCanBuy then PopupTipPanel.ShowTip(Language[10540]) else --直购商品 if AppConst.isSDKLogin then PayManager.Pay({ Id = data.goodsId }) else NetManager.RequestBuyGiftGoods(data.goodsId, function() FirstRechargeManager.RefreshAccumRechargeValue(data.goodsId) self:RefreshGiftData() CheckRedPointStatus(RedPointType.DailyGift) end) end end end) end --数据重组 function WeekMonthGiftPackPage:ResetShopData(shopData) local newData = {} local boughtNum = 0 local limitNum = 0 if extra == 1 then for i = 1, #shopData do if rechargeCommodityConfig[shopData[i].goodsId].ShowType == DirectBuyType.WEEK_GIFT then boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, shopData[i].goodsId) limitNum = rechargeCommodityConfig[ shopData[i].goodsId].Limit local curSortId = 0--临时一个数值 只用做排序用 if limitNum == -1 then curSortId = 2 elseif limitNum - boughtNum > 0 then curSortId = 1 end newData[#newData + 1] = {data = shopData[i],sortId = curSortId} end end elseif extra == 2 then for i = 1, #shopData do if rechargeCommodityConfig[shopData[i].goodsId].ShowType == DirectBuyType.MONTH_GIFT then boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, shopData[i].goodsId) limitNum = rechargeCommodityConfig[ shopData[i].goodsId].Limit local curSortId = 0--临时一个数值 只用做排序用 if limitNum == -1 then curSortId = 2 elseif limitNum - boughtNum > 0 then curSortId = 1 end newData[#newData + 1] = {data = shopData[i],sortId = curSortId} end end end return newData end --每种礼包的剩余时间 function WeekMonthGiftPackPage:GetRemainTime() local localSelf = self local freshTime = 0 --所有直购在一起 取相应类型直购第一个时间显示倒计时 local datalist = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift) if extra == 1 then for i = 1, #datalist do if rechargeCommodityConfig[datalist[i].goodsId].ShowType == DirectBuyType.WEEK_GIFT then if freshTime <= 0 then freshTime = datalist[i].endTime end end end elseif extra ==2 then for i = 1, #datalist do if rechargeCommodityConfig[datalist[i].goodsId].ShowType == DirectBuyType.MONTH_GIFT then if freshTime <= 0 then freshTime = datalist[i].endTime end end end end if freshTime and freshTime > 0 then else return end local UpDate = function() if not localSelf.localTimer then return end local showfreshTime = freshTime - GetTimeStamp() if showfreshTime > 0 then -- 剩余小时 local formatTime, leftHour = TimeToHMS(showfreshTime) if leftHour > 24 then self.endTime.text = Language[10028]..TimeToDHMS(showfreshTime) else self.endTime.text = Language[10028]..self:TimeToHMS(showfreshTime) end elseif showfreshTime == 0 then -- 时间到刷一下数据 Log(Language[11450]) self:RefreshGiftData(self.choooseTab) elseif showfreshTime==-1 then --不刷新显示内容 self.endTime.text="" end end if self.localTimer then self.localTimer:Stop() self.localTimer = nil end if not self.localTimer then self.localTimer = Timer.New(UpDate, 1, -1, true) self.localTimer:Start() end UpDate() end function WeekMonthGiftPackPage:OnHide() if self.localTimer then self.localTimer:Stop() self.localTimer = nil end self.gameObject:SetActive(false) end function WeekMonthGiftPackPage:OnDestroy() self.scrollView=nil self.scrollView2=nil if self.localTimer then self.localTimer:Stop() self.localTimer = nil end end --------------------- function WeekMonthGiftPackPage:OnSortingOrderChange(cursortingOrder) for i, v in pairs(self.ItemList) do for j = 1, #self.ItemList[i] do self.ItemList[i][j]:SetEffectLayer(cursortingOrder) end end end -----------本模块特殊使用----------- function WeekMonthGiftPackPage:TimeToHMS(t) if not t or t < 0 then return Language[11463] end local _sec = t % 60 local allMin = math.floor(t / 60) local _min = allMin % 60 local _hour = math.floor(allMin / 60) return string.format(Language[10503], _hour, _min, _sec), _hour, _min, _sec end return WeekMonthGiftPackPage