feat: 导出pdf

This commit is contained in:
ycy 2024-04-10 15:06:54 +08:00
parent 4c9667e84b
commit f53d392a6c
5 changed files with 377 additions and 0 deletions

View File

@ -16,6 +16,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"less": "^4.2.0", "less": "^4.2.0",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"pdfmake": "^0.2.10",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1", "pinia-plugin-persistedstate": "^3.2.1",
"tdesign-vue-next": "^1.9.3", "tdesign-vue-next": "^1.9.3",
@ -26,6 +27,7 @@
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0", "@vitejs/plugin-vue-jsx": "^3.1.0",
"gulp": "^5.0.0",
"sass": "^1.74.1", "sass": "^1.74.1",
"vite": "^5.1.6" "vite": "^5.1.6"
} }

View File

@ -34,6 +34,9 @@
<t-menu-item value="2-7" to="/Bill/DetailReport"> <t-menu-item value="2-7" to="/Bill/DetailReport">
<span>报表明细</span> <span>报表明细</span>
</t-menu-item> </t-menu-item>
<t-menu-item value="2-8" to="/Bill/BillDraw">
<span>票据列表</span>
</t-menu-item>
</t-submenu> </t-submenu>
<t-submenu value="3" title="应收款管理"> <t-submenu value="3" title="应收款管理">
<template #icon> <template #icon>

View File

@ -0,0 +1,343 @@
<template>
<div class="back-color">
<t-layout style="height: 90%; background-color: #f5f7fb">
<t-header class="scarch-box">
<t-form
ref="form"
:data="formData"
label-width="calc(2em + 40px)"
layout="inline"
scroll-to-first-error="smooth"
class="scarch-from"
@reset="resetting"
@submit="headerQuery"
>
<div style="margin-left: 1rem">
<t-form-item label="票据编号:" name="billserial">
<t-input v-model="formData.billserial" maxlength="10"></t-input>
</t-form-item>
<t-form-item label="入库日期:" name="stockDate">
<t-date-picker v-model="formData.stockDate" clearable />
</t-form-item>
<t-form-item
label="票据类型:"
name="billType"
style="margin-bottom: 0.3rem"
>
<t-select
v-model="formData.billType"
placeholder="请选择票据类型"
clearable
>
<t-option
v-for="item in billType"
:key="item.value"
:value="item.value"
:label="item.label"
></t-option>
</t-select>
</t-form-item>
</div>
<t-form-item style="margin-right: 1rem">
<t-button theme="primary" type="submit">查询</t-button>
<t-button theme="primary" type="reset">重置</t-button>
</t-form-item>
</t-form>
</t-header>
<t-content class="table-box">
<div class="table-header">
<div>
<h4 style="font-size: 110%">票据列表</h4>
</div>
<div>
<t-button
shape="circle"
theme="primary"
@click="refresh"
style="margin-left: 0.8rem"
>
<template #icon><load-icon /></template>
</t-button>
</div>
</div>
<t-base-table
hover
row-key="index"
:loading="loading"
:data="tableData"
:columns="columns"
:pagination="pagination"
class="table"
:max-height="550"
>
<template #stockNum="{ row }">
{{ `${row.stockNum}` }}
</template>
<template #billType="{ row }">
<div v-for="item in billType" :key="item">
<span v-if="row.billType === item.value">{{ item.label }}</span>
</div>
</template>
<template #status="slotProps">
<t-button
theme="default"
variant="text"
size="small"
@click="exportPdf(slotProps)"
>导出pdf</t-button
>
</template>
</t-base-table>
</t-content>
</t-layout>
</div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { MessagePlugin } from "tdesign-vue-next";
import { LoadIcon } from "tdesign-icons-vue-next";
import { useStock } from "@/stores/billStock";
import { exportToPDF } from "@/utils/pdf";
//
const loading = ref(false);
const stockList = useStock();
const tableData = ref();
const data = ref();
//
const columns = ref([
{
colKey: "serial-number",
title: "序号",
width: 50,
},
{
colKey: "billserial",
title: "票据编号",
align: "center",
width: "100",
},
{
colKey: "billType",
title: "票据类型",
align: "center",
width: "100",
},
{
colKey: "stockNum",
title: "入库数量",
align: "center",
width: "100",
},
{
colKey: "stockDate",
title: "入库日期",
align: "center",
width: "100",
},
{
colKey: "operator",
title: "操作员",
align: "center",
width: "100",
},
{
colKey: "remark",
title: "备注",
align: "center",
width: "100",
},
{
colKey: "status",
title: "操作",
width: 120,
align: "center",
fixed: "right",
},
]);
//
const billType = ref([
{ label: "票据类型1", value: 0 },
{ label: "票据类型2", value: 1 },
{ label: "票据类型3", value: 2 },
{ label: "票据类型4", value: 3 },
{ label: "票据类型5", value: 4 },
]);
//
const tableList = async () => {
loading.value = true;
tableData.value = await stockList.getStockList();
data.value = await stockList.getStockList();
pagination.value.total = tableData.value.length;
const timerId = setTimeout(() => {
loading.value = false;
clearInterval(timerId);
}, 300);
};
//
const refresh = () => {
tableList();
};
//
const formData = ref({
billserial: "",
billType: "",
stockDate: "",
});
//
const pagination = ref({
defaultCurrent: 1,
defaultPageSize: 10,
total: 50,
});
//
const resetting = () => {
formData.value = {
billserial: "",
billType: "",
stockDate: "",
};
getNewTable();
};
//
const headerQuery = () => {
tableData.value = data.value;
if (
formData.value.billserial === "" &&
(formData.value.billType === undefined || formData.value.billType === "") &&
formData.value.stockDate === ""
) {
getNewTable();
} else {
const list = tableData.value.filter((item) => {
let arrList;
if (formData.value.billserial === item.billserial) {
arrList = item;
}
if (formData.value.billType === item.billType) {
arrList = item;
}
if (formData.value.stockDate === item.stockDate) {
arrList = item;
}
if (
formData.value.billserial === "" &&
formData.value.billType === "" &&
formData.value.stockDate === ""
) {
arrList = item;
}
return arrList;
});
tableData.value = list;
pagination.value.total = list.length;
}
};
// menuManagement
const getNewTable = () => {
let arr = JSON.parse(localStorage.getItem("menuManagement"));
if (arr) {
tableData.value = arr.stockList;
data.value = arr.stockList;
pagination.value.total = tableData.value.length;
} else {
tableList();
}
};
// pdf
const exportPdf = (slotProps) => {
// const content = slotProps.row;
const content = [
//
{
text: "票据标题",
style: "header",
alignment: "center",
margin: [0, 0, 0, 0],
},
//
{
columns: [
{ text: "发票编号:", style: "label", alignment: "right" },
{ text: "1234567890", style: "value" },
{ text: "日期:", style: "label", alignment: "right" },
{ text: "2023-04-05", style: "value" },
],
margin: [0, 20, 0, 0],
},
//
{
table: {
widths: ["*", "auto", "*"],
body: [
[
{ text: "商品名称", style: "tableHeader" },
{ text: "数量", style: "tableHeader" },
{ text: "单价", style: "tableHeader" },
],
["商品A", "10件", "$10.00"],
["商品B", "5件", "$20.00"],
// [{ text: "", colSpan: 2, alignment: "right" }, "$150.00"],
],
},
layout: "noBorders",
margin: [0, 20, 0, 0],
},
//
{
text: "本票据一式两份,甲乙双方各执一份,具有同等法律效力。",
style: "footer",
alignment: "center",
margin: [0, 0, 0, 30],
},
];
exportToPDF(content);
};
onMounted(() => {
getNewTable();
});
</script>
<style scoped lang="less">
.scarch-box {
width: 100%;
background-color: @base-white-color;
margin-bottom: 2rem;
.scarch-from {
height: 60px;
display: flex;
justify-content: space-between;
align-items: center;
}
}
.table-box {
height: 42rem;
background-color: @base-white-color;
padding: 1rem;
padding-top: 0;
.table-header {
height: 3rem;
display: flex;
justify-content: space-between;
align-items: center;
}
}
:deep(.t-form__controls-content) {
justify-content: space-between;
}
</style>

