Merge branch 'material-ui' of http://192.168.30.2:3000/bonus/bonus-ui into material-ui

This commit is contained in:
hongchao 2025-11-06 17:22:48 +08:00
commit 0e4b980e49
1 changed files with 252 additions and 0 deletions

View File

@ -427,6 +427,7 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="success" icon="el-icon-download" @click="exportHistoryReportList" :disabled="historyReportList.length === 0">导出Excel</el-button>
<el-button @click="historyReportListVisible = false">关闭</el-button> <el-button @click="historyReportListVisible = false">关闭</el-button>
</div> </div>
</el-dialog> </el-dialog>
@ -531,6 +532,7 @@
</el-table> </el-table>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="success" icon="el-icon-download" @click="exportHistoryCostDetail" :disabled="historyCostDetailList.length === 0">导出Excel</el-button>
<el-button @click="historyCostDetailVisible = false">关闭</el-button> <el-button @click="historyCostDetailVisible = false">关闭</el-button>
</div> </div>
</el-dialog> </el-dialog>
@ -1284,6 +1286,256 @@ export default {
}); });
}, },
// Excel
exportHistoryReportList() {
if (!this.historyReportList || this.historyReportList.length === 0) {
this.$message.warning('没有可导出的数据');
return;
}
try {
// Excel
const columns = [
{ key: 'index', title: '序号' },
{ key: 'agreementCode', title: '协议号' },
{ key: 'unitName', title: '结算单位' },
{ key: 'projectName', title: '结算工程' },
{ key: 'settlementType', title: '结算类型' },
{ key: 'leaseCost', title: '租赁费用' },
{ key: 'repairCost', title: '维修费用' },
{ key: 'loseCost', title: '丢失费用' },
{ key: 'scrapCost', title: '报废费用' },
{ key: 'totalCost', title: '合计费用(元)' }
];
// Excel
const excelData = [];
//
const headerRow = columns.map(col => col.title);
excelData.push(headerRow);
//
this.historyReportList.forEach((row, index) => {
const dataRow = columns.map(col => {
let value = '';
if (col.key === 'index') {
value = index + 1;
} else if (col.key === 'settlementType') {
const typeMap = {
0: '总费用',
1: '工器具',
2: '安全工器具'
};
value = typeMap[row.settlementType] || '';
} else if (col.key === 'totalCost') {
// 2
value = parseFloat(this.calculateTotalCost(row).toFixed(2));
} else if (['leaseCost', 'repairCost', 'loseCost', 'scrapCost'].includes(col.key)) {
// 2
const numValue = row[col.key] || 0;
value = parseFloat(parseFloat(numValue).toFixed(2));
} else {
value = row[col.key] || '';
}
return value;
});
excelData.push(dataRow);
});
// 簿
const ws = XLSX.utils.aoa_to_sheet(excelData);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, '历史报表');
//
const colWidths = [
{ wch: 8 }, //
{ wch: 15 }, //
{ wch: 15 }, //
{ wch: 15 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 15 } //
];
ws['!cols'] = colWidths;
//
const border = {
top: { style: 'thin' },
bottom: { style: 'thin' },
left: { style: 'thin' },
right: { style: 'thin' }
};
const alignment = { horizontal: 'center', vertical: 'center', wrapText: true };
//
for (let row = 0; row < excelData.length; row++) {
for (let col = 0; col < excelData[row].length; col++) {
const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
if (!ws[cellAddress]) {
ws[cellAddress] = {};
}
ws[cellAddress].border = border;
ws[cellAddress].alignment = alignment;
}
}
//
const fileName = `历史报表_${this.historyReportParams.yearMonth}.xlsx`;
XLSX.writeFile(wb, fileName);
this.$message.success('导出成功');
} catch (error) {
console.error('导出失败:', error);
this.$message.error('导出失败');
}
},
// Excel
exportHistoryCostDetail() {
if (!this.historyCostDetailList || this.historyCostDetailList.length === 0) {
this.$message.warning('没有可导出的数据');
return;
}
try {
//
let columns = [];
let fileName = '';
let sheetName = '';
switch (this.historyCostDetailType) {
case 'lease':
columns = [
{ key: 'index', title: '序号' },
{ key: 'name', title: '名称' },
{ key: 'model', title: '型号' },
{ key: 'unit', title: '单位' },
{ key: 'unitPrice', title: '单价(元)' },
{ key: 'quantity', title: '数量' },
{ key: 'returnQuantity', title: '归还数量' },
{ key: 'startTime', title: '租赁开始日期' },
{ key: 'endTime', title: '租赁结束日期' },
{ key: 'leaseDays', title: '租赁天数' },
{ key: 'cost', title: '费用(元)' }
];
fileName = `历史租赁费用详情_${this.currentHistoryRow.agreementCode}_${this.historyReportParams.yearMonth}`;
sheetName = '历史租赁费用';
break;
case 'repair':
columns = [
{ key: 'index', title: '序号' },
{ key: 'name', title: '机具名称' },
{ key: 'model', title: '规格型号' },
{ key: 'unit', title: '单位' },
{ key: 'quantity', title: '维修数量' },
{ key: 'cost', title: '维修费用(元)' }
];
fileName = `历史维修费用详情_${this.currentHistoryRow.agreementCode}_${this.historyReportParams.yearMonth}`;
sheetName = '历史维修费用';
break;
case 'lose':
columns = [
{ key: 'index', title: '序号' },
{ key: 'name', title: '机具名称' },
{ key: 'model', title: '规格型号' },
{ key: 'unit', title: '单位' },
{ key: 'quantity', title: '丢失数量' },
{ key: 'cost', title: '丢失费用(元)' }
];
fileName = `历史丢失费用详情_${this.currentHistoryRow.agreementCode}_${this.historyReportParams.yearMonth}`;
sheetName = '历史丢失费用';
break;
case 'scrap':
columns = [
{ key: 'index', title: '序号' },
{ key: 'name', title: '机具名称' },
{ key: 'model', title: '机具规格' },
{ key: 'unit', title: '单位' },
{ key: 'quantity', title: '报废数量' },
{ key: 'cost', title: '报废费用(元)' }
];
fileName = `历史报废费用详情_${this.currentHistoryRow.agreementCode}_${this.historyReportParams.yearMonth}`;
sheetName = '历史报废费用';
break;
default:
this.$message.error('未知的费用类型');
return;
}
// Excel
const excelData = [];
//
const headerRow = columns.map(col => col.title);
excelData.push(headerRow);
//
this.historyCostDetailList.forEach((row, index) => {
const dataRow = columns.map(col => {
let value = '';
if (col.key === 'index') {
value = index + 1;
} else if (['cost', 'unitPrice'].includes(col.key)) {
// 2
const numValue = row[col.key] || 0;
value = parseFloat(parseFloat(numValue).toFixed(2));
} else {
value = row[col.key] || '';
}
return value;
});
excelData.push(dataRow);
});
// 簿
const ws = XLSX.utils.aoa_to_sheet(excelData);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, sheetName);
//
const colWidths = columns.map(() => ({ wch: 15 }));
ws['!cols'] = colWidths;
//
const border = {
top: { style: 'thin' },
bottom: { style: 'thin' },
left: { style: 'thin' },
right: { style: 'thin' }
};
const alignment = { horizontal: 'center', vertical: 'center', wrapText: true };
//
for (let row = 0; row < excelData.length; row++) {
for (let col = 0; col < excelData[row].length; col++) {
const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
if (!ws[cellAddress]) {
ws[cellAddress] = {};
}
ws[cellAddress].border = border;
ws[cellAddress].alignment = alignment;
}
}
//
XLSX.writeFile(wb, `${fileName}.xlsx`);
this.$message.success('导出成功');
} catch (error) {
console.error('导出失败:', error);
this.$message.error('导出失败');
}
},
}, },
} }
</script> </script>