238 lines
8.3 KiB
Lua
238 lines
8.3 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"
|
|
local curGiftsId
|
|
---@param gameObject UnityEngine.GameObject
|
|
function GrowthGiftPage:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel
|
|
self.gameObject = gameObject
|
|
--topPart
|
|
self.topPart = Util.GetGameObject(self.gameObject, "topPart")
|
|
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.totalIncomeIcon = Util.GetGameObject(self.topPart, "giftRoot/totalIncome/icon"):GetComponent("Image")
|
|
|
|
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.bottomRewardIcon = Util.GetGameObject(self.topPart.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()
|
|
Game.GlobalEvent:AddEvent(GameEvent.MoneyPay.OnPayResultSuccess, self.OnPayResultSuccess, self)
|
|
Game.GlobalEvent:AddEvent(GameEvent.GrowGift.GetAllGift, self.onGetAllGift, 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)
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.GrowGift.GetAllGift, self.onGetAllGift, self)
|
|
end
|
|
|
|
--
|
|
function GrowthGiftPage:onGetAllGift()
|
|
self:SetPanelStatus()
|
|
self:InitGroupTaskList()
|
|
end
|
|
|
|
--立即投资
|
|
function GrowthGiftPage:SetPanelStatus()
|
|
local goodsId
|
|
local giftGoodsInfo
|
|
|
|
local giftGoodsInfo = OperatingManager.IsGrowthGiftGoodsAvailable(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)
|
|
|
|
self.investValue.text = self.rechargeConfig.Price
|
|
|
|
curGiftsId = goodsId
|
|
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 self.taskList then
|
|
table.walk(self.taskList,function(taskItem)
|
|
taskItem.cloneObj:SetActive(false)
|
|
end)
|
|
end
|
|
|
|
local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
|
|
local extraReward_1, propId_1 = 0
|
|
local index = 1
|
|
|
|
local list = {}
|
|
local openId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.GrowthReward)
|
|
for _, configInfo in ConfigPairs(actRewardConfig) do
|
|
if configInfo.ActivityId == openId then
|
|
table.insert(list, configInfo)
|
|
end
|
|
end
|
|
|
|
table.sort(list, function(a, b)
|
|
local state_a = ActivityGiftManager.GetActivityInfo(a.ActivityId, a.Id).state
|
|
local state_b = ActivityGiftManager.GetActivityInfo(b.ActivityId, b.Id).state
|
|
if state_a == 0 and state_b ~= 0 then
|
|
return true
|
|
end
|
|
if state_a ~= 0 and state_b == 0 then
|
|
return false
|
|
end
|
|
if state_a == state_b then
|
|
return a.Id < b.Id
|
|
end
|
|
return state_a < state_b
|
|
end)
|
|
|
|
for index, configInfo in ipairs(list) do
|
|
self.rewardValue.text = configInfo.MultiplyingPower
|
|
self.totalIncomeValue.text = configInfo.TotalValues
|
|
self.totalIncomeIcon.sprite = Util.LoadSprite(GetResourcePath(ConfigManager.GetConfigData(ConfigName.ItemConfig,configInfo.Reward[1][1]).ResourceID))
|
|
if configInfo.Reward[1] then
|
|
extraReward_1 = extraReward_1 + configInfo.Reward[1][2]
|
|
propId_1 = configInfo.Reward[1][1]
|
|
end
|
|
if not self.taskList[index] then
|
|
self.taskList[index] = GrowthGiftTaskItem.create(self.taskProItem, self.taskContent)
|
|
end
|
|
self.taskList[index]:Init(configInfo, sortingOrder)
|
|
self.taskList[index].cloneObj:SetActive(true)
|
|
self.taskList[index]:SetValue()
|
|
end
|
|
|
|
self.bottomRewardIcon.sprite = SetIcon(propId_1)
|
|
return
|
|
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, curGiftsId)
|
|
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, curGiftsId)
|
|
-- 设置活动开启状态
|
|
ActivityGiftManager.SetActivityOpenStatus(ActivityTypeDef.GrowthReward)
|
|
-- 添加已经购买的物品
|
|
OperatingManager.SetHadBuyGoodsId({curGiftsId})
|
|
-- 增加充值金额
|
|
FirstRechargeManager.RefreshAccumRechargeValue(curGiftsId)
|
|
-- 检测红点状态
|
|
RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift)
|
|
-- 从可购买物品列表中删除
|
|
OperatingManager.RemoveItemInfoByType(GoodsTypeDef.GrowthReward, curGiftsId)
|
|
-- 刷新当前界面显示
|
|
self.btnInvest:GetComponent("Button").enabled = false
|
|
self.btnInvestText.text = "已投资"
|
|
Util.SetGray(self.btnInvest, true)
|
|
-- 刷新任务显示
|
|
self:InitGroupTaskList()
|
|
|
|
|
|
--
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
self.remainTimes.text = ""
|
|
end
|
|
|
|
return GrowthGiftPage
|