refactor: delete worker & branch, cus-branch state

This commit is contained in:
puriphatt 2024-10-07 10:20:29 +07:00
parent 20349f0cf7
commit a9650ad1b6
3 changed files with 85 additions and 31 deletions

View file

@ -5,6 +5,8 @@ import useBranchStore from 'src/stores/branch';
import useCustomerStore from 'src/stores/customer'; import useCustomerStore from 'src/stores/customer';
import SelectInput from '../shared/SelectInput.vue'; import SelectInput from '../shared/SelectInput.vue';
import { QSelect } from 'quasar'; import { QSelect } from 'quasar';
import { Branch } from 'src/stores/branch/types';
import { CustomerBranch } from 'src/stores/customer/types';
const { locale } = useI18n({ useScope: 'global' }); const { locale } = useI18n({ useScope: 'global' });
const branchStore = useBranchStore(); const branchStore = useBranchStore();
@ -66,17 +68,20 @@ async function init(val: string, type: 'branch' | 'customer') {
}); });
if (res) { if (res) {
if (type === 'branch') { if (type === 'branch') {
branchOption.value = res.result.map((v) => ({ branchOption.value = (res.result as Branch[]).map((v: Branch) => ({
value: v.id, value: v.id,
label: v.name, label: v.name,
labelEN: v.nameEN, labelEN: v.nameEN,
})); }));
} else if (type === 'customer') { } else if (type === 'customer') {
customerOption.value = res.result.map((v) => ({ customerOption.value = (res.result as CustomerBranch[]).map(
value: v.id, (v: CustomerBranch) => ({
label: v.registerName || `${v.firstName} ${v.lastName}` || '-', value: v.id,
labelEN: v.registerNameEN || `${v.firstNameEN} ${v.lastNameEN}` || '-', label: v.registerName || `${v.firstName} ${v.lastName}` || '-',
})); labelEN:
v.registerNameEN || `${v.firstNameEN} ${v.lastNameEN}` || '-',
}),
);
} }
} }
} }
@ -89,7 +94,8 @@ onMounted(async () => {
watch( watch(
() => branchId.value, () => branchId.value,
async (v) => { async (v) => {
if (v && props.onCreate) { if (v && customerBranchId.value && props.onCreate) {
console.log('form');
customerBranchId.value = ''; customerBranchId.value = '';
} }
}, },
@ -137,7 +143,7 @@ watch(
:label="$t('quotation.branch')" :label="$t('quotation.branch')"
:option-label="locale === 'eng' ? 'labelEN' : 'label'" :option-label="locale === 'eng' ? 'labelEN' : 'label'"
:rules="[(val: string) => !!val || $t('form.error.required')]" :rules="[(val: string) => !!val || $t('form.error.required')]"
@filter="(val, update) => filter(val, update, 'branch')" @filter="(val: string, update) => filter(val, update, 'branch')"
/> />
<SelectInput <SelectInput
@ -151,7 +157,7 @@ watch(
:label="$t('quotation.customer')" :label="$t('quotation.customer')"
:option-label="locale === 'eng' ? 'labelEN' : 'label'" :option-label="locale === 'eng' ? 'labelEN' : 'label'"
:rules="[(val: string) => !!val || $t('form.error.required')]" :rules="[(val: string) => !!val || $t('form.error.required')]"
@filter="(val, update) => filter(val, update, 'customer')" @filter="(val: string, update) => filter(val, update, 'customer')"
> >
<template #option="{ scope }"> <template #option="{ scope }">
<q-item <q-item

View file

@ -3,7 +3,7 @@ import { QTableProps } from 'quasar';
import TableComponents from 'src/components/TableComponents.vue'; import TableComponents from 'src/components/TableComponents.vue';
defineEmits<{ defineEmits<{
(e: 'delete'): void; (e: 'delete', index: number): void;
}>(); }>();
withDefaults( withDefaults(
@ -89,7 +89,7 @@ const columns = [
:columns :columns
:rows :rows
hidePagination hidePagination
@delete="$emit('delete')" @delete="(i) => $emit('delete', i)"
> >
<template v-slot:img-column="{ props }"> <template v-slot:img-column="{ props }">
<q-avatar class="q-mr-sm" size="md"> <q-avatar class="q-mr-sm" size="md">

View file

@ -2,7 +2,7 @@
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { nextTick, onMounted, reactive, ref } from 'vue'; import { nextTick, onBeforeMount, onMounted, reactive, ref, watch } from 'vue';
// NOTE: Import stores // NOTE: Import stores
import { setLocale, dateFormat, calculateAge } from 'src/utils/datetime'; import { setLocale, dateFormat, calculateAge } from 'src/utils/datetime';
@ -14,6 +14,7 @@ import useEmployeeStore from 'stores/employee';
import useOptionStore from 'stores/options'; import useOptionStore from 'stores/options';
import { useQuotationForm } from './form'; import { useQuotationForm } from './form';
import useOcrStore from 'stores/ocr'; import useOcrStore from 'stores/ocr';
import { deleteItem } from 'stores/utils';
// NOTE Import Types // NOTE Import Types
import { QuotationPayload } from 'src/stores/quotations/types'; import { QuotationPayload } from 'src/stores/quotations/types';
@ -112,6 +113,7 @@ const pageState = reactive({
statusFilter: 'all', statusFilter: 'all',
fieldSelected: [], fieldSelected: [],
gridView: false, gridView: false,
isLoaded: false,
currentTab: 'all', currentTab: 'all',
addModal: false, addModal: false,
@ -223,6 +225,7 @@ function triggerProductServiceDialog() {
} }
function toggleDeleteProduct(index: number) { function toggleDeleteProduct(index: number) {
deleteItem(productServiceList.value, index);
console.log(index); console.log(index);
} }
@ -319,26 +322,70 @@ onMounted(async () => {
}); });
if (ret) productGroup.value = ret.result; if (ret) productGroup.value = ret.result;
const retEmp = await customerStore.fetchBranchEmployee( if (quotationFormData.value.customerBranchId) {
quotationFormData.value.customerBranchId, const retEmp = await customerStore.fetchBranchEmployee(
); quotationFormData.value.customerBranchId,
if (retEmp) );
workerList.value = retEmp.data.result.map((value) => ({ if (retEmp)
alienReferencNumber: '', workerList.value = retEmp.data.result.map((value) => ({
documentExpireDate: new Date(), alienReferencNumber: '',
lastNameEN: value.lastNameEN, documentExpireDate: new Date(),
lastName: value.lastName, lastNameEN: value.lastNameEN,
middleNameEN: value.middleNameEN, lastName: value.lastName,
middleName: value.middleName, middleNameEN: value.middleNameEN,
firstNameEN: value.firstNameEN, middleName: value.middleName,
firstName: value.firstName, firstNameEN: value.firstNameEN,
namePrefix: value.namePrefix, firstName: value.firstName,
nationality: value.nationality, namePrefix: value.namePrefix,
gender: value.gender, nationality: value.nationality,
dateOfBirth: value.dateOfBirth, gender: value.gender,
code: value.code, dateOfBirth: value.dateOfBirth,
})); code: value.code,
}));
}
pageState.isLoaded = true;
}); });
watch(
() => quotationFormData.value.customerBranchId,
async (v) => {
const url = new URL(window.location.href);
url.searchParams.set('customerBranchId', v);
history.pushState({}, '', url.toString());
if (!v) return;
const retEmp = await customerStore.fetchBranchEmployee(v);
if (retEmp) {
workerList.value = retEmp.data.result.map((value) => ({
alienReferencNumber: '',
documentExpireDate: new Date(),
lastNameEN: value.lastNameEN,
lastName: value.lastName,
middleNameEN: value.middleNameEN,
middleName: value.middleName,
firstNameEN: value.firstNameEN,
firstName: value.firstName,
namePrefix: value.namePrefix,
nationality: value.nationality,
gender: value.gender,
dateOfBirth: value.dateOfBirth,
code: value.code,
}));
}
},
);
watch(
() => branchId.value,
async (v) => {
if (!pageState.isLoaded) return;
const url = new URL(window.location.href);
url.searchParams.set('branchId', v);
history.pushState({}, '', url.toString());
quotationFormData.value.customerBranchId = '';
},
);
</script> </script>
<template> <template>
@ -444,6 +491,7 @@ onMounted(async () => {
status: e.status, status: e.status,
})) }))
" "
@delete="(i) => deleteItem(selectedWorker, i)"
/> />
</div> </div>
</q-expansion-item> </q-expansion-item>