sk-client/Assets/ManagedResources/~Lua/Modules/Pay/DailyFlashBuyPanel.lua

149 lines
5.2 KiB
Lua

require("Base/BasePanel")
DailyFlashBuyPanel = Inherit(BasePanel)
local this = DailyFlashBuyPanel
local RechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local itemList = {}
function this:InitComponent()
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
this.scroll = Util.GetGameObject(this.gameObject, "scroll")
this.pre = Util.GetGameObject(this.gameObject, "scroll/pre")
local v = this.scroll:GetComponent("RectTransform").rect
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.pre, nil, Vector2.New(v.width, v.height), 1, 1, Vector2.New(0, 5))
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 1
this.btnAllBuy = Util.GetGameObject(this.gameObject, "btnAllBuy")
this.btnAllBuyOriginal = Util.GetGameObject(this.gameObject, "btnAllBuy/original"):GetComponent("Text")
this.btnAllBuyCurrent = Util.GetGameObject(this.gameObject, "btnAllBuy/current"):GetComponent("Text")
end
function this:BindEvent()
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnOpen()
end
function this:OnShow()
local activeId = ActivityGiftManager.GetActivityIdByType(6002)
-- LogError(activeId)
local globalActivity = GlobalActivity[activeId]
-- local globalActivity = ConfigManager.GetConfigDataByKey(ConfigName.GlobalActivity, "Type", 6002)
local tab = {}
local state = true
for i = 1, 3 do
tab[i] = RechargeCommodityConfig[globalActivity.CanBuyRechargeId[i]]
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, tab[i].Id) or 0
if tab[i].Limit - boughtNum <= 0 then
state = false
end
end
this.scrollView:SetData(tab, function(index, go)
this.SetItemInfo(go, tab[index])
end)
local allBuyConfig = RechargeCommodityConfig[globalActivity.CanBuyRechargeId[4]]
this.btnAllBuyOriginal.text = GetLanguageStrById(10537)..MoneyUtil.GetMoney(allBuyConfig.Rebate)
this.btnAllBuyCurrent.text = GetLanguageStrById(10640)..MoneyUtil.GetMoney(allBuyConfig.Price)
Util.SetGray(this.btnAllBuy, not state)
Util.AddOnceClick(this.btnAllBuy, function ()
if not state then
return
end
PayManager.Pay({Id = allBuyConfig.Id}, function ()
this:OnShow()
if UIManager.IsOpen(UIName.OperatingPanel) then
UIManager.GetOpenPanel(UIName.OperatingPanel).OnlineRewards:OnShow()
end
end)
end)
end
function this:OnSortingOrderChange()
end
function this:OnClose()
end
function this:OnDestroy()
itemList = {}
end
function this.SetItemInfo(go, data)
local title = Util.GetGameObject(go, "title"):GetComponent("Text")
local grid = Util.GetGameObject(go, "grid/rect")
local btn = Util.GetGameObject(go, "btn")
local price = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local original = Util.GetGameObject(go, "original"):GetComponent("Text")
if not itemList[go] then
itemList[go] = {}
end
for i = 1, #itemList[go] do
itemList[go][i].gameObject:SetActive(false)
end
for i = 1, #data.RewardShow do
if not itemList[go][i] then
itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
end
itemList[go][i]:OnOpen(false, data.RewardShow[i], 0.7)
itemList[go][i].gameObject:SetActive(true)
end
title.text = GetLanguageStrById(data.Name)
price.text = MoneyUtil.GetMoney(data.Price)
original.text = GetLanguageStrById(10537)..MoneyUtil.GetMoney(data.Rebate)
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
if data.Limit - boughtNum > 0 then
btn:GetComponent("Button").enabled = true
Util.SetGray(btn, false)
else
price.text = GetLanguageStrById(10539)
btn:GetComponent("Button").enabled = false
Util.SetGray(btn, true)
end
Util.AddOnceClick(btn, function ()
PayManager.Pay({Id = data.Id}, function ()
this:OnShow()
if UIManager.IsOpen(UIName.OperatingPanel) then
UIManager.GetOpenPanel(UIName.OperatingPanel).OnlineRewards:OnShow()
end
end)
end)
end
function this.DiscountOnlineRewardTimer(timeTxt)
if this.discountTimer then
this.discountTimer:Stop()
this.discountTimer = nil
end
this.discountTimer = Timer.New(function()
if NetManager.IsConnect() then--是否在线状态
local data = ConfigManager.GetConfigDataByKey(ConfigName.DeValueConfig, "Type", 3)
local time = TaskManager.GetOnlineTimeData(TaskTypeDef.Discount, data.Id).time-GetTimeStamp()
if time <= 0 then
this.discountTimer:Stop()
this.discountTimer = nil
timeTxt.text = GetLanguageStrById(10471)
else
timeTxt.text = TimeToMS(time)
end
end
end, 1, -1, true)
this.discountTimer:Start()
end
return DailyFlashBuyPanel