var table, form, layer, laydate, element;
var currentDate = new Date();
var tabList = [];
var month = currentDate.getMonth() + 1; //当前第几月
var year = currentDate.getFullYear();
var resultMonth = localStorage.getItem("resultMakeMonth");
var resultUserId;
var resultProId;
layui.use(['form', 'layer', 'table', 'laydate', 'element'], function() {
table = layui.table;
form = layui.form;
layer = layui.layer;
laydate = layui.laydate;
element = layui.element;
// 渲染时间选择器
laydate.render({
elem: '#month', //指定元素 元素选择器
type: 'month', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
trigger: 'click',
min: firstDayStr(),
max: lastDayStr(),
format: 'yyyy-MM',
btns: ['now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
value: formatCurrentMonth(), // 如果你想预设当前日期为选中状态
done: function(value, date) { //时间回调
console.log("date:", date);
resultMonth = value;
init(date.year, date.month);
}
});
$("#month").val(resultMonth);
setData()
let result = getYearMonth(resultMonth);
init(result.oldYear, result.oldMonth);
});
function firstDayStr() {
var today = new Date();
var thisMonth = today.getMonth(); // 获取当前月份(从0开始)
var year = today.getFullYear(); // 获取当前年份
// 当月的第一天
var firstDay = new Date(year, thisMonth - 1, 2);
var firstDayString = firstDay.toISOString().slice(0, 10); // 转换为YYYY-MM-DD格式
// 当月的最后一天
var lastDay = new Date(year, thisMonth + 1, 1);
var lastDayString = lastDay.toISOString().slice(0, 7); // 转换为YYYY-MM-DD格式
console.log("First day of this month: " + firstDayString);
return firstDayString;
}
function lastDayStr() {
var today = new Date();
var thisMonth = today.getMonth(); // 获取当前月份(从0开始)
var year = today.getFullYear(); // 获取当前年份
// 当月的第一天
var firstDay = new Date(year, thisMonth, 1);
var firstDayString = firstDay.toISOString().slice(0, 7); // 转换为YYYY-MM-DD格式
// 当月的最后一天
var lastDay = new Date();
var lastDayString = lastDay.toISOString().slice(0, 10); // 转换为YYYY-MM-DD格式
return lastDayString;
}
function currMonth() {
var lastDay = new Date();
var lastDayString = lastDay.toISOString().slice(0, 7); // 转换为YYYY-MM格式
return lastDayString;
}
function currUpdateMonth(update) {
var lastDay = new Date();
lastDay.setMonth(lastDay.getMonth() + update);
var lastDayString = lastDay.toISOString().slice(0, 7); // 转换为YYYY-MM格式
return lastDayString;
}
//工程切换
function projectTab(event, proId) {
resultProId = proId;
localStorage.setItem("resultProId", resultProId);
console.log(resultProId, 'resultProId')
//修改所点工程样式
$("#projects>div").removeClass("projectsStyle");
$(event).addClass("projectsStyle")
getView();
let result = getYearMonth(resultMonth);
// init(result.oldYear,result.oldMonth);
getSpecial(result.oldYear, result.oldMonth);
}
function formatCurrentMonth() {
var date = new Date();
var month = date.getMonth() + 1; // 注意月份是从0开始的,所以加1
return date.getFullYear() + '-' + (month < 10 ? '0' + month : month);
}
/**
* 初始化数据
*/
function init(chosenYear, chosenMonth) {
layui.use(['table'], function() {
getTab(chosenMonth)
if (resultMonth != currMonth() && resultMonth != currUpdateMonth(-1) ) {
$("#normalInspectionUpload").css("display", "none")
getViewc();
} else {
$("#normalInspectionUpload").css("display", "")
getView();
}
getSpecial(chosenYear, chosenMonth)
})
}
function getSpecial(chosenYear, chosenMonth) {
let table = layui.table;
let daysInMonth = new Date(chosenYear, chosenMonth, 0).getDate();
console.log(daysInMonth)
let tableData = []
$.ajax({ //id获取详情打开弹窗传值子页面
type: 'post',
url: PATH_URL + "/makeInfo/getSpecialData",
dataType: 'json',
async: false,
data: {
userId: localStorage.getItem("resultUserId"),
proId: localStorage.getItem("resultProId"),
makeMonth: resultMonth
},
success: function(data) {
console.log(data, "resultSpecial");
var isWorkData = [];
$.each(data.data, function(index, item) {
isWorkData.push(item.makeTime)
})
var isWork = {};
isWork.isWork = isWorkData;
tableData.push(isWork);
},
error: function(e) {
}
})
let cols = []
for (let k = 1; k <= daysInMonth; k++) {
let str = chosenMonth + '.' + k;
let obj = {
field: 'isWork',
title: str,
align: 'center',
width: 70,
templet: function(d) {
if (d.isWork.includes(d.LAY_COL.title)) {
return ` `
} else {
return `
${gtName} `
if ("1" == viewList1[i].state || "1" == viewList1[i].makeType) {
html += `
`
}
html += `
`
html += `
`
html += `
${gtName}
`
if ("1" == viewList2[i].state || "1" == viewList2[i].makeType) {
html += `
`
}
html += `
`
html += `
`
html += `
${gtName}
${gtName}
${gtName}
${gtName}