This commit is contained in:
dzc committed 2025-06-24 17:06:20 +08:00
commit e3b808ca09
2 files changed
+104 -89

No files matched your search

@@ -180,6 +180,7 @@
icon="printer" icon="printer"
text text
type="primary" type="primary"
:loading="getReceiptDataLoading"
@click="previewInvoice(row)" @click="previewInvoice(row)"
> >
打印发票 打印发票
@@ -205,7 +206,7 @@
<process-drawer ref="processDrawerRef" @task-submit-event="taskSubmitEvent" /> <process-drawer ref="processDrawerRef" @task-submit-event="taskSubmitEvent" />
<!-- 发票预览 --> <!-- 发票预览 -->
<print-dialog v-model="printDialogVisible" :receipt-data="receiptData" /> <print-dialog ref="printDialogRef" />
</div> </div>
</template> </template>
@@ -243,15 +244,8 @@ const multiple = ref(true)
const activeName = ref() const activeName = ref()
const tabItems = ref<any>([{}]) const tabItems = ref<any>([{}])
const processDrawerRef = ref() const processDrawerRef = ref()
const printDialogVisible = ref(false) const printDialogRef = ref()
const receiptData = ref({ const getReceiptDataLoading = ref(false)
receiptNo: "",
date: "",
payer: "",
content: "",
amount: "",
amountInWords: "",
})
const state: BasicTableProps = reactive<BasicTableProps>({ const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {}, queryForm: {},
@@ -371,14 +365,18 @@ const taskSubmitEvent = () => {
// 预览发票 // 预览发票
const previewInvoice = async (row: any) => { const previewInvoice = async (row: any) => {
try { try {
getReceiptDataLoading.value = true
const res = await getInvoice({ id: row.id }) const res = await getInvoice({ id: row.id })
if (res.code == 0) { if (res.code == 0) {
receiptData.value = res.data if (printDialogRef.value) {
printDialogVisible.value = true printDialogRef.value.openDialog(res.data)
}
return return
} }
} catch (error: any) { } catch (error: any) {
useMessage().error(error.msg) useMessage().error(error.msg)
} finally {
getReceiptDataLoading.value = false
} }
} }
</script> </script>
@@ -5,8 +5,8 @@
<div class="flex justify-between items-end mb-1"> <div class="flex justify-between items-end mb-1">
<div></div> <div></div>
<div class="text-lg">{{ receiptData.date || " 年 月 日".replace(/ /g, "&nbsp;&nbsp;") }}</div> <div class="text-lg">{{ receiptData.time || " 年 月 日".replace(/ /g, "&nbsp;&nbsp;") }}</div>
<span class="text-xl text-red-500">No. {{ receiptData.receiptNo || "0000000" }}</span> <span class="text-xl text-red-500">No. {{ receiptData.code || "0000000" }}</span>
</div> </div>
<div class="flex flex-row"> <div class="flex flex-row">
@@ -15,43 +15,43 @@
<tr class="border border-gray-300"> <tr class="border border-gray-300">
<td class="border border-gray-300 px-2 w-3/12 h-10">交款单位(或个人)</td> <td class="border border-gray-300 px-2 w-3/12 h-10">交款单位(或个人)</td>
<td class="border border-gray-300 px-2 w-9/12 h-10 text-sm text-blue-800" colspan="4"> <td class="border border-gray-300 px-2 w-9/12 h-10 text-sm text-blue-800" colspan="4">
{{ receiptData.payer }} <input type="text" v-model="receiptData.deptOrUser" class="w-full h-full bg-transparent" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="border border-gray-300 px-2 h-10" colspan="4">款项内容</td> <td class="border border-gray-300 px-2 h-10" colspan="4">款项内容</td>
<td class="border border-gray-300 px-2 h-10">金额</td> <td class="border border-gray-300 px-2 h-10">金额</td>
</tr> </tr>
<tr> <tr v-for="(item, index) in 3" :key="index">
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800" colspan="4">{{}}</td> <td class="border border-gray-300 px-2 h-10 text-sm text-blue-800" colspan="4">{{ receiptDataItems[item - 1]?.name }}</td>
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800">{{}}</td> <td class="border border-gray-300 px-2 h-10 text-sm text-blue-800">{{ receiptDataItems[item - 1]?.price }}</td>
</tr>
<tr>
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800" colspan="4">{{}}</td>
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800">{{}}</td>
</tr>
<tr>
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800" colspan="4">{{}}</td>
<td class="border border-gray-300 px-2 h-10 text-sm text-blue-800">{{}}</td>
</tr> </tr>
<tr> <tr>
<td class="border border-gray-300 px-2 text-left h-10" colspan="4"> <td class="border border-gray-300 px-2 text-left h-10" colspan="4">
<span>合计人民币(大写):</span> <div class="flex items-center">
<span class="text-sm text-blue-800">{{}}</span> <span>合计人民币(大写):</span>
<span class="text-sm text-blue-800">
<input type="text" v-model="receiptData.totalPriceCnStr" class="w-full h-full bg-transparent" />
</span>
</div>
</td> </td>
<td class="border border-gray-300 px-2 text-left h-10"> <td class="border border-gray-300 px-2 text-left h-10">
<span>¥:</span> <div class="flex items-center">
<span class="text-sm text-blue-800">{{ receiptData.amountInWords }}</span> <span>¥:</span>
<span class="text-sm text-blue-800">
<input type="text" v-model="totalPrice" class="w-full h-full bg-transparent" />
</span>
</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="border border-gray-300 px-2 w-1/6 h-10">收款单位<br />(盖章)</td> <td class="border border-gray-300 px-2 w-1/6 h-10">收款单位<br />(盖章)</td>
<td class="border border-gray-300 px-2 text-left w-1/6 h-10"></td> <td class="border border-gray-300 px-2 text-left w-1/6 h-10 text-sm text-blue-800">{{ receiptData.payeeDept }}</td>
<td class="border border-gray-300 px-2 w-1/6 h-10">收款人<br />(签名)</td> <td class="border border-gray-300 px-2 w-1/6 h-10">收款人<br />(签名)</td>
<td class="border border-gray-300 px-2 text-left w-1/6 h-10 text-sm text-blue-800">{{}}</td> <td class="border border-gray-300 px-2 text-left w-1/6 h-10 text-sm text-blue-800">{{ receiptData.payeeUser }}</td>
<td class="border border-gray-300 px-2 text-left align-text-top w-1/3 h-10"> <td class="border border-gray-300 px-2 text-left align-text-top w-1/3 h-10">
<span>备注:</span> <span>备注:</span>
<span class="text-sm text-blue-800">{{}}</span> <span class="text-sm text-blue-800">{{ receiptData.remark }}</span>
</td> </td>
</tr> </tr>
</table> </table>
@@ -64,8 +64,8 @@
<template #footer> <template #footer>
<el-button @click="handleClose">关闭</el-button> <el-button @click="handleClose">关闭</el-button>
<el-button type="primary" @click="saveReceipt">保存</el-button> <el-button type="primary" @click="saveReceipt" :disabled="loading">保存</el-button>
<el-button type="primary" @click="handlePrint">打印</el-button> <el-button type="primary" @click="handlePrint" :disabled="loading">打印</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
@@ -75,80 +75,97 @@ import { ref, computed } from "vue"
import * as htmlToImage from "html-to-image" import * as htmlToImage from "html-to-image"
import { toPng, toJpeg, toBlob, toPixelData, toSvg } from "html-to-image" import { toPng, toJpeg, toBlob, toPixelData, toSvg } from "html-to-image"
import { useMessage } from "/@/hooks/message" import { useMessage } from "/@/hooks/message"
import request from "/@/utils/request"
import { displayPrice } from "/@/utils/formatMoney"
interface ReceiptData { interface ReceiptData {
receiptNo?: string itemJson: string
date?: string code: string
payer?: string time: string
content?: string deptOrUser: string
amount?: string totalPrice: string
amountInWords?: string payeeDept: string
cashier?: string payeeUser: string
remark: string
totalPriceCnStr: string
} }
const props = defineProps<{ const visible = ref(false)
modelValue: boolean const receiptData = ref<ReceiptData>({
receiptData?: ReceiptData itemJson: "", // 款项json
}>() code: "", // 发票代码(七位数)
time: "", // 发票日期
const emit = defineEmits(["update:modelValue"]) deptOrUser: "", // 交款单位或个人
totalPrice: "", // 合计人民币
const visible = ref(props.modelValue) totalPriceCnStr: "", // 合计人民币大写
const receiptData = computed( payeeDept: "", // 收款单位
() => payeeUser: "", // 收款人
props.receiptData || { remark: "", // 备注
receiptNo: "", })
date: "", const loading = ref(false)
payer: "", const receiptDataItems = computed(() => {
content: "", try {
amount: "", return JSON.parse(receiptData.value.itemJson)
amountInWords: "", } catch (error) {
cashier: "", return 3
}, }
) })
const totalPrice = computed(() => {
return displayPrice(receiptData.value.totalPrice)
})
const receiptRef = ref<HTMLElement | null>() const receiptRef = ref<HTMLElement | null>()
watch( const openDialog = (data: ReceiptData) => {
() => visible.value, visible.value = true
(newVal) => { receiptData.value = data
emit("update:modelValue", newVal) }
},
)
watch(
() => props.modelValue,
(newVal) => {
visible.value = newVal
},
)
const handleClose = () => { const handleClose = () => {
visible.value = false visible.value = false
} }
const saveReceipt = () => { const saveReceipt = async () => {
if (receiptRef.value) { if (receiptRef.value) {
htmlToImage try {
.toPng(receiptRef.value, { loading.value = true
const blob = await htmlToImage.toBlob(receiptRef.value, {
canvasWidth: 1920, canvasWidth: 1920,
canvasHeight: 900, canvasHeight: 900,
backgroundColor: "#ffffff", backgroundColor: "#ffffff",
// style: {},
}) })
.then((dataUrl: string) => {
console.log(dataUrl)
const img = new Image()
img.src = dataUrl
})
.catch((err) => {
useMessage().error(err)
})
}
// visible.value = false if (blob) {
const formData = new FormData()
formData.append("file", blob, "receipt.png")
const { code, data } = await request({
url: "/admin/sys-file/upload",
method: "post",
headers: {
"Content-Type": "multipart/form-data",
},
data: formData,
})
if (code == 0) {
useMessage().success("保存成功")
console.log(data)
return data
}
useMessage().error(data.msg || "保存失败")
}
} catch (err) {
useMessage().error(err as string)
} finally {
loading.value = false
}
}
} }
const handlePrint = () => { const handlePrint = () => {
window.print() window.print()
} }
defineExpose({
openDialog,
})
</script> </script>