feat:重新生成发票

This commit is contained in:
dzc committed 2025-08-01 11:12:32 +08:00
1 parent 95625c7c1a
commit 7ca84b8c06
3 files changed
+56 -12

No files matched your search

+12
View File
@@ -8,6 +8,18 @@ export function invoiceBack(query: any) {
})
}
/**
* 重新生成发票
*/
export function refreshInvoice(data: any) {
return request({
url: "/wallet/walletRechargeInvoice/refreshInvoice",
method: "post",
data: data,
})
}
/**
* 发票申请
* @param id 发票id
@@ -142,12 +142,11 @@
<script setup lang="ts" name="systemWalletRechargeInvoice">
import { BasicTableProps, useTable } from "/@/hooks/table"
import { fetchList, delObjs } from "/@/api/wallet/wallet-recharge-invoice"
import * as WalletRechargeInvoiceApi from "/@/api/wallet/wallet-recharge-invoice"
import { useMessage, useMessageBox } from "/@/hooks/message"
import { displayPrice } from "/@/utils/formatMoney"
import { parseTime } from "/@/utils/formatTime"
import { useDict } from "/@/hooks/dict"
import { getObj } from "/@/api/wallet/wallet-recharge-invoice"
import ProcessDrawer from "/@/components/processDrawer/index.vue"
import { getDicts } from "/@/api/admin/dict"
@@ -174,7 +173,7 @@ const tabItems = ref<any>([{}])
const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {},
pageList: fetchList,
pageList: WalletRechargeInvoiceApi.fetchList,
})
const printDialogRef = ref()
const loading = ref(false)
@@ -234,7 +233,7 @@ const handleDelete = async (ids: string[]) => {
}
try {
await delObjs(ids)
await WalletRechargeInvoiceApi.delObjs(ids)
getDataList()
useMessage().success("删除成功")
} catch (err: any) {
@@ -247,7 +246,7 @@ const previewInvoice = async (row: any) => {
try {
loading.value = true
if (!row.id) return useMessage().error("发票ID不存在")
const res = await getObj(row.id)
const res = await WalletRechargeInvoiceApi.getObj(row.id)
if (res.code == 0 && printDialogRef.value) return printDialogRef.value.openDialog(res.data, res.data.id)
return useMessage().error(res.data.msg || "获取发票信息失败")
} catch (error: any) {
@@ -101,6 +101,8 @@
:disabled="loading">保存</el-button>
<el-button v-if="receiptData.stampPicUrl && !['6'].includes(receiptData.status!)" type="warning"
@click="handlePrint" :disabled="loading">打印</el-button>
<el-button v-if="receiptData.stampPicUrl && !['6'].includes(receiptData.status!)" type="primary" plain
icon="RefreshRight" @click="refreshInvoice" :disabled="refreshLoading">重新生成发票</el-button>
</template>
</el-dialog>
</template>
@@ -108,12 +110,12 @@
<script setup lang="ts">
import { ref, computed } from "vue"
import * as htmlToImage from "html-to-image"
import { useMessage } from "/@/hooks/message"
import { useMessage, useMessageBox } from "/@/hooks/message"
import request from "/@/utils/request"
import { formatDate } from "/@/utils/formatTime"
import { displayPrice } from "/@/utils/formatMoney"
import printJS from "print-js"
import { bindInvoice, invoiceBack, getObj, apply } from "/@/api/wallet/wallet-recharge-invoice"
import * as WalletRechargeInvoiceApi from "/@/api/wallet/wallet-recharge-invoice"
import { useDict } from "/@/hooks/dict"
interface ReceiptData {
@@ -139,6 +141,7 @@ const { check_status } = useDict("check_status")
let timer
const visible = ref(false)
const loading = ref(false)
const refreshLoading = ref(false)
const receiptRef = ref<HTMLElement | null>(null)
const deptOrUserInput = ref<HTMLInputElement | null>(null)
const receiptData = ref<ReceiptData>({
@@ -183,12 +186,41 @@ const handleClose = () => {
timer = null
}
// 刷新发票
const refreshInvoice = async () => {
try {
await useMessageBox().confirm("是否重新生成发票")
} catch {
return
}
refreshLoading.value = true
try {
// 申请审批
const blob = await genImage()
if (!blob) return useMessage().error("图片生成失败")
const picUrl = await uploadImage(blob)
if (!picUrl) return useMessage().error("图片上传失败")
const _data = {
id: receiptData.value.id,
picUrl: picUrl
}
await WalletRechargeInvoiceApi.refreshInvoice(_data)
useMessage().success("重新生成发票成功")
} catch (err: any) {
console.error(err);
useMessage().error(err.msg)
} finally {
refreshLoading.value = false
}
}
// 发票作废
const backInvoice = async () => {
loading.value = true
try {
await invoiceBack({ id: receiptData.value.id })
const res = await getObj(receiptData.value.id)
await WalletRechargeInvoiceApi.invoiceBack({ id: receiptData.value.id })
const res = await WalletRechargeInvoiceApi.getObj(receiptData.value.id)
receiptData.value = res.data
emit("refresh")
useMessage().success("作废成功")
@@ -211,6 +243,7 @@ const genImage = async (): Promise<Blob | void | null> => {
pixelRatio: 6,
})
.catch((error) => {
console.error(error);
return useMessage().error("图片生成错误")
})
return blob
@@ -237,7 +270,7 @@ const uploadImage = async (blob: Blob): Promise<string | void> => {
const saveReceipt = async (): Promise<void> => {
try {
loading.value = true
const { code, data } = await bindInvoice({
const { code, data } = await WalletRechargeInvoiceApi.bindInvoice({
...receiptData.value,
deptOrUser: receiptData.value.deptOrUser,
applyId: receiptData.value.id,
@@ -262,7 +295,7 @@ const applyStamp = async () => {
loading.value = true
try {
// 先保存
const res = await bindInvoice({
const res = await WalletRechargeInvoiceApi.bindInvoice({
...receiptData.value,
deptOrUser: receiptData.value.deptOrUser,
applyId: receiptData.value.id,
@@ -277,7 +310,7 @@ const applyStamp = async () => {
const picUrl = await uploadImage(blob)
if (!picUrl) return useMessage().error("图片上传失败")
const { code, msg } = await apply({ id: receiptData.value.id, picUrl })
const { code, msg } = await WalletRechargeInvoiceApi.apply({ id: receiptData.value.id, picUrl })
if (code == 0) {
useMessage().success("申请成功")
emit("refresh")