feat: edit and delete branch

This commit is contained in:
Methapon2001 2024-04-11 14:56:01 +07:00
parent b9e0d18d8b
commit 48c23b339e
2 changed files with 66 additions and 18 deletions

View file

@ -270,6 +270,7 @@ function triggerDeleteHeadOffice(id: string) {
async function fetchFormEditBranch(id: string) {
const result = await branchStore.fetchById<Branch>(id);
if (result) {
formData.value = {
taxNo: result.taxNo,
@ -303,12 +304,15 @@ async function fetchFormEditBranchContact(id: string) {
const result = await branchContactStore.fetchList(id);
if (result) {
const resultFilter = result.result.filter((v) => v.branchId === id);
currentBranchContactIdEdit.value = resultFilter[0].id;
urlQrCode.value = resultFilter[0].qrCodeImageUrl;
const first = result.result.pop();
if (!first) return;
currentBranchContactIdEdit.value = first.id;
urlQrCode.value = first.qrCodeImageUrl;
formDataContact.value = {
lineId: resultFilter[0].lineId,
telephoneNo: resultFilter[0].telephoneNo,
lineId: first.lineId,
telephoneNo: first.telephoneNo,
};
}
}
@ -335,12 +339,21 @@ async function submitForm(
}
if (typeSubmit === 'edit') {
await branchStore.editById(currentBranchIdEdit.value, inputBranchCreate);
await branchContactStore.editById(
currentBranchIdEdit.value,
currentBranchContactIdEdit.value,
inputBranchContactCreate,
profileFile.value ? profileFile.value : undefined,
);
if (currentBranchIdEdit.value && currentBranchContactIdEdit.value) {
await branchContactStore.editById(
currentBranchIdEdit.value,
currentBranchContactIdEdit.value,
inputBranchContactCreate,
profileFile.value ? profileFile.value : undefined,
);
} else {
await branchContactStore.create(
currentBranchIdEdit.value,
inputBranchContactCreate,
profileFile.value ? profileFile.value : undefined,
);
}
getTree();
modal.value = false;
@ -771,7 +784,8 @@ onMounted(async () => {
style="overflow-y: auto"
>
<CardDetailsComponent
:data="showCurrentBranch as Branch"
v-if="showCurrentBranch"
:data="showCurrentBranch"
class="q-pa-sm"
/>
</div>
@ -780,6 +794,21 @@ onMounted(async () => {
</div>
<DetailBranchDrawerComponent
@trigger-edit="
(v) => {
subBranch
? triggerEditSubBranch(v.code, v.id)
: triggerEditHeadOffice(v.id);
openBranchDrawer = false;
}
"
@trigger-delete="
(v) => {
subBranch
? triggerDeleteSubBranch(v.id)
: triggerDeleteHeadOffice(v.id);
}
"
v-if="showCurrentBranch"
v-model:open="openBranchDrawer"
:data="showCurrentBranch"