feat: utils => format address
This commit is contained in:
parent
040f29aed9
commit
b03774957b
1 changed files with 56 additions and 0 deletions
56
src/utils/address.ts
Normal file
56
src/utils/address.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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(' ');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue