var a = getApp(),
  os = a.globalData.setting,
  util = require("../../../../utils/util.js"),
  ut = util;
Page({
  data: {
    url: os.url,
    iurl: os.imghost,
    total: 0, //数据的总量
    ismore: 0,//数据是否加载完毕
    page:1,
    pageSize:10,
    isload:0,
    show_pop:0,
    sele_item:null,
    input_val:null,

    is_back:0
  },
  //------初始化加载----------
  onLoad: function(t) {
       if(t.is_back){
           this.data.is_back=t.is_back
       }

  },

  onShow: function() {
    getApp().check_can_share();
    this.data.ismore=0;this.data.isload=0;
    this.setData({list:null});
    this.get_list();
  },

  //--点击分享事件---
  onShareAppMessage: function(t) {
      getApp().globalData.no_clear=1
	  return o.share;
  },
  get_list: function() {
    var th = this, e = th;
    var r_data={
      storeId: os.stoid,
      pickupId: a.globalData.userInfo.pickup_id,
      page: th.data.page,
      pageSize: th.data.pageSize
    };

    //关键字搜索
    if(this.data.input_val){
      r_data.KeyWord= encodeURIComponent(this.data.input_val);
    }

    getApp().request.promiseGet("/api/weshop/users/staff/page", {
      data:r_data
    }).then(res => {
      th.setData({isload:1});
      if(res.data.code==0 && res.data.data.pageData &&  res.data.data.pageData.length>0) {
        th.data.page++;//当前页数+1
        var arr1 = th.data.list;//获取明细数组
        var arr2 = res.data.data.pageData;//获取当前查询数据
        if(!arr1)	arr1=[];

        var arr3 = [...arr1, ...arr2];//把当前查询数组拼接到原本数组后面
        var ismore = 0;
        if (arr3.length == res.data.data.total) ismore = 1 //数据已加载完判断

        th.setData({
          list: arr3,
          total: res.data.data.total,
          ismore: ismore,
        })
      }
    })

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (this.data.total <= this.data.pageSize) return;
    if (this.data.ismore) {
      t.my_warnning("加载完啦!", 0, this);return
    };
    this.get_list();
  },

  //返回
  back:function () {
    wx.navigateBack({ delta: 1})
  },

  pop_sele:function (e) {
    var index=e.currentTarget.dataset.index;
    var item=this.data.list[index];
    this.setData({show_pop:1,sele_item:item});
  },
  close_pop:function () {
    this.setData({show_pop:0});
  },
  //选择了导购，就跳转到会员中心页面
  go_user_info:function () {
     var item=this.data.sele_item;
     getApp().globalData.choice_guide=item;

     if( this.data.is_back)
         wx.navigateBack({ delta: 1 })
     else
        getApp().goto("/packageG/pages/user/userinfo/userinfo");
  },

  img_err:function (e) {
      var txt=e.currentTarget.dataset.err_img;
      this.setData({[txt]:this.data.iurl+'/miniapp/images/no-head.jpg'});
  },

  get_input_val:function(e){
     var value=e.detail.value;
     this.data.input_val=value;
  },
  sear:function(){
    this.data.ismore=0;this.data.page=1;
    this.setData({isload:0});
    this.setData({list:null});
    this.get_list();
  }


  


});