205 lines
8.1 KiB
Lua
205 lines
8.1 KiB
Lua
--[[
|
|
* @ClassName GrowthGiftPage
|
|
* @Description 成长礼金页
|
|
* @Date 2019/5/25 14:18
|
|
* @Author MagicianJoker, fengliudianshao@outlook.com
|
|
* @Copyright Copyright (c) 2019, MagicianJoker
|
|
--]]
|
|
|
|
local GrowthGiftTaskItem = require("Modules/Operating/GrowthGiftTaskItem")
|
|
|
|
---@class GrowthGiftPage
|
|
local GrowthGiftPage = quick_class("GrowthGiftPage")
|
|
|
|
local PrefixDiscountTitle = "s_shop_zhekou_0"
|
|
|
|
---@param gameObject UnityEngine.GameObject
|
|
function GrowthGiftPage:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel
|
|
self.gameObject = gameObject
|
|
--topPart
|
|
self.topPart = Util.GetGameObject(self.gameObject, "topPart")
|
|
self.discountValue = Util.GetGameObject(self.topPart, "giftRoot/discountBg/value"):GetComponent("Image")
|
|
self.remainTimes = Util.GetGameObject(self.topPart, "giftRoot/remainDiscountTime"):GetComponent("Text")
|
|
self.investValue = Util.GetGameObject(self.topPart, "giftRoot/investAndReward/invest/value"):GetComponent("Text")
|
|
self.rewardValue = Util.GetGameObject(self.topPart, "giftRoot/investAndReward/reward/value"):GetComponent("Text")
|
|
self.totalIncomeValue = Util.GetGameObject(self.topPart, "giftRoot/totalIncome/value"):GetComponent("Text")
|
|
|
|
self.btnInvest = Util.GetGameObject(self.topPart, "btnInvest")
|
|
self.btnInvest:GetComponent("Button").onClick:AddListener(function()
|
|
self:OnBtnInvestClicked()
|
|
end)
|
|
self.btnInvestText = Util.GetGameObject(self.btnInvest, "Text"):GetComponent("Text")
|
|
|
|
self.topTips = Util.GetGameObject(self.topPart, "topTips"):GetComponent("Text")
|
|
self.topRewardIcon = Util.GetGameObject(self.topTips.transform, "rewardIcon"):GetComponent("Image")
|
|
self.bottomTips_1 = Util.GetGameObject(self.topPart, "bottomTips_1"):GetComponent("Text")
|
|
self.bottomRewardIcon_1 = Util.GetGameObject(self.bottomTips_1.transform, "rewardIcon"):GetComponent("Image")
|
|
self.bottomTips_2 = Util.GetGameObject(self.topPart, "bottomTips_2"):GetComponent("Text")
|
|
self.bottomRewardIcon_2 = Util.GetGameObject(self.bottomTips_2.transform, "rewardIcon"):GetComponent("Image")
|
|
--bottomPart
|
|
self.taskContent = Util.GetGameObject(self.gameObject, "bottomPart/taskList/viewPort/content")
|
|
self.taskProItem = Util.GetGameObject(self.taskContent, "itemPro")
|
|
self.taskProItem:SetActive(false)
|
|
self.taskList = {}
|
|
|
|
end
|
|
local sortingOrder = 0
|
|
function GrowthGiftPage:OnShow(_sortingOrder)
|
|
sortingOrder = _sortingOrder
|
|
self.gameObject.gameObject:SetActive(true)
|
|
self:SetPanelStatus()
|
|
self:InitGroupTaskList()
|
|
self:SetGroupTaskList()
|
|
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, self.OnPayResultSuccess, self)
|
|
end
|
|
function GrowthGiftPage:OnSortingOrderChange(cursortingOrder)
|
|
if self.taskList then
|
|
for i = 1, #self.taskList do
|
|
self.taskList[i]:OnSortingOrderChange(cursortingOrder)
|
|
end
|
|
end
|
|
end
|
|
function GrowthGiftPage:OnHide()
|
|
self.gameObject.gameObject:SetActive(false)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.MoneyPay.OnPayResultSuccess, self.OnPayResultSuccess, self)
|
|
end
|
|
|
|
function GrowthGiftPage:SetPanelStatus()
|
|
local goodsId
|
|
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward)
|
|
if giftGoodsInfo then
|
|
self.btnInvest:GetComponent("Button").enabled = true
|
|
self.btnInvestText.text = "立即投资"
|
|
Util.SetGray(self.btnInvest, false)
|
|
if giftGoodsInfo.endTime ~= 0 then
|
|
self:SetDisCountRemainTimes(giftGoodsInfo.endTime - GetTimeStamp())
|
|
else
|
|
self.remainTimes.text = ""
|
|
end
|
|
goodsId = giftGoodsInfo.goodsId
|
|
else
|
|
self.btnInvest:GetComponent("Button").enabled = false
|
|
self.btnInvestText.text = "已投资"
|
|
Util.SetGray(self.btnInvest, true)
|
|
goodsId = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)
|
|
self.remainTimes.text = ""
|
|
end
|
|
self.rechargeConfig = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, goodsId)
|
|
if self.rechargeConfig.IsDiscount ~= 0 then
|
|
self.discountValue.gameObject:SetActive(true)
|
|
self.discountValue.sprite = Util.LoadSprite(PrefixDiscountTitle .. self.rechargeConfig.IsDiscount)
|
|
self.discountValue:SetNativeSize()
|
|
else
|
|
self.discountValue.gameObject:SetActive(false)
|
|
end
|
|
self.investValue.text = self.rechargeConfig.Price
|
|
self.topTips.text = "X" .. self.rechargeConfig.BaseReward[1][2]
|
|
self.topRewardIcon.sprite = SetIcon(self.rechargeConfig.BaseReward[1][1])
|
|
end
|
|
|
|
function GrowthGiftPage:SetDisCountRemainTimes(timeDown)
|
|
self.timer = Timer.New(function()
|
|
self.remainTimes.text = string.format("限时折扣:%s", DateUtils.GetTimeFormat(timeDown))
|
|
if timeDown < 0 then
|
|
self.countDownTime.text = "限时活动已结束"
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
timeDown = timeDown - 1
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function GrowthGiftPage:InitGroupTaskList()
|
|
if table.nums(self.taskList) > 0 then
|
|
return
|
|
end
|
|
local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
|
|
local extraReward_1, propId_1 = 0
|
|
local extraReward_2, propId_2 = 0
|
|
for _, configInfo in ConfigPairs(actRewardConfig) do
|
|
if configInfo.ActivityId == ActivityTypeDef.GrowthReward then
|
|
self.rewardValue.text = configInfo.MultiplyingPower
|
|
self.totalIncomeValue.text = configInfo.TotalValues
|
|
if configInfo.Reward[1] then
|
|
extraReward_1 = extraReward_1 + configInfo.Reward[1][2]
|
|
propId_1 = configInfo.Reward[1][1]
|
|
end
|
|
if configInfo.Reward[2] then
|
|
extraReward_2 = extraReward_2 + configInfo.Reward[2][2]
|
|
propId_2 = configInfo.Reward[2][1]
|
|
end
|
|
local taskItem = GrowthGiftTaskItem.create(self.taskProItem, self.taskContent)
|
|
taskItem:Init(configInfo,sortingOrder)
|
|
table.insert(self.taskList, taskItem)
|
|
end
|
|
end
|
|
self.bottomTips_1.text = "X" .. extraReward_1
|
|
self.bottomRewardIcon_1.sprite = SetIcon(propId_1)
|
|
self.bottomTips_2.text = "X" .. extraReward_2
|
|
self.bottomRewardIcon_2.sprite = SetIcon(propId_2)
|
|
end
|
|
|
|
function GrowthGiftPage:SetGroupTaskList()
|
|
table.walk(self.taskList, function(taskItem)
|
|
taskItem:SetValue()
|
|
if taskItem.state == 1 then
|
|
taskItem.cloneObj.transform:SetAsLastSibling()
|
|
end
|
|
end)
|
|
|
|
end
|
|
|
|
function GrowthGiftPage:OnBtnInvestClicked()
|
|
local status = OperatingManager.IsRechargeable(GoodsTypeDef.GrowthReward)
|
|
if not status then
|
|
self.btnInvest:GetComponent("Button").enabled = false
|
|
Util.SetGray(self.btnInvest, true)
|
|
return
|
|
end
|
|
self.btnInvest:GetComponent("Button").enabled = true
|
|
Util.SetGray(self.btnInvest, false)
|
|
self:RequestBuy()
|
|
end
|
|
|
|
function GrowthGiftPage:RequestBuy()
|
|
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward)
|
|
if AppConst.isSDK then
|
|
PayManager.Pay({ Id = giftGoodsInfo.goodsId })
|
|
else
|
|
NetManager.RequestBuyGiftGoods(giftGoodsInfo.goodsId, function(respond)
|
|
--PopupTipPanel.ShowTip("奖励已发送到邮件,请前往领取")
|
|
self:RefreshStatus()
|
|
end)
|
|
end
|
|
end
|
|
|
|
function GrowthGiftPage:OnPayResultSuccess()
|
|
self:RefreshStatus()
|
|
end
|
|
|
|
function GrowthGiftPage:RefreshStatus()
|
|
local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward)
|
|
ActivityGiftManager.SetActivityOpenStatus(ActivityTypeDef.GrowthReward)
|
|
OperatingManager.SetHadBuyGoodsId({ giftGoodsInfo.goodsId })
|
|
FirstRechargeManager.RefreshAccumRechargeValue(giftGoodsInfo.goodsId)
|
|
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
|
|
OperatingManager.RemoveGiftInfoList(GoodsTypeDef.GrowthReward)
|
|
self.btnInvest:GetComponent("Button").enabled = false
|
|
self.btnInvestText.text = "已投资"
|
|
Util.SetGray(self.btnInvest, true)
|
|
self:SetGroupTaskList()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
self.remainTimes.text = ""
|
|
end
|
|
|
|
return GrowthGiftPage
|