refactor: format address add address EN

This commit is contained in:
puriphatt 2024-11-11 11:49:29 +07:00
parent a2720d0f76
commit ed56228964
2 changed files with 9 additions and 5 deletions

View file

@ -91,6 +91,7 @@ const fullAddress = computed(() => {
if (province && district && sDistrict) {
const fullAddress = formatAddress({
address: address.value,
addressEN: addressEN.value,
moo: moo.value ? moo.value : '',
mooEN: mooEN.value ? mooEN.value : '',
soi: soi.value ? soi.value : '',
@ -116,6 +117,7 @@ const fullAddressEN = computed(() => {
if (province && district && sDistrict) {
const fullAddress = formatAddress({
address: address.value,
addressEN: addressEN.value,
moo: moo.value ? moo.value : '',
mooEN: mooEN.value ? mooEN.value : '',
soi: soi.value ? soi.value : '',

View file

@ -3,6 +3,7 @@ import { District, Province, SubDistrict } from 'src/stores/address';
export function formatAddress(opt: {
address: string;
addressEN: string;
moo?: string;
mooEN?: string;
soi?: string;
@ -15,19 +16,20 @@ export function formatAddress(opt: {
en?: boolean;
}) {
const { t } = useI18n();
const addressParts = [`${opt.address},`];
let addressParts: string[];
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 = [`${opt.addressEN},`];
if (opt.mooEN) addressParts.push(`Moo ${opt.mooEN},`);
if (opt.soiEN) addressParts.push(`Soi ${opt.soiEN},`);
if (opt.streetEN) 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
addressParts = [`${opt.address},`];
if (opt.moo) addressParts.push(`หมู่ ${opt.moo},`);
if (opt.soi) addressParts.push(`ซอย ${opt.soi},`);
if (opt.street) addressParts.push(`ถนน ${opt.street},`);