fix: แก้ function แก้ไข สร้าง
This commit is contained in:
parent
7e0471889d
commit
01e41402b2
1 changed files with 71 additions and 169 deletions
|
|
@ -104,11 +104,6 @@ onMounted(async () => {
|
||||||
|
|
||||||
const statusFilter = ref<'all' | 'statusACTIVE' | 'statusINACTIVE'>('all');
|
const statusFilter = ref<'all' | 'statusACTIVE' | 'statusINACTIVE'>('all');
|
||||||
|
|
||||||
const currentHq = ref<{ id: string; code: string }>({
|
|
||||||
id: '',
|
|
||||||
code: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
const beforeBranch = ref<{ id: string; code: string }>({
|
const beforeBranch = ref<{ id: string; code: string }>({
|
||||||
id: '',
|
id: '',
|
||||||
code: '',
|
code: '',
|
||||||
|
|
@ -158,8 +153,8 @@ const formDialogRef = ref();
|
||||||
|
|
||||||
const formType = ref<'create' | 'edit' | 'delete' | 'view'>('create');
|
const formType = ref<'create' | 'edit' | 'delete' | 'view'>('create');
|
||||||
const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice');
|
const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice');
|
||||||
const codeHq = ref<{ id: string; code: string }>({ id: '', code: '' });
|
const currentHq = ref<{ id: string; code: string }>({ id: '', code: '' });
|
||||||
const codeSubBranch = ref<{ id: string; code: string }>({ id: '', code: '' });
|
const currentEdit = ref<{ id: string; code: string }>({ id: '', code: '' });
|
||||||
const formData = ref<Omit<BranchCreate, 'qrCodeImage' | 'imageUrl'>>(
|
const formData = ref<Omit<BranchCreate, 'qrCodeImage' | 'imageUrl'>>(
|
||||||
structuredClone(defaultFormData),
|
structuredClone(defaultFormData),
|
||||||
);
|
);
|
||||||
|
|
@ -184,10 +179,7 @@ async function fetchBranchById(id: string) {
|
||||||
if (res) {
|
if (res) {
|
||||||
qrCodeimageUrl.value = res.qrCodeImageUrl;
|
qrCodeimageUrl.value = res.qrCodeImageUrl;
|
||||||
imageUrl.value = res.imageUrl;
|
imageUrl.value = res.imageUrl;
|
||||||
codeSubBranch.value = {
|
|
||||||
id: res.id,
|
|
||||||
code: res.code,
|
|
||||||
};
|
|
||||||
formData.value = {
|
formData.value = {
|
||||||
headOfficeId: res.headOfficeId,
|
headOfficeId: res.headOfficeId,
|
||||||
taxNo: res.taxNo,
|
taxNo: res.taxNo,
|
||||||
|
|
@ -198,7 +190,7 @@ async function fetchBranchById(id: string) {
|
||||||
zipCode: res.zipCode,
|
zipCode: res.zipCode,
|
||||||
email: res.email,
|
email: res.email,
|
||||||
contactName: res.contactName,
|
contactName: res.contactName,
|
||||||
contact: res.contact[0].telephoneNo,
|
contact: res.contact.length > 0 ? res.contact[0].telephoneNo : ' ',
|
||||||
telephoneNo: res.telephoneNo,
|
telephoneNo: res.telephoneNo,
|
||||||
longitude: res.longitude,
|
longitude: res.longitude,
|
||||||
latitude: res.latitude,
|
latitude: res.latitude,
|
||||||
|
|
@ -215,70 +207,30 @@ function clearData() {
|
||||||
formData.value = structuredClone(defaultFormData);
|
formData.value = structuredClone(defaultFormData);
|
||||||
imageUrl.value = null;
|
imageUrl.value = null;
|
||||||
qrCodeimageUrl.value = null;
|
qrCodeimageUrl.value = null;
|
||||||
codeSubBranch.value = {
|
currentEdit.value = {
|
||||||
id: '',
|
id: '',
|
||||||
code: '',
|
code: '',
|
||||||
};
|
};
|
||||||
profileFile.value = undefined;
|
profileFile.value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerView(
|
|
||||||
id: string,
|
|
||||||
typeBranch: 'headOffice' | 'subBranch',
|
|
||||||
code?: string,
|
|
||||||
) {
|
|
||||||
await fetchBranchById(id);
|
|
||||||
if (id && code && typeBranch === 'headOffice') {
|
|
||||||
formTypeBranch.value = 'headOffice';
|
|
||||||
codeHq.value = {
|
|
||||||
id: id,
|
|
||||||
code: code,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (typeBranch === 'subBranch' && id && code) {
|
|
||||||
formTypeBranch.value = 'subBranch';
|
|
||||||
codeHq.value = {
|
|
||||||
id: id,
|
|
||||||
code: code,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentRecord = branchData.value.result.find((x) => x.id === id);
|
|
||||||
|
|
||||||
if (!currentRecord) return;
|
|
||||||
|
|
||||||
const currentRecordHead = branchData.value.result.find(
|
|
||||||
(x) => x.id === currentRecord.headOfficeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentRecordHead) {
|
|
||||||
codeHq.value.code = currentRecordHead.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
formTypeBranch.value = typeBranch;
|
|
||||||
formType.value = 'view';
|
|
||||||
|
|
||||||
openDrawer();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function undo() {
|
async function undo() {
|
||||||
formType.value = 'view';
|
formType.value = 'view';
|
||||||
formData.value = prevFormData.value;
|
formData.value = prevFormData.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerCreate(type: string, id?: string, code?: string) {
|
function triggerCreate(
|
||||||
|
type: 'headOffice' | 'subBranch',
|
||||||
|
id?: string,
|
||||||
|
code?: string,
|
||||||
|
) {
|
||||||
clearData();
|
clearData();
|
||||||
|
|
||||||
if (type === 'subBranch' && id && code) {
|
formTypeBranch.value = type;
|
||||||
formTypeBranch.value = 'subBranch';
|
currentHq.value = {
|
||||||
codeHq.value = {
|
id: id ?? '',
|
||||||
id: id,
|
code: code ?? '',
|
||||||
code: code,
|
};
|
||||||
};
|
|
||||||
} else {
|
|
||||||
formTypeBranch.value = 'headOffice';
|
|
||||||
codeHq.value = { id: '', code: '' };
|
|
||||||
}
|
|
||||||
|
|
||||||
formType.value = 'create';
|
formType.value = 'create';
|
||||||
openDialog();
|
openDialog();
|
||||||
|
|
@ -291,39 +243,40 @@ function drawerEdit() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerEdit(type: string, id: string, code?: string) {
|
async function triggerEdit(
|
||||||
|
openFormType: string,
|
||||||
|
id: string,
|
||||||
|
typeBranch: 'headOffice' | 'subBranch',
|
||||||
|
) {
|
||||||
await fetchBranchById(id);
|
await fetchBranchById(id);
|
||||||
|
if (openFormType === 'form') {
|
||||||
|
formType.value = 'edit';
|
||||||
|
openDialog();
|
||||||
|
}
|
||||||
|
if (openFormType === 'drawer') {
|
||||||
|
formType.value = 'view';
|
||||||
|
openDrawer();
|
||||||
|
}
|
||||||
|
|
||||||
if (id && code && type === 'headOffice') {
|
formTypeBranch.value = typeBranch;
|
||||||
formTypeBranch.value = 'headOffice';
|
|
||||||
codeHq.value = {
|
|
||||||
id: id,
|
|
||||||
code: code,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (type === 'subBranch' && id && code) {
|
|
||||||
formTypeBranch.value = 'subBranch';
|
|
||||||
codeHq.value = {
|
|
||||||
id: id,
|
|
||||||
code: code,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentRecord = branchData.value.result.find((x) => x.id === id);
|
const currentRecord = branchData.value.result.find((x) => x.id === id);
|
||||||
|
|
||||||
if (!currentRecord) return;
|
if (!currentRecord) return;
|
||||||
|
|
||||||
|
currentEdit.value = {
|
||||||
|
id: currentRecord.id,
|
||||||
|
code: currentRecord.code,
|
||||||
|
};
|
||||||
|
|
||||||
const currentRecordHead = branchData.value.result.find(
|
const currentRecordHead = branchData.value.result.find(
|
||||||
(x) => x.id === currentRecord.headOfficeId,
|
(x) => x.id === currentRecord.headOfficeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (currentRecordHead) {
|
if (currentRecordHead) {
|
||||||
codeHq.value.code = currentRecordHead.code;
|
currentHq.value.id = currentRecordHead.id;
|
||||||
|
currentHq.value.code = currentRecordHead.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
formType.value = 'edit';
|
|
||||||
|
|
||||||
openDialog();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerDelete(id: string) {
|
function triggerDelete(id: string) {
|
||||||
|
|
@ -348,77 +301,34 @@ function triggerDelete(id: string) {
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (formType.value === 'edit') {
|
if (formType.value === 'edit') {
|
||||||
if (modalDrawer.value) {
|
await branchStore.editById(
|
||||||
dialog({
|
currentEdit.value.id,
|
||||||
color: 'primary',
|
{
|
||||||
icon: 'mdi-pencil-outline',
|
...formData.value,
|
||||||
title: 'ยืนยันการแก้ไขข้อมูล',
|
status: undefined,
|
||||||
actionText: 'ตกลง',
|
},
|
||||||
persistent: true,
|
profileFile.value,
|
||||||
message: 'คุณต้องการแก้ไขข้อมูล ใช่หรือไม่',
|
profileFileImg.value,
|
||||||
action: async () => {
|
);
|
||||||
await branchStore.editById(
|
|
||||||
codeHq.value.id,
|
|
||||||
{
|
|
||||||
...formData.value,
|
|
||||||
status: undefined,
|
|
||||||
},
|
|
||||||
profileFile.value,
|
|
||||||
profileFileImg.value,
|
|
||||||
);
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
|
||||||
formType.value = 'view';
|
|
||||||
},
|
|
||||||
cancel: () => {},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await branchStore.editById(
|
|
||||||
codeHq.value.id,
|
|
||||||
{
|
|
||||||
...formData.value,
|
|
||||||
status: undefined,
|
|
||||||
},
|
|
||||||
profileFile.value,
|
|
||||||
profileFileImg.value,
|
|
||||||
);
|
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
}
|
modalDrawer.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formTypeBranch.value === 'headOffice') {
|
if (formType.value === 'create') {
|
||||||
if (
|
if (formTypeBranch.value === 'subBranch') {
|
||||||
formType.value === 'create' &&
|
formData.value.headOfficeId = currentHq.value.id;
|
||||||
profileFile.value &&
|
|
||||||
profileFileImg.value
|
|
||||||
) {
|
|
||||||
await branchStore.create({
|
|
||||||
...formData.value,
|
|
||||||
qrCodeImage: profileFile.value,
|
|
||||||
imageUrl: profileFileImg.value,
|
|
||||||
});
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
|
||||||
modal.value = false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (formTypeBranch.value === 'subBranch') {
|
await branchStore.create({
|
||||||
if (
|
...formData.value,
|
||||||
formType.value === 'create' &&
|
qrCodeImage: profileFile.value,
|
||||||
profileFile.value &&
|
imageUrl: profileFileImg.value,
|
||||||
profileFileImg.value
|
});
|
||||||
) {
|
|
||||||
formData.value.headOfficeId = codeHq.value.id;
|
|
||||||
|
|
||||||
await branchStore.create({
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
...formData.value,
|
modal.value = false;
|
||||||
qrCodeImage: profileFile.value,
|
|
||||||
imageUrl: profileFileImg.value,
|
|
||||||
});
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
|
||||||
modal.value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const _stats = await branchStore.stats();
|
const _stats = await branchStore.stats();
|
||||||
|
|
@ -591,9 +501,9 @@ watch(locale, () => {
|
||||||
<q-item
|
<q-item
|
||||||
@click="
|
@click="
|
||||||
if (node.isHeadOffice) {
|
if (node.isHeadOffice) {
|
||||||
triggerView(node.id, 'headOffice', node.code);
|
triggerEdit('drawer', node.id, 'headOffice');
|
||||||
} else {
|
} else {
|
||||||
triggerView(node.id, 'subBranch', node.code);
|
triggerEdit('drawer', node.id, 'subBranch');
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
clickable
|
clickable
|
||||||
|
|
@ -619,17 +529,9 @@ watch(locale, () => {
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
if (node.isHeadOffice) {
|
if (node.isHeadOffice) {
|
||||||
triggerEdit(
|
triggerEdit('form', node.id, 'headOffice');
|
||||||
'headOffice',
|
|
||||||
node.id,
|
|
||||||
node.code,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
triggerEdit(
|
triggerEdit('form', node.id, 'subBranch');
|
||||||
'subBranch',
|
|
||||||
node.id,
|
|
||||||
node.code,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
|
@ -882,9 +784,9 @@ watch(locale, () => {
|
||||||
@view-detail="
|
@view-detail="
|
||||||
(b) => {
|
(b) => {
|
||||||
if (b.hq) {
|
if (b.hq) {
|
||||||
triggerView(b.id, 'headOffice', b.branchLabelCode);
|
triggerEdit('drawer', b.id, 'headOffice');
|
||||||
} else {
|
} else {
|
||||||
triggerView(b.id, 'subBranch', b.branchLabelCode);
|
triggerEdit('drawer', b.id, 'subBranch');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
|
@ -904,7 +806,7 @@ watch(locale, () => {
|
||||||
v-model:province-id="formData.provinceId"
|
v-model:province-id="formData.provinceId"
|
||||||
v-model:district-id="formData.districtId"
|
v-model:district-id="formData.districtId"
|
||||||
v-model:sub-district-id="formData.subDistrictId"
|
v-model:sub-district-id="formData.subDistrictId"
|
||||||
:title="changeTitle(formType, formTypeBranch) + ' ' + codeSubBranch.code"
|
:title="changeTitle(formType, formTypeBranch) + ' ' + currentEdit.code"
|
||||||
:titleFormAddress="$t('formDialogTitleAddress')"
|
:titleFormAddress="$t('formDialogTitleAddress')"
|
||||||
:addressSeparator="true"
|
:addressSeparator="true"
|
||||||
:submit="
|
:submit="
|
||||||
|
|
@ -915,8 +817,8 @@ watch(locale, () => {
|
||||||
>
|
>
|
||||||
<template #information>
|
<template #information>
|
||||||
<FormBranchInformation
|
<FormBranchInformation
|
||||||
v-model:code="codeHq.code"
|
v-model:code="currentHq.code"
|
||||||
v-model:code-sub-branch="codeSubBranch.code"
|
v-model:code-sub-branch="currentEdit.code"
|
||||||
v-model:taxNo="formData.taxNo"
|
v-model:taxNo="formData.taxNo"
|
||||||
v-model:name="formData.name"
|
v-model:name="formData.name"
|
||||||
v-model:nameEN="formData.nameEN"
|
v-model:nameEN="formData.nameEN"
|
||||||
|
|
@ -985,14 +887,14 @@ watch(locale, () => {
|
||||||
<DrawerInfo
|
<DrawerInfo
|
||||||
ref="formDialogRef"
|
ref="formDialogRef"
|
||||||
v-model:drawerOpen="modalDrawer"
|
v-model:drawerOpen="modalDrawer"
|
||||||
:title="changeTitle(formType, formTypeBranch) + ' ' + codeSubBranch.code"
|
:title="changeTitle(formType, formTypeBranch) + ' ' + currentEdit.code"
|
||||||
:titleFormAddress="$t('formDialogTitleAddress')"
|
:titleFormAddress="$t('formDialogTitleAddress')"
|
||||||
:addressSeparator="true"
|
:addressSeparator="true"
|
||||||
:undo="() => undo()"
|
:undo="() => undo()"
|
||||||
:isEdit="formType === 'edit'"
|
:isEdit="formType === 'edit'"
|
||||||
:editData="() => drawerEdit()"
|
:editData="() => drawerEdit()"
|
||||||
:submit="() => onSubmit()"
|
:submit="() => onSubmit()"
|
||||||
:delete-data="() => triggerDelete(codeSubBranch.id)"
|
:delete-data="() => triggerDelete(currentEdit.id)"
|
||||||
:close="() => (modalDrawer = false)"
|
:close="() => (modalDrawer = false)"
|
||||||
:statusBranch="formData.status"
|
:statusBranch="formData.status"
|
||||||
>
|
>
|
||||||
|
|
@ -1007,8 +909,8 @@ watch(locale, () => {
|
||||||
>
|
>
|
||||||
<template #information>
|
<template #information>
|
||||||
<FormBranchInformation
|
<FormBranchInformation
|
||||||
v-model:code="codeHq.code"
|
v-model:code="currentHq.code"
|
||||||
v-model:code-sub-branch="codeSubBranch.code"
|
v-model:code-sub-branch="currentEdit.code"
|
||||||
v-model:taxNo="formData.taxNo"
|
v-model:taxNo="formData.taxNo"
|
||||||
v-model:name="formData.name"
|
v-model:name="formData.name"
|
||||||
v-model:nameEN="formData.nameEN"
|
v-model:nameEN="formData.nameEN"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue