57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
|
|
import { useI18n } from 'vue-i18n';
|
||
|
|
import { District, Province, SubDistrict } from 'src/stores/address';
|
||
|
|
|
||
|
|
export function formatAddress(opt: {
|
||
|
|
address: string;
|
||
|
|
moo?: string;
|
||
|
|
mooEN?: string;
|
||
|
|
soi?: string;
|
||
|
|
soiEN?: string;
|
||
|
|
street?: string;
|
||
|
|
streetEN?: string;
|
||
|
|
province: Province;
|
||
|
|
district: District;
|
||
|
|
subDistrict: SubDistrict;
|
||
|
|
en?: boolean;
|
||
|
|
}) {
|
||
|
|
const { t } = useI18n();
|
||
|
|
const addressParts = [`${opt.address},`];
|
||
|
|
|
||
|
|
if (opt.en) {
|
||
|
|
// en
|
||
|
|
if (opt.moo) addressParts.push(`Moo ${opt.mooEN},`);
|
||
|
|
if (opt.soi) addressParts.push(`Soi ${opt.soiEN},`);
|
||
|
|
if (opt.street) addressParts.push(`${opt.streetEN} Rd.`);
|
||
|
|
|
||
|
|
addressParts.push(`${opt.subDistrict.nameEN} sub-district,`);
|
||
|
|
addressParts.push(`${opt.district.nameEN} district,`);
|
||
|
|
addressParts.push(`${opt.province.nameEN},`);
|
||
|
|
} else {
|
||
|
|
// th
|
||
|
|
if (opt.moo) addressParts.push(`หมู่ ${opt.moo},`);
|
||
|
|
if (opt.soi) addressParts.push(`ซอย ${opt.soi},`);
|
||
|
|
if (opt.street) addressParts.push(`ถนน ${opt.street},`);
|
||
|
|
|
||
|
|
addressParts.push(
|
||
|
|
`${opt.province.id === '10' ? 'แขวง' : 'ตำบล'}${opt.subDistrict.name},`,
|
||
|
|
);
|
||
|
|
addressParts.push(
|
||
|
|
`${opt.province.id === '10' ? 'เขต' : 'อำเภอ'}${opt.district.name},`,
|
||
|
|
);
|
||
|
|
addressParts.push(`จังหวัด${opt.province.name},`);
|
||
|
|
// addressParts.push(
|
||
|
|
// `${opt.province.id === '10' ? t('address.subArea') : t('address.subDistrict')}${opt.subDistrict.name},`,
|
||
|
|
// );
|
||
|
|
// addressParts.push(
|
||
|
|
// `${opt.province.id === '10' ? t('address.area') : t('address.district')}${opt.district.name},`,
|
||
|
|
// );
|
||
|
|
// addressParts.push(
|
||
|
|
// ` ${opt.province.id === '10' ? t('address.province') : t('address.province')}${opt.province.name},`,
|
||
|
|
// );
|
||
|
|
}
|
||
|
|
|
||
|
|
addressParts.push(`${opt.subDistrict.zipCode}`);
|
||
|
|
|
||
|
|
return addressParts.join(' ');
|
||
|
|
}
|