202 lines
6.7 KiB
Lua
202 lines
6.7 KiB
Lua
local SelfRecruitOEM = quick_class("SelfRecruitOEM")
|
|
local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
|
|
local this = SelfRecruitOEM
|
|
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
|
local allData = {}
|
|
local itemsGrid = {}
|
|
local curtype
|
|
function SelfRecruitOEM:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel
|
|
self.gameObject = gameObject
|
|
self:InitComponent(gameObject)
|
|
self:BindEvent()
|
|
end
|
|
|
|
--初始化组件(用于子类重写)
|
|
function SelfRecruitOEM:InitComponent(gameObject)
|
|
-- this.gameObject = parent
|
|
this.endTimeObj = Util.GetGameObject(gameObject,"time")
|
|
this.endTime = Util.GetGameObject(gameObject,"time/timeText"):GetComponent("Text")
|
|
this.pre = Util.GetGameObject(gameObject, "ItemPre")
|
|
this.scroll = Util.GetGameObject(gameObject, "scrollItem")
|
|
|
|
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, 0))
|
|
this.scrollView.moveTween.MomentumAmount = 1
|
|
this.scrollView.moveTween.Strength = 1
|
|
|
|
Util.GetGameObject(gameObject, "bg"):GetComponent("Image").sprite = Util.LoadSprite(GetPictureFont("X1_bt_zixuanzm_bg_libao"))
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function SelfRecruitOEM:BindEvent()
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function SelfRecruitOEM:AddListener()
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function SelfRecruitOEM:RemoveListener()
|
|
end
|
|
|
|
function SelfRecruitOEM:OnShow(sortingOrder,parent,_type)
|
|
curtype = _type
|
|
this:Refresh()
|
|
this:GetRemainTime()
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function SelfRecruitOEM:OnClose()
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function SelfRecruitOEM:OnHide()
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function SelfRecruitOEM:OnDestroy()
|
|
end
|
|
|
|
function SelfRecruitOEM:Refresh()
|
|
this.endTimeObj.gameObject:SetActive(true)
|
|
allData = {}
|
|
local curActId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.SelfRecruitOEM) --自选招募礼包
|
|
--curActId = 510011
|
|
if curActId then
|
|
for i = 1, #GlobalActivity[curActId].CanBuyRechargeId do
|
|
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", GlobalActivity[curActId].CanBuyRechargeId[i])
|
|
table.insert(allData,data)
|
|
end
|
|
if allData then
|
|
this:SortData()
|
|
allData[#allData + 1] = {}
|
|
this.scrollView:SetData(allData, function (index, go)
|
|
if index == #allData then
|
|
go:SetActive(false)
|
|
return
|
|
end
|
|
go:SetActive(true)
|
|
SelfRecruitOEM:SetItemData(go, allData[index])
|
|
end)
|
|
end
|
|
else
|
|
Log("server not add")
|
|
end
|
|
end
|
|
|
|
function SelfRecruitOEM:SortData()
|
|
table.sort(allData, function(a,b)
|
|
local aboughtNum = a.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, a.Id) > 0 and 2 or 1
|
|
local bboughtNum = b.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, b.Id) > 0 and 2 or 1
|
|
if aboughtNum == bboughtNum then
|
|
if a.Sequence == b.Sequence then
|
|
return a.Price < b.Price
|
|
else
|
|
return a.Sequence < b.Sequence
|
|
end
|
|
else
|
|
return aboughtNum > bboughtNum
|
|
end
|
|
end)
|
|
end
|
|
|
|
function SelfRecruitOEM:SetItemData(go, data)
|
|
local price = Util.GetGameObject(go, "btnBuy/price"):GetComponent("Text")
|
|
local buyInfo = Util.GetGameObject(go, "buyInfo"):GetComponent("Text")
|
|
local btnBuy = Util.GetGameObject(go, "btnBuy")
|
|
local grid = Util.GetGameObject(go, "scrollView/grid")
|
|
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
|
|
|
|
local num = data.Limit - boughtNum
|
|
if num < 0 then
|
|
num = 0
|
|
end
|
|
buyInfo.text = GetLanguageStrById(11454)..num.."/"..data.Limit..GetLanguageStrById(10054)
|
|
if data.Limit - boughtNum > 0 then
|
|
price.text = MoneyUtil.GetMoney(data.Price)
|
|
btnBuy:GetComponent("Button").enabled = true
|
|
Util.SetGray(btnBuy, false)
|
|
else
|
|
price.text = GetLanguageStrById(10526)
|
|
btnBuy:GetComponent("Button").enabled = false
|
|
Util.SetGray(btnBuy, true)
|
|
end
|
|
|
|
if not itemsGrid[go] then
|
|
itemsGrid[go] = {}
|
|
end
|
|
for i = 1, #itemsGrid[go] do
|
|
itemsGrid[go][i].gameObject:SetActive(false)
|
|
end
|
|
for i = 1, #data.RewardShow do
|
|
if not itemsGrid[go][i] then
|
|
itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
|
|
end
|
|
itemsGrid[go][i]:OnOpen(false, data.RewardShow[i], 0.65)
|
|
itemsGrid[go][i].gameObject:SetActive(true)
|
|
end
|
|
|
|
Util.AddOnceClick(btnBuy, function()
|
|
if data.Limit <= boughtNum then
|
|
PopupTipPanel.ShowTip(GetLanguageStrById(10540))
|
|
else
|
|
PayManager.Pay({Id = data.Id}, function ()
|
|
-- FirstRechargeManager.RefreshAccumRechargeValue(data.Id)
|
|
this:Refresh()
|
|
end)
|
|
end
|
|
end)
|
|
end
|
|
|
|
--每种礼包的剩余时间
|
|
function SelfRecruitOEM:GetRemainTime()
|
|
local localSelf = self
|
|
local freshTime = 0
|
|
--所有直购在一起 取相应类型直购第一个时间显示倒计时
|
|
local datalist = OperatingManager.GetGiftGoodsInfoList(GoodsTypeDef.DirectPurchaseGift)
|
|
for i = 1, #datalist do
|
|
if rechargeCommodityConfig[datalist[i].goodsId].ShowType == 991 then
|
|
if freshTime <= 0 then
|
|
freshTime = datalist[i].endTime
|
|
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 = GetLanguageStrById(10028)..TimeToDH(showfreshTime)
|
|
else
|
|
self.endTime.text = GetLanguageStrById(10028)..TimeToMS(showfreshTime)
|
|
end
|
|
elseif showfreshTime <= 0 then
|
|
-- 时间到刷一下数据
|
|
self:Refresh()
|
|
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
|
|
|
|
return SelfRecruitOEM |