ทะเบียนประวัติ: ข้อมูลที่อยู่ (history, การ fetch ข้อมูล)

This commit is contained in:
puriphatt 2024-03-28 15:49:33 +07:00
parent 569ab2931a
commit cc90c26942
5 changed files with 129 additions and 229 deletions

View file

@ -11,11 +11,11 @@ import type {
DataOption,
AddressOps,
zipCodeOption,
Address,
} from "@/modules/04_registryNew/interface/index/Main";
export const useAddressDataStore = defineStore("addess", () => {
const $q = useQuasar();
const profileIdBefore = ref<string>("");
const mixin = useCounterMixin();
const {
showLoader,
@ -69,14 +69,14 @@ export const useAddressDataStore = defineStore("addess", () => {
};
function findData(ops: any, id: string | null) {
if(id === null) return "";
if (id === null) return "";
return ops.find((r: { id: string }) => r.id === id) || {};
}
async function fetchProvince() {
showLoader();
await http
.get(config.API.province)
.get(config.API.profileNewProvince)
.then(async (res) => {
const data = res.data.result;
let option: DataOption[] = [];
@ -94,16 +94,16 @@ export const useAddressDataStore = defineStore("addess", () => {
});
}
async function fetchDistrict(id: string, position: string) {
async function fetchDistrict(id: string | null, position: string) {
if (!id) return;
showLoader();
await http
.get(config.API.listDistrict(id))
.get(config.API.profileNewDistrictByPId(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() });
data.districts.map((r: any) => {
option.push({ id: r.id, name: r.name });
});
if (position == "1") {
Ops.value.districtOps = option;
@ -126,11 +126,11 @@ export const useAddressDataStore = defineStore("addess", () => {
if (!id) return;
showLoader();
await http
.get(config.API.listSubDistrict(id))
.get(config.API.profileNewSubDistrictByDId(id))
.then(async (res) => {
const data = res.data.result;
let option: zipCodeOption[] = [];
data.map((r: any) => {
data.subDistricts.map((r: any) => {
option.push({
id: r.id.toString(),
name: r.name.toString(),
@ -197,6 +197,7 @@ export const useAddressDataStore = defineStore("addess", () => {
}
return {
profileIdBefore,
defaultAddress,
defaultAddressForm,
Ops,