2025-05-20 18:43:03 +08:00
|
|
|
local FamilyChooseTimeView = {}
|
|
|
|
|
|
|
|
|
|
local M = FamilyChooseTimeView
|
|
|
|
|
|
|
|
|
|
function FamilyChooseTimeView.New(root, view)
|
|
|
|
|
setmetatable(M, { __index = root })
|
|
|
|
|
local self = setmetatable({}, { __index = M })
|
|
|
|
|
|
|
|
|
|
self.minTime = os.date("*t")
|
|
|
|
|
self.maxTime = os.date("*t")
|
|
|
|
|
self.minTime.hour = 0
|
|
|
|
|
self.minTime.min = 0
|
|
|
|
|
self.minTime.sec = 0
|
|
|
|
|
self.maxTime.hour = 23
|
|
|
|
|
self.maxTime.min = 59
|
|
|
|
|
self.maxTime.sec = 59
|
|
|
|
|
self._view_local = view
|
|
|
|
|
self._view_local:GetChild('left').onClick:Set(function()
|
|
|
|
|
self.currenTime.month = self.currenTime.month - 1
|
|
|
|
|
self:UpdateMonth()
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
self._view_local:GetChild('right').onClick:Set(function()
|
|
|
|
|
self.currenTime.month = self.currenTime.month + 1
|
|
|
|
|
self:UpdateMonth()
|
|
|
|
|
end)
|
|
|
|
|
self.list = view:GetChild('list')
|
|
|
|
|
self.list:SetVirtual()
|
|
|
|
|
self.list.itemRenderer = function(index, obj)
|
|
|
|
|
obj.data = {}
|
|
|
|
|
obj.data.day = index + 1
|
|
|
|
|
obj.text = string.format("%02d", index + 1)
|
|
|
|
|
end
|
|
|
|
|
self.list.onClickItem:Set(function(context)
|
|
|
|
|
self.currenTime.day = context.data.data.day
|
|
|
|
|
print("lingmeng", os.time(self.minTime), os.time(self.maxTime), os.time(self.minTime) > os.time(self.maxTime))
|
|
|
|
|
if os.time(self.minTime) > os.time(self.maxTime) then
|
|
|
|
|
local y = self.currenTime.year
|
|
|
|
|
local m = self.currenTime.month
|
|
|
|
|
local d = self.currenTime.day
|
|
|
|
|
self.minTime.year = y
|
|
|
|
|
self.minTime.month = m
|
|
|
|
|
self.minTime.day = d
|
|
|
|
|
self.maxTime.year = y
|
|
|
|
|
self.maxTime.month = m
|
|
|
|
|
self.maxTime.day = d
|
|
|
|
|
|
|
|
|
|
self._callback_clickDay(1, string.format("%s-%02d-%02d", self.minTime.year, self.minTime.month,
|
|
|
|
|
self.minTime.day), string.format("%s-%02d-%02d", self.maxTime.year, self.maxTime.month,
|
|
|
|
|
self.maxTime.day))
|
|
|
|
|
else
|
|
|
|
|
self._callback_clickDay(0, string.format("%s-%02d-%02d", self.currenTime.year, self.currenTime.month,
|
|
|
|
|
self.currenTime.day))
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:UpdateMonth()
|
|
|
|
|
if self.currenTime.month > 12 then
|
|
|
|
|
self.currenTime.month = 1
|
|
|
|
|
self.currenTime.year = self.currenTime.year + 1
|
|
|
|
|
elseif self.currenTime.month < 0 then
|
|
|
|
|
self.currenTime.month = 12
|
|
|
|
|
self.currenTime.year = self.currenTime.year - 1
|
|
|
|
|
end
|
|
|
|
|
self._view_local:GetChild('title').text = string.format("%s-%02d-%02d", self.currenTime.year, self.currenTime.month,
|
|
|
|
|
self.currenTime.day)
|
|
|
|
|
self.list.numItems = self:CalculateMonth()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:CalculateMonth()
|
|
|
|
|
if self.currenTime.month == 2 then
|
|
|
|
|
if (self.currenTime.year % 4 == 0 and self.currenTime.year % 100 ~= 0) or (self.currenTime.year % 400 == 0) then
|
|
|
|
|
return 28
|
|
|
|
|
else
|
|
|
|
|
return 29
|
|
|
|
|
end
|
|
|
|
|
elseif self.currenTime.month <= 7 then
|
|
|
|
|
return self.currenTime.month % 2 == 1 and 31 or 30
|
|
|
|
|
else
|
|
|
|
|
return self.currenTime.month % 2 == 0 and 31 or 30
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:ChooseTime(type, callback)
|
|
|
|
|
if type == 0 then
|
|
|
|
|
self.currenTime = self.minTime
|
|
|
|
|
else
|
|
|
|
|
self.currenTime = self.maxTime
|
|
|
|
|
end
|
|
|
|
|
self:UpdateMonth()
|
|
|
|
|
self._callback_clickDay = callback
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:GetBeginTime()
|
|
|
|
|
return os.time(self.minTime)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function M:GetEndTime()
|
|
|
|
|
return os.time(self.maxTime)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return M
|