refactor: ปรับ layout ของ branch

This commit is contained in:
Net 2024-07-04 17:56:37 +07:00
parent aefb42717d
commit 7efdc066e8

View file

@ -2,6 +2,8 @@
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { ref, onMounted, computed } from 'vue'; import { ref, onMounted, computed } from 'vue';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
import { BranchContact } from 'src/stores/branch-contact/types';
import type { QTableProps } from 'quasar';
import useBranchStore from 'stores/branch'; import useBranchStore from 'stores/branch';
@ -28,6 +30,37 @@ import useFlowStore from 'src/stores/flow';
const { t } = useI18n(); const { t } = useI18n();
const utilsStore = useUtilsStore(); const utilsStore = useUtilsStore();
const labelBtnStatus = ref<string>(t('all'));
const columns = [
{
name: 'name',
align: 'left',
label: 'office',
field: 'name',
sortable: true,
},
{
name: 'address',
align: 'left',
label: 'address',
field: 'address',
sortable: true,
},
{
name: 'telephoneNo',
align: 'left',
label: 'formDialogTelephone',
field: 'telephoneNo',
},
{
name: 'isHeadOffice',
align: 'left',
label: 'type',
field: 'isHeadOffice',
},
] satisfies QTableProps['columns'];
const modal = ref<boolean>(false); const modal = ref<boolean>(false);
const profileFileImg = ref<File | undefined>(undefined); const profileFileImg = ref<File | undefined>(undefined);
@ -152,6 +185,10 @@ const stats = ref<
{ icon: string; count: number; label: string; color: 'pink' | 'purple' }[] { icon: string; count: number; label: string; color: 'pink' | 'purple' }[]
>([]); >([]);
const modeView = ref<boolean>(false);
const splitterModel = ref(25);
const defaultFormData = { const defaultFormData = {
headOfficeId: null, headOfficeId: null,
taxNo: '', taxNo: '',
@ -442,7 +479,7 @@ watch(locale, () => {
/> />
<div <div
class="column col surface-1 bordered rounded scroll" class="column col surface-1 rounded scroll"
:no-padding="!!branchData.total" :no-padding="!!branchData.total"
> >
<template v-if="!branchData.total"> <template v-if="!branchData.total">
@ -462,60 +499,20 @@ watch(locale, () => {
</template> </template>
<template v-else> <template v-else>
<div class="row" style="flex-grow: 1; flex-wrap: nowrap"> <div class="row" style="flex-grow: 1; flex-wrap: nowrap">
<div class="tree-container q-pa-md bordered-r surface-2"> <q-splitter
<div class="row"> v-model="splitterModel"
<button :limits="[25, 80]"
style="border: none; background: transparent" style="width: 100%"
:class="{ 'cursor-pointer': !!currentHq.id }"
id="br-prev"
> >
<Icon <template v-slot:before>
icon="ep:arrow-left-bold" <div class="rounded surface-1 full-height">
width="21px" <div
:class="{ 'app-text-muted': !currentHq.id }" class="row bordered-b q-pl-sm text-weight-bold surface-2"
@click=" style="height: 50px; display: flex; align-items: center"
() => {
if (currentHq.id) {
beforeBranch = currentHq;
currentHq = { id: '', code: '' };
fieldSelectedBranch = {
label: $t('branchHQLabel'),
value: 'branchHQLabel',
};
}
}
"
/>
</button>
<button
style="border: none; background: transparent; padding: 0"
:class="{ 'cursor-pointer': !!beforeBranch.id }"
id="br-next"
> >
<Icon <div class="col">ดการสาขาทงหมด</div>
icon="ep:arrow-right-bold"
width="21px"
:class="{
'app-text-muted': !beforeBranch.id,
}"
@click="
() => {
if (beforeBranch.id) {
currentHq = beforeBranch;
beforeBranch = { id: '', code: '' };
fieldSelectedBranch = {
label: '',
value: '',
};
}
}
"
/>
</button>
<q-space />
<div>
<button <button
id="hq-add-btn" id="hq-add-btn"
style="border: none; background: transparent" style="border: none; background: transparent"
@ -523,7 +520,7 @@ watch(locale, () => {
<Icon <Icon
icon="pixelarticons:plus" icon="pixelarticons:plus"
height="26" height="26"
class="color-icon-plus cursor-pointer" class="cursor-pointer"
@click=" @click="
() => { () => {
if (!currentHq.id) { if (!currentHq.id) {
@ -540,14 +537,6 @@ watch(locale, () => {
/> />
</button> </button>
</div> </div>
<div class="bordered rounded q-mt-sm surface-1">
<div
class="bordered-b q-pl-sm text-weight-bold surface-3"
style="height: 50px; display: flex; align-items: center"
>
<Icon icon="flowbite:home-solid" width="24px" class="q-mr-md" />
{{ $t('all') }}
</div> </div>
<q-tree <q-tree
@ -683,7 +672,8 @@ watch(locale, () => {
" "
@click=" @click="
async () => { async () => {
const res = await branchStore.editById( const res =
await branchStore.editById(
node.id, node.id,
{ {
status: status:
@ -711,31 +701,91 @@ watch(locale, () => {
</template> </template>
</q-tree> </q-tree>
</div> </div>
</div> </template>
<div class="branch-wrapper q-pa-md">
<div class="q-mb-md flex" style="gap: var(--size-4)"> <template v-slot:after>
<div class="full-width">
<div <div
style=" class="row justify-between q-pl-md items-center surface-2 bordered-b q-pr-md"
flex-grow: 1; style="height: 50px"
display: flex; >
align-items: stretch; <div class="col-6">
gap: var(--size-2); <q-input
bg-color="white"
for="input-Search"
style="width: 250px"
outlined
dense
label="ค้นหา"
v-model="inputSearch"
debounce="500"
></q-input>
</div>
<div class="col-6 row q-gutter-x-sm justify-end text-right">
<q-btn-dropdown
class="bordered rounded"
color="white"
text-color="grey-10"
dense
unelevated
:label="labelBtnStatus"
>
<q-list>
<q-item
clickable
v-close-popup
@click="
async () => {
labelBtnStatus = $t('all');
statusFilter = 'all';
}
" "
> >
<template v-if="!currentHq.id"> <q-item-section>
<q-select <q-item-label>{{ $t('all') }}</q-item-label>
id="select-branch" </q-item-section>
for="select-branch" </q-item>
v-model="fieldSelectedBranch"
style="min-width: 120px" <q-item
outlined clickable
:options=" v-close-popup
fieldBranch.map((v) => ({ label: $t(v), value: v })) @click="
async () => {
labelBtnStatus = $t('statusACTIVE');
statusFilter = 'statusACTIVE';
}
" "
:label="$t('select')" >
dense <q-item-section>
/> <q-item-label>
{{ $t('statusACTIVE') }}
</q-item-label>
</q-item-section>
</q-item>
<q-item
clickable
v-close-popup
@click="
async () => {
labelBtnStatus = $t('statusINACTIVE');
statusFilter = 'statusINACTIVE';
}
"
>
<q-item-section>
<q-item-label>
{{ $t('statusINACTIVE') }}
</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-btn-dropdown>
<q-btn <q-btn
color="white"
text-color="grey-10"
id="btn-filter" id="btn-filter"
icon="mdi-tune-vertical-variant" icon="mdi-tune-vertical-variant"
size="sm" size="sm"
@ -749,7 +799,9 @@ watch(locale, () => {
id="btn-filter-all" id="btn-filter-all"
clickable clickable
class="flex items-center" class="flex items-center"
:class="{ 'app-text-info': statusFilter === 'all' }" :class="{
'app-text-info': statusFilter === 'all',
}"
@click="statusFilter = 'all'" @click="statusFilter = 'all'"
> >
{{ $t('all') }} {{ $t('all') }}
@ -770,7 +822,8 @@ watch(locale, () => {
clickable clickable
class="flex items-center" class="flex items-center"
:class="{ :class="{
'app-text-info': statusFilter === 'statusINACTIVE', 'app-text-info':
statusFilter === 'statusINACTIVE',
}" }"
@click="statusFilter = 'statusINACTIVE'" @click="statusFilter = 'statusINACTIVE'"
> >
@ -779,48 +832,202 @@ watch(locale, () => {
</q-list> </q-list>
</q-menu> </q-menu>
</q-btn> </q-btn>
</template>
<div v-else class="text-weight-bold text">
{{ $t('branchInHQ') }}
{{ currentHq.code }}
</div>
</div>
<div <q-btn-toggle
style="flex-grow: 1; display: flex; justify-content: flex-end" v-model="modeView"
id="btn-mode"
dense
class="no-shadow"
toggle-color="white"
size="xs"
:options="[
{ value: true, slot: 'folder' },
{ value: false, slot: 'list' },
]"
> >
<q-input <template v-slot:folder>
for="input-Search" <q-icon
style="width: 250px" name="mdi-view-grid-outline"
outlined size="16px"
dense class="q-px-sm q-py-xs rounded"
label="ค้นหา" :style="{
v-model="inputSearch" color: modeView ? '#787B7C' : '#C9D3DB',
debounce="500" }"
></q-input> />
</template>
<template v-slot:list>
<q-icon
name="mdi-format-list-bulleted"
class="q-px-sm q-py-xs rounded"
size="16px"
:style="{
color: modeView === false ? '#787B7C' : '#C9D3DB',
}"
/>
</template>
</q-btn-toggle>
</div> </div>
</div>
<div class="q-pa-md">
<q-table
flat
bordered
:rows="treeData"
:columns="columns"
:grid="modeView"
card-container-class="row q-col-gutter-md"
row-key="name"
hide-pagination
>
<template v-slot:header="props">
<q-tr class="surface-2" :props="props">
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
>
{{ $t(col.label) }}
</q-th>
<q-th auto-width />
</q-tr>
</template>
<div style="flex-grow: 1"> <template v-slot:body="props">
<q-select <q-tr
id="select-field" :class="{
for="select-field" 'app-text-muted': props.row.status === 'INACTIVE',
:options=" }"
fieldDisplay.map((v) => ({ label: $t(v), value: v })) :props="props"
>
<q-td>
<div class="row items-center">
<div
:class="{
'status-active':
props.row.status !== 'INACTIVE',
'status-inactive':
props.row.status === 'INACTIVE',
'branch-card__hq': props.row.isHeadOffice,
'branch-card__br': !props.row.isHeadOffice,
}"
style="
width: 50px;
display: flex;
margin-bottom: var(--size-2);
" "
:display-value="$t('displayField')" >
v-model="fieldSelected" <div class="branch-card__icon">
option-label="label" <q-icon
option-value="value" size="md"
map-options style="scale: 0.8"
emit-value name="mdi-office-building-outline"
outlined
multiple
dense
/> />
</div> </div>
</div> </div>
<div class="branch-container"> <div class="col">
<div class="col">{{ props.row.name }}</div>
<div class="col app-text-muted">
{{ props.row.code }}
</div>
</div>
</div>
</q-td>
<q-td>
{{ props.row.address }}
</q-td>
<q-td>
{{ props.row.contact[0].telephoneNo }}
</q-td>
<q-td>
{{
props.row.isHeadOffice
? $t('branchHQLabel')
: $t('branchLabel')
}}
</q-td>
<q-td>
<q-btn
icon="mdi-eye"
size="sm"
dense
round
flat
@click.stop
/>
<q-btn
icon="mdi-dots-vertical"
size="sm"
dense
round
flat
@click.stop
/>
</q-td>
</q-tr>
</template>
<template v-slot:item="props">
<div class="col-6">
<BranchCard <BranchCard
:id="`branch-card-${props.row.name}`"
@click="
() => {
if (props.row.isHeadOffice) {
fieldSelectedBranch.value = '';
inputSearch = '';
currentHq = {
id: props.row.id,
code: props.row.code,
};
beforeBranch = {
id: '',
code: '',
};
}
}
"
:metadata="props.row"
:color="props.row.isHeadOffice ? 'hq' : 'br'"
:key="props.row.id"
:data="{
branchLabelCode: props.row.code,
branchLabelName:
$i18n.locale === 'en-US'
? props.row.nameEN
: props.row.name,
branchLabelTel: props.row.contact
.map((c: BranchContact) => c.telephoneNo)
.join(','),
branchLabelAddress:
$i18n.locale === 'en-US'
? `${props.row.addressEN || ''} ${props.row.subDistrict?.nameEN || ''} ${props.row.district?.nameEN || ''} ${props.row.province?.nameEN || ''}`
: `${props.row.address || ''} ${props.row.subDistrict?.name || ''} ${props.row.district?.name || ''} ${props.row.province?.name || ''}`,
branchLabelType: $t(
props.row.isHeadOffice
? 'branchHQLabel'
: 'branchLabel',
),
}"
:field-selected="fieldSelected"
:badge-field="['branchLabelStatus']"
:inactive="props.row.status === 'INACTIVE'"
@view-detail="
(v) => {
triggerEdit(
'drawer',
v.id,
v.isHeadOffice ? 'headOffice' : 'subBranch',
v.code,
);
}
"
/>
</div>
</template>
</q-table>
<!-- <BranchCard
class="col-6"
:id="`branch-card-${item.name}`" :id="`branch-card-${item.name}`"
v-for="item in treeData v-for="item in treeData
.flatMap((v) => [v, ...v.branch]) .flatMap((v) => [v, ...v.branch])
@ -900,9 +1107,70 @@ watch(locale, () => {
); );
} }
" "
/> -->
</div>
</div>
</template>
</q-splitter>
<!-- <div class="tree-container bordered-r surface-2">
<div class="row">
<button
style="border: none; background: transparent"
:class="{ 'cursor-pointer': !!currentHq.id }"
id="br-prev"
>
<Icon
icon="ep:arrow-left-bold"
width="21px"
:class="{ 'app-text-muted': !currentHq.id }"
@click="
() => {
if (currentHq.id) {
beforeBranch = currentHq;
currentHq = { id: '', code: '' };
fieldSelectedBranch = {
label: $t('branchHQLabel'),
value: 'branchHQLabel',
};
}
}
"
/> />
</button>
<button
style="border: none; background: transparent; padding: 0"
:class="{ 'cursor-pointer': !!beforeBranch.id }"
id="br-next"
>
<Icon
icon="ep:arrow-right-bold"
width="21px"
:class="{
'app-text-muted': !beforeBranch.id,
}"
@click="
() => {
if (beforeBranch.id) {
currentHq = beforeBranch;
beforeBranch = { id: '', code: '' };
fieldSelectedBranch = {
label: '',
value: '',
};
}
}
"
/>
</button>
<q-space />
</div> </div>
</div> </div> -->
<!-- ssssssssssssssssssss -->
<!-- ---- -->
</div> </div>
</template> </template>
</div> </div>
@ -1126,4 +1394,54 @@ watch(locale, () => {
gap: var(--size-4); gap: var(--size-4);
} }
} }
.branch-card__hq {
--_branch-card-bg: var(--pink-6-hsl);
}
.branch-card__br {
--_branch-card-bg: var(--violet-11-hsl);
&.branch-card__dark {
--_branch-card-bg: var(--violet-10-hsl);
}
}
.status-active {
--_branch-status-color: var(--green-6-hsl);
}
.status-inactive {
--_branch-status-color: var(--red-4-hsl);
--_branch-badge-bg: var(--red-4-hsl);
filter: grayscale(1);
background-color: hsl(var(--gray-6-hsl) / 0.1);
opacity: 0.5;
}
.branch-card__icon {
background-color: hsla(var(--_branch-card-bg) / 0.15);
border-radius: 50%;
padding: var(--size-1);
position: relative;
transform: rotate(45deg);
&::after {
content: ' ';
display: block;
block-size: 0.5rem;
aspect-ratio: 1;
position: absolute;
border-radius: 50%;
right: -0.25rem;
top: calc(50% - 0.25rem);
bottom: calc(50% - 0.25rem);
background-color: hsla(var(--_branch-status-color) / 1);
}
& :deep(.q-icon) {
transform: rotate(-45deg);
color: hsla(var(--_branch-card-bg) / 1);
}
}
</style> </style>