302 lines
9.8 KiB
JavaScript
302 lines
9.8 KiB
JavaScript
let form, table;
|
|
let tableIns;
|
|
let pageNum = 1; // 定义分页
|
|
layui.use(["form", "table"], function () {
|
|
form = layui.form;
|
|
table = layui.table;
|
|
initTable();
|
|
// getStatistics();
|
|
});
|
|
|
|
|
|
// 数据概览
|
|
function getStatistics() {
|
|
let encryptedData = {};
|
|
let url = dataUrl + 'backstage/projectMaterial/getStatistics?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData));
|
|
ajaxRequest(url, "GET", null, true, function () {
|
|
}, function (result) {
|
|
if (result.code === 200) {
|
|
setNum(result.data);
|
|
}
|
|
}, function (xhr, status, error) {
|
|
errorFn(xhr, status, error)
|
|
}, null);
|
|
|
|
// 数据概览赋值
|
|
function setNum(obj) {
|
|
$('#num').html(parseInt(obj.projectCount || 0));
|
|
$('#num2').html(parseInt(obj.totalPurchaseCount || 0));
|
|
$('#num3').html(parseInt(obj.totalOutCount || 0));
|
|
$('#num4').html(parseInt(obj.totalShortageCount || 0));
|
|
}
|
|
}
|
|
|
|
// 查询/重置
|
|
function queryTable(type) {
|
|
if (type === 1) {
|
|
let keyWord = $('#keyWord').val();
|
|
let flag = checkValue(keyWord);
|
|
if (flag) {
|
|
$('#keyWord').val('');
|
|
return layer.msg('关键字查询包含特殊字符,请重新输入', { icon: 2 });
|
|
}
|
|
let useUnit = $('#useUnit').val();
|
|
let flag2 = checkValue(useUnit);
|
|
if (flag2) {
|
|
$('#useUnit').val('');
|
|
return layer.msg('领用单位查询包含特殊字符,请重新输入', { icon: 2 });
|
|
}
|
|
reloadTable(1);
|
|
} else if (type === 2) {
|
|
$('#keyWord').val('');
|
|
$('#useUnit').val('');
|
|
$('#isShortage').val('');
|
|
layui.form.render();
|
|
reloadTable(1);
|
|
}
|
|
}
|
|
|
|
// 刷新页面数据
|
|
function reloadData() {
|
|
reloadTable(1);
|
|
getStatistics();
|
|
}
|
|
|
|
// 重载表格
|
|
function reloadTable(pageNum) {
|
|
table.reload("currentTableId", {
|
|
where: {
|
|
encryptedData: JSON.stringify({
|
|
'keyWord': $('#keyWord').val(),
|
|
'isShortage': $('#isShortage').val()
|
|
}),
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
// 初始化表格
|
|
function initTable() {
|
|
tableIns = table.render({
|
|
elem: "#currentTableId",
|
|
id: 'currentTableId',
|
|
headers: {
|
|
authorization: sessionStorage.getItem("gz-token"),
|
|
},
|
|
// height: "full-300",
|
|
url: dataUrl + "backstage/inventoryCount/queryLedgerListByProjectAndModel",
|
|
where: {
|
|
encryptedData: JSON.stringify({
|
|
'keyWord': $('#keyWord').val(),
|
|
'leaseUnit': $('#useUnit').val(),
|
|
'isShortage': $('#isShortage').val()
|
|
}),
|
|
},
|
|
request: {
|
|
pageName: 'pageNum',
|
|
limitName: 'pageSize'
|
|
},
|
|
parseData: function (res) { // res 即为原始返回的数据
|
|
if(res.code === 401){
|
|
closeWindowOpen();
|
|
}
|
|
return {
|
|
"code": 0, // 解析接口状态
|
|
"msg": '获取成功', // 解析提示文本
|
|
"count": res.total, // 解析数据长度
|
|
"data": res.list // 解析数据列表
|
|
};
|
|
},
|
|
cols: [
|
|
[
|
|
{
|
|
width: '5%',
|
|
title: "序号",
|
|
align: "center",
|
|
templet: function (d) {
|
|
return d.LAY_NUM;
|
|
},
|
|
},
|
|
{
|
|
field: "proName",
|
|
width: '10%',
|
|
title: "工程名称",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
},
|
|
{
|
|
field: "type",
|
|
width: '10%',
|
|
title: "物资类型",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
},
|
|
{
|
|
field: "name",
|
|
width: '10%',
|
|
title: "物资名称",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
},
|
|
{
|
|
field: "model",
|
|
width: '10%',
|
|
title: "规格型号",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
},
|
|
{
|
|
field: "unit",
|
|
width: '6%',
|
|
title: "单位",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
},
|
|
{
|
|
field: "needNum",
|
|
width: '8%',
|
|
title: "需用量",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
return d.totalCg || 0;
|
|
},
|
|
},
|
|
{
|
|
field: "totalCg",
|
|
width: '8%',
|
|
title: "采购量",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
return d.totalCg || 0;
|
|
},
|
|
},
|
|
{
|
|
field: "totalLk",
|
|
title: "利库量",
|
|
width: '8%',
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
const totalLk = d.totalLk || 0;
|
|
const rowData = JSON.stringify(d).replace(/"/g, '"');
|
|
return `<a style='color: #1E9FFF' onclick='viewDetail(${rowData},1)'>${totalLk}</a>`;
|
|
},
|
|
},
|
|
{
|
|
field: "totalCk",
|
|
width: '8%',
|
|
title: "出库总量",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
const totalCk = d.totalCk || 0;
|
|
const rowData = JSON.stringify(d).replace(/"/g, '"');
|
|
return `<a style='color: #1E9FFF' onclick='viewDetail(${rowData},2)'>${totalCk}</a>`;
|
|
},
|
|
},
|
|
{
|
|
field: "totalBack",
|
|
width: '8%',
|
|
title: "退还数量",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
const totalBack = d.totalBack || 0;
|
|
const rowData = JSON.stringify(d).replace(/"/g, '"');
|
|
return `<a style='color: #1E9FFF' onclick='viewDetail(${rowData},3)'>${totalBack}</a>`;
|
|
},
|
|
},
|
|
{
|
|
field: "totalDiff",
|
|
width: '8%',
|
|
title: "差缺量",
|
|
unresize: true,
|
|
align: "center",
|
|
sort: true,
|
|
templet: function (d) {
|
|
let totalDiff = d.totalDiff || 0;
|
|
if (totalDiff > 0) {
|
|
return '<span style="background-color: #f56c6c; color: #fff; border-radius: 5px; padding: 2px 5px;">' + totalDiff + '</span>';
|
|
}
|
|
return totalDiff;
|
|
},
|
|
},
|
|
],
|
|
],
|
|
limits: [10, 20, 30, 50, 100],
|
|
limit: 50,
|
|
page: false,
|
|
done: function (res, curr, count) {
|
|
pageNum = tableIns.config.page.curr;
|
|
table.resize("currentTableId");
|
|
},
|
|
});
|
|
}
|
|
|
|
// 查看详情
|
|
function viewDetail(obj, type) {
|
|
console.log('查看详情', type, obj);
|
|
if (type === 1) {
|
|
openIframeByParamObj("projectLkDetails", "利库详情", "./child/project_lk_details.html", "92%", "95%", obj, 0);
|
|
} else if (type===2){
|
|
openIframeByParamObj("projectCkDetails", "出库详情", "./child/project_ck_details.html", "92%", "95%", obj, 0);
|
|
} else {
|
|
openIframeByParamObj("projectTkDetails", "退库详情", "./child/project_tk_details.html", "92%", "95%", obj, 0);
|
|
}
|
|
}
|
|
|
|
|
|
// 导出Excel
|
|
function exportExcel() {
|
|
let keyWord = $('#keyWord').val();
|
|
let isShortage = $('#isShortage').val();
|
|
|
|
let params = {
|
|
'keyWord': keyWord,
|
|
'isShortage': isShortage
|
|
};
|
|
|
|
let encryptedData = JSON.stringify(params);
|
|
let url = dataUrl + 'backstage/inventoryCount/exportLedgerListByProjectAndModel?encryptedData=' + encodeURIComponent(encryptedData);
|
|
|
|
// 创建隐藏的下载链接
|
|
let link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = '工程物料统计_' + new Date().getTime() + '.xlsx';
|
|
link.style.display = 'none';
|
|
|
|
// 添加授权头并下载
|
|
fetch(url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'authorization': sessionStorage.getItem("gz-token")
|
|
}
|
|
}).then(response => {
|
|
if (response.ok) {
|
|
return response.blob();
|
|
}
|
|
throw new Error('导出失败');
|
|
}).then(blob => {
|
|
let downloadUrl = window.URL.createObjectURL(blob);
|
|
link.href = downloadUrl;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
window.URL.revokeObjectURL(downloadUrl);
|
|
layer.msg('导出成功', { icon: 1 });
|
|
}).catch(error => {
|
|
layer.msg('导出失败:' + error.message, { icon: 2 });
|
|
});
|
|
} |