2020-08-20 18:32:14 +08:00
|
|
|
local LeiJiChongZhiPage = quick_class("LeiJiChongZhiPage")
|
2020-08-20 17:36:19 +08:00
|
|
|
local allData={}
|
|
|
|
local itemsGrid = {}--item重复利用
|
2020-08-20 18:32:14 +08:00
|
|
|
local this=LeiJiChongZhiPage
|
2020-08-20 17:36:19 +08:00
|
|
|
local parent
|
|
|
|
local endtime = 0
|
2020-08-21 18:30:44 +08:00
|
|
|
local rechargeNum
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:ctor(mainPanel, gameObject)
|
2020-08-20 17:36:19 +08:00
|
|
|
self.mainPanel = mainPanel
|
|
|
|
self.gameObject = gameObject
|
|
|
|
self:InitComponent(gameObject)
|
|
|
|
self:BindEvent()
|
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:InitComponent(gameObject)
|
2020-08-21 18:30:44 +08:00
|
|
|
this.time = Util.GetGameObject(gameObject, "tiao/time"):GetComponent("Text")
|
|
|
|
this.itemPre = Util.GetGameObject(gameObject, "ItemPre")
|
|
|
|
this.scrollItem = Util.GetGameObject(gameObject, "grid")
|
|
|
|
local rootHight = this.scrollItem:GetComponent("RectTransform").sizeDelta
|
2020-08-20 17:36:19 +08:00
|
|
|
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
|
2020-08-21 20:11:24 +08:00
|
|
|
this.itemPre, nil, Vector2.New(rootHight.x, rootHight.y), 1, 1, Vector2.New(0, 30))
|
2020-08-20 17:36:19 +08:00
|
|
|
this.ScrollView.moveTween.MomentumAmount = 1
|
|
|
|
this.ScrollView.moveTween.Strength = 2
|
|
|
|
end
|
|
|
|
|
|
|
|
--绑定事件(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:BindEvent()
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:AddListener()
|
2020-08-21 18:30:44 +08:00
|
|
|
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
--移除事件监听(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:RemoveListener()
|
2020-08-21 18:30:44 +08:00
|
|
|
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
local sortingOrder = 0
|
|
|
|
--界面打开时调用(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnOpen()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnShow(_sortingOrder,_parent)
|
2020-08-21 18:30:44 +08:00
|
|
|
rechargeNum= VipManager.GetChargedNum()--已经充值的金额
|
2020-08-20 17:36:19 +08:00
|
|
|
sortingOrder = _sortingOrder
|
|
|
|
parent = _parent
|
2020-08-21 18:30:44 +08:00
|
|
|
this.Refresh()
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function this.Refresh()
|
|
|
|
this:OnShowData()
|
|
|
|
this:SetTime()
|
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:SetTime()
|
2020-08-20 17:36:19 +08:00
|
|
|
if self.timer then
|
|
|
|
self.timer:Stop()
|
|
|
|
self.timer = nil
|
|
|
|
end
|
2020-08-21 18:30:44 +08:00
|
|
|
local timeDown = endtime - GetTimeStamp()
|
|
|
|
this.time.text = "剩余时间:"..TimeToDHMS(timeDown)
|
2020-08-20 17:36:19 +08:00
|
|
|
self.timer = Timer.New(function()
|
2020-08-21 18:30:44 +08:00
|
|
|
timeDown = timeDown - 1
|
|
|
|
if timeDown < 1 then
|
|
|
|
parent:ClosePanel()
|
|
|
|
return
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
2020-08-21 18:30:44 +08:00
|
|
|
this.time.text = "剩余时间:"..TimeToDHMS(timeDown)
|
2020-08-20 17:36:19 +08:00
|
|
|
end, 1, -1, true)
|
|
|
|
self.timer:Start()
|
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnShowData()
|
2020-08-21 18:30:44 +08:00
|
|
|
allData =OperatingManager.InitLeiJiChongZhiData()
|
2020-08-20 17:36:19 +08:00
|
|
|
if allData then
|
2020-08-21 18:30:44 +08:00
|
|
|
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.pozhenzhuxian_recharge)
|
2020-08-20 17:36:19 +08:00
|
|
|
this.SortData(allData)
|
|
|
|
this.ScrollView:SetData(allData, function (index, go)
|
|
|
|
this.SingleDataShow(go, allData[index])
|
|
|
|
end)
|
|
|
|
else
|
|
|
|
parent.OnPageTabChange(1)
|
|
|
|
PopupTipPanel.ShowTip("活动已结束")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2020-08-21 18:30:44 +08:00
|
|
|
local typeIndex = {
|
|
|
|
[0] = 2,
|
|
|
|
[1] = 3,
|
|
|
|
[2] = 1,
|
|
|
|
}
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:SortData()
|
2020-08-20 17:36:19 +08:00
|
|
|
if allData==nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
table.sort(allData, function(a,b)
|
2020-08-21 18:30:44 +08:00
|
|
|
if typeIndex[a.state] == typeIndex[b.state] then
|
2020-08-20 17:36:19 +08:00
|
|
|
return a.id < b.id
|
2020-08-21 18:30:44 +08:00
|
|
|
else
|
|
|
|
return typeIndex[a.state] < typeIndex[b.state]
|
|
|
|
end
|
2020-08-20 17:36:19 +08:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
local type={
|
|
|
|
[0]={sprite = "s_slbz_1anniuhuangse",text = "前往"},
|
|
|
|
[1]={sprite = "s_slbz_1anniuhuise",text = "已领取"},
|
|
|
|
[2]={sprite = "s_slbz_1anniuongse",text = "领取"},
|
|
|
|
}
|
|
|
|
--刷新每一条的显示数据
|
|
|
|
function this.SingleDataShow(pre,value)
|
|
|
|
if pre==nil or value==nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
--绑定组件
|
|
|
|
local activityRewardGo = pre
|
|
|
|
activityRewardGo:SetActive(true)
|
|
|
|
local sConFigData = value
|
|
|
|
|
2020-08-21 20:11:24 +08:00
|
|
|
local num = Util.GetGameObject(activityRewardGo, "context/num")
|
|
|
|
this:NumToNum(num,sConFigData.value)
|
|
|
|
-- num.text = sConFigData.value
|
2020-08-21 18:30:44 +08:00
|
|
|
local progress = Util.GetGameObject(activityRewardGo, "context/progress"):GetComponent("Text")
|
|
|
|
progress.text ="可领取".."("..(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) .."/"..sConFigData.value..")"
|
|
|
|
|
|
|
|
local reward = Util.GetGameObject(activityRewardGo.gameObject, "scrollView/grid")
|
2020-08-20 17:36:19 +08:00
|
|
|
if (not itemsGrid) then
|
|
|
|
itemsGrid = {}
|
|
|
|
end
|
|
|
|
if not itemsGrid[pre] then
|
2020-08-21 18:30:44 +08:00
|
|
|
itemsGrid[pre] = {}
|
|
|
|
end
|
|
|
|
for k,v in ipairs(sConFigData.reward) do
|
|
|
|
if not itemsGrid[pre][k] then
|
|
|
|
itemsGrid[pre][k] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
|
|
|
|
end
|
|
|
|
itemsGrid[pre][k]:OnOpen(false, {v[1],v[2]}, 0.9, false)
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
2020-08-21 18:30:44 +08:00
|
|
|
local lingquButton = Util.GetGameObject(activityRewardGo.gameObject, "btnBuy")
|
|
|
|
local state = sConFigData.state
|
2020-08-20 17:36:19 +08:00
|
|
|
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
|
|
|
red:SetActive(state == 2)
|
|
|
|
|
2020-08-21 18:30:44 +08:00
|
|
|
Util.GetGameObject(lingquButton.gameObject, "price"):GetComponent("Text").text = type[state].text
|
|
|
|
lingquButton:GetComponent("Image").sprite = Util.LoadSprite(type[state].sprite)
|
|
|
|
lingquButton:GetComponent("Button").enabled = (state ~= 1)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
2020-08-21 18:30:44 +08:00
|
|
|
Util.AddOnceClick(lingquButton, function()
|
2020-08-20 17:36:19 +08:00
|
|
|
if state == 2 then
|
2020-08-21 18:30:44 +08:00
|
|
|
local curActivityId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.pozhenzhuxian_recharge)
|
2020-08-20 17:36:19 +08:00
|
|
|
NetManager.GetActivityRewardRequest(sConFigData.id, curActivityId,function(respond)
|
2020-08-21 18:30:44 +08:00
|
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1)
|
2020-08-20 17:36:19 +08:00
|
|
|
this.Refresh()
|
|
|
|
end)
|
|
|
|
elseif state == 0 then
|
|
|
|
if sConFigData.jump then
|
2020-08-21 18:30:44 +08:00
|
|
|
JumpManager.GoJump(sConFigData.jump)
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-08-21 20:11:24 +08:00
|
|
|
function LeiJiChongZhiPage:NumToNum(num,_value)
|
|
|
|
local value = _value
|
|
|
|
local isFirst = true
|
|
|
|
for i = 1, 5 do
|
|
|
|
local m = Util.GetGameObject(num,"num"..i)
|
|
|
|
m:SetActive(false)
|
|
|
|
local t1 = math.floor(value/math.pow(10, (5-i)))
|
|
|
|
value = value%(math.pow(10, (5-i)))
|
|
|
|
if t1<1 and isFirst then
|
|
|
|
m:SetActive(false)
|
|
|
|
else
|
|
|
|
m:SetActive(true)
|
|
|
|
isFirst = false
|
|
|
|
m:GetComponent("Text").text = t1
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-20 17:36:19 +08:00
|
|
|
--界面打开时调用(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnOpen()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function this.RechargeSuccessFunc(id)
|
2020-08-21 18:30:44 +08:00
|
|
|
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnClose()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--界面销毁时调用(用于子类重写)
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnDestroy()
|
2020-08-20 17:36:19 +08:00
|
|
|
sortingOrder = 0
|
2020-08-21 18:30:44 +08:00
|
|
|
allData={}
|
|
|
|
itemsGrid = {}
|
2020-08-20 17:36:19 +08:00
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:OnHide()
|
2020-08-20 17:36:19 +08:00
|
|
|
sortingOrder = 0
|
|
|
|
end
|
|
|
|
--- 将一段时间转换为天时分秒
|
2020-08-20 18:32:14 +08:00
|
|
|
function LeiJiChongZhiPage:TimeToDHMS(second)
|
2020-08-20 17:36:19 +08:00
|
|
|
local day = math.floor(second / (24 * 3600))
|
|
|
|
local minute = math.floor(second / 60) % 60
|
|
|
|
local sec = second % 60
|
|
|
|
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
|
|
|
|
if day <= 0 and hour <= 0 then
|
|
|
|
return string.format(Language[12231],minute, sec)
|
|
|
|
else
|
|
|
|
return string.format(Language[12232],day, hour)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-20 18:32:14 +08:00
|
|
|
return LeiJiChongZhiPage
|