diff --git a/src/components/05_quotation/ProductItem.vue b/src/components/05_quotation/ProductItem.vue index c5c514ef..6ef1544e 100644 --- a/src/components/05_quotation/ProductItem.vue +++ b/src/components/05_quotation/ProductItem.vue @@ -6,7 +6,7 @@ import { storeToRefs } from 'pinia'; import WorkerItem from './WorkerItem.vue'; import DeleteButton from '../button/DeleteButton.vue'; import { precisionRound } from 'src/utils/arithmetic'; -import { QuotationPayload } from 'stores/quotations/types'; +import { ProductServiceList, QuotationPayload } from 'stores/quotations/types'; import { formatNumberDecimal, commaInput } from 'stores/utils'; import { useConfigStore } from 'stores/config'; @@ -14,6 +14,7 @@ const props = defineProps<{ readonly?: boolean; agentPrice: boolean; installmentInput?: boolean; + maxInstallment?: number | null; employeeRows?: { foreignRefNo: string; employeeName: string; @@ -29,6 +30,13 @@ const props = defineProps<{ defineEmits<{ (e: 'delete', index: number): void; + ( + e: 'updateTable', + data: QuotationPayload['productServiceList'][number], + opt?: { + newInstallmentNo: number; + }, + ): void; }>(); const configStore = useConfigStore(); @@ -224,6 +232,26 @@ watch( } }, ); + +watch( + () => props.maxInstallment, + () => { + if (!props.maxInstallment) return; + let test: ProductServiceList[] = []; + const items = groupByServiceId( + rows.value.map((v, i) => Object.assign(v, { i })), + ) || [{ title: '', product: [] }]; + + items.forEach((p) => { + test = test.concat(p.product.flatMap((item) => item)); + }); + test.forEach((p) => { + if ((props.maxInstallment || 0) < (p.installmentNo || 0)) { + p.installmentNo = Number(props.maxInstallment); + } + }); + }, +);