diff --git a/src/pages/05_quotation/ReceiptDialog.vue b/src/pages/05_quotation/PaymentForm.vue similarity index 91% rename from src/pages/05_quotation/ReceiptDialog.vue rename to src/pages/05_quotation/PaymentForm.vue index a67ceba4..47ed2a6c 100644 --- a/src/pages/05_quotation/ReceiptDialog.vue +++ b/src/pages/05_quotation/PaymentForm.vue @@ -3,27 +3,25 @@ import { baseUrl } from 'stores/utils'; import { storeToRefs } from 'pinia'; import { useConfigStore } from 'stores/config'; import { formatNumberDecimal } from 'stores/utils'; -import DialogForm from 'src/components/DialogForm.vue'; -import { reactive, ref, watch } from 'vue'; +import { reactive, ref } from 'vue'; import { useQuotationPayment } from 'src/stores/quotations'; import { PaymentPayload, Quotation, + QuotationFull, QuotationPaymentData, } from 'src/stores/quotations/types'; import { dateFormat } from 'src/utils/datetime'; import { QFile, QMenu } from 'quasar'; import UploadFileCard from 'src/components/upload-file/UploadFileCard.vue'; +import { onMounted } from 'vue'; const configStore = useConfigStore(); const quotationPayment = useQuotationPayment(); const { data: config } = storeToRefs(configStore); -const model = defineModel({ default: false, required: true }); -const data = defineModel('data', { required: true }); +const prop = defineProps<{ data?: Quotation | QuotationFull }>(); -const fileManager = - ref>(); const refQFile = ref[]>([]); const refQMenu = ref[]>([]); const paymentData = ref([]); @@ -51,7 +49,6 @@ const paymentStatusOpts = [ ]; const slipFile = ref< { - quotationId: string; paymentId: string; data: { name: string; progress: number; loaded: number; total: number }[]; file?: File; @@ -74,8 +71,7 @@ function pickFile(index: number) { } async function getSlipList(payment: QuotationPaymentData, index: number) { - if (!fileManager.value) return; - const slipList = await fileManager.value.listAttachment({ + const slipList = await quotationPayment.listAttachment({ parentId: payment.id, }); @@ -106,19 +102,18 @@ async function triggerUpload( index: number, file?: File, ) { - if (!data.value || !fileManager.value || !file) return; + if (!file) return; slipFile.value[index].data.push({ name: file.name, progress: 0, loaded: 0, total: 0, }); - const ret = await fileManager.value.putAttachment({ + const ret = await quotationPayment.putAttachment({ parentId: payment.id, name: file.name, file: file, onUploadProgress: (e) => { - console.log(e); slipFile.value[index].data[slipFile.value[index].data.length - 1] = { name: file.name, progress: e.progress || 0, @@ -136,14 +131,12 @@ async function triggerDelete( name: string, index: number, ) { - if (!data.value || !fileManager.value) return; - await fileManager.value.delAttachment({ parentId: payment.id, name }); + await quotationPayment.delAttachment({ parentId: payment.id, name }); await getSlipList(payment, index); } function triggerViewSlip(payment: QuotationPaymentData, name: string) { - if (!data.value || !fileManager.value) return; - const url = `${baseUrl}/quotation/${data.value.id}/payment/${payment.id}/attachment/${name}`; + const url = `${baseUrl}/payment/${payment.id}/attachment/${name}`; window.open(url, '_blank'); } @@ -168,60 +161,36 @@ function selectStatus( async function triggerSubmit() { submitPaymentData.value.forEach(async (p) => { - if (!data.value) return; - const payload: PaymentPayload = { paymentStatus: p.paymentStatus, - remark: p.remark || '', date: new Date(p.date), amount: p.amount, }; - await quotationPayment.updateQuotationPayment(data.value.id, p.id, payload); + await quotationPayment.updateQuotationPayment(p.id, payload); }); - model.value = false; } -watch( - () => model.value, - async (open) => { - if (!data.value) return; - if (!open) { - paymentData.value = []; - state.payExpansion = []; - slipFile.value = []; - submitPaymentData.value = []; - } else { - fileManager.value = quotationPayment.createPaymentFileManager( - data.value.id, - ); - const ret = await quotationPayment.getQuotationPayment(data.value.id); - if (ret) { - paymentData.value = ret.quotationPaymentData; - slipFile.value = paymentData.value.map((v) => ({ - quotationId: ret.id, - paymentId: v.id, - data: [], - })); - } - } - }, -); +onMounted(async () => { + if (!prop.data) return; + const ret = await quotationPayment.getQuotationPayment(prop.data.id); + if (ret) { + paymentData.value = ret.result; + slipFile.value = paymentData.value.map((v) => ({ + paymentId: v.id, + data: [], + })); + } +});