2020-07-04 14:41:25 +08:00
|
|
|
|
-- xx单元
|
|
|
|
|
|
do
|
|
|
|
|
|
local _cell = {}
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local csSelf = nil
|
|
|
|
|
|
local transform = nil
|
|
|
|
|
|
local grid
|
|
|
|
|
|
local dayPrefab = nil
|
|
|
|
|
|
local mData = nil
|
|
|
|
|
|
|
|
|
|
|
|
local dayList
|
2020-07-04 14:41:25 +08:00
|
|
|
|
|
|
|
|
|
|
-- 初始化,只调用一次
|
|
|
|
|
|
function _cell.init(csObj)
|
2020-07-24 22:12:55 +08:00
|
|
|
|
csSelf = csObj
|
|
|
|
|
|
transform = csSelf.transform
|
|
|
|
|
|
grid = getChild(transform, "Grid"):GetComponent("UIGrid")
|
|
|
|
|
|
dayPrefab = getChild(grid.transform, "00000").gameObject
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- 注意,c#侧不会在调用show时,调用refresh
|
|
|
|
|
|
function _cell.refresh(data, pageIndex)
|
2020-07-24 22:12:55 +08:00
|
|
|
|
mData = data
|
2020-07-04 14:41:25 +08:00
|
|
|
|
if (mData == nil) then
|
|
|
|
|
|
mData = {}
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local curYear, curMonth = PanelCalender.getData()
|
2020-07-04 14:41:25 +08:00
|
|
|
|
if (pageIndex < 0) then
|
2020-07-24 22:12:55 +08:00
|
|
|
|
mData.year, mData.month = PanelCalender.getYYHH_ByaddMonth(curYear, curMonth, -6 + pageIndex)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
else
|
2020-07-24 22:12:55 +08:00
|
|
|
|
mData.year, mData.month = PanelCalender.getYYHH_ByaddMonth(curYear, curMonth, -6 + pageIndex)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
end
|
2020-07-24 22:12:55 +08:00
|
|
|
|
dayList = _cell.resetCalender(mData.year, mData.month)
|
|
|
|
|
|
CLUIUtl.resetList4Lua(grid, dayPrefab, dayList, _cell.initCellDay)
|
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
|
|
2020-07-24 22:12:55 +08:00
|
|
|
|
function _cell.doRefresh()
|
|
|
|
|
|
CLUIUtl.resetList4Lua(grid, dayPrefab, dayList, _cell.initCellDay)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- 取得数据
|
|
|
|
|
|
function _cell.getData()
|
2020-07-24 22:12:55 +08:00
|
|
|
|
return mData
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _cell.initCellDay(cell, day)
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local data
|
|
|
|
|
|
if cell.luaTable then
|
|
|
|
|
|
data = cell.luaTable.getData()
|
|
|
|
|
|
else
|
|
|
|
|
|
data = {}
|
|
|
|
|
|
end
|
|
|
|
|
|
data.day = day
|
|
|
|
|
|
local selectedYear, selectedMonth, selectedDay = PanelCalender.getSelectDate()
|
|
|
|
|
|
if (mData.year == DateTime.Now.Year and mData.month == DateTime.Now.Month and day == DateTime.Now.Day) then
|
|
|
|
|
|
data.isToday = true
|
|
|
|
|
|
if selectedYear == nil then
|
|
|
|
|
|
PanelCalender.setDefalutSelectDate(cell, mData.year, mData.month, day)
|
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
|
else
|
2020-07-24 22:12:55 +08:00
|
|
|
|
data.isToday = false
|
|
|
|
|
|
data.isSelected = false
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
2020-07-24 22:12:55 +08:00
|
|
|
|
data.isSelected = false
|
|
|
|
|
|
local isDateRange, startDate, endDate = PanelCalender.getDateRangeDate()
|
|
|
|
|
|
if isDateRange then
|
|
|
|
|
|
local tmpDate =
|
|
|
|
|
|
tonumber(
|
|
|
|
|
|
joinStr(
|
|
|
|
|
|
NumEx.nStrForLen(mData.year, 4),
|
|
|
|
|
|
NumEx.nStrForLen(mData.month, 2),
|
|
|
|
|
|
NumEx.nStrForLen(data.day, 2)
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
if tmpDate and (startDate and tmpDate >= startDate) and (endDate and tmpDate <= endDate) then
|
|
|
|
|
|
data.isSelected = true
|
|
|
|
|
|
elseif tmpDate and (startDate and tmpDate == startDate) and endDate == nil then
|
|
|
|
|
|
data.isSelected = true
|
|
|
|
|
|
else
|
|
|
|
|
|
data.isSelected = false
|
|
|
|
|
|
end
|
|
|
|
|
|
else
|
|
|
|
|
|
if (mData.year == selectedYear and mData.month == selectedMonth and selectedDay == data.day) then
|
|
|
|
|
|
data.isSelected = true
|
|
|
|
|
|
PanelCalender.setDefalutSelectDate(cell, mData.year, mData.month, day)
|
|
|
|
|
|
end
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
2020-07-24 22:12:55 +08:00
|
|
|
|
cell:init(data, _cell.onClickDay)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _cell.onClickDay(cell)
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local d = cell.luaTable.getData()
|
2020-07-04 14:41:25 +08:00
|
|
|
|
if (d.day == -1) then
|
2020-07-24 22:12:55 +08:00
|
|
|
|
return
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local selectedDay = cell.luaTable.getData().day
|
|
|
|
|
|
local selectedMonth = mData.month
|
|
|
|
|
|
local selectedYear = mData.year
|
2020-07-04 14:41:25 +08:00
|
|
|
|
|
2020-07-24 22:12:55 +08:00
|
|
|
|
PanelCalender.setSelectDate(cell, selectedYear, selectedMonth, selectedDay)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _cell.resetCalender(year, month)
|
2020-07-24 22:12:55 +08:00
|
|
|
|
local list = ArrayList()
|
|
|
|
|
|
local dayCount = DateEx.getMothDays(year, month)
|
|
|
|
|
|
local week = DateEx.getWeek(year, month, 1)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
for i = 0, week - 1 do
|
2020-07-24 22:12:55 +08:00
|
|
|
|
list:Add(-1)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
for i = week, dayCount - 1 + week do
|
|
|
|
|
|
-- print(i .. "-" .. week .. "+1");
|
2020-07-24 22:12:55 +08:00
|
|
|
|
list:Add(i - week + 1)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
for i = dayCount + week, 41 do
|
2020-07-24 22:12:55 +08:00
|
|
|
|
list:Add(-1)
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
2020-07-24 22:12:55 +08:00
|
|
|
|
return list
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------
|
2020-07-24 22:12:55 +08:00
|
|
|
|
return _cell
|
2020-07-04 14:41:25 +08:00
|
|
|
|
end
|