ทะเบียนประวัติ: ข้อมูลที่อยู่

This commit is contained in:
puriphatt 2024-03-27 18:32:03 +07:00
parent 4c3d5c8fb8
commit ba9fea5515
5 changed files with 510 additions and 519 deletions

View file

@ -22,6 +22,13 @@ export default {
profileNewProfileHisById: (dataId: string) => profileNewProfileHisById: (dataId: string) =>
`${registryNew}history/${dataId}`, `${registryNew}history/${dataId}`,
// ข้อมูลที่อยู่
profileNewAddressByProfileId: (profileId: string) =>
`${registryNew}address/${profileId}`,
profileNewAddressById: (dataId: string) => `${registryNew}address/${dataId}`,
profileNewAddressHisById: (dataId: string) =>
`${registryNew}address/history/${dataId}`,
// บันทึกวันที่ไม่ได้รับเงินเดือนฯ // บันทึกวันที่ไม่ได้รับเงินเดือนฯ
profileNewNoPaid: `${registryNew}nopaid`, profileNewNoPaid: `${registryNew}nopaid`,
profileNewNoPaidByProfileId: (profileId: string) => profileNewNoPaidByProfileId: (profileId: string) =>

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from "vue"; import { onMounted, ref, reactive, watch } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
@ -9,45 +9,54 @@ import config from "@/app.config";
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
import HistoryTable from "@/components/TableHistory.vue"; import HistoryTable from "@/components/TableHistory.vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { import { useAddressDataStore } from "@/modules/04_registryNew/stores/Address";
DataOption,
AddressOps,
zipCodeOption,
Address,
} from "@/modules/04_registryNew/interface/index/Main";
import { defaultAddress } from "@/modules/04_registryNew/interface/index/Main";
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/Address"; import type { ResponseObject } from "@/modules/04_registryNew/interface/response/Address";
import type { RequestItemsHistoryObject } from "@/modules/04_registryNew/interface/request/Address"; import type { RequestObject } from "@/modules/04_registryNew/interface/request/Address";
const $q = useQuasar(); const $q = useQuasar();
const store = useAddressDataStore();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const route = useRoute(); const route = useRoute();
const { date2Thai, success, messageError, showLoader, hideLoader } = mixin; const {
fetchProvince,
fetchDistrict,
fetchSubDistrict,
findData,
filterSelector,
} = store;
const {
date2Thai,
success,
messageError,
showLoader,
hideLoader,
dialogConfirm,
} = mixin;
const profileId = ref<string>(
route.params.id ? route.params.id.toString() : ""
);
const statusAdd = ref(false); const statusAdd = ref(false);
const isLoad = ref<number>(0);
const modal = ref<boolean>(false); const modal = ref<boolean>(false);
const myForm = ref<any>(); const modalHistory = ref<boolean>(false);
const rowsHistory = ref<RequestItemsHistoryObject[]>([]); const rowsHistory = ref<ResponseObject[]>([]);
const tittleHistory = ref<string>("ประวัติแก้ไขข้อมูลที่อยู่"); // const tittleHistory = ref<string>("ประวัติแก้ไขข้อมูลที่อยู่"); //
const filterHistory = ref<string>(""); const filterHistory = ref<string>("");
const modalHistory = ref<boolean>(false);
const addressData = ref<Address>(defaultAddress);
// mock data const id = ref<string>("");
const resultData = ref({ const sameAddress = ref<string>("0");
registrationAddress: "123123488", const addressData = reactive<ResponseObject>(store.defaultAddress);
registrationProvinceId: "24b22b3c-67aa-4631-bf7c-69ec6b735767", const formData = reactive<RequestObject>(store.defaultAddressForm);
registrationDistrictId: "ce9a2984-938f-454c-a758-26dcf8176afe",
registrationSubDistrictId: "97dba284-7cdc-45c6-863c-9590810fe8e2",
registrationZipCode: "50100",
currentAddress: "66664444", const adsName = reactive({
currentProvinceId: "24b22b3c-67aa-4631-bf7c-69ec6b735767", regisP: "",
currentDistrictId: "ce9a2984-938f-454c-a758-26dcf8176afe", regisD: "",
currentSubDistrictId: "97dba284-7cdc-45c6-863c-9590810fe8e2", regisSD: "",
currentZipCode: "50100",
registrationSame: "0", currentP: "",
currentD: "",
currentSD: "",
}); });
const dataLabel = { const dataLabel = {
@ -228,135 +237,21 @@ const columnsHistory = ref<QTableProps["columns"]>([
}, },
]); ]);
const Ops = ref<AddressOps>({ async function getData() {
provinceOps: [],
districtOps: [],
districtCOps: [],
subdistrictOps: [],
subdistrictCOps: [],
});
const OpsFilter = ref<AddressOps>({
provinceOps: [],
districtOps: [],
districtCOps: [],
subdistrictOps: [],
subdistrictCOps: [],
});
function defaultAdd() {
if (statusAdd) {
addressData.value = {
address: null,
provinceId: null,
districtId: null,
subdistrictId: null,
addressC: null,
provinceIdC: null,
districtIdC: null,
subdistrictIdC: null,
codep: null,
codec: null,
same: "0",
};
}
}
async function fetchData() {
// mock data
addressData.value.address = resultData.value.registrationAddress;
addressData.value.provinceId = resultData.value.registrationProvinceId;
addressData.value.districtId = resultData.value.registrationDistrictId;
addressData.value.subdistrictId = resultData.value.registrationSubDistrictId;
addressData.value.codep = resultData.value.registrationZipCode;
addressData.value.same = resultData.value.registrationSame;
addressData.value.addressC = resultData.value.currentAddress;
addressData.value.provinceIdC = resultData.value.currentProvinceId;
addressData.value.districtIdC = resultData.value.currentDistrictId;
addressData.value.subdistrictIdC = resultData.value.currentSubDistrictId;
addressData.value.codec = resultData.value.currentZipCode;
// if (route.params.id) {
// // showLoader();
// await http
// .get(config.API.profileAdrsId(route.params.id.toString()))
// .then((res) => {
// const data: ResponseObject = res.data.result;
// addressData.value.address = data.registrationAddress;
// addressData.value.addressC = data.currentAddress;
// addressData.value.districtId =
// data.registrationDistrictId !== "00000000-0000-0000-0000-000000000000"
// ? data.registrationDistrictId
// : "";
// addressData.value.districtIdC =
// data.currentDistrictId !== "00000000-0000-0000-0000-000000000000"
// ? data.currentDistrictId
// : "";
// addressData.value.provinceId =
// data.registrationProvinceId !== "00000000-0000-0000-0000-000000000000"
// ? data.registrationProvinceId
// : "";
// addressData.value.provinceIdC =
// data.currentProvinceId !== "00000000-0000-0000-0000-000000000000"
// ? data.currentProvinceId
// : "";
// addressData.value.subdistrictId =
// data.registrationSubDistrictId !==
// "00000000-0000-0000-0000-000000000000"
// ? data.registrationSubDistrictId
// : "";
// addressData.value.subdistrictIdC =
// data.currentSubDistrictId !== "00000000-0000-0000-0000-000000000000"
// ? data.currentSubDistrictId
// : "";
// addressData.value.same = data.registrationSame ? "1" : "0";
// addressData.value.codec = data.currentZipCode;
// addressData.value.codep = data.registrationZipCode;
// })
// .catch((e) => {
// messageError($q, e);
// })
// .finally(() => {
// // hideLoader();
// isLoad.value++;
// });
// }
}
async function fetchProvince() {
showLoader(); showLoader();
await http await http
.get(config.API.province) .get(config.API.profileNewAddressByProfileId(profileId.value))
.then(async (res) => { .then((res) => {
const data = res.data.result; Object.assign(addressData, res.data.result);
let option: DataOption[] = [];
data.map((r: any) => {
option.push({ id: r.id.toString(), name: r.name.toString() });
});
Ops.value.provinceOps = option;
OpsFilter.value.provinceOps = option;
const checkRegistProvinceId = await option.find( if (addressData) {
(e: any) => e.id === addressData.value.provinceId id.value = addressData.id;
); if (
if (checkRegistProvinceId) { addressData.currentAddress === addressData.registrationAddress &&
addressData.value = addressData.value; addressData.currentZipCode === addressData.registrationZipCode
} else { ) {
addressData.value.provinceId = ""; sameAddress.value = "1";
addressData.value.districtId = ""; }
addressData.value.subdistrictId = "";
addressData.value.codep = "";
}
const checkCurrentProvinceId = await option.find(
(e: any) => e.id === addressData.value.provinceIdC
);
if (checkCurrentProvinceId) {
addressData.value = addressData.value;
} else {
addressData.value.provinceIdC = "";
addressData.value.districtIdC = "";
addressData.value.subdistrictIdC = "";
addressData.value.codec = "";
} }
}) })
.catch((e) => { .catch((e) => {
@ -364,132 +259,89 @@ async function fetchProvince() {
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
isLoad.value++;
}); });
} }
async function fetchDistrict(id: string | null, position: string) { async function getProvince() {
if (id != null && id != "") { await fetchProvince();
showLoader(); const checkRegistProvinceId = await store.Ops.provinceOps.find(
await http (e: any) => e.id === addressData.registrationProvinceId
.get(config.API.listDistrict(id)) );
.then(async (res) => { if (!checkRegistProvinceId) {
const data = res.data.result; addressData.registrationProvinceId = "";
let option: DataOption[] = []; addressData.registrationDistrictId = "";
data.map((r: any) => { addressData.registrationSubDistrictId = "";
option.push({ id: r.id.toString(), name: r.name.toString() }); addressData.registrationZipCode = "";
}); }
if (position == "1") { const checkCurrentProvinceId = await store.Ops.provinceOps.find(
Ops.value.districtOps = option; (e: any) => e.id === addressData.currentProvinceId
OpsFilter.value.districtOps = option; );
if (!checkCurrentProvinceId) {
const checkRegistDistrictId = await option.find( addressData.currentProvinceId = "";
(e: any) => e.id === addressData.value.districtId addressData.currentDistrictId = "";
); addressData.currentSubDistrictId = "";
if (checkRegistDistrictId) { addressData.currentZipCode = "";
addressData.value.districtId = addressData.value.districtId; }
addressData.value.subdistrictId = addressData.value.subdistrictId;
addressData.value.codep = addressData.value.codep;
} else {
addressData.value.districtId = "";
addressData.value.subdistrictId = "";
addressData.value.codep = "";
}
} else {
Ops.value.districtCOps = option;
OpsFilter.value.districtCOps = option;
const checkCurrentDistrictIdC = await option.find(
(e: any) => e.id === addressData.value.districtIdC
);
if (checkCurrentDistrictIdC) {
addressData.value.districtIdC = addressData.value.districtIdC;
addressData.value.subdistrictIdC = addressData.value.subdistrictIdC;
addressData.value.codec = addressData.value.codec;
} else {
addressData.value.districtIdC = "";
addressData.value.subdistrictIdC = "";
addressData.value.codec = "";
}
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
isLoad.value++;
});
} else isLoad.value++;
} }
async function fetchSubDistrict(id: string | null, position: string) { async function getDistrict(id: string | null, position: string) {
if (id != null && id != "") { if (!id) return;
showLoader(); await fetchDistrict(id, position);
await http
.get(config.API.listSubDistrict(id))
.then(async (res) => {
const data = res.data.result;
let option: zipCodeOption[] = [];
data.map((r: any) => {
option.push({
id: r.id.toString(),
name: r.name.toString(),
zipCode: r.zipCode.toString(),
});
});
if (position == "1") {
Ops.value.subdistrictOps = option;
OpsFilter.value.subdistrictOps = option;
const checkRegistSubdistrictId = await option.find( if (position == "1") {
(e: any) => e.id === addressData.value.subdistrictId const checkRegistDistrictId = await store.Ops.districtOps.find(
); (e: any) => e.id === addressData.registrationDistrictId
if (checkRegistSubdistrictId) { );
addressData.value.subdistrictId = addressData.value.subdistrictId; if (!checkRegistDistrictId) {
addressData.value.codep = addressData.value.codep; addressData.registrationDistrictId = "";
} else { addressData.registrationSubDistrictId = "";
addressData.value.subdistrictId = ""; addressData.registrationZipCode = "";
addressData.value.codep = ""; }
} } else {
} else { const checkCurrentDistrictIdC = await store.Ops.districtCOps.find(
Ops.value.subdistrictCOps = option; (e: any) => e.id === addressData.currentDistrictId
OpsFilter.value.subdistrictCOps = option; );
if (!checkCurrentDistrictIdC) {
addressData.currentDistrictId = "";
addressData.currentSubDistrictId = "";
addressData.currentZipCode = "";
}
}
}
const checkCurrentSubdistrictIdC = await option.find( async function getSubDistrict(id: string | null, position: string) {
(e: any) => e.id === addressData.value.subdistrictIdC if (!id) return;
); await fetchSubDistrict(id, position);
if (checkCurrentSubdistrictIdC) { if (position == "1") {
addressData.value.subdistrictIdC = addressData.value.subdistrictIdC; const checkRegistSubdistrictId = await store.Ops.subdistrictOps.find(
addressData.value.codec = addressData.value.codec; (e: any) => e.id === addressData.registrationSubDistrictId
} else { );
addressData.value.subdistrictIdC = ""; if (!checkRegistSubdistrictId) {
addressData.value.codec = ""; addressData.registrationSubDistrictId = "";
} addressData.registrationZipCode = "";
} }
}) } else {
.catch((e) => { const checkCurrentSubdistrictIdC = await store.Ops.subdistrictCOps.find(
messageError($q, e); (e: any) => e.id === addressData.currentSubDistrictId
}) );
.finally(() => { if (!checkCurrentSubdistrictIdC) {
hideLoader(); addressData.currentSubDistrictId = "";
isLoad.value++; addressData.currentZipCode = "";
}); }
} else isLoad.value++; }
} }
async function selectProvince(e: string | null, name: string) { async function selectProvince(e: string | null, name: string) {
if (e != null) { if (e != null) {
if (name == "1") { if (name == "1") {
addressData.value.districtId = ""; formData.registrationDistrictId = "";
addressData.value.subdistrictId = ""; formData.registrationSubDistrictId = "";
addressData.value.codep = ""; formData.registrationZipCode = "";
} else { } else {
addressData.value.districtIdC = ""; formData.currentDistrictId = "";
addressData.value.subdistrictIdC = ""; formData.currentSubDistrictId = "";
addressData.value.codec = ""; formData.currentZipCode = "";
} }
myForm.value.resetValidation();
await fetchDistrict(e, name); await fetchDistrict(e, name);
} }
} }
@ -497,13 +349,12 @@ async function selectProvince(e: string | null, name: string) {
async function selectDistrict(e: string | null, name: string) { async function selectDistrict(e: string | null, name: string) {
if (e != null) { if (e != null) {
if (name == "1") { if (name == "1") {
addressData.value.subdistrictId = ""; formData.registrationSubDistrictId = "";
addressData.value.codep = ""; formData.registrationZipCode = "";
} else { } else {
addressData.value.subdistrictIdC = ""; formData.currentSubDistrictId = "";
addressData.value.codec = ""; formData.currentZipCode = "";
} }
myForm.value.resetValidation();
await fetchSubDistrict(e, name); await fetchSubDistrict(e, name);
} }
} }
@ -511,115 +362,131 @@ async function selectDistrict(e: string | null, name: string) {
function selectSubDistrict(e: string | null, name: string) { function selectSubDistrict(e: string | null, name: string) {
if (e != null) { if (e != null) {
if (name == "1") { if (name == "1") {
const findcode = Ops.value.subdistrictOps.filter((r) => r.id == e); const findcode = store.Ops.subdistrictOps.filter((r) => r.id == e);
const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; const namecode = findcode.length > 0 ? findcode[0].zipCode : "";
addressData.value.codep = namecode; formData.registrationZipCode = namecode;
} else { } else {
const findcode = Ops.value.subdistrictCOps.filter((r) => r.id == e); const findcode = store.Ops.subdistrictCOps.filter((r) => r.id == e);
const namecode = findcode.length > 0 ? findcode[0].zipCode : ""; const namecode = findcode.length > 0 ? findcode[0].zipCode : "";
addressData.value.codec = namecode; formData.currentZipCode = namecode;
} }
} }
} }
async function getNewData() { async function fetchAll() {
await fetchData(); await getData();
await fetchProvince(); if (
await fetchDistrict(addressData.value.provinceId, "1"); store.Ops.provinceOps.length === 0 ||
await fetchDistrict(addressData.value.provinceIdC, "2"); store.Ops.districtOps.length === 0 ||
await fetchSubDistrict(addressData.value.districtId, "1"); store.Ops.districtCOps.length === 0 ||
await fetchSubDistrict(addressData.value.districtIdC, "2"); store.Ops.subdistrictOps.length === 0 ||
store.Ops.subdistrictCOps.length === 0
) {
await getProvince();
await getDistrict(addressData.registrationProvinceId, "1");
await getDistrict(addressData.currentProvinceId, "2");
await getSubDistrict(addressData.registrationDistrictId, "1");
await getSubDistrict(addressData.currentDistrictId, "2");
}
adsName.regisP = findData(
store.Ops.provinceOps,
addressData.registrationProvinceId
).name;
adsName.regisD = findData(
store.Ops.districtOps,
addressData.registrationDistrictId
).name;
adsName.regisSD = findData(
store.Ops.subdistrictOps,
addressData.registrationSubDistrictId
).name;
adsName.currentP = findData(
store.Ops.provinceOps,
addressData.currentProvinceId
).name;
adsName.currentD = findData(
store.Ops.districtCOps,
addressData.currentDistrictId
).name;
adsName.currentSD = findData(
store.Ops.subdistrictCOps,
addressData.currentSubDistrictId
).name;
} }
function filterSelector(val: any, update: Function, refData: string) { async function editData() {
switch (refData) { showLoader();
case "provinceOps": await http
update(() => { .patch(config.API.profileNewAddressById(id.value), {
Ops.value.provinceOps = OpsFilter.value.provinceOps.filter( ...formData,
(v: DataOption) => v.name.indexOf(val) > -1 id: undefined,
); })
}); .then((res) => {
break; success($q, "บันทึกข้อมูลสำเร็จ");
case "districtOps": fetchAll();
update(() => { modal.value = false;
Ops.value.districtOps = OpsFilter.value.districtOps.filter( })
(v: DataOption) => v.name.indexOf(val) > -1 .catch((e) => {
); messageError($q, e);
}); })
break; .finally(() => {
case "districtCOps": hideLoader();
update(() => { });
Ops.value.districtCOps = OpsFilter.value.districtCOps.filter( }
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "subdistrictOps":
update(() => {
Ops.value.subdistrictOps = OpsFilter.value.subdistrictOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "subdistrictCOps":
update(() => {
Ops.value.subdistrictCOps = OpsFilter.value.subdistrictCOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
default: function onClickOpenDialog() {
break; if (!addressData) return;
} modal.value = true;
Object.assign(formData, addressData);
} }
async function clickHistory() { async function clickHistory() {
modalHistory.value = true; modalHistory.value = true;
// showLoader(); await http
// await http .get(config.API.profileNewAddressHisById(id.value))
// .get(config.API.profileAdrsHisId(route.params.id.toString())) .then((res) => {
// .then((res) => { rowsHistory.value = res.data.result;
// let data = res.data.result; console.log(rowsHistory.value);
// rowsHistory.value = []; })
// data.map((e: RequestItemsHistoryObject) => { .catch((e) => {
// rowsHistory.value.push({ messageError($q, e);
// currentAddress: e.currentAddress ?? "-", })
// currentDistrict: e.currentDistrict ?? "-", .finally(() => {
// currentProvince: e.currentProvince ?? "-", hideLoader();
// currentSubDistrict: e.currentSubDistrict ?? "-", });
// currentZipCode: e.currentZipCode ?? "-",
// registrationSame: e.registrationSame,
// registrationAddress: e.registrationAddress ?? "-",
// registrationDistrict: e.registrationDistrict ?? "-",
// registrationProvince: e.registrationProvince ?? "-",
// registrationSubDistrict: e.registrationSubDistrict ?? "-",
// registrationZipCode: e.registrationZipCode ?? "-",
// createdFullName: e.createdFullName ?? "-",
// createdAt: new Date(e.createdAt) ?? "-",
// });
// });
// })
// .catch((e) => {
// messageError($q, e);
// })
// .finally(() => {
// hideLoader();
// });
} }
function onSubmit() { function onSubmit() {
myForm.value.validate().then(async (result: boolean) => { dialogConfirm(
if (result) { $q,
// await saveData(); async () => {
editData();
modal.value = false; modal.value = false;
} },
}); "ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
} }
watch(
() => sameAddress.value,
(v) => {
if (v === "1") {
formData.currentAddress = formData.registrationAddress;
formData.currentProvinceId = formData.registrationProvinceId;
formData.currentDistrictId = formData.registrationDistrictId;
formData.currentSubDistrictId = formData.registrationSubDistrictId;
formData.currentZipCode = formData.registrationZipCode;
store.Ops.districtCOps = store.Ops.districtOps
store.Ops.subdistrictCOps = store.Ops.subdistrictOps
}
}
);
onMounted(async () => { onMounted(async () => {
defaultAdd(); await fetchAll();
await getNewData();
}); });
</script> </script>
<template> <template>
@ -630,7 +497,7 @@ onMounted(async () => {
round round
icon="mdi-pencil-outline" icon="mdi-pencil-outline"
color="primary" color="primary"
@click="modal = true" @click="onClickOpenDialog"
> >
<q-tooltip>แกไขขอม</q-tooltip> <q-tooltip>แกไขขอม</q-tooltip>
</q-btn> </q-btn>
@ -644,7 +511,7 @@ onMounted(async () => {
<div :class="$q.screen.gt.xs ? 'row' : 'column'"> <div :class="$q.screen.gt.xs ? 'row' : 'column'">
<!-- column 1 --> <!-- column 1 -->
<div class="col-md-6 col-12 row"> <div class="col-md-6 col-12 row">
<div class="col-5 text-grey-6 text-weight-medium"> <div class="col-6 text-grey-6 text-weight-medium">
<div <div
v-for="label in Object.keys(dataLabel).slice(0, 5)" v-for="label in Object.keys(dataLabel).slice(0, 5)"
class="q-py-xs" class="q-py-xs"
@ -653,58 +520,34 @@ onMounted(async () => {
</div> </div>
</div> </div>
<!-- data --> <!-- data -->
<div class="col-7"> <div class="col-6">
<div class="q-py-xs"> <div class="q-py-xs">
{{ addressData.address }} {{ addressData.registrationAddress || "-" }}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.regisP || "-" }}
addressData.provinceId
? (
Ops.provinceOps.find(
(r) => r.id === addressData.provinceId
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.regisD || "-" }}
addressData.districtId
? (
Ops.districtOps.find(
(r) => r.id === addressData.districtId
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.regisSD || "-" }}
addressData.subdistrictId
? (
Ops.subdistrictOps.find(
(r) => r.id === addressData.subdistrictId
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ addressData.codep }} {{ addressData.registrationZipCode || "-" }}
</div> </div>
</div> </div>
</div> </div>
<!-- column 2 --> <!-- column 2 -->
<div <!-- <div
class="text-grey-6 text-weight-medium" class="text-grey-6 text-weight-medium"
v-if="addressData.same === '1'" v-if="addressData.same === '1'"
> >
อยจจนตรงกบทอยตามทะเบยนบาน อยจจนตรงกบทอยตามทะเบยนบาน
</div> </div> -->
<div class="col-md-6 col-12 row" v-else> <div class="col-md-6 col-12 row">
<div class="col-5 text-grey-6 text-weight-medium"> <div class="col-6 text-grey-6 text-weight-medium">
<div <div
v-for="label in Object.keys(dataLabel).slice(5, 10)" v-for="label in Object.keys(dataLabel).slice(5, 10)"
class="q-py-xs" class="q-py-xs"
@ -713,45 +556,21 @@ onMounted(async () => {
</div> </div>
</div> </div>
<!-- data --> <!-- data -->
<div class="col-7"> <div class="col-6">
<div class="q-py-xs"> <div class="q-py-xs">
{{ addressData.addressC }} {{ addressData.currentAddress || "-" }}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.currentP || "-" }}
addressData.provinceIdC
? (
Ops.provinceOps.find(
(r) => r.id === addressData.provinceIdC
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.currentD || "-" }}
addressData.districtIdC
? (
Ops.districtCOps.find(
(r) => r.id === addressData.districtIdC
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ {{ adsName.currentSD || "-" }}
addressData.subdistrictIdC
? (
Ops.subdistrictCOps.find(
(r) => r.id === addressData.subdistrictIdC
) || {}
).name
: "-"
}}
</div> </div>
<div class="q-py-xs"> <div class="q-py-xs">
{{ addressData.codec }} {{ addressData.currentZipCode || "-" }}
</div> </div>
</div> </div>
</div> </div>
@ -761,7 +580,7 @@ onMounted(async () => {
<!-- Edit Dialog --> <!-- Edit Dialog -->
<q-dialog v-model="modal" persistent> <q-dialog v-model="modal" persistent>
<q-card style="width: 600px"> <q-card style="width: 600px">
<q-form ref="myForm" @submit="onSubmit"> <q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader <DialogHeader
tittle="แก้ไขข้อมูลที่อยู่" tittle="แก้ไขข้อมูลที่อยู่"
:close="() => (modal = false)" :close="() => (modal = false)"
@ -776,7 +595,8 @@ onMounted(async () => {
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
type="textarea" type="textarea"
v-model="addressData.address" class="inputgreen"
v-model="formData.registrationAddress"
:label="dataLabel.registrationAddress" :label="dataLabel.registrationAddress"
:rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ตามทะเบียนบ้าน'}`]" :rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ตามทะเบียนบ้าน'}`]"
/> />
@ -794,8 +614,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.provinceId" class="inputgreen"
:options="Ops.provinceOps" v-model="formData.registrationProvinceId"
:options="store.Ops.provinceOps"
:label="dataLabel.registrationProvince" :label="dataLabel.registrationProvince"
:rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]"
@update:model-value="(value:string) => selectProvince(value, '1')" @update:model-value="(value:string) => selectProvince(value, '1')"
@ -816,8 +637,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.districtId" class="inputgreen"
:options="Ops.districtOps" v-model="formData.registrationDistrictId"
:options="store.Ops.districtOps"
:label="dataLabel.registrationDistrict" :label="dataLabel.registrationDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]"
@update:model-value="(value:string) => selectDistrict(value, '1')" @update:model-value="(value:string) => selectDistrict(value, '1')"
@ -838,8 +660,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.subdistrictId" class="inputgreen"
:options="Ops.subdistrictOps" v-model="formData.registrationSubDistrictId"
:options="store.Ops.subdistrictOps"
:label="dataLabel.registrationSubDistrict" :label="dataLabel.registrationSubDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]"
@update:model-value="(value:string) => selectSubDistrict(value, '1')" @update:model-value="(value:string) => selectSubDistrict(value, '1')"
@ -855,7 +678,8 @@ onMounted(async () => {
outlined outlined
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
v-model="addressData.codep" class="inputgreen"
v-model="formData.registrationZipCode"
:label="dataLabel.registrationZipCode" :label="dataLabel.registrationZipCode"
/> />
</div> </div>
@ -870,7 +694,8 @@ onMounted(async () => {
val="1" val="1"
label="ใช่" label="ใช่"
checked-icon="task_alt" checked-icon="task_alt"
v-model="addressData.same" class="inputgreen"
v-model="sameAddress"
unchecked-icon="panorama_fish_eye" unchecked-icon="panorama_fish_eye"
/> />
<q-radio <q-radio
@ -878,12 +703,13 @@ onMounted(async () => {
val="0" val="0"
label="ไม่" label="ไม่"
checked-icon="task_alt" checked-icon="task_alt"
v-model="addressData.same" class="inputgreen"
v-model="sameAddress"
unchecked-icon="panorama_fish_eye" unchecked-icon="panorama_fish_eye"
/> />
</div> </div>
<!-- current address --> <!-- current address -->
<div v-if="addressData.same === '0'"> <div v-if="sameAddress === '0'">
<div class="col-12 q-pb-xs"> <div class="col-12 q-pb-xs">
<q-input <q-input
dense dense
@ -891,7 +717,8 @@ onMounted(async () => {
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
type="textarea" type="textarea"
v-model="addressData.addressC" class="inputgreen"
v-model="formData.currentAddress"
:label="dataLabel.currentAddress" :label="dataLabel.currentAddress"
:rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ปัจจุบัน'}`]" :rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ปัจจุบัน'}`]"
/> />
@ -909,8 +736,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.provinceIdC" class="inputgreen"
:options="Ops.provinceOps" v-model="formData.currentProvinceId"
:options="store.Ops.provinceOps"
:label="dataLabel.currentProvince" :label="dataLabel.currentProvince"
:rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]"
@update:model-value="(value:string) => selectProvince(value, '2')" @update:model-value="(value:string) => selectProvince(value, '2')"
@ -931,8 +759,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.districtIdC" class="inputgreen"
:options="Ops.districtCOps" v-model="formData.currentDistrictId"
:options="store.Ops.districtCOps"
:label="dataLabel.currentDistrict" :label="dataLabel.currentDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]"
@update:model-value="(value:string) => selectDistrict(value, '2')" @update:model-value="(value:string) => selectDistrict(value, '2')"
@ -953,8 +782,9 @@ onMounted(async () => {
option-value="id" option-value="id"
option-label="name" option-label="name"
input-debounce="0" input-debounce="0"
v-model="addressData.subdistrictIdC" class="inputgreen"
:options="Ops.subdistrictCOps" v-model="formData.currentSubDistrictId"
:options="store.Ops.subdistrictCOps"
:label="dataLabel.currentSubDistrict" :label="dataLabel.currentSubDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]" :rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]"
@update:model-value="(value:string) => selectSubDistrict(value, '2')" @update:model-value="(value:string) => selectSubDistrict(value, '2')"
@ -970,7 +800,8 @@ onMounted(async () => {
outlined outlined
lazy-rules lazy-rules
hide-bottom-space hide-bottom-space
v-model="addressData.codec" class="inputgreen"
v-model="formData.currentZipCode"
:label="dataLabel.registrationZipCode" :label="dataLabel.registrationZipCode"
/> />
</div> </div>

View file

@ -1,55 +1,16 @@
interface DataProps { interface RequestObject {
row: RequestItemsObject; currentZipCode: string | null;
rowIndex: number; currentSubDistrictId: string | null;
} currentDistrictId: string | null;
currentProvinceId: string | null;
//ข้อมูล currentAddress: string | null;
interface RequestItemsObject { registrationZipCode: string | null;
currentAddress: String | null; registrationSubDistrictId: string | null;
currentDistrictId: String | null; registrationDistrictId: string | null;
currentProvinceId: String | null; registrationProvinceId: string | null;
currentSubDistrictId: String | null; registrationAddress: string | null;
currentZipCode: String | null;
registrationAddress: String | null;
registrationDistrictId: String | null;
registrationProvinceId: String | null;
registrationSame: Boolean | null;
registrationSubDistrictId: String | null;
registrationZipCode: String | null;
}
interface RequestItemsHistoryObject {
currentAddress: String | null;
currentDistrict: String | null;
currentProvince: String | null;
currentSubDistrict: String | null;
currentZipCode: String | null;
registrationAddress: String | null;
registrationDistrict: String | null;
registrationProvince: String | null;
registrationSame: Boolean | null;
registrationSubDistrict: String | null;
registrationZipCode: String | null;
createdFullName: String | null;
createdAt: Date;
}
//columns
interface Columns {
[index: number]: {
name: String;
align: String;
label: String;
sortable: Boolean;
field: String;
headerStyle: String;
style: String;
};
} }
export type { export type {
RequestItemsObject, RequestObject,
Columns,
DataProps,
RequestItemsHistoryObject,
}; };

View file

@ -1,34 +1,15 @@
//ข้อมูล
interface ResponseObject { interface ResponseObject {
currentAddress: string | null; id: string;
currentDistrictId: string | null;
currentProvinceId: string | null;
currentSubDistrictId: string | null;
currentZipCode: string | null;
registrationAddress: string | null; registrationAddress: string | null;
registrationDistrictId: string | null;
registrationProvinceId: string | null; registrationProvinceId: string | null;
registrationSame: Boolean | null; registrationDistrictId: string | null;
registrationSubDistrictId: string | null; registrationSubDistrictId: string | null;
registrationZipCode: string | null; registrationZipCode: string | null;
createdFullName: string | null;
createdAt: Date;
}
interface ResponseHistory {
currentAddress: string | null; currentAddress: string | null;
currentDistrictId: string | null;
currentProvinceId: string | null; currentProvinceId: string | null;
currentDistrictId: string | null;
currentSubDistrictId: string | null; currentSubDistrictId: string | null;
currentZipCode: string | null; currentZipCode: string | null;
registrationAddress: string | null;
registrationDistrictId: string | null;
registrationProvinceId: string | null;
registrationSame: string | null;
registrationSubDistrictId: string | null;
registrationZipCode: string | null;
createdFullName: string | null;
createdAt: Date;
} }
export type { ResponseObject, ResponseHistory }; export type { ResponseObject };

View file

@ -0,0 +1,211 @@
import { ref } from "vue";
import { defineStore } from "pinia";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { RequestObject } from "@/modules/04_registryNew/interface/request/Address";
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/Address";
import type {
DataOption,
AddressOps,
zipCodeOption,
Address,
} from "@/modules/04_registryNew/interface/index/Main";
export const useAddressDataStore = defineStore("addess", () => {
const $q = useQuasar();
const mixin = useCounterMixin();
const {
showLoader,
hideLoader,
date2Thai,
messageError,
convertDate,
dateToISO,
} = mixin;
const Ops = ref<AddressOps>({
provinceOps: [],
districtOps: [],
districtCOps: [],
subdistrictOps: [],
subdistrictCOps: [],
});
const OpsFilter = ref<AddressOps>({
provinceOps: [],
districtOps: [],
districtCOps: [],
subdistrictOps: [],
subdistrictCOps: [],
});
const defaultAddress: ResponseObject = {
id: "",
currentZipCode: "",
currentSubDistrictId: "",
currentDistrictId: "",
currentProvinceId: "",
currentAddress: "",
registrationZipCode: "",
registrationSubDistrictId: "",
registrationDistrictId: "",
registrationProvinceId: "",
registrationAddress: "",
};
const defaultAddressForm: RequestObject = {
currentZipCode: "",
currentSubDistrictId: "",
currentDistrictId: "",
currentProvinceId: "",
currentAddress: "",
registrationZipCode: "",
registrationSubDistrictId: "",
registrationDistrictId: "",
registrationProvinceId: "",
registrationAddress: "",
};
function findData(ops: any, id: string | null) {
if(id === null) return "";
return ops.find((r: { id: string }) => r.id === id) || {};
}
async function fetchProvince() {
showLoader();
await http
.get(config.API.province)
.then(async (res) => {
const data = res.data.result;
let option: DataOption[] = [];
data.map((r: any) => {
option.push({ id: r.id.toString(), name: r.name.toString() });
});
Ops.value.provinceOps = option;
OpsFilter.value.provinceOps = option;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
async function fetchDistrict(id: string, position: string) {
if (!id) return;
showLoader();
await http
.get(config.API.listDistrict(id))
.then(async (res) => {
const data = res.data.result;
let option: DataOption[] = [];
data.map((r: any) => {
option.push({ id: r.id.toString(), name: r.name.toString() });
});
if (position == "1") {
Ops.value.districtOps = option;
OpsFilter.value.districtOps = option;
} else {
Ops.value.districtCOps = option;
OpsFilter.value.districtCOps = option;
}
return option;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
async function fetchSubDistrict(id: string | null, position: string) {
if (!id) return;
showLoader();
await http
.get(config.API.listSubDistrict(id))
.then(async (res) => {
const data = res.data.result;
let option: zipCodeOption[] = [];
data.map((r: any) => {
option.push({
id: r.id.toString(),
name: r.name.toString(),
zipCode: r.zipCode.toString(),
});
});
if (position == "1") {
Ops.value.subdistrictOps = option;
OpsFilter.value.subdistrictOps = option;
} else {
Ops.value.subdistrictCOps = option;
OpsFilter.value.subdistrictCOps = option;
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function filterSelector(val: any, update: Function, refData: string) {
switch (refData) {
case "provinceOps":
update(() => {
Ops.value.provinceOps = OpsFilter.value.provinceOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "districtOps":
update(() => {
Ops.value.districtOps = OpsFilter.value.districtOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "districtCOps":
update(() => {
Ops.value.districtCOps = OpsFilter.value.districtCOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "subdistrictOps":
update(() => {
Ops.value.subdistrictOps = OpsFilter.value.subdistrictOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
case "subdistrictCOps":
update(() => {
Ops.value.subdistrictCOps = OpsFilter.value.subdistrictCOps.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
default:
break;
}
}
return {
defaultAddress,
defaultAddressForm,
Ops,
OpsFilter,
findData,
fetchProvince,
fetchDistrict,
fetchSubDistrict,
filterSelector,
};
});