cc-jjsp-web/bns/js/dutyTask/dailyDutyReportAjax.js

132 lines
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 加载日报数据
function getDaily(currentDay, orgIds) {
let loadingMsg = layer.msg("数据加载中,请稍候...", { icon: 16, scrollbar: false, time: 0 });
$.ajax({
headers: {
encrypt: sm3(
JSON.stringify({
currentDay: currentDay,
})
),
},
type: "POST",
url: dataUrl + "proteam/pot/cityDailyDutyReport/getDailyData?token=" + token,
data: {
currentDay: currentDay
},
async: false,
dataType: "json",
success: function (result) {
layer.close(loadingMsg);
if (result.code === 500) {
setCityDailyData(currentDay, null);
return layer.alert(data.msg, { icon: 2, });
} else if (result.code === 401) {
logout(1);
} else if (result.code === 200) {
if (result.data) {
setCityDailyData(currentDay, result.data);
} else {
setCityDailyData(currentDay, null);
}
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
layer.close(loadingMsg); // 关闭提示层
layer.msg("数据加载发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000 });
setCityDailyData(currentDay, null);
},
});
}
// 下载日报
function downloadDaily() {
let suffix = 'doc';
let downloadType = dataObj.downloadType;
if(downloadType && downloadType.length > 0){
suffix = downloadType[0];
}
$('.download-btn').addClass("layui-btn-disabled").attr("disabled", true);
let loadingMsg = layer.msg("日报下载中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
let url = dataUrl + "proteam/pot/cityDailyDutyReport/downloadDaily?currentDay=" + checkedDate + "&chineseDate=" + setDate(checkedDate) + "&token=" + token;
let xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader(
"encrypt", sm3(
JSON.stringify({
currentDay: checkedDate,
chineseDate: setDate(checkedDate),
})
)
);
xhr.setRequestHeader("encryption","encryption");
xhr.onload = function () {
layer.close(loadingMsg);
$('.download-btn').removeClass("layui-btn-disabled").attr("disabled", false);
if (this.status === 200) {
let blob = this.response;
var a = document.createElement("a");
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = "基建安全日报_" + setDate(checkedDate) + "." + suffix; // 文件名
} else {
layer.msg("服务异常,请稍后重试", {
icon: 16,
scrollbar: false,
time: 2000,
});
}
a.click();
window.URL.revokeObjectURL(url);
};
xhr.send();
}
// 远程督导下载
function downloadRemoteSupervision() {
$('.download-btn').addClass("layui-btn-disabled").attr("disabled", true);
let loadingMsg = layer.msg("远程督导下载中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
let url = dataUrl + "proteam/pot/remoteSupervision/downloadRemoteSupervision?currentDay=" + checkedDate + "&chineseDate=" + setDate(checkedDate) + "&token=" + token;
let xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "blob"; // 转换流
xhr.setRequestHeader(
"encrypt", sm3(
JSON.stringify({
currentDay: checkedDate,
chineseDate: setDate(checkedDate),
})
)
);
xhr.setRequestHeader("encryption","encryption");
xhr.onload = function () {
layer.close(loadingMsg);
$('.download-btn').removeClass("layui-btn-disabled").attr("disabled", false);
if (this.status === 200) {
let blob = this.response;
var a = document.createElement("a");
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = formatDateToMonthDay(checkedDate)+"输变电工程建设信息一览及高风险作业远程督导" + "." + "docx"; // 文件名
} else {
layer.msg("服务异常,请稍后重试", {
icon: 16,
scrollbar: false,
time: 2000,
});
}
a.click();
window.URL.revokeObjectURL(url);
};
xhr.send();
}
// 日期转换
function formatDateToMonthDay(dateStr) {
const date = new Date(dateStr);
const month = date.getMonth() + 1; // 月份从0开始所以要+1
const day = date.getDate();
return `${month}${day}`;
}