refactor: header After deletion branch

This commit is contained in:
Net 2024-09-23 12:54:09 +07:00
parent 6338977e6d
commit cfe33ee154

View file

@ -409,6 +409,12 @@ function openDialog() {
modal.value = true; modal.value = true;
} }
watch(treeData, () => {
if (currentSubBranch.value !== undefined) {
selectedSubBranche(currentHq.value.id);
}
});
async function selectedSubBranche(id: string) { async function selectedSubBranche(id: string) {
const res = await branchStore.fetchById(id, { const res = await branchStore.fetchById(id, {
includeSubBranch: true, includeSubBranch: true,
@ -632,7 +638,7 @@ async function triggerEdit(
currentBranchAdmin.value = branchAdmin; currentBranchAdmin.value = branchAdmin;
} }
function triggerDelete(id: string) { async function triggerDelete(id: string) {
if (id) { if (id) {
dialog({ dialog({
color: 'negative', color: 'negative',
@ -642,9 +648,14 @@ function triggerDelete(id: string) {
persistent: true, persistent: true,
message: t('dialog.message.confirmDelete'), message: t('dialog.message.confirmDelete'),
action: async () => { action: async () => {
await branchStore.deleteById(id); const res = await branchStore.deleteById(id);
console.log(res);
if (res) {
await fetchList({ tree: true, pageSize: 99999 }); await fetchList({ tree: true, pageSize: 99999 });
modalDrawer.value = false; modalDrawer.value = false;
modal.value = false;
await calculateStats(); await calculateStats();
const branchLength = treeData.value.find( const branchLength = treeData.value.find(
@ -659,6 +670,7 @@ function triggerDelete(id: string) {
}; };
} }
flowStore.rotate(); flowStore.rotate();
}
}, },
cancel: () => {}, cancel: () => {},
}); });
@ -745,8 +757,8 @@ async function triggerChangeStatus(
} }
async function onSubmit(submitSelectedItem?: boolean) { async function onSubmit(submitSelectedItem?: boolean) {
if (formType.value === 'edit' || submitSelectedItem) {
delete formData.value['codeHeadOffice']; delete formData.value['codeHeadOffice'];
if (formType.value === 'edit' || submitSelectedItem) {
delete formData.value['code']; delete formData.value['code'];
const res = await branchStore.editById( const res = await branchStore.editById(
@ -773,6 +785,11 @@ async function onSubmit(submitSelectedItem?: boolean) {
} }
if (formType.value === 'create') { if (formType.value === 'create') {
if (formData.value.headOfficeId !== undefined) {
formData.value.code = formData.value?.code?.slice(0, -5);
formData.value.codeHeadOffice = formData.value?.codeHeadOffice?.slice(-5);
}
const createBranch = async () => { const createBranch = async () => {
const res = await branchStore.create( const res = await branchStore.create(
{ {
@ -1796,7 +1813,11 @@ watch(currentHq, () => {
v-if="formType !== 'edit' && !!currentId" v-if="formType !== 'edit' && !!currentId"
id="btn-info-basic-delete" id="btn-info-basic-delete"
icon-only icon-only
@click="triggerDelete(currentEdit.id)" @click="
() => {
triggerDelete(currentEdit.id);
}
"
type="button" type="button"
/> />
</div> </div>