<template>
|
<div class="app-container">
|
<div style="margin-bottom: 10px">
|
<el-form style="display: flex;flex-wrap: wrap;">
|
<el-form-item>
|
<el-button
|
type="primary"
|
plain
|
icon="Plus"
|
@click="openDialog('add',{})"
|
v-hasPermi="['qualityFinancialAnalysis:list:add']"
|
>新增</el-button>
|
</el-form-item>
|
<el-form-item label="企业名称:" v-if="data.isAdmin" style="margin-left: 20px">
|
<el-select v-model="data.queryParams.companyId" placeholder="请选择" filterable clearable>
|
<el-option
|
v-for="item in data.companyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="年份:" style="margin-left: 20px">
|
<!-- <el-input v-model="data.queryParams.year" placeholder="请输入年份"></el-input>-->
|
<el-select
|
v-model="data.queryParams.year"
|
placeholder="请选择年份"
|
style="width: 240px"
|
filterable
|
allow-create
|
default-first-option
|
:reserve-keyword="false"
|
@change="handleChangeNum"
|
>
|
<el-option
|
v-for="item in data.yearList"
|
:key="item.value"
|
:label="item.label"
|
:value="item.label"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button>
|
<el-button plain @click="reset">重置</el-button>
|
</el-form-item>
|
<el-form-item style="margin-left: 15px">
|
<el-button
|
type="primary"
|
@click="exportData"
|
>导出</el-button>
|
</el-form-item>
|
|
</el-form>
|
</div>
|
<!-- 表格数据 -->
|
<el-table v-loading="loading" :data="dataList" :border="true" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" />
|
<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
<el-table-column label="企业名称" prop="companyName" align="center" v-if="data.isAdmin" />
|
<el-table-column label="名称" prop="year" align="center" >
|
<template #default="scope">
|
<span>{{scope.row.year}}年质量经济性分析报告</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" >
|
<template #default="scope">
|
<el-button link type="primary" @click="openDialog('review',scope.row)">查看</el-button>
|
<el-button link type="primary" @click="openDialog('edit',scope.row)" v-hasPermi="['qualityFinancialAnalysis:list:edit']">编辑</el-button>
|
<el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['qualityFinancialAnalysis:list:del']">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<div class="pag-container">
|
<el-pagination
|
v-model:current-page="data.queryParams.pageNum"
|
v-model:page-size="data.queryParams.pageSize"
|
:page-sizes="[10,15,20,25]"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total"
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
/>
|
</div>
|
<editDialog ref="noticeRef" @getList = "getList"></editDialog>
|
</div>
|
</template>
|
|
<script setup>
|
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
|
import editDialog from "./components/editDialog.vue"
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import {getCompany} from "@/api/onlineEducation/company";
|
import Cookies from "js-cookie";
|
import { Document, Paragraph, TextRun, Table, TableRow, TableCell,BorderStyle , Packer, AlignmentType, HeadingLevel } from "docx";
|
import { saveAs } from "file-saver";
|
import {delEconomy, getEconomy} from "@/api/qualityFinancialAnalysis";
|
const { proxy } = getCurrentInstance();
|
const loading = ref(false);
|
const noticeRef = ref();
|
const loadingCompany = ref(false)
|
const choosedData = ref([])
|
const data = reactive({
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
companyId: null,
|
year: '',
|
type: ''
|
},
|
companyList: [],
|
isAdmin: false,
|
yearList: [
|
{
|
value: 1,
|
label: '2025'
|
},
|
{
|
value: 2,
|
label: '2024'
|
},
|
{
|
value: 3,
|
label: '2023'
|
},
|
{
|
value: 4,
|
label: '2022'
|
},
|
{
|
value: 5,
|
label: '2021'
|
},
|
],
|
});
|
const dataList = ref([]);
|
const total = ref(0);
|
|
const { queryParams } = toRefs(data);
|
|
onMounted(() => {
|
const userInfo = JSON.parse(Cookies.get('userInfo'))
|
console.log("userInfo",userInfo)
|
data.isAdmin = userInfo.userType === 0;
|
if(data.isAdmin){
|
data.queryParams.companyId = null
|
}else {
|
data.queryParams.companyId = userInfo.companyId
|
}
|
getList();
|
if(data.isAdmin){
|
getCompanyList()
|
}
|
});
|
const getList = async () => {
|
loading.value = true;
|
const res = await getEconomy(data.queryParams);
|
if(res.code === 200){
|
dataList.value = res.data.list
|
total.value = res.data.total
|
}else{
|
ElMessage.warning(res.message)
|
}
|
loading.value = false;
|
}
|
|
const searchClick = () => {
|
getList();
|
}
|
const openDialog = (type, value) => {
|
noticeRef.value.openDialog(type, value,data.companyList);
|
}
|
const selectValue = (val) => {
|
data.companyList.forEach(item => {
|
if(item.name === val){
|
data.queryParams.companyId = item.id
|
}
|
})
|
}
|
|
const getCompanyList = async ()=>{
|
const queryParams = {
|
pageNum: 1,
|
pageSize: 999
|
}
|
const res = await getCompany(queryParams)
|
if (res.code == 200) {
|
data.companyList = res.data.list?res.data.list:[]
|
// data.queryParams.companyId = data.companyList[0].id
|
} else {
|
ElMessage.warning(res.message)
|
}
|
}
|
|
const handleSizeChange = (val) => {
|
data.queryParams.pageSize = val
|
getList()
|
}
|
const handleCurrentChange = (val) => {
|
data.queryParams.pageNum = val
|
getList()
|
}
|
|
/** 重置新增的表单以及其他数据 */
|
function reset() {
|
if(data.isAdmin){
|
data.queryParams = {
|
companyId: '',
|
pageNum: 1,
|
pageSize: 10,
|
year: '',
|
type: ''
|
}
|
choosedData.value = []
|
data.companyList = [];
|
getCompanyList()
|
}else {
|
data.queryParams = {
|
companyId: data.queryParams.companyId,
|
pageNum: 1,
|
pageSize: 10,
|
year: '',
|
type: ''
|
}
|
}
|
getList();
|
|
}
|
const exportData = () => {
|
if(choosedData.value && choosedData.value.length === 0){
|
ElMessage.warning('请选择需要导出的数据')
|
}else {
|
startGeneration()
|
}
|
}
|
|
const templatePath = ref('/qualityFinancialAnalysisExample.docx')
|
const startGeneration = async () => {
|
let name = ''
|
choosedData.value.forEach(item => {
|
// 执行导出
|
createQualityEconomicReport(item).catch(console.error);
|
})
|
}
|
|
const handleSelectionChange = (val) => {
|
choosedData.value = val
|
}
|
const handleDelete = (val) => {
|
ElMessageBox.confirm(
|
'确定删除此条数据?',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then( async() => {
|
const res = await delEconomy(val.id);
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '删除成功'
|
});
|
getList();
|
}else{
|
ElMessage.warning(res.message)
|
}
|
})
|
}
|
const handleChangeNum = (value) => {
|
if (!/^\d+$/.test(value)) { // 验证是否为数字
|
ElMessage.warning('只能输入数字')
|
data.queryParams.year = '' // 重置选择,避免非法值被添加到options中
|
} else if (!data.yearList.some(option => option.label == value)) { // 确保不是已存在的选项
|
data.yearList.push({ value, label: value }); // 添加新选项(这里简单地将值和标签设为相同)
|
}
|
}
|
|
|
function processHtmlTable(htmlTable) {
|
const docxRows = [];
|
|
htmlTable.querySelectorAll("tr").forEach(htmlRow => {
|
const cells = [];
|
let colIndex = 0;
|
|
htmlRow.querySelectorAll("th, td").forEach(htmlCell => {
|
// 处理合并单元格
|
const colspan = parseInt(htmlCell.getAttribute('colspan')) || 1;
|
const rowspan = parseInt(htmlCell.getAttribute('rowspan')) || 1;
|
|
// 处理单元格内容(包括空格的转换)
|
const cellText = htmlCell.innerHTML === ' ' ? ' ' : htmlCell.textContent;
|
|
// 创建Word表格单元格
|
cells.push(
|
new TableCell({
|
children: [
|
new Paragraph({
|
children: [new TextRun(cellText)],
|
})
|
],
|
columnSpan: colspan,
|
rowSpan: rowspan,
|
margins: { top: 100, bottom: 100, left: 100, right: 100 },
|
borders: {
|
top: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
bottom: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
left: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
right: { style: BorderStyle.SINGLE, size: 4, color: "000000" }
|
}
|
})
|
);
|
|
colIndex += colspan;
|
});
|
|
docxRows.push(new TableRow({ children: cells }));
|
});
|
|
return docxRows;
|
}
|
function convertHtmlToDocx(htmlString) {
|
const parser = new DOMParser();
|
const doc = parser.parseFromString(htmlString, "text/html");
|
const elements = [];
|
|
Array.from(doc.body.childNodes).forEach(node => {
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
const tagName = node.tagName.toUpperCase();
|
|
if (tagName === 'TABLE') {
|
elements.push(new Table({
|
rows: processHtmlTable(node),
|
width: { size: 100, type: "pct" }, // 宽度100%
|
margins: { top: 400, bottom: 400 },
|
layout: "fixed", // 固定布局
|
borders: {
|
top: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
bottom: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
left: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
right: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
insideHorizontal: { style: BorderStyle.SINGLE, size: 4, color: "000000" },
|
insideVertical: { style: BorderStyle.SINGLE, size: 4, color: "000000" }
|
}
|
}));
|
} else if (tagName === 'P') {
|
elements.push(new Paragraph({
|
text: node.textContent,
|
spacing: { after: 200 }
|
}));
|
}
|
}
|
});
|
|
return elements;
|
}
|
|
// 2. 示例HTML表格数据
|
const sampleTableHTML = `
|
b
|
`;
|
// 3. 创建完整报告文档
|
async function createQualityEconomicReport(data) {
|
|
const doc = new Document({
|
sections: [{
|
properties: {},
|
children: [
|
// 报告标题
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "质量经济性分析报告",
|
font: "宋体",
|
size: 26,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.CENTER,
|
spacing: { after: 300 }
|
}),
|
|
// // 报告时间范围
|
// new Paragraph({
|
// text: data.dutyTime,
|
// alignment: AlignmentType.CENTER,
|
// indent: { left: 3700 },
|
// spacing: { after: 500 }
|
// }),
|
|
// 1. 基本情况
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "一、基本情况",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
//基本情况内容
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: data.basic, // 替换为实际内容
|
font: "宋体", // 与标题一致
|
size: 20, // 小四号(20 half-points)
|
bold: false, // 常规
|
color: "000000" // 纯黑
|
})
|
],
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 300 } // 和下一段的间距
|
}),
|
// 二、综合分析
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "二、综合分析",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
// 二、综合分析内容
|
...convertHtmlToDocx(data.synthesize),
|
new Paragraph({
|
children: [
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
|
|
// 三、内外部损失
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "三、内外部损失",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
//内外部损失内容
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: data.damage, // 替换为实际内容
|
font: "宋体", // 与标题一致
|
size: 20, // 小四号(20 half-points)
|
bold: false, // 常规
|
color: "000000" // 纯黑
|
})
|
],
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 300 } // 和下一段的间距
|
}),
|
|
// 四、纠正措施
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "四、纠正措施",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
//纠正措施内容
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: data.measure, // 替换为实际内容
|
font: "宋体", // 与标题一致
|
size: 20, // 小四号(20 half-points)
|
bold: false, // 常规
|
color: "000000" // 纯黑
|
})
|
],
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 300 } // 和下一段的间距
|
}),
|
//五、分析结果
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "六、分析结果",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
//分析结果内容
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: data.suggest, // 替换为实际内容
|
font: "宋体", // 与标题一致
|
size: 20, // 小四号(20 half-points)
|
bold: false, // 常规
|
color: "000000" // 纯黑
|
})
|
],
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 300 } // 和下一段的间距
|
}),
|
|
// 二、改进建议
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: "六、改进建议",
|
font: "宋体",
|
size: 22,
|
bold: true,
|
color: "000000"
|
})
|
],
|
heading: HeadingLevel.HEADING_1,
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 100 }
|
}),
|
//改进建议内容
|
new Paragraph({
|
children: [
|
new TextRun({
|
text: data.suggest, // 替换为实际内容
|
font: "宋体", // 与标题一致
|
size: 20, // 小四号(20 half-points)
|
bold: false, // 常规
|
color: "000000" // 纯黑
|
})
|
],
|
alignment: AlignmentType.LEFT,
|
spacing: { after: 300 } // 和下一段的间距
|
}),
|
|
// 10. 综合部落款
|
new Paragraph({
|
text: data.dutyName,
|
alignment: AlignmentType.RIGHT,
|
spacing: { before: 1200 }
|
}),
|
|
// 11. 日期落款
|
new Paragraph({
|
text: data.dutyTime,
|
alignment: AlignmentType.RIGHT,
|
spacing: { before: 200 }
|
})
|
]
|
}]
|
});
|
// 导出文件
|
const blob = await Packer.toBlob(doc);
|
saveAs(blob, data.companyName + "_质量经济性分析报告.docx");
|
}
|
|
|
|
|
</script>
|
<style lang="scss">
|
.pag-container{
|
float: right;
|
margin-top: 10px;
|
}
|
</style>
|