feat: add function edit quotation data

This commit is contained in:
Methapon Metanipat 2024-10-03 14:43:41 +07:00
parent 017f757de2
commit b7308d1833
2 changed files with 23 additions and 10 deletions

View file

@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { pageTabs, fieldSelectedOption } from './constants'; import { pageTabs, fieldSelectedOption } from './constants';
import { useQuotationForm } from './form';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
@ -15,6 +14,7 @@ import useEmployeeStore from 'stores/employee';
import useFlowStore from 'src/stores/flow'; import useFlowStore from 'src/stores/flow';
import useOcrStore from 'stores/ocr'; import useOcrStore from 'stores/ocr';
import useMyBranch from 'stores/my-branch'; import useMyBranch from 'stores/my-branch';
import { useQuotationForm } from './form';
// NOTE Import Types // NOTE Import Types
import { CustomerBranchCreate } from 'stores/customer/types'; import { CustomerBranchCreate } from 'stores/customer/types';
@ -74,7 +74,7 @@ import {
import QuotationView from './QuotationView.vue'; import QuotationView from './QuotationView.vue';
import { watch } from 'vue'; import { watch } from 'vue';
const quotationForm = useQuotationForm(); const quotationFormStore = useQuotationForm();
const customerFormStore = useCustomerForm(); const customerFormStore = useCustomerForm();
const employeeFormStore = useEmployeeForm(); const employeeFormStore = useEmployeeForm();
const employeeStore = useEmployeeStore(); const employeeStore = useEmployeeStore();
@ -83,7 +83,7 @@ const flowStore = useFlowStore();
const userBranch = useMyBranch(); const userBranch = useMyBranch();
const ocrStore = useOcrStore(); const ocrStore = useOcrStore();
const { currentFormData: quotationFormData } = storeToRefs(quotationForm); const { currentFormData: quotationFormData } = storeToRefs(quotationFormStore);
const { state: customerFormState, currentFormData: customerFormData } = const { state: customerFormState, currentFormData: customerFormData } =
storeToRefs(customerFormStore); storeToRefs(customerFormStore);
const { state: employeeFormState, currentFromDataEmployee } = const { state: employeeFormState, currentFromDataEmployee } =
@ -753,13 +753,13 @@ watch(() => pageState.currentTab, fetchQuotationList);
:date="new Date(v.createdAt).toLocaleString()" :date="new Date(v.createdAt).toLocaleString()"
:amount="v.workerCount" :amount="v.workerCount"
:customer-name=" :customer-name="
v.customerBranch?.registerName || v.customerBranch.registerName ||
`${v.customerBranch?.firstName || '-'} ${v.customerBranch?.lastName || ''}` `${v.customerBranch.firstName || '-'} ${v.customerBranch.lastName || ''}`
" "
:reporter="v.actorName" :reporter="v.actorName"
:total-price="v.totalPrice" :total-price="v.totalPrice"
@view="console.log('view')" @view="quotationFormStore.assignFormData(v.id)"
@edit="console.log('edit')" @edit="quotationFormStore.assignFormData(v.id, 'edit')"
@link="console.log('link')" @link="console.log('link')"
@upload="console.log('upload')" @upload="console.log('upload')"
@delete="console.log('delete')" @delete="console.log('delete')"

View file

@ -7,7 +7,7 @@ import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
// NOTE: Import stores // NOTE: Import stores
import { useQuotationStore } from 'stores/quotations'; import { useQuotationStore } from 'stores/quotations';
const DEFAULT_DATA: QuotationPayload = { const DEFAULT_DATA: QuotationPayload & { id?: string } = {
productServiceList: [], productServiceList: [],
urgent: false, urgent: false,
customerBranchId: '', customerBranchId: '',
@ -56,12 +56,24 @@ export const useQuotationForm = defineStore('form-quotation', () => {
currentFormData.value = structuredClone(resetFormData); currentFormData.value = structuredClone(resetFormData);
} }
async function assignFormData(id: string) { async function assignFormData(id: string, mode: 'info' | 'edit' = 'info') {
const data = await quotationStore.getQuotation(id); const data = await quotationStore.getQuotation(id);
if (!data) return; // NOTE: Error should be handled globally by axios instance if (!data) return; // NOTE: Error should be handled globally by axios instance
currentFormState.value.mode = 'edit'; resetFormData = Object.assign(data, {
dueDate: new Date(data.dueDate),
payBillDate: data.payBillDate ? new Date(data.payBillDate) : undefined,
worker: data.worker.map((v) =>
Object.assign(v.employee, {
dateOfBirth: new Date(v.employee.dateOfBirth),
}),
),
});
currentFormData.value = structuredClone(resetFormData);
currentFormState.value.mode = mode;
} }
function submiQuotationt() { function submiQuotationt() {
@ -87,6 +99,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
return { return {
currentFormData, currentFormData,
currentFormState,
injectNewEmployee, injectNewEmployee,
isFormDataDifferent, isFormDataDifferent,