// 内库使用-start
import Request from "./../../../../utils/Request";
// 内库使用-end

/* 测试使用-start
import { Request } from 'seedsui-react'
测试使用-end */

function loadStreets(districtId) {
  return new Promise(function (resolve) {
    var _window$districtStree;
    // 优先读取缓存
    window.districtStreets = window.districtStreets || JSON.parse(window.sessionStorage.getItem('districtStreets') || '{}');
    if ((_window$districtStree = window.districtStreets) !== null && _window$districtStree !== void 0 && _window$districtStree[districtId]) {
      resolve(window.districtStreets[districtId]);
      return;
    }

    // 加载语言对应的文件
    Request.post('https://url/getStreet.do', {
      districtId: districtId
    }, {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    }).then(function (list) {
      // 存到缓存中
      window.districtStreets = JSON.parse(window.sessionStorage.getItem('districtStreets') || '{}');
      window.districtStreets[districtId] = list || [];
      window.sessionStorage.setItem('districtStreets', JSON.stringify(window.districtStreets));
      resolve(window.districtStreets[districtId]);
    }).catch(function () {
      resolve('获取街道异常');
    });
  });
}
export default loadStreets;