function e(e, a, r) {
  return a in e ? Object.defineProperty(e, a, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[a] = r, e;
}   

var a = getApp(),
  r = a.globalData.setting,
  t = a.request,
  s = require("../../../../utils/common.js"),
  util = require("../../../../utils/util.js"),
  ut = util,
  d = getApp().globalData; 

var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
const {
  barcode,
  qrcode
} = require('../../../../utils/index.js');

Page({
  data: {
    phone: "",
    url: r.url,
    resourceUrl: r.resourceUrl,
    iurl: r.imghost,
    defaultAvatar: r.resourceUrl + "/static/images/user68.jpg",
    user: null,
    tc_hide: true,
    stoname: "",
    checkDate: false,
    datet: "",
    year: date.getFullYear(),
    store: 0,
    all_sto: "",
    region_name: "",
    def_pick_store: "",
    sort_store: 0, //门店分类
    sec_sto: "",
    more_store: 0, //选择门店
    choice_sort_store: 0, //选择分类门店
    more_store: 0, //选择门店
    lat: null, //维度
    lon: null, //经度
    fir_pick_index: 0,
    sec_pick_index: 0,
    is_gps: 1,
    is_no_plus:1,
    lon: 0,
    only_pk: 0,
    open_ind_store: 0, //哪里打开的门店列表的控制属性
    ispwhid: 1, //是否隐藏密码显示
    isstcsp: 0, //是否启用密码消费
    isGender: 1, //什么性别
    iscalendar: 0, //是否是农历
    consumption: "", //消费密码
    identity_card: "", //身份证值
    address: "", //地址
    openid: "", //openid
    pulscardname: "", //PLUS会员的卡
    gradename: "", //会员权益的卡
    isBool: "",
    sto_sele_id: "", //所属门店id
    is_zy: 0, //是否执行onshow
    is_lable_set: "", //是否启用我的兴趣标签
    check_label: [], //我选择的兴趣标签
    fir_guide_id:null,  //存储会员详情接口出来的美导ID

    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
    getusercode_vailtime:10,//会员二维码时效

    sele_ing:0,
    set_isstcsp:0,
    brcode:'',

    showvipcode:false,

     all_pick_list:null, //所有的门店的集合
     old_all_sto:null,
     keyword:'',  //搜索门店的关键字
     sec_i:-1
  },
  //通过路径跳转到其他页面
  goto: function(e) {
    this.data.is_zy=1; //避免页面重新加载
    var url = e.currentTarget.dataset.url;
    getApp().goto(url);
  },
  showtext:function(){
    this.setData({
      showvipcode:true
    })
  },
  //获取配置信息
  get_config: function() {
    var th = this;
    getApp().getConfig2(function(ee) {
      console.log('ee',ee);
      var sms_conf = ee.switch_list;
      sms_conf = JSON.parse(sms_conf);
        let reg_type = ee.reg_type;
        let reg_info =  ee.reg_info;
        var con_f={
            rank_switch:sms_conf.rank_switch,
            is_lable_set: sms_conf.user_label_set,  //是不是会员标签设置
            guide_title:sms_conf.guide_consultant,  //系统参数  导购标题
            guide_change_time:sms_conf.guide_change_time,     //每月能修改几次
        }
        if(reg_type) con_f.reg_info= JSON.parse(reg_info);
        th.setData(con_f)

      if (sms_conf.usercode_vailtime!=null && parseInt(sms_conf.usercode_vailtime)>0)                              
      {
        th.setData({ getusercode_vailtime: sms_conf.usercode_vailtime });
      }
      if (sms_conf.user_label_set) {
        th.query_checklabels();
      }
    },1)
  },
  //查找会员选择的兴趣标签
  query_checklabels: function() {
    var th = this;
    var url = "/api/weshop/marketing/holiday/vip/interest/label/get";
    var interest_lables = th.data.interest_lables; //兴趣标签
    getApp().request.promiseGet(url, {
      data: {
        userId: d.user_id,
        storeId: r.stoid
      }
    }).then(res => {
      if (res.data.code == 0) {
        var data = res.data.data;
        var VipLabel = th.data.check_label; //通过id标签找到已选择的标签
        var dateList = data.VipLabel.split(",");
        for (var i in dateList) {
          if (dateList[i] != "") {
            VipLabel.push(dateList[i]);
          }
        }
        th.setData({
          check_label: VipLabel
        })
      } else {
        getApp().my_warnning("系统繁忙，请稍后再试", 0, th);
      }
    })
  },
  //是否启动密码消费
  isstcsp: function() {
    var th = this;
    var isstcsp = th.data.isstcsp;
    if (isstcsp == 0) {
      th.setData({
        isstcsp: 1
      })
    } else {

      if(this.data.user.isVerification) {
            getApp().my_warnning("已设置消费需启用密码，无法取消", 0, th);
            return false;
        }

      th.setData({
        isstcsp: 0
      })
    }
  },
  //出生日期是否是农历
  iscalendar: function() {
	   
	if(this.data.user.birthday)  return false;	  
    var th = this;
    var iscalendar = th.data.iscalendar;
    if (iscalendar == 0) {
      th.setData({
        iscalendar: 1
      })
    } else {
      th.setData({
        iscalendar: 0
      })
    }
  },
  //性别
  isGender: function(e) {
    var th = this;
    var sex = e.currentTarget.dataset.sex;
    th.setData({
      isGender: sex
    })
  },
  //密码是否隐藏显示
  ispwhid: function() {
    var th = this;
    var ispwhid = th.data.ispwhid;

    if (ispwhid == 0) {
      th.setData({
        ispwhid: 1
      })
    } else {
      th.setData({
        ispwhid: 0
      })
    }
  },
  checkDate: function() {
    var th = this;
    if (th.data.checkDate) {
      th.setData({
        checkDate: false
      })
    } else {
      th.setData({
        checkDate: true
      })
    }
  },
  bindChange: function(e) {
    this.setData({
      datet: e.detail.value,
    });
  },
  //---点击二级之后的选择---
  choose_for_store: function(e) {
    var index_c = e.currentTarget.dataset.ind;

    this.setData({
      sec_pick_index: index_c,
      fir_pick_index: index_c
    })
  },
  //确定def_pick为选择的门店
  sure_pick: function(e) {
    var th = this;
    var item = null;
    var openindstore = th.data.open_ind_store;
    if (th.data.choice_sort_store == 0) {
      var index = th.data.fir_pick_index;
      if (th.data.is_show_sto_cat == 1) {
        item = th.data.def_pickpu_list[index];
      } else {
        item = th.data.only_pk?th.data.only_pk[index]:null; //当没有门店分类的时候
      }

    } else {
      var index = th.data.sec_pick_index;
      item = th.data.sec_sto.s_arr[index];
    }
    if(!item) return false;
    th.setData({
      def_pick_store: item,
      stoname: item.pickup_name,
      sto_sele_name: item.pickup_name,
      sto_sele_id: item.pickup_id,
      sto_sele_distr: item.distr_type,
      store: 0,
      choice_sort_store: 0,
      fir_pick_index: 0
    });

    if (openindstore == 1) {
      th.setData({
        openSpecModal: !0,
        openSpecModal_ind: openindstore,
      });
    } else if (openindstore == 2) {
      th.setData({
        openSpecModal: !0,
        openSpecModal_ind: openindstore,
        openSpecModal_pt: 1
      });
    }
  },
  choose_for_store_fir: function(e) {
    var index_c = e.currentTarget.dataset.ind;
    this.setData({
      fir_pick_index: index_c
    })
  },
  wait_for_store_config: function() {
    var th = this;
    wx.getLocation({
      type: 'gcj02',
      success: function(res) {
        th.data.lat = res.latitude;
        th.data.lon = res.longitude;
        th.data.is_get_local_ok = 1;
      },
      fail: function(res) {
        if (res.errCode == 2) {
          th.setData({
            is_gps: 0
          });
          if (th.data.is_gps == 0) {
            getApp().confirmBox("请开启GPS定位", null, 10000, !1);
          }
        } else {
          th.setData({
            is_gps: "3"
          });
        }
        th.data.is_get_local_ok = 1;
      }
    })
  },
  onclickstore: function() {
    var th = this;
    //检验门店的点击，看下次数是不是到了	
	this.check_click_ok(function(){
		if (th.data.store == 0) {
		  th.setData({
		    store: 1
		  })
		} else {
		  th.setData({
		    store: 0
		  })
		}
		var dd = {
		  store_id: r.stoid,
		  isstop: 0,
		  pageSize: 2000
		}
		th.setData({
		  sort_store: 0
		});
		var i = getApp().request;
		//如果有距离的话
		if (th.data.lat != null) {
		  dd.lat = th.data.lat;
		  dd.lon = th.data.lon;
		}
		//----------获取门店----------------
		getApp().request.get("/api/weshop/pickup/list", {
		  data: dd,
		  success:function(res){
			    var e = res;
			    if (e.data.code == 0) {
			      //-- 如果有默认选择门店的时候，要把默认门店放在第一位 --
			      if (th.data.def_pick_store) {
			        for (var k = 0; k < e.data.data.pageData.length; k++) {
			          if (e.data.data.pageData[k].pickup_id == th.data.def_pick_store.pickup_id) {
			            e.data.data.pageData.splice(k, 1); //删除
			            break;
			          }
			        }
			        e.data.data.pageData.splice(0, 0, th.data.def_pick_store); //添加
			      }


                   th.setData({
                        all_pick_list: e.data.data.pageData
                   });
			    		
			      //单总量超出5个的时候
			      if (e.data.data.total > 10) {
			        i.get("/api/weshop/storagecategory/page", {
			          data: {
			              store_id: r.stoid,
                          pageSize: 1000,
                          orderField:"sort",
                          orderType:'asc',
			          },
			          success: function(ee) {
			            if (ee.data.code == 0) {

                            var check_all_cate=0;
                            if (ee.data.data && ee.data.data.pageData && ee.data.data.pageData.length > 0){
                                for(let i in ee.data.data.pageData){
                                    let item=ee.data.data.pageData[i];
                                    if(item.is_show==1){
                                        check_all_cate=1;break
                                    }
                                }
                            }


			              if (check_all_cate) {

			                var sto_cate = ee.data.data.pageData;
			                var sto_arr = e.data.data.pageData;
			                var newarr = new Array();
			                var qita = new Array();

                            var is_del_pk=0;
			                //----要进行门店分组--------
			                for (var i = 0; i < sto_arr.length; i++) {
			                  //找一下这个门店有没有在分类数组内
			                  var find2 = 0, find2name = "",sort=0;
                              is_del_pk=0;
			                  for (var m = 0; m < sto_cate.length; m++) {
			                    if (sto_arr[i].category_id == sto_cate[m].cat_id) {
                                    if(sto_cate[m].is_show!=1){
                                        is_del_pk=1; sto_arr.splice(i,1);
                                        i--;
                                    }else {
                                        find2 = sto_cate[m].cat_id;
                                        find2name = sto_cate[m].cat_name;
                                        sort = sto_cate[m].sort;
                                        is_del_pk=0;
                                    }
			                      break;
			                    }
			                  }

                              if(is_del_pk) continue;
			                  if (newarr.length > 0) {
			                    var find = 0;
			                    //如果有找到，那门店就在这个分组内，否则，分类就要排在其他
			                    if (find2 != 0) {
			                      for (var ii = 0; ii < newarr.length; ii++) {
			                        if (sto_arr[i].category_id == newarr[ii].cat_id) {
			                          newarr[ii].s_arr.push(sto_arr[i]);
			                          find = 1;
			                          break;
			                        }
			                      }
			                      if (find == 0) {
			                        var arr0 = new Array();
			                        arr0.push(sto_arr[i]);
			                        var item = {
			                          cat_id: find2,
			                          name: find2name,
                                      sort:sort,
			                          s_arr: arr0
			                        };
			                        newarr.push(item);
			                      }
			                    } else {
			                      qita.push(sto_arr[i]);
			                    }
			                  } else {
			                    //如果有找到，那门店就在这个分组内，否则，分类就要排在其他
			                    if (find2 != 0) {
			                      var arr0 = new Array();
			                      arr0.push(sto_arr[i]);
			                      var item = {
			                        cat_id: find2,
			                        name: find2name,
                                    sort:sort,
			                        s_arr: arr0
			                      };
			                      newarr.push(item);
			                    } else {
			                      qita.push(sto_arr[i]);
			                    }
			                  }
			                }

                              var def_arr = new Array();
                              //-- 开始就看10个门店 --
                              for (var k = 0; k < 10; k++) {
                                  if (k == e.data.data.pageData.length) break;
                                  def_arr.push(e.data.data.pageData[k]);
                              }

                              th.setData({
                                  def_pickpu_list: def_arr,
                                  pickpu_list: ee.data.data.pageData
                              });

                            //门店分类要排序下
                            function compare(property){
                                  return function(a,b){
                                      var value1 = a[property];
                                      var value2 = b[property];
                                      return value1 - value2;
                                  }
                              }
                            if(newarr.length>0)
                                  newarr.sort(compare("sort"));
			    		
			                //----安排其他的分类-----
			                if (qita.length > 0) {
			                  var item = {
			                    cat_id: -1,
			                    name: "其他",
			                    s_arr: qita
			                  };
			                  newarr.push(item);
			                }
			                th.setData({
			                  is_show_sto_cat: 1,
			                  all_sto: newarr
			                });
			    		
			              } else {
			                th.setData({
			                  is_show_sto_cat: -1,
			                  only_pk: e.data.data.pageData
			                });
			              }
			            } else {
			              th.setData({
			                is_show_sto_cat: -1,
			                only_pk: e.data.data.pageData
			              });
			            }
			          }
			        });
			      } else {
			        th.setData({
			          is_show_sto_cat: 0,
			          only_pk: e.data.data.pageData
			        });
			      }
			    }
		  }	  
		})	 
						  
	},2)
	 
  },
  
  //选择更多门店
  more_store: function() {
    this.setData({
      sort_store: 1
    });
  },
  //---选择分类门店---
  choice_sort_store: function(e) {
    var index = e.currentTarget.dataset.index;
    var region_name = e.currentTarget.dataset.region;
    var item = this.data.all_sto[index];
    this.setData({
      region_name: region_name,
      sort_store: 0,
      choice_sort_store: 1,
      sec_sto: item,
      sec_pick_index: 0,
      sec_i: index,
    });
  },
  // 返回按钮
  returns: function() {
    this.setData({
      sort_store: 0,
      choice_sort_store: 0
    });
  },
  //身份证号严格校验
  IdentityIDCard: function(e) {
    var code = e.detail.value;
    //身份证号前两位代表区域
    var city = {
      11: "北京",
      12: "天津",
      13: "河北",
      14: "山西",
      15: "内蒙古",
      21: "辽宁",
      22: "吉林",
      23: "黑龙江 ",
      31: "上海",
      32: "江苏",
      33: "浙江",
      34: "安徽",
      35: "福建",
      36: "江西",
      37: "山东",
      41: "河南",
      42: "湖北 ",
      43: "湖南",
      44: "广东",
      45: "广西",
      46: "海南",
      50: "重庆",
      51: "四川",
      52: "贵州",
      53: "云南",
      54: "西藏 ",
      61: "陕西",
      62: "甘肃",
      63: "青海",
      64: "宁夏",
      65: "新疆",
      71: "台湾",
      81: "香港",
      82: "澳门",
      91: "国外 "
    };
    //身份证格式正则表达式
    var idCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
    var errorMess = ""; //错误提示信息
    var isPass = true; //身份证验证是否通过（true通过、false未通过）

    //如果身份证不满足格式正则表达式
    if (!code || !idCardReg.test(code)) {
      errorMess = "您输入的身份证号格式有误！";
      isPass = false;
    }

    //区域数组中不包含需验证的身份证前两位
    else if (!city[code.substr(0, 2)]) {
      errorMess = "您输入的身份证地址编码有误！";
      isPass = false;
    } else {
      //18位身份证需要验证最后一位校验位
      if (code.length == 18) {
        code = code.split('');
        //∑(ai×Wi)(mod 11)
        //加权因子
        var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
        //校验位
        var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
        var sum = 0;
        var ai = 0;
        var wi = 0;
        for (var i = 0; i < 17; i++) {
          ai = code[i];
          wi = factor[i];
          sum += ai * wi;
        }
        var last = parity[sum % 11];
        if (parity[sum % 11] != code[17]) {
          errorMess = "您输入的身份证号不存在！";
          isPass = false;
        }
      }
    }
    var returnParam = {
      'errorMess': errorMess,
      'isPass': isPass
    }
    if (errorMess != "") {
      wx.showModal({
        title: errorMess,
        content: '',
        showCancel: false,
        confirmText: '确定',
        confirmColor: '',
        success: function(res) {},
        fail: function(res) {},
        complete: function(res) {},
      })
    }
    return returnParam;
  },
  //------初始化加载----------
  onLoad: function(t) {
    let th= this;
    var user = getApp().globalData.userInfo;
    if (user.card_field != '' && user.card_field != null && user.card_field != undefined && user.card_expiredate) {
      var now = ut.gettimestamp();
      var str = user.card_expiredate.replace(/-/g, '/');;
      var end = new Date(str);
      end = Date.parse(end) / 1000;
      if (now < end) {
        this.puls_user();
      }
    }
    //调用接口判断商家plus有没有过期
    getApp().request.promiseGet("/store/storemoduleendtime/page?store_id=" + r.stoid + "&type=3", {}).then(res => {
      if (res.data.code == 0) {
          var arr = res.data.data.pageData;
          if (arr.length > 0) {
              var item = arr[0];
              if (item.is_sy == 0) {
                  var now = Date.parse(new Date()); now = now / 1000;
                  if (item.end_time < now) {
                      th.setData({ is_no_plus: 0 })
                  }
              }
          }
      }
  })
    this.initial_user();
    // 获取用户昵称
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
    //如果有指定要启用密码的时候
    if(t.isstcsp){
        this.setData({set_isstcsp:1,ispwhid:0});
    }

  },

  // 获取用户头像昵称
  getUserProfile(e) {
    var th = this;

    var ob={
        nickname:this.data.user.nickname,
        head_pic:this.data.user.head_pic,
    }
    getApp().globalData.up_nick_avatar=ob;
    getApp().goto('/packageE/pages/user/nick_avatar/nick_avatar');


    // new Promise((resolve, reject) => {
    //   wx.getUserProfile({
    //     desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
    //     success: (res) => {
    //       th.data.user.nickname = res.userInfo.nickName;
    //       th.data.user.head_pic = res.userInfo.avatarUrl;
    //       this.setData({
    //         userInfo: res.userInfo,
    //         hasUserInfo: true,
    //         user: th.data.user,
    //       });
    //       resolve(res.userInfo);
    //     },
    //
    //   });
    // }).then((userInfo) => {
    //   getApp().request.put("/api/weshop/users/update", {
    //     data: {
    //       storeId: r.stoid,
    //       user_id: getApp().globalData.user_id,
    //       nickname: userInfo.nickName,
    //       head_pic: userInfo.avatarUrl
    //
    //     },
    //     success: function(su) {
    //       if (su.data.code == 0) {
    //         console.log("update user info OK");
    //       }
    //     }
    //   });
    // });


  },


  //-----------会员是否初始化---------------------
  initial_user: function() {

    var th = this;
    getApp().request.get("/api/weshop/users/grade/vip/init/get", {
      data: {
        storeId: r.stoid,
      },
      success: function(su) {
        var isBool = su.data.data.isBool;
        th.setData({
          isBool: isBool
        });

        if (!isBool) return false;
        //-----会员权益获取--------------		
        getApp().request.get("/api/weshop/users/grade/aftervipinfo/get", {
          data: {
            storeId: r.stoid,
            userId: getApp().globalData.user_id,
          },
          success: function(su) {
            var gradename = su.data.data.GradeName;
            th.setData({
              gradename: gradename
            });
          }
        });

      }
    });
    this.get_config();
  },


  //-----Plus会员获取-----------
  puls_user: function() {
    var th = this;
    getApp().request.get("/api/weshop/plus/vip/mem/list", {
      data: {
        storeId: r.stoid,
        userId: getApp().globalData.user_id,
      },
      success: function(su) {

        if (su.data.code == 0) {
          var cardname = su.data.data[0].MemCardName;
          th.setData({
            pulscardname: cardname
          });
        }
      }
    });
  },

  onShow: function() {
    getApp().check_can_share();
    var e = this;

      //如果有传值进行跳转的话,
    var choice_guide=null;
    if(getApp().globalData.choice_guide){
          choice_guide=JSON.parse(JSON.stringify(getApp().globalData.choice_guide));
          getApp().globalData.choice_guide=null;
          let user=this.data.user;
          this.setData({
              'user.staffName':choice_guide.StaffName,
              'user.staffId':choice_guide.Id,
              'user.staffTel':choice_guide.Tel
          })
          return false;
    }

    if (this.data.is_zy){
      this.data.is_zy=0;
      return false;
    } 
    this.wait_for_store_config();



    var req = t;
    req.get("/api/weshop/users/getAndUpdateUser/" + r.stoid + "/" + getApp().globalData.user_id, {
      success: function(src) {
        var a = src.data.data;
	
		if(!a) a={};	
        var time ="",birthday =""; 
		 if(a && a.reg_time) time=util.formatTime(a.reg_time, "'Y/M/D");       
		 if(a && a.birthday) birthday=util.formatTime(a.birthday, "'Y/M/D");
		  
        a.reg_time = time;
        a.birthday = birthday

        if(a.address=='null' || !a.address){
          a.address="";
        }

        e.data.fir_guide_id=a.staffId;
        if(choice_guide){
          a.staffName=choice_guide.StaffName;
          a.staffId=choice_guide.Id;
          a.staffTel=choice_guide.Tel;
        }

        if(e.data.set_isstcsp){
            a.vipnopwd=1;
        }

        e.setData({
          phone: a.mobile,
          user: a,
          openid: a.openid,
          sto_sele_id: a.pickup_id,
          consumption: a.paypwd,
          identity_card: a.idcard,
          address: a.address,
          isGender: a.sex,
          isstcsp: a.vipnopwd,
		  iscalendar:a.islunar
        });

      }
    })


    a.getUserInfo(function(a) {
      var txt = util.formatTime(a.birthday, 'yyyy-M-d'),
        arr = txt.split(' ');
      a.birthday = arr[0];
      var txt2 = util.formatTime(a.reg_time, 'yyyy-M-d'),
        arr2 = txt.split(' ');
      a.reg_time = arr2[0];
      if (a.pickup_id != null) {
        req.get("/api/weshop/pickup/get/" + r.stoid + "/" + a.pickup_id, {
          success: function(da) {
            if(da.data.data){
              //设置门店
              e.setData({
                stoname: da.data.data.pickup_name
              });
            }

          }
        })
      }

    }, !0);
  },

  onHide:function (){
      this.data.sele_ing=0;
  },

  editUserInfo: function(e) {
    var r = e.currentTarget.dataset.type;
    if (("password" == r || "paypwd" == r) && !this.data.user.mobile) return a.showWarning("请先绑定手机号码");
    r && this.data.user && wx.navigateTo({
      url: "/pages/user/userinfo_edit/userinfo_edit?type=" + r
    });
  },

  /*--------------------修改头像---------------------*/
  changeAvatar: function() {
    return false;
    var r = this;
      getApp().globalData.no_clear=1;
    wx.chooseImage({
      count: 1,
      sizeType: ["compressed", "original"],
      sourceType: ["camera", "album"],
      success: function(u) {
        t.uploadFile(r.data.url + "/api/user/upload_headpic", {
          filePath: u.tempFilePaths[0],
          name: "head_pic",
          success: function(t) {
            var u = s.getFullUrl(t.data.result);
            r.setData(e({}, "user.head_pic", u)), a.globalData.userInfo.head_pic = u, a.showSuccess("设置头像成功");
          }
        });
      }
    });
  },



  //------卡片的显示和关闭--------
  show_tc: function() {
    var that=this;
    var req = t;
    if (!getApp().globalData.userInfo) return false;
    //base64_encode($user.mobile.'|'.date('Y-m-d H:i:s')
    var getnowtime;
    req.get("/api/weshop/users/getServerTime", {    
      success: function (res) {
        if (res.data.code == 0)
        {
          getnowtime=res.data.data;
          if (!getnowtime)
          {
            getApp().showWarning("获取服务时间失败");
            return;
          }
          //base64_encode($user.mobile.'|'.date('Y-m-d H:i:s')
          var val =  getApp().globalData.userInfo.mobile + "|" +getnowtime+"|"+that.data.getusercode_vailtime;

          val = "^" + ut.base64_encode(val);
          let userInfo = getApp().globalData.userInfo;
          qrcode('qrcode', val, 350, 350, that);
          barcode('barcode', userInfo.userQrcode, 480,140);
          that.setData({
            tc_hide: false,
            brcode:userInfo.userQrcode
          });
        }
      }
    })


  },
  hide_tc: function() {
    this.setData({
      tc_hide: true,
    });
  },
  //消费密码输入框失去焦点事件
  lose_focus: function(e) {
    var th = this;
    var val = e.detail.value;
      this.setData({
        consumption: val
    })
  },

  //地址
  address: function(e) {
    var val = e.detail;
    this.setData({
      address: val.value
    });
  },

  //身份证验证
  identity_card: function(e) {
    var val = e.detail;

    this.setData({
      identity_card: val.value
    });

  },
  //用户名字
  user_name: function(e) {
    var th = this;
    var name = e.detail.value;
    var vipname = 'user.vipname';
    if (name != "" || name != null) {
      th.setData({
        [vipname]: name
      });
    }

  },

  //点击确认修改信息
  confirm_revision: function() {
    var th = this;
    var isstcsp = th.data.isstcsp; //是否启用消费密码
    var phone = th.data.phone; //手机号码
    if (phone == "" || phone == null) {
      getApp().my_warnning("手机不能为空", 0, th);
      return false;
    }
    var consumption = th.data.consumption; //消费密码    
    var isstcsp = th.data.isstcsp;
    if (isstcsp == 1) {

      if (consumption == null || consumption == "" || consumption == undefined) {
        getApp().my_warnning("消费密码不能为空", 0, th);
        return false;
      }
      if (consumption.length < 6) {
        getApp().my_warnning("消费密码不能小于6位", 0, th);
        return false;
      }
    }
    var sex = th.data.isGender; //性别

    if (sex != "1" && sex != "2") {
      getApp().my_warnning("请选择性别", 0, th);
      return false;
    }
    var user_name = th.data.user.vipname; //用户姓名
    if (user_name == "" || user_name == null) {
      getApp().my_warnning("请输入名字", 0, th);
      return false;
    }
    var identity_card = th.data.identity_card; //身份证

    if (identity_card!=null && identity_card!=undefined &&  identity_card != "" && !(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(identity_card))) {
      getApp().my_warnning("身份证号码错误", 0, th);
      return false;
    }
    var address = th.data.address; //地址
    var sto_sele_id = th.data.sto_sele_id;
    var datas = {
      mobile: phone, //手机号码
      store_id: r.stoid,
      user_id: getApp().globalData.user_id,
      vipnopwd: isstcsp,
      //vippass: consumption, //消费密码
      sex: sex, //性别
      vipname: user_name, //昵称
      idcard: identity_card, //身份证
      address: address, //地址
      pickup_id: sto_sele_id ,//自提门店 所属门店
	  islunar:th.data.iscalendar,
	  birthday:th.data.datet  
    }

      if (isstcsp == 1) {
          datas.vippass=consumption;
      }


    //往上提交美导的ID
    if(th.data.fir_guide_id!=th.data.user.staffId){
      datas.staffId=th.data.user.staffId;
      datas.StaffName=th.data.user.staffName;
    }

    getApp().request.put("/api/weshop/users/updateUserInfo", {
      data: datas,
      success: function(res) {
        if (res.data.code == 0) {
          getApp().my_warnning("修改成功", 1, th);
		  getApp().goto("/pages/user/index/index");
        } else {
          getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
        }
      }
    })
  },
  //选择地址
  goto_address: function() {
    // this.setData({ is_zy: 1 });
  },
  //更换手机
  go_phone: function(e) {
    var url = e.currentTarget.dataset.url;
    this.setData({
      is_zy: 1
    });
    getApp().goto(url);
  },
  
  //--点击分享事件---
  onShareAppMessage: function(t) {
      getApp().globalData.no_clear=1;
	  return o.share;   
  },

  //-- 跳转到获取导购的列表 --
  go_get_guide:function () {
    let th=this;

    if(this.data.sele_ing) return false;
    this.data.sele_ing=1;
	  this.check_click_ok(function(){
       th.data.is_zy=1;
		   getApp().goto("/packageB/pages/user/choice_guide/choice_guide?is_back=1");

	  },1)	      
  },
  
  //点击门店，导购的次数判断, type 1=导购  2=门店
  check_click_ok:function(func,idx){	
	   var th=this;
	   var userId=getApp().globalData.user_id;
	   getApp().request.get("/api/weshop/users/getGuideNum/"+r.stoid+"/"+userId+"/"+idx, {
		    success: function(res) {
				if(res.data.code==0){
					func();
				}else{
					getApp().my_warnning(res.data.msg, 0, th);
				}
			}
	   });
  },

   //获取搜索门店输入的值
   input_store: function (e) {
    this.setData({
        keyword: e.detail.value
    })
   },

  //搜索门店
  searchfn() {
        let choice_sort_store = this.data.choice_sort_store
        if (choice_sort_store == 0) { //全局搜索
            let all_pick_list = this.data.all_pick_list
            let def_pickpu_list = this.data.def_pickpu_list
            let keyword = this.data.keyword
            if (keyword) {
                let arr = all_pick_list.filter(item => {
                    let i = item.pickup_name.indexOf(keyword)
                    if (i > -1) {
                        return true
                    } else {
                        return false
                    }
                })
                if (arr && arr.length > 0) {
                    if (this.data.is_show_sto_cat == 1) {
                        this.setData({
                            def_pickpu_list: arr
                        })
                    } else {
                        this.setData({
                            only_pk: arr
                        })
                    }
                } else {
                    wx.showToast({
                        title: '没有搜索到门店',
                        icon: 'none',
                        duration: 2000
                    })
                }
            } else {
                if (this.data.is_show_sto_cat == 1) {
                    this.setData({
                        def_pickpu_list: all_pick_list.slice(0, 10)
                    })
                } else {
                    this.setData({
                        only_pk: all_pick_list
                    })
                }

            }
        } else { //分类下搜索
            let sec_i = this.data.sec_i
            let all_sto = this.data.all_sto
            let old_all_sto = this.data.old_all_sto
            if (!old_all_sto) {
                this.setData({
                    old_all_sto:JSON.parse(JSON.stringify(all_sto))
                })
            }
            let sec_sto = this.data.sec_sto
            let sec_arr = this.data.old_all_sto[sec_i].s_arr
            let keyword = this.data.keyword
            let text = 'sec_sto.s_arr'
            if (keyword) {
                let arr = sec_arr.filter(item => {
                    let i = item.pickup_name.indexOf(keyword)
                    if (i > -1) {
                        return true
                    } else {
                        return false
                    }
                })
                if (arr && arr.length > 0) {
                    this.setData({
                        [text]: arr
                    })
                } else {
                    wx.showToast({
                        title: '没有搜索到门店',
                        icon: 'none',
                        duration: 2000
                    })
                }
            } else {
                if(this.data.old_all_sto){
                    this.setData({
                        [text]: this.data.old_all_sto[sec_i].s_arr
                    })
                }else{
                    this.setData({
                        [text]: all_sto[sec_i].s_arr
                    })
                }
            }


        }
    },


});