var app = getApp();
var $ = require('../../js/util.js');
Page({
  data: {
    list: [],//数据
    page: 1,//当前页码
    param: {},
    list_none:[],
    true_count:0,
    none_count:0,
    shop_id:0,
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true,//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    app.HCsetNavigationBarTitle('附近');
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onReady: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      //获取定位信息
      app.showLoading('加载中...');
      app.HCgetlocation(function (ret) {
        self.setData({
          param: {
            lng: ret.longitude,
            lat: ret.latitude
          }
        });
        self.getData();
      });
    });
   
  },
  //加载数据
  getData: function () {
    var self = this;
    var HCshopid = app.globalData.HCshopid;
    app.showLoading('加载中...');
    var action = 'c=Nearby&a=nearby';
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      if (ret.status == 1) {
        if (ret.data.true_list){
          var is_check=false;
          for (var i in ret.data.true_list){
            if (ret.data.true_list[i].id == HCshopid){
              ret.data.true_list[i].is_check=true;
            }else{
              ret.data.true_list[i].is_check = false;
            }
          }
        }
       self.setData({
         list:ret.data.true_list,
         list_none:ret.data.false_list,
         true_count:ret.data.true_count,
         none_count:ret.data.false_count,
       })
      }else{
        app.HCerror('提示', ret.msg, false);
      }
    },true);
  },
  call:function(event){
    var mobile = event.currentTarget.dataset.id;
    if (mobile){
      app.HCmakePhoneCall(mobile);
    }else{
      app.HCerror('提示','暂无联系方式',false);
    }
  },
  call_shop: function (event) {
    app.HCmakePhoneCall(event.currentTarget.dataset.call);
  },
  onShareAppMessage: function () {
    return {
      title: '附近',
      desc: '查看附近门店',
      path: '/' + $.getCurrentPageUrl() + '?invite_key=' + app.globalData.init_invite_key
    }
  },
  goToMap: function (event) {
    var data = event.currentTarget.dataset.id;
    app.HCviewlocation(data);
  },
  goToShop:function(event){
    var shop_id = event.currentTarget.dataset.shopid;
    app.globalData.HCshopid = shop_id;
    //console.log(app.globalData.HCshopid);
    app.HCswitchTab('../index/index');
  }
});