import axios from 'axios'
import { reactive } from 'vue'
import { 
  getVrCityList,
  getPropertyList,
  getCompanyList
} from '../request/config'

const citys = reactive([])
export const getCitys = () => {
  return citys
}

const propertys = reactive([])
export const getPropertys = () => {
  return propertys
}

const companys = reactive([])
export const getCompanys = () => {
  return companys
}
export const getCompanyById = (qid) => {
  return companys.find(({id}) => id === qid)
}


const requestLists = () => {
  axios.post(getVrCityList, { currentPage: 1, pageSize: 999, keyword: '' })
    .then(res => {
      citys.length = 0
      res.data.records.forEach(city => {
        citys.push(city)
      })
    })
  
  axios.post(getPropertyList)
    .then(res => {
      propertys.length = 0
      res.data.forEach(property => {
        propertys.push(property)
      })
    })

    
  axios.post(getCompanyList)
    .then(res => {
      companys.length = 0
      res.data.forEach(property => {
        companys.push(property)
      })
    })
}

Promise.resolve().then(requestLists)