jws-frontend/src/components/03_customer-management/CustomerInfoComponent.vue
2024-07-03 02:27:18 +00:00

244 lines
6.6 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, watch } from 'vue';
import { Status } from 'src/stores/types';
import useCustomerStore from 'src/stores/customer';
import { CustomerBranch, CustomerType } from 'src/stores/customer/types';
import AppBox from 'components/app/AppBox.vue';
import BranchCardCustomer from 'components/03_customer-management/BranchCardCustomer.vue';
import PaginationComponent from 'src/components/PaginationComponent.vue';
import NoData from 'components/NoData.vue';
const userCustomer = useCustomerStore();
const { fetchListBranch } = userCustomer;
const inputSearch = ref<string>('');
const branch = defineModel<CustomerBranch[]>('branch');
const currentCustomerName = defineModel<string>('currentCustomerName');
const currentCustomerUrlImage = defineModel<string | null>(
'currentCustomerUrlImage',
);
const currentStatus = ref<Status | 'All'>('All');
const totalBranch = ref(0);
const currentPageBranch = ref<number>(1);
const maxPageBranch = ref<number>(1);
const pageSizeBranch = ref<number>(30);
const prop = withDefaults(
defineProps<{
color?: 'purple' | 'green';
customerId: string;
customerType: CustomerType;
}>(),
{
color: 'green',
},
);
const emit = defineEmits<{
(e: 'back'): void;
(e: 'viewDetail', branch: CustomerBranch[]): void;
(e: 'dialog'): void;
}>();
onMounted(async () => {
await fetchList();
});
async function fetchList() {
const result = await fetchListBranch({
customerId: prop.customerId,
query: !!inputSearch.value ? inputSearch.value : undefined,
page: currentPageBranch.value,
pageSize: pageSizeBranch.value,
includeCustomer: true,
status:
currentStatus.value === 'All'
? undefined
: currentStatus.value === 'ACTIVE'
? 'ACTIVE'
: 'INACTIVE',
});
if (result) {
totalBranch.value = result.total;
maxPageBranch.value = Math.ceil(result.total / pageSizeBranch.value);
branch.value = result.result;
}
}
watch(inputSearch, async () => {
await fetchList();
});
watch(currentStatus, async () => {
await fetchList();
});
</script>
<template>
<AppBox no-padding bordered>
<div class="row no-wrap justify-between bordered-b surface-2">
<div class="row items-center">
<q-btn
round
icon="mdi-arrow-left"
flat
dense
@click="$emit('back')"
class="q-mr-md"
/>
<q-card-section
class="q-pa-sm q-pt-md q-mr-md q-mb-sm"
:class="{
color__purple: customerType === 'CORP',
color__green: customerType === 'PERS',
}"
style="border-radius: 0 0 40px 40px; position: relative"
>
<q-avatar no-padding size="50px">
<img :src="currentCustomerUrlImage ?? '/no-profile.png'" />
</q-avatar>
</q-card-section>
<div>
<div>{{ currentCustomerName }}</div>
<div class="row items-center">
<i
class="isax isax-frame5"
style="font-size: 1rem; color: var(--stone-6)"
/>
<div class="q-px-sm">
{{ '10' }}
</div>
<q-icon name="mdi-home" size="16px" style="color: var(--stone-6)" />
<div class="q-px-sm">
{{ '2' }}
</div>
</div>
</div>
</div>
<div class="row items-center q-pa-md">
<q-btn
id="btn-add-customer"
dense
unelevated
:label="'+ ' + $t('formDialogTitleCreateSubBranch')"
padding="4px 16px"
@click="$emit('dialog')"
style="background-color: var(--cyan-6); color: white"
/>
<q-separator vertical inset class="q-mx-lg" />
<q-input
style="width: 250px"
outlined
dense
:label="$t('search')"
class="q-mr-lg"
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="inputSearch"
debounce="500"
></q-input>
<q-btn
icon="mdi-tune-vertical-variant"
size="sm"
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
class="bordered rounded"
unelevated
>
<q-menu class="bordered">
<q-list v-close-popup dense>
<q-item
clickable
class="flex items-center"
@click="currentStatus = 'All'"
>
{{ $t('all') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="currentStatus = 'ACTIVE'"
>
{{ $t('statusACTIVE') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="currentStatus = 'INACTIVE'"
>
{{ $t('statusINACTIVE') }}
</q-item>
</q-list>
</q-menu>
</q-btn>
</div>
</div>
<div
class="row q-pa-lg q-col-gutter-xl"
:class="{ 'justify-center': totalBranch === 0 }"
style="min-height: 350px"
>
<NoData v-if="totalBranch === 0" :not-found="!!inputSearch" />
<div
v-for="(br, i) in branch?.sort((a, b) => a.branchNo - b.branchNo)"
:key="i"
class="col-4"
>
<BranchCardCustomer
:inactive="br.status === 'INACTIVE'"
:color="customerType"
:badgeField="['status']"
:data="{
customerBranchFormTab: br.branchNo,
branchName: br.name,
address: br.address,
telephone: br.telephoneNo,
businessTypePure: br.bussinessType,
status: 'ดำเนินการอยู่',
totalEmployee: br._count?.employee,
}"
@view-detail="emit('viewDetail', [br])"
/>
</div>
</div>
<div class="row justify-between q-pb-md q-px-lg">
<div class="app-text-muted">
{{
$t('recordsPage', {
resultcurrentPage: branch?.length,
total: totalBranch,
})
}}
</div>
<PaginationComponent
v-model:current-page="currentPageBranch"
v-model:max-page="maxPageBranch"
:fetch-data="
async () => {
await fetchList();
flowStore.rotate();
}
"
/>
</div>
</AppBox>
</template>
<style scoped>
.color__purple {
background: hsl(var(--purple-11-hsl));
}
.color__green {
background: hsl(var(--teal-9-hsl));
}
</style>