Merge branch 'refactor/branch-search' into develop
This commit is contained in:
commit
ab0b3bb4f3
3 changed files with 80 additions and 51 deletions
|
|
@ -3,6 +3,7 @@ import { boot } from 'quasar/wrappers';
|
||||||
import { getToken } from 'src/services/keycloak';
|
import { getToken } from 'src/services/keycloak';
|
||||||
import { dialog } from 'stores/utils';
|
import { dialog } from 'stores/utils';
|
||||||
import useLoader from 'stores/loader';
|
import useLoader from 'stores/loader';
|
||||||
|
import useFlowStore from 'src/stores/flow';
|
||||||
|
|
||||||
declare module '@vue/runtime-core' {
|
declare module '@vue/runtime-core' {
|
||||||
interface ComponentCustomProperties {
|
interface ComponentCustomProperties {
|
||||||
|
|
@ -32,6 +33,7 @@ function parseError(
|
||||||
api.interceptors.request.use(async (config) => {
|
api.interceptors.request.use(async (config) => {
|
||||||
useLoader().show();
|
useLoader().show();
|
||||||
config.headers.Authorization = `Bearer ${await getToken()}`;
|
config.headers.Authorization = `Bearer ${await getToken()}`;
|
||||||
|
config.headers['X-Rtid'] = useFlowStore().rtid;
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,22 +177,28 @@ const { locale } = useI18n();
|
||||||
|
|
||||||
const { data: branchData } = storeToRefs(branchStore);
|
const { data: branchData } = storeToRefs(branchStore);
|
||||||
|
|
||||||
|
const currentSubBranch = ref<Branch[] | undefined>(undefined);
|
||||||
const treeData = computed(() => {
|
const treeData = computed(() => {
|
||||||
const map: Record<string, BranchWithChildren> = {};
|
const map: Record<string, BranchWithChildren> = {};
|
||||||
const children: Branch[] = [];
|
|
||||||
|
|
||||||
branchData.value?.result.forEach((v) => {
|
branchData.value?.result.forEach((v) => {
|
||||||
const name = locale.value === 'eng' ? v.nameEN : v.name;
|
const name = locale.value === 'eng' ? v.nameEN : v.name;
|
||||||
if (v.isHeadOffice) map[v.id] = { ...v, name, branch: [] };
|
|
||||||
else children.push({ ...v, name });
|
map[v.id] = { ...v, name, branch: v.branch || [] };
|
||||||
});
|
});
|
||||||
|
|
||||||
children.forEach((v) => {
|
// branchData.value?.result.forEach((v) => {
|
||||||
const name = locale.value === 'eng' ? v.nameEN : v.name;
|
// const name = locale.value === 'eng' ? v.nameEN : v.name;
|
||||||
if (v.headOfficeId && map[v.headOfficeId]) {
|
// if (v.isHeadOffice) map[v.id] = { ...v, name, branch: [] };
|
||||||
map[v.headOfficeId].branch.push({ ...v, name });
|
// else children.push({ ...v, name });
|
||||||
}
|
// });
|
||||||
});
|
|
||||||
|
// children.forEach((v) => {
|
||||||
|
// const name = locale.value === 'eng' ? v.nameEN : v.name;
|
||||||
|
// if (v.headOfficeId && map[v.headOfficeId]) {
|
||||||
|
// map[v.headOfficeId].branch.push({ ...v, name });
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
return Object.values(map);
|
return Object.values(map);
|
||||||
});
|
});
|
||||||
|
|
@ -254,7 +260,7 @@ onMounted(async () => {
|
||||||
// object, we are effectively unselecting any HQ branch.
|
// object, we are effectively unselecting any HQ branch.
|
||||||
];
|
];
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await fetchList({ pageSize: 99999, tree: true });
|
||||||
await calculateStats();
|
await calculateStats();
|
||||||
|
|
||||||
modeView.value = $q.screen.lt.md ? true : false;
|
modeView.value = $q.screen.lt.md ? true : false;
|
||||||
|
|
@ -361,6 +367,19 @@ function openDialog() {
|
||||||
modal.value = true;
|
modal.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function selectedSubBranche(id: string) {
|
||||||
|
const res = await branchStore.fetchById(id, {
|
||||||
|
includeSubBranch: true,
|
||||||
|
includeContact: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
currentSubBranch.value = res.branch;
|
||||||
|
} else {
|
||||||
|
currentSubBranch.value = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchBranchById(id: string) {
|
async function fetchBranchById(id: string) {
|
||||||
const res = await branchStore.fetchById(id, { includeContact: true });
|
const res = await branchStore.fetchById(id, { includeContact: true });
|
||||||
if (res) {
|
if (res) {
|
||||||
|
|
@ -556,7 +575,7 @@ function triggerDelete(id: string) {
|
||||||
message: t('dialog.message.confirmDelete'),
|
message: t('dialog.message.confirmDelete'),
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await branchStore.deleteById(id);
|
await branchStore.deleteById(id);
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await fetchList({ pageSize: 99999 });
|
||||||
modalDrawer.value = false;
|
modalDrawer.value = false;
|
||||||
await calculateStats();
|
await calculateStats();
|
||||||
|
|
||||||
|
|
@ -612,6 +631,23 @@ function triggerEditQrCodeBank(opts?: { save?: boolean }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchList(opts: {
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
zipCode?: string;
|
||||||
|
query?: string;
|
||||||
|
tree?: boolean;
|
||||||
|
filter?: 'head' | 'sub';
|
||||||
|
}) {
|
||||||
|
await branchStore.fetchList(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(inputSearch, () => {
|
||||||
|
console.log(inputSearch.value);
|
||||||
|
fetchList({ tree: true, query: inputSearch.value });
|
||||||
|
currentSubBranch.value = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
async function triggerChangeStatus(
|
async function triggerChangeStatus(
|
||||||
id: string,
|
id: string,
|
||||||
status: string,
|
status: string,
|
||||||
|
|
@ -659,7 +695,7 @@ async function onSubmit() {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await fetchList({ pageSize: 99999 });
|
||||||
if (!imageDialog.value) modalDrawer.value = false;
|
if (!imageDialog.value) modalDrawer.value = false;
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
}
|
}
|
||||||
|
|
@ -675,7 +711,7 @@ async function onSubmit() {
|
||||||
formBankBook.value,
|
formBankBook.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await fetchList({ pageSize: 99999 });
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -818,6 +854,8 @@ watch(currentHq, () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectedSubBranche(currentHq.value.id);
|
||||||
|
|
||||||
utilsStore.currentTitle.path = tmp;
|
utilsStore.currentTitle.path = tmp;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -1131,41 +1169,26 @@ watch(currentHq, () => {
|
||||||
class="full-width"
|
class="full-width"
|
||||||
:rows-per-page-options="[0]"
|
:rows-per-page-options="[0]"
|
||||||
:rows="
|
:rows="
|
||||||
treeData
|
(
|
||||||
.flatMap((v) => [v, ...v.branch])
|
currentSubBranch ||
|
||||||
.filter((v) => {
|
(inputSearch !== ''
|
||||||
if (
|
? treeData.flatMap((v) => [v, ...v.branch])
|
||||||
statusFilter === 'statusACTIVE' &&
|
: treeData)
|
||||||
v.status === 'INACTIVE'
|
).filter((v) => {
|
||||||
) {
|
if (
|
||||||
return false;
|
statusFilter === 'statusACTIVE' &&
|
||||||
}
|
v.status === 'INACTIVE'
|
||||||
if (
|
) {
|
||||||
statusFilter === 'statusINACTIVE' &&
|
|
||||||
v.status !== 'INACTIVE'
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const terms = `${v.code} ${$i18n.locale === 'eng' ? v.nameEN : v.name} ${v.telephoneNo}`;
|
|
||||||
if (inputSearch && !terms.includes(inputSearch)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!!currentHq.id &&
|
|
||||||
currentHq.id === v.headOfficeId
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (fieldSelectedBranch.value === 'all') return true;
|
|
||||||
if (fieldSelectedBranch.value === 'branchHQLabel')
|
|
||||||
return v.isHeadOffice;
|
|
||||||
if (fieldSelectedBranch.value === 'branchLabel')
|
|
||||||
return !v.isHeadOffice;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
})
|
}
|
||||||
|
if (
|
||||||
|
statusFilter === 'statusINACTIVE' &&
|
||||||
|
v.status !== 'INACTIVE'
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
"
|
"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:grid="modeView"
|
:grid="modeView"
|
||||||
|
|
@ -1197,7 +1220,7 @@ watch(currentHq, () => {
|
||||||
<q-tr
|
<q-tr
|
||||||
:class="{
|
:class="{
|
||||||
'app-text-muted': props.row.status === 'INACTIVE',
|
'app-text-muted': props.row.status === 'INACTIVE',
|
||||||
'cursor-pointer': props.row._count.branch !== 0,
|
'cursor-pointer': props.row._count?.branch !== 0,
|
||||||
}"
|
}"
|
||||||
:style="
|
:style="
|
||||||
props.rowIndex % 2 !== 0
|
props.rowIndex % 2 !== 0
|
||||||
|
|
@ -1317,7 +1340,11 @@ watch(currentHq, () => {
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td v-if="fieldSelected.includes('branchLabelTel')">
|
<q-td v-if="fieldSelected.includes('branchLabelTel')">
|
||||||
{{ props.row.contact[0]?.telephoneNo || '-' }}
|
{{
|
||||||
|
props.row.contact !== undefined
|
||||||
|
? props.row.contact[0]?.telephoneNo
|
||||||
|
: '-'
|
||||||
|
}}
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td v-if="fieldSelected.includes('contactName')">
|
<q-td v-if="fieldSelected.includes('contactName')">
|
||||||
|
|
@ -1806,7 +1833,7 @@ watch(currentHq, () => {
|
||||||
formType = 'view';
|
formType = 'view';
|
||||||
}
|
}
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await fetchList({ pageSize: 99999 });
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:readonly="formType === 'view'"
|
:readonly="formType === 'view'"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ type BranchId = string;
|
||||||
|
|
||||||
const useBranchStore = defineStore('api-branch', () => {
|
const useBranchStore = defineStore('api-branch', () => {
|
||||||
const flowStore = useFlowStore();
|
const flowStore = useFlowStore();
|
||||||
const data = ref<Pagination<Branch[]>>({
|
const data = ref<Pagination<(Branch & { branch?: Branch[] })[]>>({
|
||||||
result: [],
|
result: [],
|
||||||
page: 0,
|
page: 0,
|
||||||
pageSize: 0,
|
pageSize: 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue