223 lines
7.3 KiB
JavaScript
223 lines
7.3 KiB
JavaScript
var timer = null;
|
|
|
|
function setMonthCalendar(year, month, id) {
|
|
//一月份所有事件
|
|
var momentMonth = moment({ year: year, month: (month - 1) });
|
|
var monthpad = (month + "").padStart(2, "0");
|
|
var startDate = "{0}-{1}-01".template(year, monthpad);
|
|
var endDate = "{0}-{1}-{2}".template(year, monthpad, momentMonth.daysInMonth());
|
|
var eventArray1 = []; //控件需要日期
|
|
Calendar.HolidyObj = [];
|
|
if (Calendar.HolidayJson) {
|
|
Calendar.HolidyObj = JSON.parse(Calendar.HolidayJson);
|
|
}
|
|
var monthArray = [year, monthpad];
|
|
var holidays1 = $.grep(Calendar.HolidyObj, function (val) {
|
|
return val.indexOf(monthArray.join(",")) >= 0;
|
|
});
|
|
|
|
$.each(holidays1, function (i, d) {
|
|
var wWeight = d.indexOf("*") > 0 ? d.split('*')[1] : "";
|
|
eventArray1.push({ startDate: d, endDate: d, withWeight: wWeight });
|
|
});
|
|
|
|
$('#' + id).clndr({
|
|
template: $('#clndr-template').html(),
|
|
events: eventArray1,
|
|
constraints: {
|
|
startDate: startDate,
|
|
endDate: endDate
|
|
},
|
|
multiDayEvents: {
|
|
singleDay: 'date',
|
|
endDate: 'endDate',
|
|
startDate: 'startDate'
|
|
},
|
|
clickEvents: {
|
|
click: function (target) {
|
|
var calObj = this;
|
|
eventArray1 = calObj.eventsThisInterval;
|
|
clearTimeout(timer);
|
|
timer = setTimeout(function () {
|
|
var clickday = target.date.format("YYYY,MM,DD");
|
|
//维护eventArray1
|
|
var existholiday = $.grep(eventArray1, function (v) {
|
|
return v.startDate.indexOf(clickday) >= 0;
|
|
});
|
|
if (existholiday.length == 0) {
|
|
eventArray1.push({ startDate: clickday, endDate: clickday });
|
|
} else {
|
|
eventArray1 = $.grep(eventArray1, function (v) {
|
|
return v.startDate.indexOf(clickday) < 0;
|
|
});
|
|
}
|
|
|
|
Calendar.HolidyObj = $.grep(Calendar.HolidyObj, function (val) {
|
|
return val.indexOf(monthArray.join(",")) < 0;
|
|
});
|
|
$.each(eventArray1, function (i, d) {
|
|
Calendar.HolidyObj.push(d.startDate);
|
|
});
|
|
Calendar.HolidyObj.sort(function (a, b) { return b - a; });
|
|
Calendar.HolidayJson = JSON.stringify(Calendar.HolidyObj);
|
|
calObj.setEvents(eventArray1);
|
|
$(".today").removeClass("today");
|
|
|
|
}, 230);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
$(function () {
|
|
for (var month = 1; month <= 12; month++) {
|
|
setMonthCalendar(Calendar.Year, month, "month" + month);
|
|
}
|
|
|
|
//今天显示样式补丁
|
|
$(".today").removeClass("today");
|
|
});
|
|
|
|
function deletecalendar(id) {
|
|
main.confirm("确定删除吗?", function () {
|
|
$.ajax({
|
|
type: "Post",
|
|
url: "/calendar/Deletecalendar",
|
|
data: { id: id, d: new Date() },
|
|
success: function (data) {
|
|
alert(data.msg);
|
|
if (data.success == true) {
|
|
window.parent.location = window.parent.location;
|
|
window.close();
|
|
}
|
|
},
|
|
error: function (msg) {
|
|
alert("error:" + msg);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function save_yearcalendar() {
|
|
main.confirm("确定保存修改?", function () {
|
|
main.post("/calendar/SaveYearCalendar", Calendar).done(function () {
|
|
});
|
|
});
|
|
}
|
|
|
|
function saveSetWeight() {
|
|
var kob = this;
|
|
var newWeight = $('#setWeightInput').val().trim();
|
|
if (newWeight !== "") {
|
|
var savedWeight = parseFloat(newWeight);
|
|
if (!savedWeight || savedWeight < 0 || savedWeight > 1) {
|
|
return main.alert('请设置合理的权重(0~1范围)');
|
|
}
|
|
} else { newWeight = "0"; }
|
|
|
|
var curdate = $("#holidayDate").val();//可能带权重的旧值
|
|
var curyearmonth = curdate.split(',')[0] + "," + curdate.split(',')[1];
|
|
var datepart = curdate.indexOf('*') >= 0 ? curdate.split('*')[0] : curdate;
|
|
var newcurDate = datepart + (newWeight !== "0" ? "*" + newWeight : "");
|
|
var eventArray1 = [];
|
|
var curclndr = $("#month" + parseInt(curdate.split(',')[1]));
|
|
|
|
Calendar.HolidyObj = JSON.parse(Calendar.HolidayJson);
|
|
Calendar.HolidyObj = $.grep(Calendar.HolidyObj, function (val) {
|
|
return val.indexOf(curdate) < 0;
|
|
});
|
|
Calendar.HolidyObj.push(newcurDate);//update
|
|
Calendar.HolidyObj.sort(function (a, b) { return b - a; });
|
|
Calendar.HolidayJson = JSON.stringify(Calendar.HolidyObj);
|
|
|
|
$.each(Calendar.HolidyObj, function (i, d) {
|
|
if (d.indexOf(curyearmonth) >= 0) { //限当月
|
|
var wWeight = d.indexOf("*") > 0 ? d.split('*')[1] : "";
|
|
eventArray1.push({ startDate: d, endDate: d, withWeight: wWeight });
|
|
}
|
|
});
|
|
|
|
curclndr.clndr().setEvents(eventArray1);//re-render calendar
|
|
$(".today").removeClass("today");
|
|
layer.closeAll();
|
|
|
|
if (newWeight === "0") {
|
|
layer.msg('已清除权重');
|
|
}
|
|
else {
|
|
layer.msg('设置成功');
|
|
}
|
|
}
|
|
|
|
//设置日期权重
|
|
function showDateWeight(parm) {
|
|
clearTimeout(timer);
|
|
if (transferChineseToMonth(parm.curMonth) !== parm.curDay.split('-')[1]) {
|
|
return;
|
|
}
|
|
|
|
var curdate = parm.curDay.replace(new RegExp("-", "g"), ',');
|
|
var curWeight = parm.wWeight;
|
|
|
|
//console.log(parm);
|
|
|
|
$("#setWeightInput").val(curWeight);
|
|
$("#holidayDate").val(curWeight === "" ? curdate : curdate + "*" + curWeight);
|
|
layer.open({
|
|
type: 1,
|
|
title: "当前为日期: <b>" + parm.curDay + "</b> 设置权重",
|
|
area: '350px',
|
|
content: $('#setWeight')
|
|
});
|
|
}
|
|
|
|
function transferChineseToMonth(cnMonth) {
|
|
|
|
if (cnMonth == "一月") {
|
|
return "01";
|
|
}
|
|
else if (cnMonth == "二月") {
|
|
return "02";
|
|
}
|
|
else if (cnMonth == "三月") {
|
|
return "03";
|
|
} else if (cnMonth == "四月") {
|
|
return "04";
|
|
} else if (cnMonth == "五月") {
|
|
return "05";
|
|
} else if (cnMonth == "六月") {
|
|
return "06";
|
|
} else if (cnMonth == "七月") {
|
|
return "07";
|
|
} else if (cnMonth == "八月") {
|
|
return "08";
|
|
} else if (cnMonth == "九月") {
|
|
return "09";
|
|
} else if (cnMonth == "十月") {
|
|
return "10";
|
|
} else if (cnMonth == "十一月") {
|
|
return "11";
|
|
} else if (cnMonth == "十二月") {
|
|
return "12";
|
|
}
|
|
}
|
|
|
|
function getDayInfo(day, eventsThisMonth) {
|
|
let dayInfo = {
|
|
curDay: day.date._d.Format('yyyy-MM-dd'), bholiday: false,
|
|
weightValue: '', weightTitle: '', classes: day.classes + ' day-clndr'
|
|
};
|
|
let index = _.findIndex(eventsThisMonth, function (val) {
|
|
return val.startDate.replace(new RegExp(",", "g"), '-').indexOf(dayInfo.curDay) >= 0;
|
|
});
|
|
if (index >= 0) {
|
|
dayInfo.bholiday = true;
|
|
dayInfo.classes += " isholiday";
|
|
dayInfo.weightValue = eventsThisMonth[index].withWeight || '';
|
|
if (dayInfo.weightValue) {
|
|
dayInfo.classes += ' withWeight';
|
|
dayInfo.weightTitle = "权重:" + dayInfo.weightValue;
|
|
}
|
|
}
|
|
return dayInfo;
|
|
} |