View File

@ -6,6 +6,7 @@ import BillQuitneckURL from "@/pages/finance-bill-manage/billQuitneck.vue";
import BillBreakagekURL from "@/pages/finance-bill-manage/billBreakage.vue"; import BillBreakagekURL from "@/pages/finance-bill-manage/billBreakage.vue";
import BillDestroyURL from "@/pages/finance-bill-manage/billDestroy.vue"; import BillDestroyURL from "@/pages/finance-bill-manage/billDestroy.vue";
import DetailReportURL from "@/pages/finance-bill-manage/detailReport.vue"; import DetailReportURL from "@/pages/finance-bill-manage/detailReport.vue";
import BillDrawURL from "@/pages/finance-bill-manage/billDraw.vue";
const financeBillManage = [ const financeBillManage = [
{ {
@ -70,6 +71,14 @@ const financeBillManage = [
title: "报表明细", title: "报表明细",
}, },
}, },
{
path: "BillDraw",
name: "billDraw",
component: BillDrawURL,
meta: {
title: "报表明细",
},
},
], ],
}, },
]; ];

20
src/utils/pdf.js Normal file
View File

@ -0,0 +1,20 @@
import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.vfs = pdfFonts.pdfMake.vfs;
export const exportToPDF = (content) => {
const docDefinition = {
pageSize: "A4",
pageMargins: [40, 70, 40, 90],
content: content,
styles: {
header: { fontSize: 16, bold: true },
label: { fontSize: 12, bold: true },
value: { fontSize: 12 },
tableHeader: { fontSize: 12, bold: true, color: "#666" },
footer: { fontSize: 10, italics: true },
},
};
pdfMake.createPdf(docDefinition).download("output.pdf");
};