fix: แก้การค้นหา ให้ล้างค่า

This commit is contained in:
Net 2024-06-18 13:29:45 +07:00
parent 2fe3de2e11
commit b945624404

View file

@ -29,6 +29,8 @@ import FormBusiness from 'src/components/03_customer-management/FormBusiness.vue
import DrawerInfo from 'src/components/DrawerInfo.vue'; import DrawerInfo from 'src/components/DrawerInfo.vue';
import InfoForm from 'src/components/02_personnel-management/InfoForm.vue'; import InfoForm from 'src/components/02_personnel-management/InfoForm.vue';
import CustomerInfoComponent from 'src/components/03_customer-management/CustomerInfoComponent.vue'; import CustomerInfoComponent from 'src/components/03_customer-management/CustomerInfoComponent.vue';
import NoData from 'components/NoData.vue';
import { import {
CustomerCreate, CustomerCreate,
CustomerStats, CustomerStats,
@ -111,7 +113,7 @@ const formData = ref<CustomerCreate>({
image: null, image: null,
}); });
const inputSearch = ref<string>(''); const inputSearch = ref<string>();
const fieldSelectedCustomer = ref<{ label: string; value: string }>({ const fieldSelectedCustomer = ref<{ label: string; value: string }>({
label: t('all'), label: t('all'),
value: 'all', value: 'all',
@ -250,6 +252,8 @@ const currentCustomerName = ref<string>('');
const currentCustomerUrlImage = ref<string | null>(null); const currentCustomerUrlImage = ref<string | null>(null);
const genderselector = ref<string>(''); const genderselector = ref<string>('');
const totalCustomer = ref<number>(0);
const currentStatus = ref<Status | 'All'>('All'); const currentStatus = ref<Status | 'All'>('All');
const inputFile = (() => { const inputFile = (() => {
@ -1024,7 +1028,11 @@ onMounted(async () => {
pageSize: pageSizeCustomer.value, pageSize: pageSizeCustomer.value,
}); });
if (resultStats) statsCustomerType.value = resultStats; if (resultStats) {
totalCustomer.value = resultStats.CORP + resultStats.PERS;
statsCustomerType.value = resultStats;
}
if (resultList) listCustomer.value = resultList.result; if (resultList) listCustomer.value = resultList.result;
@ -1075,13 +1083,6 @@ watch(locale, () => {
}; };
}); });
watch(locale, () => {
fieldSelectedCustomer.value = {
label: `${fieldSelectedCustomer.value.label}`,
value: fieldSelectedCustomer.value?.value,
};
});
watch(currentPageCustomer, async () => { watch(currentPageCustomer, async () => {
await fetchListCustomer(); await fetchListCustomer();
}); });
@ -1163,6 +1164,14 @@ watch(currentStatus, async () => {
}); });
} }
}); });
watch(selectorLabel, async () => {
if (inputSearch.value) {
inputSearch.value = undefined;
resultSearch.value = undefined;
resultSearchEmployee.value = undefined;
}
});
</script> </script>
<template> <template>
@ -1345,7 +1354,7 @@ watch(currentStatus, async () => {
class="q-mr-lg" class="q-mr-lg"
:bg-color="$q.dark.isActive ? 'dark' : 'white'" :bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="inputSearch" v-model="inputSearch"
debounce="500" debounce="200"
@update:model-value=" @update:model-value="
selectorLabel === 'EMPLOYEE' ? searchEmployee() : searchCustomer() selectorLabel === 'EMPLOYEE' ? searchEmployee() : searchCustomer()
" "
@ -1393,18 +1402,30 @@ watch(currentStatus, async () => {
<template <template
v-if=" v-if="
listCustomer && listCustomer && totalCustomer > 0 && selectorLabel === 'EMPLOYER'
listCustomer.length > 0 &&
selectorLabel === 'EMPLOYER'
" "
> >
<div <div
v-if="
listCustomer.length === 0 ||
(resultSearch?.length === 0 && inputSearch !== undefined)
"
class="row full-width items-center justify-center"
style="min-height: 250px"
>
<NoData />
</div>
<div
v-if="listCustomer.length !== 0 && resultSearch?.length !== 0"
class="row full-width customer-row" class="row full-width customer-row"
:style="`grid-template-columns: repeat(${$q.screen.lt.sm ? '2' : $q.screen.lt.md ? '3' : $q.screen.lt.lg ? '5' : '6'}, 1fr)`" :style="`grid-template-columns: repeat(${$q.screen.lt.sm ? '2' : $q.screen.lt.md ? '3' : $q.screen.lt.lg ? '5' : '6'}, 1fr)`"
style="min-height: 250px" style="min-height: 250px"
> >
<UsersDetailCardComponent <UsersDetailCardComponent
v-for="i in inputSearch ? resultSearch : listCustomer" v-for="i in inputSearch !== undefined
? resultSearch ?? []
: listCustomer"
:key="i.id" :key="i.id"
class="hover-card" class="hover-card"
:color="i.customerType === 'CORP' ? 'purple' : 'green'" :color="i.customerType === 'CORP' ? 'purple' : 'green'"
@ -1469,7 +1490,8 @@ watch(currentStatus, async () => {
@delete-card="deleteCustomerById(i.id)" @delete-card="deleteCustomerById(i.id)"
/> />
</div> </div>
<div class="row flex-center q-pt-md">
<div v-if="listCustomer.length !== 0" class="row flex-center q-pt-md">
<q-pagination <q-pagination
claess="pagination" claess="pagination"
v-model="currentPageCustomer" v-model="currentPageCustomer"
@ -1483,15 +1505,23 @@ watch(currentStatus, async () => {
<template <template
v-if=" v-if="
listEmployee && listEmployee && statsEmployee > 0 && selectorLabel === 'EMPLOYEE'
listEmployee.length > 0 &&
selectorLabel === 'EMPLOYEE'
" "
> >
<div> <div
v-if="
listEmployee.length === 0 || resultSearchEmployee?.length === 0
"
class="row full-width items-center justify-center"
style="min-height: 250px"
>
<NoData />
</div>
<div v-if="listEmployee.length !== 0">
<PersonCard <PersonCard
:list=" :list="
(!!inputSearch ? resultSearchEmployee : listEmployee).map( (!!inputSearch ? resultSearchEmployee ?? [] : listEmployee).map(
(v: Employee) => ({ (v: Employee) => ({
img: v.profileImageUrl, img: v.profileImageUrl,
id: v.id, id: v.id,
@ -1519,7 +1549,6 @@ watch(currentStatus, async () => {
@enter-card="openDialogInputForm" @enter-card="openDialogInputForm"
@delete-card="onDelete" @delete-card="onDelete"
/> />
</div>
<div class="row flex-center q-pt-md"> <div class="row flex-center q-pt-md">
<q-pagination <q-pagination
@ -1531,12 +1560,13 @@ watch(currentStatus, async () => {
gutter="sm" gutter="sm"
/> />
</div> </div>
</div>
</template> </template>
<template <template
v-if=" v-if="
(listCustomer?.length === 0 && selectorLabel === 'EMPLOYER') || (totalCustomer === 0 && selectorLabel === 'EMPLOYER') ||
(listEmployee?.length === 0 && selectorLabel === 'EMPLOYEE') (statsEmployee === 0 && selectorLabel === 'EMPLOYEE')
" "
> >
<TooltipComponent <TooltipComponent