local WeekMonthGiftPackPage = quick_class("WeekMonthGiftPackPage") local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local sortingOrder = 0 local extra=nil--判断周、月礼包 local isPlayAnim = true local data = { [1]={picture = "m_meiyuelibao_banner1",picture2 = "m_meiyuelibao_banner11_zh",}, --周礼包 [2]={picture = "m_meiyuelibao_banner2",picture2 = "m_meiyuelibao_banner22_zh",}, --月礼包 [3]={picture = "z_zhenqibaoge_banner_zh",}, --珍奇宝阁 [4]={picture = "s_shengxingyouli_banner_zh",}, --升星有礼 [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.spLoader = SpriteLoader.New() self.itemPre = Util.GetGameObject(gameObject, "rzyBg/ItemPre") self.bg = Util.GetGameObject(gameObject, "rzyBg") self.titleBg = Util.GetGameObject(gameObject, "rzyBg/bg"):GetComponent("Image") self.bgTextImage = Util.GetGameObject(gameObject, "rzyBg/bg/bgTextImage") 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) isPlayAnim = true sortingOrder = _sortingOrder extra=extraTab self:RefreshData() self.gameObject:SetActive(true) end function WeekMonthGiftPackPage:RefreshData() -- 刷新商品数据 self:RefreshGiftData(true,true) -- 刷新剩余时间 self:GetRemainTime() end function WeekMonthGiftPackPage:RefreshGiftData(isTop,isAni) local shopData = {} self.titleBg.sprite = self.spLoader:LoadSprite(data[extra].picture) if extra <= 2 then self.bgTextImage:SetActive(true) self.bgTextImage:GetComponent("Image").sprite = self.spLoader:LoadSprite(data[extra].picture2) else self.bgTextImage:SetActive(false) end 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 rechargeCommodityConfig[a.data.goodsId].Price < rechargeCommodityConfig[b.data.goodsId].Price 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, not isTop,not isAni) if isPlayAnim then SecTorPlayAnimByScroll(self.scrollView) isPlayAnim = false end 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 -- if isPlayAnim then -- item:SetActive(false) -- else -- item:SetActive(true) -- end --滚动条复用重设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 if shopItemData.Price <= 0 then redPoint.gameObject:SetActive(true) else redPoint.gameObject:SetActive(false) end price.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(finalNum))--..MoneyUtil.GetMoneyUnitName() buyInfo.text = Language[10580]..limitNum - boughtNum..Language[10048] else redPoint.gameObject:SetActive(false) price.alignment="MiddleCenter" price.text=Language[10514] buyInfo.text="" end Util.AddOnceClick(btnBuy, function() if not isCanBuy then PopupTipPanel.ShowTip(Language[10515]) else --直购商品 PayManager.Pay(data.goodsId, function(id) FirstRechargeManager.RefreshAccumRechargeValue(data.goodsId) self:RefreshGiftData(false,false) CheckRedPointStatus(RedPointType.DailyGift) CheckRedPointStatus(RedPointType.WeekGiftPage) CheckRedPointStatus(RedPointType.MonthGiftPage) 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[10023]..TimeToDHMS(showfreshTime) else self.endTime.text = Language[10023]..self:TimeToHMS(showfreshTime) end elseif showfreshTime == 0 then -- 时间到刷一下数据 Log("刷新时间到了") 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.spLoader:Destroy() 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[11365] 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[10551], _hour, _min, _sec), _hour, _min, _sec end return WeekMonthGiftPackPage