feat: form ดูรายละเอียด
This commit is contained in:
parent
f9d9b83792
commit
6b0a1a56b5
1 changed files with 190 additions and 16 deletions
|
|
@ -17,6 +17,8 @@ import FormLocation from 'src/components/01_branch-management/FormLocation.vue';
|
||||||
import FormQr from 'src/components/01_branch-management/FormQr.vue';
|
import FormQr from 'src/components/01_branch-management/FormQr.vue';
|
||||||
import FormBranchContact from 'src/components/01_branch-management/FormBranchContact.vue';
|
import FormBranchContact from 'src/components/01_branch-management/FormBranchContact.vue';
|
||||||
import FormImage from 'src/components/01_branch-management/FormImage.vue';
|
import FormImage from 'src/components/01_branch-management/FormImage.vue';
|
||||||
|
import DrawerInfo from 'src/components/DrawerInfo.vue';
|
||||||
|
import infoForm from 'src/components/02_personnel-management/infoForm.vue';
|
||||||
|
|
||||||
import { BranchWithChildren, BranchCreate } from 'stores/branch/types';
|
import { BranchWithChildren, BranchCreate } from 'stores/branch/types';
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
|
@ -157,10 +159,21 @@ 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 codeHq = ref<{ id: string; code: string }>({ id: '', code: '' });
|
||||||
|
const codeSubBranch = 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),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const prevFormData = ref<Omit<BranchCreate, 'qrCodeImage' | 'imageUrl'>>(
|
||||||
|
structuredClone(defaultFormData),
|
||||||
|
);
|
||||||
|
|
||||||
|
const modalDrawer = ref<boolean>(false);
|
||||||
|
|
||||||
|
function openDrawer() {
|
||||||
|
modalDrawer.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
modal.value = true;
|
modal.value = true;
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +184,10 @@ 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,21 +215,42 @@ function clearData() {
|
||||||
formData.value = structuredClone(defaultFormData);
|
formData.value = structuredClone(defaultFormData);
|
||||||
imageUrl.value = null;
|
imageUrl.value = null;
|
||||||
qrCodeimageUrl.value = null;
|
qrCodeimageUrl.value = null;
|
||||||
|
codeSubBranch.value = {
|
||||||
|
id: '',
|
||||||
|
code: '',
|
||||||
|
};
|
||||||
profileFile.value = undefined;
|
profileFile.value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerView(id: string, code?: string) {
|
function triggerView(
|
||||||
|
id: string,
|
||||||
|
typeBranch: 'headOffice' | 'subBranch',
|
||||||
|
code?: string,
|
||||||
|
) {
|
||||||
fetchBranchById(id);
|
fetchBranchById(id);
|
||||||
if (id && code) {
|
if (id && code && typeBranch === 'headOffice') {
|
||||||
codeHq.value = {
|
codeHq.value = {
|
||||||
id: id,
|
id: id,
|
||||||
code: code,
|
code: code,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formTypeBranch.value = typeBranch;
|
||||||
formType.value = 'view';
|
formType.value = 'view';
|
||||||
|
|
||||||
openDialog();
|
openDrawer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawerEdit() {
|
||||||
|
formType.value = 'edit';
|
||||||
|
prevFormData.value = {
|
||||||
|
...formData.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function undo() {
|
||||||
|
formType.value = 'view';
|
||||||
|
formData.value = prevFormData.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerCreate(type: string, id?: string, code?: string) {
|
function triggerCreate(type: string, id?: string, code?: string) {
|
||||||
|
|
@ -235,7 +273,7 @@ function triggerCreate(type: string, id?: string, code?: string) {
|
||||||
|
|
||||||
function triggerEdit(type: string, id: string, code?: string) {
|
function triggerEdit(type: string, id: string, code?: string) {
|
||||||
fetchBranchById(id);
|
fetchBranchById(id);
|
||||||
if (id && code) {
|
if (id && code && type === 'headOffice') {
|
||||||
codeHq.value = {
|
codeHq.value = {
|
||||||
id: id,
|
id: id,
|
||||||
code: code,
|
code: code,
|
||||||
|
|
@ -265,6 +303,7 @@ function triggerDelete(id: string) {
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await branchStore.deleteById(id);
|
await branchStore.deleteById(id);
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
|
modalDrawer.value = false;
|
||||||
},
|
},
|
||||||
cancel: () => {},
|
cancel: () => {},
|
||||||
});
|
});
|
||||||
|
|
@ -273,15 +312,37 @@ function triggerDelete(id: string) {
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (formType.value === 'edit') {
|
if (formType.value === 'edit') {
|
||||||
await branchStore.editById(
|
if (modalDrawer.value) {
|
||||||
codeHq.value.id,
|
dialog({
|
||||||
formData.value,
|
color: 'primary',
|
||||||
profileFile.value,
|
icon: 'mdi-pencil-outline',
|
||||||
profileFileImg.value,
|
title: 'ยืนยันการแก้ไขข้อมูล',
|
||||||
);
|
actionText: 'ตกลง',
|
||||||
|
persistent: true,
|
||||||
|
message: 'คุณต้องการแก้ไขข้อมูล ใช่หรือไม่',
|
||||||
|
action: async () => {
|
||||||
|
await branchStore.editById(
|
||||||
|
codeHq.value.id,
|
||||||
|
formData.value,
|
||||||
|
profileFile.value,
|
||||||
|
profileFileImg.value,
|
||||||
|
);
|
||||||
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
|
formType.value = 'view';
|
||||||
|
},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await branchStore.editById(
|
||||||
|
codeHq.value.id,
|
||||||
|
formData.value,
|
||||||
|
profileFile.value,
|
||||||
|
profileFileImg.value,
|
||||||
|
);
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formTypeBranch.value === 'headOffice') {
|
if (formTypeBranch.value === 'headOffice') {
|
||||||
|
|
@ -326,12 +387,16 @@ function changeTitle(
|
||||||
if (typeBranch === 'headOffice') {
|
if (typeBranch === 'headOffice') {
|
||||||
return formType === 'create'
|
return formType === 'create'
|
||||||
? t('formDialogTitleCreateHeadOffice')
|
? t('formDialogTitleCreateHeadOffice')
|
||||||
: t('formDialogTitleEditHeadOffice');
|
: formType === 'view'
|
||||||
|
? t('formDialogTitleViewHeadOffice')
|
||||||
|
: t('formDialogTitleEditHeadOffice');
|
||||||
}
|
}
|
||||||
if (typeBranch === 'subBranch') {
|
if (typeBranch === 'subBranch') {
|
||||||
return formType === 'create'
|
return formType === 'create'
|
||||||
? t('formDialogTitleCreateSubBranch')
|
? t('formDialogTitleCreateSubBranch')
|
||||||
: t('formDialogTitleEditSubBranch');
|
: formType === 'view'
|
||||||
|
? t('formDialogTitleViewSubBranch')
|
||||||
|
: t('formDialogTitleEditSubBranch');
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
@ -740,7 +805,16 @@ watch(locale, () => {
|
||||||
:data="item"
|
:data="item"
|
||||||
:field-selected="fieldSelected"
|
:field-selected="fieldSelected"
|
||||||
:inactive="item.status === 'INACTIVE'"
|
:inactive="item.status === 'INACTIVE'"
|
||||||
@view-detail="(b) => triggerView(b.id, b.branchLabelCode)"
|
@view-detail="
|
||||||
|
(b) => {
|
||||||
|
console.log(b);
|
||||||
|
if (b.hq) {
|
||||||
|
triggerView(b.id, 'headOffice', b.branchLabelCode);
|
||||||
|
} else {
|
||||||
|
triggerView(b.id, 'subBranch', b.branchLabelCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -757,7 +831,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)"
|
:title="changeTitle(formType, formTypeBranch) + ' ' + codeSubBranch.code"
|
||||||
:titleFormAddress="$t('formDialogTitleAddress')"
|
:titleFormAddress="$t('formDialogTitleAddress')"
|
||||||
:addressSeparator="true"
|
:addressSeparator="true"
|
||||||
:submit="
|
:submit="
|
||||||
|
|
@ -769,6 +843,7 @@ watch(locale, () => {
|
||||||
<template #information>
|
<template #information>
|
||||||
<FormBranchInformation
|
<FormBranchInformation
|
||||||
v-model:code="codeHq.code"
|
v-model:code="codeHq.code"
|
||||||
|
v-model:code-sub-branch="codeSubBranch.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"
|
||||||
|
|
@ -776,6 +851,8 @@ watch(locale, () => {
|
||||||
:separator="true"
|
:separator="true"
|
||||||
:dense="true"
|
:dense="true"
|
||||||
:outlined="true"
|
:outlined="true"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
:view="formType === 'view'"
|
||||||
title="formDialogTitleInformation"
|
title="formDialogTitleInformation"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -799,6 +876,7 @@ watch(locale, () => {
|
||||||
title="QR Code"
|
title="QR Code"
|
||||||
:separator="true"
|
:separator="true"
|
||||||
:qr="qrCodeimageUrl"
|
:qr="qrCodeimageUrl"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
@upload="
|
@upload="
|
||||||
() => {
|
() => {
|
||||||
inputFile.click();
|
inputFile.click();
|
||||||
|
|
@ -809,6 +887,7 @@ watch(locale, () => {
|
||||||
|
|
||||||
<template #location>
|
<template #location>
|
||||||
<FormLocation
|
<FormLocation
|
||||||
|
:readonly="formType === 'view'"
|
||||||
:separator="true"
|
:separator="true"
|
||||||
v-model:latitude="formData.latitude"
|
v-model:latitude="formData.latitude"
|
||||||
v-model:longitude="formData.longitude"
|
v-model:longitude="formData.longitude"
|
||||||
|
|
@ -818,6 +897,7 @@ watch(locale, () => {
|
||||||
|
|
||||||
<template #by-type>
|
<template #by-type>
|
||||||
<FormImage
|
<FormImage
|
||||||
|
:readonly="formType === 'view'"
|
||||||
v-model:image="imageUrl"
|
v-model:image="imageUrl"
|
||||||
@upload="
|
@upload="
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -828,6 +908,100 @@ watch(locale, () => {
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</FormDialog>
|
</FormDialog>
|
||||||
|
|
||||||
|
<DrawerInfo
|
||||||
|
ref="formDialogRef"
|
||||||
|
v-model:drawerOpen="modalDrawer"
|
||||||
|
:title="changeTitle(formType, formTypeBranch) + ' ' + codeSubBranch.code"
|
||||||
|
:titleFormAddress="$t('formDialogTitleAddress')"
|
||||||
|
:addressSeparator="true"
|
||||||
|
:undo="() => undo()"
|
||||||
|
:isEdit="formType === 'edit'"
|
||||||
|
:editData="() => drawerEdit()"
|
||||||
|
:submit="() => onSubmit()"
|
||||||
|
:delete-data="() => triggerDelete(codeSubBranch.id)"
|
||||||
|
>
|
||||||
|
<template #info>
|
||||||
|
<infoForm
|
||||||
|
v-model:address="formData.address"
|
||||||
|
v-model:addressEN="formData.addressEN"
|
||||||
|
v-model:province-id="formData.provinceId"
|
||||||
|
v-model:district-id="formData.districtId"
|
||||||
|
v-model:sub-district-id="formData.subDistrictId"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
>
|
||||||
|
<template #information>
|
||||||
|
<FormBranchInformation
|
||||||
|
v-model:code="codeHq.code"
|
||||||
|
v-model:code-sub-branch="codeSubBranch.code"
|
||||||
|
v-model:taxNo="formData.taxNo"
|
||||||
|
v-model:name="formData.name"
|
||||||
|
v-model:nameEN="formData.nameEN"
|
||||||
|
v-model:type-branch="formTypeBranch"
|
||||||
|
:separator="true"
|
||||||
|
:dense="true"
|
||||||
|
:outlined="true"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
:view="formType === 'view'"
|
||||||
|
title="formDialogTitleInformation"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #person>
|
||||||
|
<FormBranchContact
|
||||||
|
title="formDialogTitleContact"
|
||||||
|
v-model:telephone-no="formData.telephoneNo"
|
||||||
|
v-model:contact="formData.contact"
|
||||||
|
v-model:email="formData.email"
|
||||||
|
v-model:contact-name="formData.contactName"
|
||||||
|
v-model:line-id="formData.lineId"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
:view="formType === 'view'"
|
||||||
|
:separator="true"
|
||||||
|
:dense="true"
|
||||||
|
:outlined="true"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #qr-code>
|
||||||
|
<FormQr
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
title="QR Code"
|
||||||
|
:separator="true"
|
||||||
|
:qr="qrCodeimageUrl"
|
||||||
|
@upload="
|
||||||
|
() => {
|
||||||
|
inputFile.click();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #location>
|
||||||
|
<FormLocation
|
||||||
|
title="formDialogTitleLocation"
|
||||||
|
v-model:latitude="formData.latitude"
|
||||||
|
v-model:longitude="formData.longitude"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
:separator="true"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #by-type>
|
||||||
|
<FormImage
|
||||||
|
@upload="
|
||||||
|
() => {
|
||||||
|
inputFileImg.click();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
v-model:image="imageUrl"
|
||||||
|
:title="$t('formDialogTitleImg')"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</infoForm>
|
||||||
|
</template>
|
||||||
|
</DrawerInfo>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue