import getLocationInfo from '../../utils/getLocationInfo';
import { connect } from 'herculex';
Component(connect({
  mapStateToProps: {
    hasTabBar: state => state.hasTabBar
  }
})({
  props: {
    tabbarInfo: {}
  },
  data: {
    tabbarHeight: 0,
    show: false
  },
  methods: {
    show(show) {
      my.createSelectorQuery().select('.tabbar-box').boundingClientRect().exec(ret => {
        this.setData({
          tabbarHeight: ret[0].height
        });
      });
      show = show === undefined ? true : show;
      this.setData({
        show
      });
    },

    onClose() {
      this.setData({
        show: false
      });
    },

    handleEnable() {
      getLocationInfo().then(() => {
        this.onClose();
        this.props.onGetLocation();
      }).catch(e => {
        // 处理app本身没开启定位, 模拟器跟真机code不一致
        if (e.error === 11) {
          my.showToast({
            content: e.errorMessage || '请开启定位权限'
          });
        }
      });
    }

  }
}));