fix: receipt dialog

This commit is contained in:
puriphatt 2024-10-21 13:51:18 +07:00
parent 6df13d034e
commit 8d87368a7c
2 changed files with 149 additions and 22 deletions

View file

@ -11,6 +11,7 @@ import {
QuotationStats,
} from './types';
import { PaginationResult } from 'src/types';
import { AxiosInstance } from 'axios';
export const useQuotationStore = defineStore('quotation-store', () => {
const data = ref<Quotation[]>([]);
@ -25,7 +26,7 @@ export const useQuotationStore = defineStore('quotation-store', () => {
});
async function getQuotationStats() {
const res = await api.get<QuotationStats>(`/quotation/stats`);
const res = await api.get<QuotationStats>('/quotation/stats');
if (res.status < 400) {
return res.data;
}
@ -128,6 +129,61 @@ export const useQuotationStore = defineStore('quotation-store', () => {
};
});
function managePaymentFile(api: AxiosInstance) {
return {
listFile: async (opts: { quotationId: string; paymentId: string }) => {
const res = await api.get<string[]>(`/${base}/${opts.quotationId}/file`);
if (res.status >= 400) return false;
return res.data;
},
getFile: async (opts: {
group: T;
parentId: string;
fileId: string;
download?: boolean;
}) => {
const url = `/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`;
const res = await api.get<string>(url);
if (opts.download) {
fetch(res.data)
.then(async (res) => await res.blob())
.then((blob) => {
const a = document.createElement('a');
a.download = opts.fileId;
a.href = window.URL.createObjectURL(blob);
a.click();
a.remove();
});
}
return res.data;
},
putFile: async (opts: {
group: T;
parentId: string;
fileId: string;
file: File;
}) => {
const res = await api.put(
`/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
opts.file,
{
headers: { 'Content-Type': opts.file.type },
onUploadProgress: (e) => console.log(e),
},
);
if (res.status < 400) return true;
return false;
},
delFile: async (opts: { group: T; parentId: string; fileId: string }) => {
const res = await api.delete(
`/${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
);
if (res.status < 400) return true;
return false;
},
};
}
export const useQuotationPayment = defineStore('quotation-payment', () => {
async function getQuotationPayment(quotationId: string) {
const res = await api.get<