{
lazy-rules
hide-bottom-space
type="textarea"
- v-model="addressData.addressC"
+ class="inputgreen"
+ v-model="formData.currentAddress"
:label="dataLabel.currentAddress"
:rules="[(val:string) => !!val || `${'กรุณากรอก ที่อยู่ปัจจุบัน'}`]"
/>
@@ -909,8 +736,9 @@ onMounted(async () => {
option-value="id"
option-label="name"
input-debounce="0"
- v-model="addressData.provinceIdC"
- :options="Ops.provinceOps"
+ class="inputgreen"
+ v-model="formData.currentProvinceId"
+ :options="store.Ops.provinceOps"
:label="dataLabel.currentProvince"
:rules="[(val:string) => !!val || `${'กรุณาเลือก จังหวัด'}`]"
@update:model-value="(value:string) => selectProvince(value, '2')"
@@ -931,8 +759,9 @@ onMounted(async () => {
option-value="id"
option-label="name"
input-debounce="0"
- v-model="addressData.districtIdC"
- :options="Ops.districtCOps"
+ class="inputgreen"
+ v-model="formData.currentDistrictId"
+ :options="store.Ops.districtCOps"
:label="dataLabel.currentDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก เขต / อำเภอ'}`]"
@update:model-value="(value:string) => selectDistrict(value, '2')"
@@ -953,8 +782,9 @@ onMounted(async () => {
option-value="id"
option-label="name"
input-debounce="0"
- v-model="addressData.subdistrictIdC"
- :options="Ops.subdistrictCOps"
+ class="inputgreen"
+ v-model="formData.currentSubDistrictId"
+ :options="store.Ops.subdistrictCOps"
:label="dataLabel.currentSubDistrict"
:rules="[(val:string) => !!val || `${'กรุณาเลือก แขวง / ตำบล'}`]"
@update:model-value="(value:string) => selectSubDistrict(value, '2')"
@@ -970,7 +800,8 @@ onMounted(async () => {
outlined
lazy-rules
hide-bottom-space
- v-model="addressData.codec"
+ class="inputgreen"
+ v-model="formData.currentZipCode"
:label="dataLabel.registrationZipCode"
/>
diff --git a/src/modules/04_registryNew/interface/request/Address.ts b/src/modules/04_registryNew/interface/request/Address.ts
index f8cff7753..208a47369 100644
--- a/src/modules/04_registryNew/interface/request/Address.ts
+++ b/src/modules/04_registryNew/interface/request/Address.ts
@@ -1,55 +1,16 @@
-interface DataProps {
- row: RequestItemsObject;
- rowIndex: number;
-}
-
-//ข้อมูล
-interface RequestItemsObject {
- currentAddress: String | null;
- currentDistrictId: String | null;
- currentProvinceId: String | null;
- currentSubDistrictId: 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;
- };
+interface RequestObject {
+ currentZipCode: string | null;
+ currentSubDistrictId: string | null;
+ currentDistrictId: string | null;
+ currentProvinceId: string | null;
+ currentAddress: string | null;
+ registrationZipCode: string | null;
+ registrationSubDistrictId: string | null;
+ registrationDistrictId: string | null;
+ registrationProvinceId: string | null;
+ registrationAddress: string | null;
}
export type {
- RequestItemsObject,
- Columns,
- DataProps,
- RequestItemsHistoryObject,
+ RequestObject,
};
diff --git a/src/modules/04_registryNew/interface/response/Address.ts b/src/modules/04_registryNew/interface/response/Address.ts
index 8769bd1b4..c446955fa 100644
--- a/src/modules/04_registryNew/interface/response/Address.ts
+++ b/src/modules/04_registryNew/interface/response/Address.ts
@@ -1,34 +1,15 @@
-//ข้อมูล
interface ResponseObject {
- currentAddress: string | null;
- currentDistrictId: string | null;
- currentProvinceId: string | null;
- currentSubDistrictId: string | null;
- currentZipCode: string | null;
+ id: string;
registrationAddress: string | null;
- registrationDistrictId: string | null;
registrationProvinceId: string | null;
- registrationSame: Boolean | null;
+ registrationDistrictId: string | null;
registrationSubDistrictId: string | null;
registrationZipCode: string | null;
- createdFullName: string | null;
- createdAt: Date;
-}
-
-interface ResponseHistory {
currentAddress: string | null;
- currentDistrictId: string | null;
currentProvinceId: string | null;
+ currentDistrictId: string | null;
currentSubDistrictId: 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 };
diff --git a/src/modules/04_registryNew/stores/Address.ts b/src/modules/04_registryNew/stores/Address.ts
new file mode 100644
index 000000000..ac72fe4c5
--- /dev/null
+++ b/src/modules/04_registryNew/stores/Address.ts
@@ -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
({
+ provinceOps: [],
+ districtOps: [],
+ districtCOps: [],
+ subdistrictOps: [],
+ subdistrictCOps: [],
+ });
+ const OpsFilter = ref({
+ 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,
+ };
+});