增加外层导出Excel及时间筛选

This commit is contained in:
syruan 2025-08-22 13:51:15 +08:00
parent 4dabad5713
commit 10fcfcb1d4
5 changed files with 299 additions and 59 deletions

View File

@ -9,7 +9,7 @@ export function getSltAgreementInfo(query) {
})
}
// 查询费用结算申请列表
// 查询未结算费用报表---list列表
export function getSltReportList(query) {
return request({
url: '/material/slt_agreement_info/getSltReportList',

View File

@ -324,7 +324,7 @@ export default {
const params = {
// projectId: this.queryParams.projectId /* */,
}
const res = await getUnitList(params)
const res = await getUnitListFilterTeam(params)
this.unitList = res.data;
if (this.queryParams.projectId) {
@ -333,15 +333,8 @@ export default {
},
unitChange(val){
console.log('Selected values:', val); //
// this.unitIds.push(Number(val.id));
// if(val&&val.length>0){
// this.queryParams.unitId=this.unitIds[this.unitIds.length - 1]
// }else if(val&&val.length==0){
// this.queryParams.unitId=""
// }
console.log("xxxxxxxxx",this.queryParams.unitId)
console.log("yyyyyyyyy",this.unitIds)
// this.GetProData()
setTimeout(()=>{
this.queryParams.projectId=null
this.queryParams.agreementId = null
@ -361,12 +354,6 @@ export default {
this.getAgreementInfo()
},
proChange(val){
// if(val&&val.length>0){
// this.queryParams.projectId=this.projectIds[this.projectIds.length - 1]
// }else if(val&&val.length==0){
// this.queryParams.projectId=""
// }
// this.GetUnitData()
setTimeout(()=>{
this.GetUnitData()
},500)
@ -481,13 +468,6 @@ export default {
//
print() {
this.$refs.remarksPrintRef.print();
// printJS({
// printable: 'checkId',
// type: 'html',
// targetStyles: ['*'],
// maxWidth:'1400'
// //
// });
},
/** 删除按钮操作 */

View File

@ -236,9 +236,9 @@
<script>
import {
getProjectList,
getUnitList,
getAgreementInfoById,
getProjectList,
getUnitList,
getAgreementInfoById, getUnitListFilterTeam,
} from '@/api/back/index.js'
import { getSltList,costExamine, getSltInfo } from '@/api/cost/cost'
import { toChineseAmount } from '@/utils/bonus.js'
@ -338,7 +338,7 @@ export default {
const params = {
// projectId: this.queryParams.projectId /* */,
}
const res = await getUnitList(params)
const res = await getUnitListFilterTeam(params)
this.unitList = res.data;
this.getAgreementInfo()

View File

@ -22,19 +22,23 @@
<el-form-item prop="agreementCode">
<el-input v-model="queryParams.agreementCode" placeholder="请输入协议号" clearable disabled/>
</el-form-item>
<el-form-item prop="sltStatus">
<el-select v-model="queryParams.sltStatus" placeholder="请选择结算状态" clearable filterable>
<el-option
v-for="dict in statusList"
:key="dict.id"
:label="dict.name"
:value="dict.id"
></el-option>
</el-select>
<el-form-item prop="dateRange">
<el-date-picker
v-model="queryParams.dateRange"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
style="width: 240px"
@change="handleDateRangeChange">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >查询</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
<el-button type="success" icon="el-icon-download" size="mini" @click="exportExcel" :disabled="tableList.length === 0">导出Excel</el-button>
</el-form-item>
</el-form>
@ -120,13 +124,13 @@
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- <pagination-->
<!-- v-show="total > 0"-->
<!-- :total="total"-->
<!-- :page.sync="queryParams.pageNum"-->
<!-- :limit.sync="queryParams.pageSize"-->
<!-- @pagination="getList"-->
<!-- />-->
<!-- 费用详情弹窗 -->
<el-dialog
@ -263,9 +267,9 @@
<script>
import {
getProjectList,
getUnitList,
getAgreementInfoById,
getProjectList,
getUnitList,
getAgreementInfoById, getUnitListFilterTeam,
} from '@/api/back/index.js'
import {getSltList, costExamine, getSltInfo, getSltReportedList} from '@/api/cost/cost'
import { toChineseAmount } from '@/utils/bonus.js'
@ -322,6 +326,9 @@ export default {
projectId: null,
agreementId: null,
agreementCode: null,
dateRange: null,
startTime: null,
endTime: null,
},
openPrint: false,
//
@ -352,11 +359,50 @@ export default {
}
},
created() {
this.initDefaultDateRange()
this.GetUnitData()
this.GetProData()
this.getList()
},
methods: {
//
initDefaultDateRange() {
const now = new Date()
const year = now.getFullYear()
const month = now.getMonth()
//
const firstDay = new Date(year, month, 1)
const firstDayStr = this.formatDate(firstDay)
//
const lastDay = new Date(year, month + 1, 0)
const lastDayStr = this.formatDate(lastDay)
this.queryParams.dateRange = [firstDayStr, lastDayStr]
this.queryParams.startTime = firstDayStr
this.queryParams.endTime = lastDayStr
},
// yyyy-MM-dd
formatDate(date) {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
},
//
handleDateRangeChange(dateRange) {
if (dateRange && dateRange.length === 2) {
this.queryParams.startTime = dateRange[0]
this.queryParams.endTime = dateRange[1]
} else {
this.queryParams.startTime = null
this.queryParams.endTime = null
}
},
/** 转换菜单数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
@ -373,7 +419,7 @@ export default {
const params = {
// projectId: this.queryParams.projectId /* */,
}
const res = await getUnitList(params)
const res = await getUnitListFilterTeam(params)
this.unitList = res.data;
this.getAgreementInfo()
@ -449,7 +495,12 @@ export default {
projectId: null,
agreementId: '',
agreementCode: '',
dateRange: null,
startTime: null,
endTime: null,
}
//
this.initDefaultDateRange()
this.resetForm('queryForm')
this.handleQuery()
},
@ -775,6 +826,113 @@ export default {
}
},
// Excel
exportExcel() {
if (!this.tableList || this.tableList.length === 0) {
this.$modal.msgWarning('没有可导出的数据');
return;
}
try {
// Excel
const columns = [
{ key: 'index', title: '序号' },
{ key: 'agreementCode', title: '协议号' },
{ key: 'unitName', title: '结算单位' },
{ key: 'projectName', title: '结算工程' },
{ key: 'createTime', title: '结算时间' },
{ key: 'settlementType', title: '结算类型' },
{ key: 'leaseCost', title: '租赁费用' },
{ key: 'repairCost', title: '维修费用' },
{ key: 'loseCost', title: '丢失费用' },
{ key: 'scrapCost', title: '报废费用' },
{ key: 'costs', title: '合计费用(元)' }
];
// Excel
const excelData = [];
//
const headerRow = columns.map(col => col.title);
excelData.push(headerRow);
//
this.tableList.forEach((row, index) => {
const dataRow = columns.map(col => {
if (col.key === 'index') {
return (this.queryParams.pageNum - 1) * 10 + index + 1;
} else if (col.key === 'settlementType') {
//
if (row.settlementType === 1) return '工器具';
if (row.settlementType === 2) return '安全工器具';
return '总费用';
} else if (col.key === 'costs') {
//
return row.costs != null && row.costs !== '' ? parseFloat(row.costs.toFixed(2)) : 0.00;
} else if (col.key === 'leaseCost' || col.key === 'repairCost' || col.key === 'loseCost' || col.key === 'scrapCost') {
//
return row[col.key] || 0;
} else {
return row[col.key] || '';
}
});
excelData.push(dataRow);
});
// 簿
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.aoa_to_sheet(excelData);
//
const columnWidths = [
{ wch: 8 }, //
{ wch: 20 }, //
{ wch: 15 }, //
{ wch: 20 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 15 } //
];
worksheet['!cols'] = columnWidths;
// 簿
XLSX.utils.book_append_sheet(workbook, worksheet, '结算记录');
//
let fileName = '结算记录';
if (this.queryParams.startTime && this.queryParams.endTime) {
fileName += `_${this.queryParams.startTime}_至_${this.queryParams.endTime}`;
}
fileName += `_${new Date().toISOString().slice(0, 10)}.xlsx`;
// Excel
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
//
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', fileName);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// URL
URL.revokeObjectURL(url);
this.$modal.msgSuccess('Excel导出成功');
} catch (error) {
console.error('导出Excel失败:', error);
this.$modal.msgError('导出Excel失败请稍后重试');
}
},
},
}
</script>

View File

@ -25,6 +25,7 @@
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >查询</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
<el-button type="success" icon="el-icon-download" size="mini" @click="exportExcel" :disabled="tableList.length === 0">导出Excel</el-button>
</el-form-item>
</el-form>
@ -37,8 +38,8 @@
</template>
</el-table-column>
<el-table-column label="协议号" align="center" prop="agreementCode" :show-overflow-tooltip="true"/>
<el-table-column label="协议签订单位" align="center" prop="unitName" />
<el-table-column label="协议签订工程" align="center" prop="projectName" />
<el-table-column label="结算单位" align="center" prop="unitName" />
<el-table-column label="结算工程" align="center" prop="projectName" />
<el-table-column label="结算类型" align="center" prop="sltStatus" :show-overflow-tooltip="true">
<template slot-scope="scope">
@ -109,13 +110,13 @@
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- <pagination-->
<!-- v-show="total > 0"-->
<!-- :total="total"-->
<!-- :page.sync="queryParams.pageNum"-->
<!-- :limit.sync="queryParams.pageSize"-->
<!-- @pagination="getList"-->
<!-- />-->
<!-- 费用详情弹窗 -->
<el-dialog
@ -252,9 +253,9 @@
<script>
import {
getProjectList,
getUnitList,
getAgreementInfoById,
getProjectList,
getUnitList,
getAgreementInfoById, getUnitListFilterTeam,
} from '@/api/back/index.js'
import {getSltList, costExamine, getSltReportedList, getSltReportList} from '@/api/cost/cost'
import { toChineseAmount } from '@/utils/bonus.js'
@ -362,7 +363,7 @@ export default {
const params = {
// projectId: this.queryParams.projectId /* */,
}
const res = await getUnitList(params)
const res = await getUnitListFilterTeam(params)
this.unitList = res.data;
this.getAgreementInfo()
@ -595,6 +596,107 @@ export default {
});
},
// Excel
exportExcel() {
if (!this.tableList || this.tableList.length === 0) {
this.$modal.msgWarning('没有可导出的数据');
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: 'costs', title: '合计费用(元)' }
];
// Excel
const excelData = [];
//
const headerRow = columns.map(col => col.title);
excelData.push(headerRow);
//
this.tableList.forEach((row, index) => {
const dataRow = columns.map(col => {
if (col.key === 'index') {
return (this.queryParams.pageNum - 1) * 10 + index + 1;
} else if (col.key === 'settlementType') {
//
if (row.settlementType === 1) return '工器具';
if (row.settlementType === 2) return '安全工器具';
return '总费用';
} else if (col.key === 'costs') {
//
return row.costs != null && row.costs !== '' ? parseFloat(row.costs.toFixed(2)) : 0.00;
} else if (col.key === 'leaseCost' || col.key === 'repairCost' || col.key === 'loseCost' || col.key === 'scrapCost') {
//
return row[col.key] || 0;
} else {
return row[col.key] || '';
}
});
excelData.push(dataRow);
});
// 簿
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.aoa_to_sheet(excelData);
//
const columnWidths = [
{ wch: 8 }, //
{ wch: 20 }, //
{ wch: 15 }, //
{ wch: 20 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 12 }, //
{ wch: 15 } //
];
worksheet['!cols'] = columnWidths;
// 簿
XLSX.utils.book_append_sheet(workbook, worksheet, '未结算记录');
//
const fileName = `未结算记录_${new Date().toISOString().slice(0, 10)}.xlsx`;
// Excel
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
//
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', fileName);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// URL
URL.revokeObjectURL(url);
this.$modal.msgSuccess('Excel导出成功');
} catch (error) {
console.error('导出Excel失败:', error);
this.$modal.msgError('导出Excel失败请稍后重试');
}
},
// Excel
exportCostDetail() {
if (!this.costDetailList || this.costDetailList.length === 0) {