/**
 * 打开地图，查看位置
 * @param param 参数
 * @returns 查看Promise
 * @example
 * ```ts
 * openLocationInMp({
 *   lat,
 *   lng,
 *   name,
 *   address,
 * });
 * ```
 */
function openLocationInMp(_ref) {
  var _ref$lat = _ref.lat,
    lat = _ref$lat === void 0 ? '' : _ref$lat,
    _ref$lng = _ref.lng,
    lng = _ref$lng === void 0 ? '' : _ref$lng,
    _ref$name = _ref.name,
    name = _ref$name === void 0 ? '' : _ref$name,
    _ref$address = _ref.address,
    address = _ref$address === void 0 ? '' : _ref$address,
    _ref$scale = _ref.scale,
    scale = _ref$scale === void 0 ? 18 : _ref$scale;
  return new Promise(function (resolve, reject) {
    uni.openLocation({
      latitude: +lat,
      longitude: +lng,
      name: name,
      address: address,
      scale: scale,
      success: function success(res) {
        console.log('打开地图成功');
        resolve(res);
      },
      fail: function fail(err) {
        console.log('打开地图失败', err);
        reject(err);
      }
    });
  });
}
/**
 * 打开地图，查看位置
 * @param param 参数
 * @returns 查看Promise
 * @example
 * ```ts
 * openLocationInH5({
 *   lat,
 *   lng,
 *   name,
 *   address,
 *
 *   context: this,
 *   route: '/map'
 * });
 * ```
 */
function openLocationInH5(_ref2) {
  var _ref2$lat = _ref2.lat,
    lat = _ref2$lat === void 0 ? '' : _ref2$lat,
    _ref2$lng = _ref2.lng,
    lng = _ref2$lng === void 0 ? '' : _ref2$lng,
    _ref2$name = _ref2.name,
    name = _ref2$name === void 0 ? '' : _ref2$name,
    _ref2$address = _ref2.address,
    address = _ref2$address === void 0 ? '' : _ref2$address,
    route = _ref2.route,
    context = _ref2.context;
  var href = getOpenLocationUrl({
    lat: lat,
    lng: lng,
    name: name,
    address: address
  });
  if (route && context) {
    context.$router.push({
      path: route,
      query: {
        url: decodeURIComponent(href)
      }
    });
    return Promise.resolve(1);
  }
  window.location.href = href;
  return Promise.resolve(1);
}
function getOpenLocationUrl(_ref3) {
  var _ref3$lat = _ref3.lat,
    lat = _ref3$lat === void 0 ? '' : _ref3$lat,
    _ref3$lng = _ref3.lng,
    lng = _ref3$lng === void 0 ? '' : _ref3$lng,
    _ref3$name = _ref3.name,
    name = _ref3$name === void 0 ? '' : _ref3$name,
    _ref3$address = _ref3.address,
    address = _ref3$address === void 0 ? '' : _ref3$address;
  var href = "https://apis.map.qq.com/uri/v1/marker?marker=coord:".concat(lat, ",").concat(lng, ";title:").concat(name, ";addr:").concat(address, "&referer=tip");
  return href;
}

export { getOpenLocationUrl, openLocationInH5, openLocationInMp };
