feat: ต่อ api สร้าง เเม่
This commit is contained in:
parent
1885c4ceb1
commit
17b9450b47
1 changed files with 174 additions and 48 deletions
|
|
@ -10,36 +10,42 @@ import AddButton from 'components/AddButton.vue';
|
||||||
import TooltipComponent from 'components/TooltipComponent.vue';
|
import TooltipComponent from 'components/TooltipComponent.vue';
|
||||||
import StatCard from 'components/StatCardComponent.vue';
|
import StatCard from 'components/StatCardComponent.vue';
|
||||||
import BranchCard from 'src/components/01_branch-management/BranchCard.vue';
|
import BranchCard from 'src/components/01_branch-management/BranchCard.vue';
|
||||||
|
import FormDialog from 'src/components/FormDialog.vue';
|
||||||
|
import FormBranchInformation from 'src/components/01_branch-management/FormBranchInformation.vue';
|
||||||
|
import FormLocation from 'src/components/01_branch-management/FormLocation.vue';
|
||||||
|
import FormQr from 'src/components/01_branch-management/FormQr.vue';
|
||||||
|
import FormBranchContact from 'src/components/01_branch-management/FormBranchContact.vue';
|
||||||
|
|
||||||
// import { BranchWithChildren, BranchCreate } from 'stores/branch/types';
|
import { BranchWithChildren, BranchCreate } from 'stores/branch/types';
|
||||||
import { BranchWithChildren } from 'stores/branch/types';
|
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
// const profileFile = ref<File | undefined>(undefined);
|
const modal = ref<boolean>(false);
|
||||||
// const imageUrl = ref<string | null>();
|
|
||||||
|
|
||||||
// const inputFile = (() => {
|
const profileFile = ref<File | undefined>(undefined);
|
||||||
// const element = document.createElement('input');
|
const imageUrl = ref<string | null>('');
|
||||||
// element.type = 'file';
|
|
||||||
// element.accept = 'image/*';
|
const inputFile = (() => {
|
||||||
//
|
const element = document.createElement('input');
|
||||||
// const reader = new FileReader();
|
element.type = 'file';
|
||||||
// reader.addEventListener('load', () => {
|
element.accept = 'image/*';
|
||||||
// if (typeof reader.result === 'string') imageUrl.value = reader.result;
|
|
||||||
// });
|
const reader = new FileReader();
|
||||||
//
|
reader.addEventListener('load', () => {
|
||||||
// element.addEventListener('change', () => {
|
if (typeof reader.result === 'string') imageUrl.value = reader.result;
|
||||||
// profileFile.value = element.files?.[0];
|
});
|
||||||
// if (profileFile.value) {
|
|
||||||
// reader.readAsDataURL(profileFile.value);
|
element.addEventListener('change', () => {
|
||||||
// }
|
profileFile.value = element.files?.[0];
|
||||||
// });
|
if (profileFile.value) {
|
||||||
//
|
reader.readAsDataURL(profileFile.value);
|
||||||
// return element;
|
}
|
||||||
// })();
|
});
|
||||||
|
|
||||||
|
return element;
|
||||||
|
})();
|
||||||
|
|
||||||
const branchStore = useBranchStore();
|
const branchStore = useBranchStore();
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
@ -103,33 +109,86 @@ const fieldSelectedBranch = ref<{
|
||||||
|
|
||||||
const stats = ref<{ count: number; label: string }[]>([]);
|
const stats = ref<{ count: number; label: string }[]>([]);
|
||||||
|
|
||||||
// const defaultFormData = {
|
const defaultFormData = {
|
||||||
// headOfficeId: null,
|
headOfficeId: null,
|
||||||
// taxNo: '',
|
taxNo: '',
|
||||||
// nameEN: '',
|
nameEN: '',
|
||||||
// name: '',
|
name: '',
|
||||||
// addressEN: '',
|
addressEN: '',
|
||||||
// address: '',
|
address: '',
|
||||||
// zipCode: '',
|
zipCode: '',
|
||||||
// email: '',
|
email: '',
|
||||||
// telephoneNo: '',
|
contactName: '',
|
||||||
// longitude: '',
|
contact: '',
|
||||||
// latitude: '',
|
telephoneNo: '',
|
||||||
// subDistrictId: '',
|
longitude: '',
|
||||||
// districtId: '',
|
latitude: '',
|
||||||
// provinceId: '',
|
subDistrictId: '',
|
||||||
// contactName: '',
|
districtId: '',
|
||||||
// contact: [] as string[],
|
provinceId: '',
|
||||||
// };
|
lineId: '',
|
||||||
|
};
|
||||||
|
|
||||||
// const formData = ref<BranchCreate & { contact: string[] }>(
|
const formDialogRef = ref();
|
||||||
// structuredClone(defaultFormData),
|
const formType = ref<'create' | 'edit' | 'delete'>('create');
|
||||||
// );
|
const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice');
|
||||||
|
const codeHq = ref<string>('');
|
||||||
|
const formData = ref<Omit<BranchCreate, 'qrCodeImage'>>(
|
||||||
|
structuredClone(defaultFormData),
|
||||||
|
);
|
||||||
|
|
||||||
// function clearData() {
|
function openDialog() {
|
||||||
// formData.value = structuredClone(defaultFormData);
|
modal.value = true;
|
||||||
// profileFile.value = undefined;
|
}
|
||||||
// }
|
|
||||||
|
function triggerCreate(type: string, code?: string) {
|
||||||
|
clearData();
|
||||||
|
if (code) {
|
||||||
|
codeHq.value = code;
|
||||||
|
}
|
||||||
|
if (type === 'subBranch') {
|
||||||
|
formTypeBranch.value = 'subBranch';
|
||||||
|
} else {
|
||||||
|
formTypeBranch.value = 'headOffice';
|
||||||
|
}
|
||||||
|
|
||||||
|
formType.value = 'create';
|
||||||
|
openDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSubmit() {
|
||||||
|
if (formTypeBranch.value === 'headOffice') {
|
||||||
|
if (formType.value === 'create' && profileFile.value) {
|
||||||
|
await branchStore.create({
|
||||||
|
...formData.value,
|
||||||
|
qrCodeImage: profileFile.value,
|
||||||
|
});
|
||||||
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
|
modal.value = false;
|
||||||
|
}
|
||||||
|
} else if (formTypeBranch.value === 'subBranch') {
|
||||||
|
if (formType.value === 'create' && profileFile.value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearData() {
|
||||||
|
formData.value = structuredClone(defaultFormData);
|
||||||
|
profileFile.value = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeTitle(
|
||||||
|
formType: 'edit' | 'create' | 'delete',
|
||||||
|
typeBranch: 'headOffice' | 'subBranch',
|
||||||
|
) {
|
||||||
|
if (typeBranch === 'headOffice') {
|
||||||
|
return formType === 'create' ? 'เพิ่มสำนักงานใหญ่' : 'แก้ไขสำนักงานใหญ่';
|
||||||
|
}
|
||||||
|
if (typeBranch === 'subBranch') {
|
||||||
|
return formType === 'create' ? 'เพิ่มสาขา' : 'แก้ไขสาขา';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -209,6 +268,7 @@ const stats = ref<{ count: number; label: string }[]>([]);
|
||||||
icon="pixelarticons:plus"
|
icon="pixelarticons:plus"
|
||||||
height="26"
|
height="26"
|
||||||
class="color-icon-plus cursor-pointer"
|
class="color-icon-plus cursor-pointer"
|
||||||
|
@click="triggerCreate('headOffice')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -439,6 +499,72 @@ const stats = ref<{ count: number; label: string }[]>([]);
|
||||||
</template>
|
</template>
|
||||||
</AppBox>
|
</AppBox>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<FormDialog
|
||||||
|
ref="formDialogRef"
|
||||||
|
v-model:modal="modal"
|
||||||
|
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"
|
||||||
|
title="เพิ่มสำนักงานใหญ่"
|
||||||
|
:titleFormAddress="`ข้อมูลที่อยู่สำนักงานใหญ่`"
|
||||||
|
:addressSeparator="true"
|
||||||
|
:submit="
|
||||||
|
() => {
|
||||||
|
onSubmit();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<template #information>
|
||||||
|
<FormBranchInformation
|
||||||
|
v-model:code="codeHq"
|
||||||
|
v-model:taxNo="formData.taxNo"
|
||||||
|
v-model:name="formData.name"
|
||||||
|
v-model:nameEN="formData.nameEN"
|
||||||
|
:separator="true"
|
||||||
|
:dense="true"
|
||||||
|
:outlined="true"
|
||||||
|
title="formDialogTitleInformation"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #person>
|
||||||
|
<FormBranchContact
|
||||||
|
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"
|
||||||
|
:separator="true"
|
||||||
|
title="formDialogTitleContact"
|
||||||
|
:dense="true"
|
||||||
|
:outlined="true"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #qr-code>
|
||||||
|
<FormQr
|
||||||
|
title="Qr code"
|
||||||
|
:separator="true"
|
||||||
|
:qr="imageUrl"
|
||||||
|
@upload="
|
||||||
|
() => {
|
||||||
|
inputFile.click();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #location>
|
||||||
|
<FormLocation
|
||||||
|
v-model:latitude="formData.latitude"
|
||||||
|
v-model:longitude="formData.longitude"
|
||||||
|
title="formDialogTitleLocation"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</FormDialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue