jws-frontend/src/components/03_customer-management/CustomerInfoComponent.vue

222 lines
6 KiB
Vue
Raw Normal View History

2024-06-07 11:58:27 +07:00
<script setup lang="ts">
import { ref } from 'vue';
import AppBox from 'components/app/AppBox.vue';
import BranchCardCustomer from 'components/03_customer-management/BranchCardCustomer.vue';
import { onMounted } from 'vue';
import useCustomerStore from 'src/stores/customer';
import { CustomerBranch, CustomerType } from 'src/stores/customer/types';
2024-06-11 11:23:56 +07:00
import { watch } from 'vue';
const userCustomer = useCustomerStore();
const { fetchListBranch } = userCustomer;
2024-06-07 11:58:27 +07:00
const inputSearch = ref<string>('');
const branch = defineModel<CustomerBranch[]>('branch');
const currentCustomerName = defineModel<string>('currentCustomerName');
2024-06-11 11:23:56 +07:00
const currentCustomerUrlImage = defineModel<string | null>(
'currentCustomerUrlImage',
);
const currentPageBranch = ref<number>(1);
const maxPageBranch = ref<number>(1);
const pageSizeBranch = ref<number>(30);
const prop = withDefaults(
2024-06-07 11:58:27 +07:00
defineProps<{
2024-06-07 14:19:35 +07:00
color?: 'purple' | 'green';
customerId: string;
2024-06-11 11:23:56 +07:00
customerType: CustomerType;
2024-06-07 11:58:27 +07:00
}>(),
{
color: 'green',
},
);
const emit = defineEmits<{
(e: 'back'): void;
2024-06-11 11:23:56 +07:00
(e: 'viewDetail', branch: CustomerBranch[]): void;
(e: 'dialog'): void;
}>();
2024-06-11 11:23:56 +07:00
async function searchBranch() {
const resultList = await fetchListBranch({
query: inputSearch.value,
includeCustomer: true,
});
if (resultList) {
branch.value = resultList.result;
}
}
onMounted(async () => {
2024-06-11 11:23:56 +07:00
const result = await fetchListBranch({
customerId: prop.customerId,
page: 1,
pageSize: pageSizeBranch.value,
});
if (result) {
2024-06-11 11:23:56 +07:00
currentCustomerName.value = 'dasd';
maxPageBranch.value = Math.ceil(result.total / pageSizeBranch.value);
2024-06-11 11:23:56 +07:00
branch.value = result.result;
}
});
watch(currentPageBranch, async () => {
const resultList = await fetchListBranch({
customerId: prop.customerId,
2024-06-11 11:23:56 +07:00
page: currentPageBranch.value,
pageSize: pageSizeBranch.value,
});
if (resultList) {
currentPageBranch.value = resultList.page;
2024-06-11 11:23:56 +07:00
maxPageBranch.value = Math.ceil(resultList.total / pageSizeBranch.value);
branch.value = resultList.result;
}
});
2024-06-07 11:58:27 +07:00
</script>
<template>
<AppBox no-padding bordered>
<div class="row no-wrap justify-between bordered-b surface-2">
2024-06-07 11:58:27 +07:00
<div class="row items-center">
<q-btn
round
icon="mdi-arrow-left"
flat
dense
@click="$emit('back')"
class="q-mr-md"
/>
2024-06-11 11:23:56 +07:00
2024-06-07 11:58:27 +07:00
<q-card-section
2024-06-11 11:23:23 +07:00
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"
2024-06-07 11:58:27 +07:00
>
<q-avatar no-padding size="50px">
2024-06-11 15:15:24 +07:00
<img :src="currentCustomerUrlImage ?? '/no-profile.png'" />
2024-06-07 11:58:27 +07:00
</q-avatar>
</q-card-section>
<div>
<div>{{ currentCustomerName }}</div>
<div class="row items-center">
2024-06-07 11:58:27 +07:00
<i
class="isax isax-frame5"
style="font-size: 1rem; color: var(--stone-6)"
/>
<div class="q-px-sm">
{{ '10' }}
</div>
2024-06-07 11:58:27 +07:00
<q-icon name="mdi-home" size="16px" style="color: var(--stone-6)" />
<div class="q-px-sm">
{{ '2' }}
</div>
2024-06-07 11:58:27 +07:00
</div>
</div>
</div>
<div class="row items-center q-pa-md">
2024-06-07 11:58:27 +07:00
<q-btn
id="btn-add-customer"
dense
unelevated
:label="'+ ' + $t('formDialogTitleCreateSubBranch')"
2024-06-07 11:58:27 +07:00
padding="4px 16px"
@click="$emit('dialog')"
2024-06-07 11:58:27 +07:00
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')"
2024-06-07 11:58:27 +07:00
class="q-mr-lg"
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="inputSearch"
debounce="500"
2024-06-11 11:23:56 +07:00
@update:model-value="searchBranch()"
2024-06-07 11:58:27 +07:00
></q-input>
<q-btn
icon="mdi-tune-vertical-variant"
size="sm"
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
2024-06-07 11:58:27 +07:00
class="bordered rounded"
unelevated
>
<q-menu class="bordered">
<q-list v-close-popup dense>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('all') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('statusACTIVE') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('statusINACTIVE') }}
</q-item>
</q-list>
</q-menu>
</q-btn>
</div>
</div>
2024-06-11 11:23:56 +07:00
<div class="row q-pa-lg q-col-gutter-xl" style="min-height: 350px">
2024-06-07 14:19:35 +07:00
<div v-for="(br, i) in branch" :key="i" class="col-4">
<BranchCardCustomer
:color="customerType"
:badgeField="['status']"
:data="{
customerBranchFormTab: br.branchNo,
branchName: br.name,
address: br.address,
telephone: br.telephoneNo,
businessTypePure: br.bussinessType,
status: 'ดำเนินการอยู่',
totalEmployee: 0,
}"
2024-06-11 11:23:56 +07:00
@view-detail="emit('viewDetail', [br])"
/>
2024-06-07 11:58:27 +07:00
</div>
</div>
2024-06-11 11:23:56 +07:00
<div class="row flex-center q-pb-md">
<q-pagination
v-model="currentPageBranch"
:max="maxPageBranch"
direction-links
gutter="sm"
/>
</div>
2024-06-07 11:58:27 +07:00
</AppBox>
</template>
2024-06-11 11:23:56 +07:00
<style scoped>
.color__purple {
background: hsl(var(--purple-11-hsl));
}
.color__green {
background: hsl(var(--teal-9-hsl));
}
</style>