refactor: overhaul branch management

This commit is contained in:
Methapon2001 2024-04-09 16:47:52 +07:00
parent 2d13a80988
commit 65781eb480

View file

@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { storeToRefs } from 'pinia';
import { ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
@ -14,11 +15,11 @@ import FormDialog from 'src/components/FormDialog.vue';
import { BranchWithChildren, Branch } from 'src/stores/branch/types'; import { BranchWithChildren, Branch } from 'src/stores/branch/types';
const branchStore = useBranchStore(); const branchStore = useBranchStore();
const test = ref<string>(''); const { data: branchData } = storeToRefs(branchStore);
const modal = ref<boolean>(false); const modal = ref<boolean>(false);
const showCurrentBaranch = ref<Branch | boolean | null>(); const showCurrentBranch = ref<Branch | boolean | null>();
const shape = ref<boolean>(false); const shape = ref<boolean>(false);
const openBranchDrawer = ref<boolean>(true); const openBranchDrawer = ref<boolean>(true);
@ -66,7 +67,7 @@ const taxIDNumber = ref<string>('');
const nameHeadOfficeEN = ref<string>(''); const nameHeadOfficeEN = ref<string>('');
const inputPhone = ref<string>(''); const inputPhone = ref<string>('');
const inputIdLine = ref<string>(''); const inputIdLine = ref<string>('');
const inputPhonHeadOffice = ref<string>(''); const inputPhoneHeadOffice = ref<string>('');
const inputEmailHeadOffice = ref<string>(''); const inputEmailHeadOffice = ref<string>('');
const expanded = ref<string[]>([]); const expanded = ref<string[]>([]);
@ -142,8 +143,6 @@ const branchStat = ref<
const treeData = ref<BranchWithChildren[]>([]); const treeData = ref<BranchWithChildren[]>([]);
function openDialog() { function openDialog() {
console.log('openDialog');
modal.value = true; modal.value = true;
} }
@ -151,26 +150,23 @@ async function getTree() {
const result = await branchStore.fetchList<BranchWithChildren>({ const result = await branchStore.fetchList<BranchWithChildren>({
tree: true, tree: true,
}); });
if (result) treeData.value = result.result;
if (result) {
treeData.value = result.result;
}
} }
async function fetchBranch(id: string) { async function fetchBranch(id: string) {
if (typeof branchStore.fetchById(id) === 'object') { if (typeof branchStore.fetchById(id) === 'object') {
showCurrentBaranch.value = await branchStore.fetchById(id); showCurrentBranch.value = await branchStore.fetchById(id);
} }
} }
onMounted(async () => { onMounted(async () => {
getTree(); await getTree();
if ( if (
typeof branchStore.fetchById('bfff119e-079d-4b56-9699-0466ade4b517') === typeof branchStore.fetchById('bfff119e-079d-4b56-9699-0466ade4b517') ===
'object' 'object'
) { ) {
showCurrentBaranch.value = await branchStore.fetchById( showCurrentBranch.value = await branchStore.fetchById(
'bfff119e-079d-4b56-9699-0466ade4b517', 'bfff119e-079d-4b56-9699-0466ade4b517',
); );
} }
@ -182,44 +178,42 @@ onMounted(async () => {
{{ $t('branchManagement') }} {{ $t('branchManagement') }}
</div> </div>
<app-box <AppBox
bordered bordered
class="q-mb-md" class="q-mb-md"
:class="{ 'bg-card-branch-title': $q.dark.isActive }" :class="{ 'bg-card-branch-title': $q.dark.isActive }"
> >
<StatCardComponent :branch="branchStat" /> <StatCardComponent :branch="branchStat" />
</app-box> </AppBox>
<app-box bordered style="width: 100%; height: 500px"> <AppBox
bordered
style="width: 100%; height: 500px"
v-if="!branchData?.total"
>
<div class="column" style="height: 100%"> <div class="column" style="height: 100%">
<div class="col-1 self-end"> <div class="col-1 self-end">
<div class="row"> <TooltipComponent
<TooltipComponent title="branchNoMainOfficeYet"
title="branchNoMainOfficeYet" caption="branchClickToCreateMainOffice"
caption="branchClickToCreateMainOffice" imgSrc="img-table-"
imgSrc="img-table-" />
/>
</div>
</div> </div>
<div class="col self-center" style="display: flex; align-items: center">
<div
class="col test self-center"
style="display: flex; align-items: center"
>
<BtnAddComponent <BtnAddComponent
:label="'สร้างสำนักงานใหญ่'" :label="'สร้างสำนักงานใหญ่'"
@trigger="() => openDialog()" @trigger="() => openDialog()"
/> />
</div> </div>
</div> </div>
</app-box> </AppBox>
<q-card <AppBox
class="bordered branch-main-variable-color" class="bordered branch-main-variable-color"
:class="{ dark: $q.dark.isActive }" :class="{ dark: $q.dark.isActive }"
style="width: 100%; height: 500px" style="width: 100%; height: 500px; padding: 0"
> >
<q-card-section class="bordered bg-card-branch-title"> <AppBox class="bg-card-branch-title" style="border-radius: 0">
<div class="row items-center"> <div class="row items-center">
<div <div
class="col q-pl-md text-h6 text-weight-bold color-card-branch-title" class="col q-pl-md text-h6 text-weight-bold color-card-branch-title"
@ -228,11 +222,10 @@ onMounted(async () => {
</div> </div>
<div class="col-3"> <div class="col-3">
<q-input <q-input
style="border-radius: 6px" class="bordered rounded q-px-md"
class="bordered" borderless
outlined
dense dense
v-model="test" v-model="inputSearch"
label="ค้นหา" label="ค้นหา"
> >
<template #prepend> <template #prepend>
@ -241,10 +234,13 @@ onMounted(async () => {
</q-input> </q-input>
</div> </div>
</div> </div>
</q-card-section> </AppBox>
<q-card-section class="no-padding row" style="height: 423px"> <AppBox
<div class="bordered q-pa-md bg-branch-tree-box" style="width: 21%"> class="no-padding row bordered-t"
style="height: 423px; border-radius: 0"
>
<div class="q-pa-md bg-branch-tree-box bordered-r" style="width: 21%">
<div <div
@click="() => console.log('test')" @click="() => console.log('test')"
class="btn-add col-2 text-weight-bold cursor-pointer color-card-branch-btn" class="btn-add col-2 text-weight-bold cursor-pointer color-card-branch-btn"
@ -254,7 +250,7 @@ onMounted(async () => {
</div> </div>
<q-scroll-area <q-scroll-area
class="bordered q-pa-sm bg-branch-tree-scroll" class="q-pa-sm bg-branch-tree-scroll"
style="height: 350px; width: 100%; border-radius: 6px" style="height: 350px; width: 100%; border-radius: 6px"
> >
<div class="col"> <div class="col">
@ -365,8 +361,8 @@ onMounted(async () => {
</q-scroll-area> </q-scroll-area>
</div> </div>
<div class="col bordered full-height" style="overflow-y: auto"> <div class="col full-height" style="overflow-y: auto">
<q-card-section class="q-pb-none"> <AppBox class="q-pb-none">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<q-select <q-select
@ -380,8 +376,8 @@ onMounted(async () => {
</div> </div>
<div class="col-2 q-pr-md"> <div class="col-2 q-pr-md">
<q-input dense outlined v-model="inputSearch"> <q-input dense outlined v-model="inputSearch">
<template v-slot:append> <template #append>
<iconify-icon icon="ic:baseline-search" /> <Icon icon="ic:baseline-search" />
</template> </template>
</q-input> </q-input>
</div> </div>
@ -395,11 +391,11 @@ onMounted(async () => {
/> />
</div> </div>
</div> </div>
</q-card-section> </AppBox>
<q-card-section> <AppBox>
<TableCardComponent :subBranch="true" :rows="rows" /> <TableCardComponent :subBranch="true" :rows="rows" />
</q-card-section> </AppBox>
</div> </div>
<div <div
@ -408,18 +404,18 @@ onMounted(async () => {
style="overflow-y: auto" style="overflow-y: auto"
> >
<CardDetailsComponent <CardDetailsComponent
:data="showCurrentBaranch as Branch" :data="showCurrentBranch as Branch"
class="q-pa-sm" class="q-pa-sm"
/> />
</div> </div>
</q-card-section> </AppBox>
</q-card> </AppBox>
</div> </div>
<DeatailsBranchDrawerComponent <DeatailsBranchDrawerComponent
@open="openBranchDrawer = !openBranchDrawer" @open="openBranchDrawer = !openBranchDrawer"
:open="openBranchDrawer" :open="openBranchDrawer"
:data="showCurrentBaranch as Branch" :data="showCurrentBranch as Branch"
/> />
<FormDialog <FormDialog
@ -525,12 +521,12 @@ onMounted(async () => {
</AppBox> </AppBox>
</template> </template>
<template #midBottom> <template #mid-bottom>
<div> <div>
<div class="row full-width q-pb-md"> <div class="row full-width q-pb-md">
<div class="col q-pr-md"> <div class="col q-pr-md">
<q-input <q-input
v-model="inputPhonHeadOffice" v-model="inputPhoneHeadOffice"
dense dense
outlined outlined
label="เบอร์โทรศัพท์สำนักงานใหฐ่" label="เบอร์โทรศัพท์สำนักงานใหฐ่"
@ -567,8 +563,6 @@ onMounted(async () => {
</div> </div>
</template> </template>
</FormDialog> </FormDialog>
<q-btn label="test" @click="openBranchDrawer = !openBranchDrawer" />
</template> </template>
<style scoped> <style scoped>