You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
834 B
39 lines
834 B
import {
|
|
getCities
|
|
} from './cities'
|
|
export default class Malls {
|
|
constructor() {
|
|
this.currentMall = null
|
|
this.malls = []
|
|
}
|
|
async init() {
|
|
const cities = await getCities()
|
|
this.malls = cities.map(({
|
|
name: city,
|
|
malls
|
|
}) => malls.map(({
|
|
name,
|
|
code
|
|
}) => ({
|
|
name,
|
|
code,
|
|
city
|
|
}))).reduce((acc, nxt) => acc.concat(nxt), [])
|
|
|
|
this.currentMall = this.malls[0]
|
|
}
|
|
async getCurrentMall() {
|
|
if (!this.malls.length || !this.currentMall)
|
|
await this.init()
|
|
return this.currentMall
|
|
}
|
|
async getMallByCode(code) {
|
|
if (!this.malls.length || !this.currentMall)
|
|
await this.init()
|
|
this.currentMall = this.malls.find((mall) => mall.code === code)
|
|
return this.currentMall
|
|
}
|
|
setCurrentMall(mall) {
|
|
this.currentMall = mall
|
|
}
|
|
}
|