2020-07-04 14:41:25 +08:00
|
|
|
local csSelf = nil
|
|
|
|
|
local transform = nil
|
|
|
|
|
local gameObject = nil
|
|
|
|
|
local grid = nil
|
|
|
|
|
|
|
|
|
|
local LabelYY = nil
|
|
|
|
|
local LabelMM = nil
|
|
|
|
|
local curYear = nil
|
|
|
|
|
local curMonth = nil
|
|
|
|
|
local TimeRoot
|
|
|
|
|
local ButtonRoot
|
|
|
|
|
local InputHH
|
|
|
|
|
local InputMM
|
|
|
|
|
local InputSS
|
|
|
|
|
|
2020-07-24 22:12:55 +08:00
|
|
|
local LabelTitle
|
2020-07-04 14:41:25 +08:00
|
|
|
local LabelSelectDate
|
|
|
|
|
|
|
|
|
|
local callback = nil
|
|
|
|
|
|
|
|
|
|
local selectedYear
|
|
|
|
|
local selectedMonth
|
|
|
|
|
local selectedDay
|
|
|
|
|
|
|
|
|
|
local oldSelectedCell
|
|
|
|
|
local isNeedTime = false
|
2020-07-24 22:12:55 +08:00
|
|
|
local isDateRange = false
|
2020-07-04 14:41:25 +08:00
|
|
|
local curIndex = 0
|
2020-07-24 22:12:55 +08:00
|
|
|
local InputTimeStart, InputTimeEnd, InputTime
|
|
|
|
|
local startDate, endDate, startDateStr, endDateStr
|
|
|
|
|
local defaultDateStr, defaultDate, defaultDate2
|
2020-07-04 14:41:25 +08:00
|
|
|
|
|
|
|
|
PanelCalender = {}
|
|
|
|
|
function PanelCalender.init(_cs)
|
|
|
|
|
csSelf = _cs
|
|
|
|
|
transform = csSelf.transform
|
|
|
|
|
gameObject = csSelf.gameObject
|
|
|
|
|
|
|
|
|
|
local content = getChild(transform, "content")
|
|
|
|
|
LabelYY = getChild(content, "Title", "LabelYY"):GetComponent("UILabel")
|
|
|
|
|
LabelMM = getChild(content, "Title", "LabelMM"):GetComponent("UILabel")
|
2020-07-24 22:12:55 +08:00
|
|
|
LabelTitle = getChild(content, "Title", "LabelTitle"):GetComponent("UILabel")
|
|
|
|
|
---@type Coolape.UIGridPage
|
2020-07-04 14:41:25 +08:00
|
|
|
grid = getChild(content, "PanelDay/GridPage"):GetComponent("UIGridPage")
|
|
|
|
|
LabelSelectDate = getChild(content, "LabelSelectDate"):GetComponent("UILabel")
|
|
|
|
|
|
|
|
|
|
ButtonRoot = getChild(content, "ButtonRoot")
|
|
|
|
|
TimeRoot = getChild(content, "TimeRoot")
|
2020-07-24 22:12:55 +08:00
|
|
|
InputTimeStart = getCC(TimeRoot, "InputTimeStart", "CLUIElement")
|
|
|
|
|
InputTimeEnd = getCC(TimeRoot, "InputTimeEnd", "CLUIElement")
|
|
|
|
|
InputTime = getCC(TimeRoot, "InputTime", "CLUIElement")
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.setData(pars)
|
2020-07-24 22:12:55 +08:00
|
|
|
defaultDateStr = pars[0]
|
|
|
|
|
-- curMonth = pars[1]
|
|
|
|
|
callback = pars[1]
|
|
|
|
|
if (pars.Count > 2) then
|
|
|
|
|
isNeedTime = pars[2]
|
2020-07-04 14:41:25 +08:00
|
|
|
else
|
|
|
|
|
isNeedTime = false
|
|
|
|
|
end
|
2020-07-24 22:12:55 +08:00
|
|
|
if (pars.Count > 3) then
|
|
|
|
|
isDateRange = pars[3]
|
|
|
|
|
else
|
|
|
|
|
isDateRange = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if isDateRange then
|
|
|
|
|
if isNilOrEmpty(defaultDateStr) then
|
|
|
|
|
startDate = nil
|
|
|
|
|
endDate = nil
|
|
|
|
|
curYear = DateTime.Now.Year
|
|
|
|
|
curMonth = DateTime.Now.Month
|
|
|
|
|
else
|
|
|
|
|
local strs = strSplit(defaultDateStr, "~")
|
|
|
|
|
defaultDate = DateTime.Parse(strs[1])
|
|
|
|
|
local date = defaultDate
|
|
|
|
|
startDate =
|
|
|
|
|
tonumber(
|
|
|
|
|
joinStr(NumEx.nStrForLen(date.Year, 4), NumEx.nStrForLen(date.Month, 2), NumEx.nStrForLen(date.Day, 2))
|
|
|
|
|
)
|
|
|
|
|
startDateStr = joinStr(date.Year, "-", date.Month, "-", date.Day)
|
|
|
|
|
curYear = date.Year
|
|
|
|
|
curMonth = date.Month
|
|
|
|
|
|
|
|
|
|
defaultDate2 = DateTime.Parse(strs[2])
|
|
|
|
|
date = defaultDate2
|
|
|
|
|
endDate =
|
|
|
|
|
tonumber(
|
|
|
|
|
joinStr(NumEx.nStrForLen(date.Year, 4), NumEx.nStrForLen(date.Month, 2), NumEx.nStrForLen(date.Day, 2))
|
|
|
|
|
)
|
|
|
|
|
endDateStr = joinStr(date.Year, "-", date.Month, "-", date.Day)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if isNilOrEmpty(defaultDateStr) then
|
|
|
|
|
curYear = DateTime.Now.Year
|
|
|
|
|
curMonth = DateTime.Now.Month
|
|
|
|
|
defaultDate = nil
|
|
|
|
|
selectedYear = nil
|
|
|
|
|
selectedMonth = nil
|
|
|
|
|
selectedDay = nil
|
|
|
|
|
else
|
|
|
|
|
defaultDate = DateTime.Parse(defaultDateStr)
|
|
|
|
|
curYear = defaultDate.Year
|
|
|
|
|
curMonth = defaultDate.Month
|
|
|
|
|
selectedYear = defaultDate.Year
|
|
|
|
|
selectedMonth = defaultDate.Month
|
|
|
|
|
selectedDay = defaultDate.Day
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.getData()
|
|
|
|
|
return curYear, curMonth
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-24 22:12:55 +08:00
|
|
|
function PanelCalender.getDateRangeDate()
|
|
|
|
|
return isDateRange, startDate, endDate
|
|
|
|
|
end
|
|
|
|
|
|
2020-07-04 14:41:25 +08:00
|
|
|
function PanelCalender.show()
|
|
|
|
|
csSelf.panel.depth = CLPanelManager.self.depth + 80
|
|
|
|
|
oldSelectedCell = nil
|
|
|
|
|
if (isNeedTime) then
|
2020-07-24 22:12:55 +08:00
|
|
|
if isDateRange then
|
|
|
|
|
LabelTitle.text = "选择时间范围"
|
|
|
|
|
SetActive(InputTimeStart.gameObject, true)
|
|
|
|
|
if defaultDate then
|
|
|
|
|
InputTimeStart.value = defaultDate:ToString(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
else
|
|
|
|
|
InputTimeStart.value = DateEx.format(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
end
|
|
|
|
|
SetActive(InputTimeEnd.gameObject, true)
|
|
|
|
|
if defaultDate2 then
|
|
|
|
|
InputTimeEnd.value = defaultDate2:ToString(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
else
|
|
|
|
|
InputTimeEnd.value = DateEx.format(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
end
|
|
|
|
|
SetActive(InputTime.gameObject, false)
|
|
|
|
|
else
|
|
|
|
|
LabelTitle.text = "选择时间"
|
|
|
|
|
SetActive(InputTimeStart.gameObject, false)
|
|
|
|
|
SetActive(InputTimeEnd.gameObject, false)
|
|
|
|
|
SetActive(InputTime.gameObject, true)
|
|
|
|
|
if defaultDate then
|
|
|
|
|
InputTime.value = defaultDate:ToString(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
else
|
|
|
|
|
InputTime.value = DateEx.format(DateEx.fmt_HH_mm_ss)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
NGUITools.SetActive(TimeRoot.gameObject, true)
|
2020-07-24 22:12:55 +08:00
|
|
|
ButtonRoot.localPosition = Vector3(0, -915, 0)
|
2020-07-04 14:41:25 +08:00
|
|
|
else
|
2020-07-24 22:12:55 +08:00
|
|
|
if isDateRange then
|
|
|
|
|
LabelTitle.text = "选择日期范围"
|
|
|
|
|
else
|
|
|
|
|
LabelTitle.text = "选择日期"
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
NGUITools.SetActive(TimeRoot.gameObject, false)
|
|
|
|
|
ButtonRoot.localPosition = TimeRoot.localPosition
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.refresh()
|
|
|
|
|
PanelCalender.showCalender(curYear, curMonth)
|
2020-07-24 22:12:55 +08:00
|
|
|
if isDateRange then
|
|
|
|
|
if startDate and endDate then
|
|
|
|
|
LabelSelectDate.text =
|
|
|
|
|
joinStr(
|
|
|
|
|
"[999999]开始日期:[-][363636]",
|
|
|
|
|
startDateStr,
|
|
|
|
|
"[-] ",
|
|
|
|
|
"[999999]结束日期:[-][363636]",
|
|
|
|
|
endDateStr,
|
|
|
|
|
"[-]"
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
LabelSelectDate.text =
|
|
|
|
|
joinStr("[999999]开始日期:[-][363636]", "请选择", "[-] ", "[999999]结束日期:[-][363636]", "请选择", "[-]")
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
else
|
2020-07-24 22:12:55 +08:00
|
|
|
if (selectedYear ~= nil) then
|
|
|
|
|
local dataStr =
|
|
|
|
|
PStr.b():a(tostring(selectedYear)):a("-"):a(NumEx.nStrForLen(selectedMonth, 2)):a("-"):a(
|
|
|
|
|
NumEx.nStrForLen(selectedDay, 2)
|
|
|
|
|
):e()
|
|
|
|
|
LabelSelectDate.text = joinStr("[999999]选择日期:[-][363636]", dataStr, "[-])")
|
|
|
|
|
else
|
|
|
|
|
LabelSelectDate.text = ""
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.getYYHH_ByaddMonth(_year, _month, addMonth)
|
|
|
|
|
local date = DateTime(_year, _month, 1)
|
|
|
|
|
|
|
|
|
|
date = date:AddMonths(addMonth)
|
|
|
|
|
|
|
|
|
|
return date.Year, date.Month
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.showCalender(year, month)
|
|
|
|
|
LabelYY.text = year .. "年"
|
|
|
|
|
LabelMM.text = month .. "月"
|
|
|
|
|
|
|
|
|
|
local months = ArrayList()
|
|
|
|
|
local d
|
|
|
|
|
local yy, mm
|
|
|
|
|
for i = 1, 6 do
|
|
|
|
|
yy, mm = PanelCalender.getYYHH_ByaddMonth(year, month, -(7 - i))
|
|
|
|
|
d = {}
|
|
|
|
|
d.year = yy
|
|
|
|
|
d.month = mm
|
|
|
|
|
months:Add(d)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
d = {}
|
|
|
|
|
d.year = year
|
|
|
|
|
d.month = month
|
|
|
|
|
months:Add(d)
|
|
|
|
|
|
|
|
|
|
for i = 1, 6 do
|
|
|
|
|
yy, mm = PanelCalender.getYYHH_ByaddMonth(year, month, i)
|
|
|
|
|
d = {}
|
|
|
|
|
d.year = yy
|
|
|
|
|
d.month = mm
|
|
|
|
|
months:Add(d)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
grid:init(months, PanelCalender.onRefreshCurrent, 6)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.onRefreshCurrent(index, data, cell)
|
|
|
|
|
curIndex = index
|
|
|
|
|
local cellLua = cell:GetComponent("CLCellLua")
|
|
|
|
|
local d = cellLua.luaTable.getData()
|
|
|
|
|
if (d ~= nil) then
|
|
|
|
|
LabelYY.text = d.year .. "年"
|
|
|
|
|
LabelMM.text = d.month .. "月"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.getSelectDate()
|
|
|
|
|
return selectedYear, selectedMonth, selectedDay
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.setDefalutSelectDate(cell, year, month, day)
|
|
|
|
|
if (oldSelectedCell == nil) then
|
|
|
|
|
oldSelectedCell = cell
|
|
|
|
|
end
|
|
|
|
|
if (selectedDay == nil) then
|
|
|
|
|
selectedDay = day
|
|
|
|
|
selectedYear = year
|
|
|
|
|
selectedMonth = month
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.setSelectDate(cell, year, month, day)
|
|
|
|
|
selectedDay = day
|
|
|
|
|
selectedYear = year
|
|
|
|
|
selectedMonth = month
|
2020-07-24 22:12:55 +08:00
|
|
|
if isDateRange then
|
|
|
|
|
local dataStr = ""
|
|
|
|
|
local tmpDate =
|
|
|
|
|
tonumber(joinStr(NumEx.nStrForLen(year, 4), NumEx.nStrForLen(month, 2), NumEx.nStrForLen(day, 2)))
|
|
|
|
|
local tmpDateStr = joinStr(year, "-", month, "-", day)
|
|
|
|
|
-- 选择日期范围
|
|
|
|
|
if startDate == nil then
|
|
|
|
|
startDate = tmpDate
|
|
|
|
|
startDateStr = tmpDateStr
|
|
|
|
|
dataStr =
|
|
|
|
|
joinStr("[999999]开始日期:[-][363636]", startDateStr, "[-] ", "[999999]结束日期:[-][363636]", "请选择", "[-]")
|
|
|
|
|
elseif startDate > tmpDate then
|
|
|
|
|
startDate = tmpDate
|
|
|
|
|
startDateStr = tmpDateStr
|
|
|
|
|
endDate = nil
|
|
|
|
|
dataStr =
|
|
|
|
|
joinStr("[999999]开始日期:[-][363636]", startDateStr, "[-] ", "[999999]结束日期:[-][363636]", "请选择", "[-]")
|
|
|
|
|
else
|
|
|
|
|
endDate = tmpDate
|
|
|
|
|
endDateStr = tmpDateStr
|
|
|
|
|
dataStr =
|
|
|
|
|
joinStr(
|
|
|
|
|
"[999999]开始日期:[-][363636]",
|
|
|
|
|
startDateStr,
|
|
|
|
|
"[-] ",
|
|
|
|
|
"[999999]结束日期:[-][363636]",
|
|
|
|
|
tmpDateStr,
|
|
|
|
|
"[-]"
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
LabelSelectDate.text = dataStr
|
|
|
|
|
PanelCalender.refreshDays()
|
|
|
|
|
else
|
|
|
|
|
local dataStr =
|
|
|
|
|
PStr.b():a(tostring(selectedYear)):a("-"):a(NumEx.nStrForLen(selectedMonth, 2)):a("-"):a(
|
|
|
|
|
NumEx.nStrForLen(selectedDay, 2)
|
|
|
|
|
):e()
|
|
|
|
|
LabelSelectDate.text = joinStr("[999999]选择日期:[-][363636]", dataStr, "[-]")
|
|
|
|
|
|
|
|
|
|
if (oldSelectedCell ~= nil) then
|
|
|
|
|
oldSelectedCell.luaTable.refreshState(false)
|
|
|
|
|
end
|
|
|
|
|
oldSelectedCell = cell
|
|
|
|
|
oldSelectedCell.luaTable.refreshState(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.refreshDays()
|
|
|
|
|
local cell = grid.page1:GetComponent("CLCellLua")
|
|
|
|
|
if cell and cell.luaTable then
|
|
|
|
|
cell.luaTable.doRefresh()
|
|
|
|
|
end
|
|
|
|
|
cell = grid.page2:GetComponent("CLCellLua")
|
|
|
|
|
if cell and cell.luaTable then
|
|
|
|
|
cell.luaTable.doRefresh()
|
|
|
|
|
end
|
|
|
|
|
cell = grid.page3:GetComponent("CLCellLua")
|
|
|
|
|
if cell and cell.luaTable then
|
|
|
|
|
cell.luaTable.doRefresh()
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- function PanelCalender.addMonth(m)
|
|
|
|
|
-- oldSelectedCell = nil;
|
|
|
|
|
--
|
|
|
|
|
-- local yearOffset = (curMonth + m) / 13;
|
|
|
|
|
-- curMonth = (curMonth + m) % 13;
|
|
|
|
|
-- if (curMonth == 0) then
|
|
|
|
|
-- if (m < 0) then
|
|
|
|
|
-- curMonth = 12;
|
|
|
|
|
-- yearOffset = -1;
|
|
|
|
|
-- else
|
|
|
|
|
-- curMonth = 1;
|
|
|
|
|
-- end
|
|
|
|
|
-- end
|
|
|
|
|
--
|
|
|
|
|
-- curYear = curYear + math.floor(yearOffset);
|
|
|
|
|
-- PanelCalender.showCalender(curYear, curMonth);
|
|
|
|
|
-- return curYear, curMonth;
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.hide()
|
2020-07-24 22:12:55 +08:00
|
|
|
if (oldSelectedCell ~= nil) then
|
|
|
|
|
oldSelectedCell.luaTable.refreshState(false)
|
|
|
|
|
end
|
|
|
|
|
oldSelectedCell = nil
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.procNetwork(cmd, succ, msg, paras)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.uiEventDelegate(go)
|
|
|
|
|
PanelCalender.onClickBtn(go.name)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PanelCalender.onClickBtn(btnName)
|
|
|
|
|
if (btnName == "ButtonPrevMM") then
|
|
|
|
|
-- PanelCalender.addMonth(-1);
|
|
|
|
|
grid:moveTo(curIndex - 1)
|
|
|
|
|
elseif (btnName == "ButtonNextMM") then
|
|
|
|
|
-- PanelCalender.addMonth(1);
|
|
|
|
|
grid:moveTo(curIndex + 1)
|
|
|
|
|
elseif (btnName == "ButtonPrevYY") then
|
|
|
|
|
-- PanelCalender.addMonth(-13);
|
|
|
|
|
grid:moveTo(curIndex - 12)
|
|
|
|
|
elseif (btnName == "ButtonNextYY") then
|
|
|
|
|
-- PanelCalender.addMonth(13);
|
|
|
|
|
grid:moveTo(curIndex + 12)
|
|
|
|
|
elseif (btnName == "SpriteClose" or btnName == "ButtonClose") then
|
|
|
|
|
CLPanelManager.hidePanel(csSelf)
|
|
|
|
|
elseif btnName == "ButtonToday" then
|
|
|
|
|
oldSelectedCell = nil
|
|
|
|
|
curYear = DateTime.Now.Year
|
|
|
|
|
curMonth = DateTime.Now.Month
|
2020-07-24 22:12:55 +08:00
|
|
|
selectedYear = nil
|
|
|
|
|
selectedMonth = nil
|
|
|
|
|
selectedDay = nil
|
|
|
|
|
startDate = nil
|
|
|
|
|
endDate = nil
|
|
|
|
|
startDateStr = ""
|
|
|
|
|
endDateStr = ""
|
2020-07-10 13:22:24 +08:00
|
|
|
PanelCalender.show()
|
|
|
|
|
PanelCalender.refresh()
|
2020-07-04 14:41:25 +08:00
|
|
|
elseif btnName == "ButtonOkay" then
|
|
|
|
|
local dataStr = ""
|
2020-07-24 22:12:55 +08:00
|
|
|
if isDateRange then
|
|
|
|
|
if startDate == nil or endDate == nil then
|
|
|
|
|
MyUtl.toastW("请选择开始结束日期")
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
CLPanelManager.hidePanel(csSelf)
|
|
|
|
|
if isNeedTime then
|
|
|
|
|
dataStr = joinStr(startDateStr, " ", InputTimeStart.value, "~", endDateStr, " ", InputTimeEnd.value)
|
|
|
|
|
else
|
|
|
|
|
dataStr = joinStr(startDateStr, "~", endDateStr)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
CLPanelManager.hidePanel(csSelf)
|
|
|
|
|
if (selectedYear ~= nil) then
|
2020-07-04 14:41:25 +08:00
|
|
|
dataStr =
|
2020-07-24 22:12:55 +08:00
|
|
|
PStr.b():a(tostring(selectedYear)):a("-"):a(NumEx.nStrForLen(selectedMonth, 2)):a("-"):a(
|
|
|
|
|
NumEx.nStrForLen(selectedDay, 2)
|
|
|
|
|
):e()
|
|
|
|
|
if (isNeedTime) then
|
|
|
|
|
dataStr = joinStr(dataStr, " ", InputTime.value)
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
Utl.doCallback(callback, dataStr)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return PanelCalender
|