2024-04-02 17:47:32 +07:00
|
|
|
<script setup lang="ts">
|
2024-04-09 16:47:52 +07:00
|
|
|
import { storeToRefs } from 'pinia';
|
2024-04-16 18:33:41 +07:00
|
|
|
import { ref, onMounted, computed } from 'vue';
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-05 18:14:53 +07:00
|
|
|
import useBranchStore from 'stores/branch';
|
2024-04-16 18:33:41 +07:00
|
|
|
|
2024-04-02 17:47:32 +07:00
|
|
|
import AppBox from 'components/app/AppBox.vue';
|
2024-04-10 20:26:32 +07:00
|
|
|
import AddButton from 'components/AddButton.vue';
|
2024-04-05 18:14:53 +07:00
|
|
|
import TooltipComponent from 'components/TooltipComponent.vue';
|
2024-04-16 18:33:41 +07:00
|
|
|
import StatCard from 'components/StatCardComponent.vue';
|
2024-04-10 16:02:28 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
import { BranchContactCreate } from 'stores/branch-contact/types';
|
|
|
|
|
import { BranchWithChildren, BranchCreate } from 'stores/branch/types';
|
|
|
|
|
import { watch } from 'vue';
|
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
import BranchCard from 'src/components/01_branch-management/BranchCard.vue';
|
2024-04-09 15:54:47 +07:00
|
|
|
|
2024-04-10 18:49:41 +07:00
|
|
|
const profileFile = ref<File | undefined>(undefined);
|
|
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
const inputFile = (() => {
|
|
|
|
|
const element = document.createElement('input');
|
|
|
|
|
element.type = 'file';
|
|
|
|
|
element.accept = 'image/*';
|
|
|
|
|
|
|
|
|
|
element.addEventListener('change', () => {
|
|
|
|
|
profileFile.value = element.files?.[0];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return element;
|
|
|
|
|
})();
|
2024-04-10 18:49:41 +07:00
|
|
|
|
2024-04-09 15:54:47 +07:00
|
|
|
const branchStore = useBranchStore();
|
2024-04-16 18:33:41 +07:00
|
|
|
const { locale } = useI18n();
|
2024-04-10 16:02:28 +07:00
|
|
|
|
2024-04-09 16:47:52 +07:00
|
|
|
const { data: branchData } = storeToRefs(branchStore);
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
const treeData = computed(() => {
|
|
|
|
|
const arr: BranchWithChildren[] = [];
|
2024-04-09 15:54:47 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
branchData.value?.result.forEach((a) => {
|
|
|
|
|
if (a.isHeadOffice) arr.push(Object.assign(a, { branch: [] }));
|
|
|
|
|
else arr.find((b) => b.id === a.headOfficeId)?.branch.push(a);
|
|
|
|
|
});
|
2024-04-09 15:54:47 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
return arr;
|
|
|
|
|
});
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
onMounted(async () => {
|
|
|
|
|
await branchStore.fetchList({ pageSize: 99999 });
|
|
|
|
|
const _stats = await branchStore.stats();
|
|
|
|
|
|
|
|
|
|
if (_stats) {
|
|
|
|
|
stats.value.push(
|
|
|
|
|
{ count: _stats.hq, label: 'branchHQLabel' },
|
|
|
|
|
{ count: _stats.br, label: 'branchLabel' },
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
watch(locale, () => {
|
|
|
|
|
console.log(locale.value);
|
2024-04-10 16:02:28 +07:00
|
|
|
});
|
|
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
const fieldDisplay = ref([
|
|
|
|
|
'branchLabelName',
|
|
|
|
|
'branchLabelTel',
|
|
|
|
|
'branchLabelAddress',
|
|
|
|
|
'branchLabelType',
|
|
|
|
|
'branchLabelStatus',
|
|
|
|
|
]);
|
|
|
|
|
const fieldSelected = ref<string[]>(fieldDisplay.value);
|
|
|
|
|
const stats = ref<{ count: number; label: string }[]>([]);
|
|
|
|
|
|
|
|
|
|
const defaultFormData = {
|
|
|
|
|
headOfficeId: null,
|
2024-04-10 16:02:28 +07:00
|
|
|
taxNo: '',
|
|
|
|
|
nameEN: '',
|
|
|
|
|
name: '',
|
|
|
|
|
addressEN: '',
|
|
|
|
|
address: '',
|
|
|
|
|
zipCode: '',
|
2024-04-09 15:55:15 +07:00
|
|
|
email: '',
|
2024-04-10 16:02:28 +07:00
|
|
|
telephoneNo: '',
|
|
|
|
|
longitude: '',
|
|
|
|
|
latitude: '',
|
|
|
|
|
subDistrictId: '',
|
|
|
|
|
districtId: '',
|
|
|
|
|
provinceId: '',
|
2024-04-16 18:33:41 +07:00
|
|
|
contact: [{ lineId: '', telephoneNo: '' }],
|
|
|
|
|
};
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
const formData = ref<BranchCreate & { contact: BranchContactCreate[] }>(
|
|
|
|
|
structuredClone(defaultFormData),
|
|
|
|
|
);
|
2024-04-10 09:46:30 +07:00
|
|
|
|
2024-04-10 16:02:28 +07:00
|
|
|
function clearData() {
|
2024-04-16 18:33:41 +07:00
|
|
|
formData.value = structuredClone(defaultFormData);
|
2024-04-10 18:49:41 +07:00
|
|
|
profileFile.value = undefined;
|
2024-04-10 16:02:28 +07:00
|
|
|
}
|
2024-04-02 17:47:32 +07:00
|
|
|
</script>
|
2024-04-16 18:33:41 +07:00
|
|
|
|
2024-04-02 17:47:32 +07:00
|
|
|
<template>
|
|
|
|
|
<div class="column">
|
2024-04-03 14:55:37 +07:00
|
|
|
<div class="row text-h6 text-weight-bold q-mb-md">
|
|
|
|
|
{{ $t('branchManagement') }}
|
|
|
|
|
</div>
|
2024-04-02 17:47:32 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
<AppBox bordered class="q-mb-md">
|
|
|
|
|
<StatCard :branch="stats" :dark="$q.dark.isActive" />
|
2024-04-09 16:47:52 +07:00
|
|
|
</AppBox>
|
2024-04-03 15:23:59 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
<AppBox class="column" no-padding bordered style="min-height: 70vh">
|
|
|
|
|
<template v-if="!branchData.total">
|
2024-04-11 18:09:27 +07:00
|
|
|
<TooltipComponent
|
2024-04-16 18:33:41 +07:00
|
|
|
class="self-end"
|
2024-04-11 18:09:27 +07:00
|
|
|
title="branchNoMainOfficeYet"
|
|
|
|
|
caption="branchClickToCreateMainOffice"
|
2024-04-16 18:33:41 +07:00
|
|
|
imgSrc="personnel-table-"
|
2024-04-11 18:09:27 +07:00
|
|
|
/>
|
2024-04-11 14:41:29 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
<div class="row items-center justify-center" style="flex-grow: 1">
|
|
|
|
|
<AddButton label="branchAdd" @trigger="() => {}" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<div
|
|
|
|
|
class="row bordered-b q-pa-md"
|
|
|
|
|
:style="{
|
|
|
|
|
color: 'var(--brand-1)',
|
|
|
|
|
backgroundColor: 'hsla(var(--info-bg) / .1)',
|
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
<div class="text-h5"><q-icon name="mdi-home"></q-icon></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="row" style="flex-grow: 1; flex-wrap: nowrap">
|
|
|
|
|
<div class="tree-container q-pa-md bordered-r">
|
|
|
|
|
<q-tree
|
|
|
|
|
:nodes="treeData"
|
|
|
|
|
node-key="id"
|
|
|
|
|
label-key="name"
|
|
|
|
|
children-key="branch"
|
2024-04-05 18:00:30 +07:00
|
|
|
>
|
2024-04-16 18:33:41 +07:00
|
|
|
<template #default-header="{ node }">
|
|
|
|
|
<div class="row items-center justify-between full-width">
|
|
|
|
|
<span>{{ node.name }}</span>
|
|
|
|
|
<div class="q-gutter-xs" @click.stop>
|
|
|
|
|
<q-btn icon="mdi-file-plus-outline" fab-mini unelevated />
|
|
|
|
|
<q-btn icon="mdi-dots-vertical" fab-mini unelevated />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-05 18:00:30 +07:00
|
|
|
</template>
|
2024-04-16 18:33:41 +07:00
|
|
|
</q-tree>
|
2024-04-05 18:00:30 +07:00
|
|
|
</div>
|
2024-04-16 18:33:41 +07:00
|
|
|
<div class="branch-wrapper q-pa-md">
|
|
|
|
|
<div class="q-mb-md flex" style="gap: var(--size-4)">
|
|
|
|
|
<div style="flex-grow: 1">
|
2024-04-05 18:00:30 +07:00
|
|
|
<q-select
|
2024-04-16 18:33:41 +07:00
|
|
|
:options="
|
|
|
|
|
fieldDisplay.map((v) => ({ label: $t(v), value: v }))
|
|
|
|
|
"
|
|
|
|
|
v-model="fieldSelected"
|
|
|
|
|
option-label="label"
|
|
|
|
|
option-value="value"
|
|
|
|
|
map-options
|
|
|
|
|
emit-value
|
2024-04-05 18:00:30 +07:00
|
|
|
outlined
|
2024-04-16 18:33:41 +07:00
|
|
|
multiple
|
|
|
|
|
dense
|
2024-04-05 18:00:30 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
2024-04-16 18:33:41 +07:00
|
|
|
<div style="flex-grow: 1">
|
2024-04-05 18:00:30 +07:00
|
|
|
<q-select
|
2024-04-16 18:33:41 +07:00
|
|
|
:options="
|
|
|
|
|
fieldDisplay.map((v) => ({ label: $t(v), value: v }))
|
|
|
|
|
"
|
|
|
|
|
v-model="fieldSelected"
|
|
|
|
|
option-label="label"
|
|
|
|
|
option-value="value"
|
|
|
|
|
map-options
|
|
|
|
|
emit-value
|
2024-04-05 18:00:30 +07:00
|
|
|
outlined
|
2024-04-16 18:33:41 +07:00
|
|
|
multiple
|
|
|
|
|
dense
|
2024-04-05 18:00:30 +07:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-16 18:33:41 +07:00
|
|
|
<div class="branch-container">
|
|
|
|
|
<BranchCard
|
|
|
|
|
v-for="item in branchData.result.map((v) => ({
|
|
|
|
|
id: v.id,
|
|
|
|
|
hq: v.isHeadOffice,
|
|
|
|
|
branchLabelCode: v.code,
|
|
|
|
|
branchLabelName: $i18n.locale === 'en-US' ? v.nameEN : v.name,
|
|
|
|
|
branchLabelTel: v.telephoneNo,
|
|
|
|
|
branchLabelAddress:
|
|
|
|
|
$i18n.locale === 'en-US'
|
|
|
|
|
? `${v.addressEN || ''} ${v.subDistrict?.nameEN || ''} ${v.district?.nameEN || ''} ${v.province?.nameEN || ''}`
|
|
|
|
|
: `${v.address || ''} ${v.subDistrict?.name || ''} ${v.district?.name || ''} ${v.province?.name || ''}`,
|
|
|
|
|
branchLabelType: $t(
|
|
|
|
|
v.isHeadOffice ? 'branchHQLabel' : 'branchLabel',
|
|
|
|
|
),
|
|
|
|
|
branchLabelStatus: v.status,
|
|
|
|
|
}))"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:data="item"
|
|
|
|
|
:field-selected="fieldSelected"
|
|
|
|
|
@view-detail="(b) => console.log(b)"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-05 18:00:30 +07:00
|
|
|
</div>
|
2024-04-16 18:33:41 +07:00
|
|
|
</template>
|
2024-04-09 16:47:52 +07:00
|
|
|
</AppBox>
|
2024-04-02 17:47:32 +07:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-04-05 18:00:30 +07:00
|
|
|
<style scoped>
|
2024-04-16 18:33:41 +07:00
|
|
|
.tree-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
min-width: 300px;
|
|
|
|
|
max-width: 25%;
|
|
|
|
|
max-height: 100%;
|
2024-04-05 18:00:30 +07:00
|
|
|
}
|
|
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
.branch-wrapper {
|
|
|
|
|
flex-grow: 1;
|
2024-04-05 18:00:30 +07:00
|
|
|
|
2024-04-16 18:33:41 +07:00
|
|
|
& > .branch-container {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(2, 1fr);
|
|
|
|
|
grid-template-rows: unset;
|
|
|
|
|
gap: var(--size-4);
|
2024-04-05 18:00:30 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|