{"size": 1494, "ext": "js", "max_stars_repo_path": "src/common/local.js", "max_stars_repo_name": "solace-lee/market_h5-v1.3", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/common/local.js", "max_issues_repo_name": "solace-lee/market_h5-v1.3", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/common/local.js", "max_forks_repo_name": "solace-lee/market_h5-v1.3", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.2105263158, "max_line_length": 87, "alphanum_fraction": 0.5522088353}
import api from "../http/api.js"
import { config } from "../../config-api"

const localName = function getAreaName(provinceId, cityId, districtId) {
  let localID = ''
  if (!provinceId) {
    return null
  } else if (!cityId) {
    localID = provinceId + "," + 0 + "," + 0
  } else if (!districtId) {
    localID = provinceId + "," + cityId + "," + 0
  } else {
    localID = provinceId + "," + cityId + "," + districtId
  }
  let area = {}
  return new Promise((resolve, reject) => {
    api.get(config.local + '/api/getAddressDetail?ids=' + localID)
      .then(res => {
        // area = res.data.data
        area.provinceName = res.data.data.Province.provinceName
        if (!cityId) {
          area.cityName = ''
        } else {
          area.cityName = res.data.data.city.cityName
        }
        if (!districtId) {
          area.districtName = ''
        } else {
          area.districtName = res.data.data.district.districtName
        }
        resolve(area)
      })
      .catch(err => {
        reject(err)
      })
  })
}

const localID = function getAreaID(provinceName, cityName, districtName, villageName) {
  let locals = provinceName + ',' + cityName + ',' + districtName
  let area = {}
  return new Promise((resolve, reject) => {
    api.get(config.local + '/api/getAddress?names=' + locals)
      .then(res => {
        area = res.data.data
        resolve(area)
      })
      .catch(err => {
        reject(err)
      })
  })
}


export {
  localName, localID
}