var app = getApp();
var animation;
var $ = require('../../../js/util.js');
var is_first = 1;
Page({
  data: {
    param: {
      keyword: '',
      page: 1,
      no_auto_hide_toast: true//关闭自动隐藏弹窗
    },
    current_catid: 0,
    current_order: 0,
    current_childcatid: 'a',
    current_screen: [],
    current_brand: [],
    cate_list: [],
    list: [],
    order_list: [],
    screen_list: [],
    menuType: 0,
    isVisible: false,
    animationData: {},
    current_goods: {},//当前选中的商品
    count_total: 0,
    count_total_num: 0,
    showspec: false,
    speclist: {},
    optionslist: {},//临时存储规格参数
    no_num: [],//临时存储不可点击的规格
    current_spec: {},//临时存储当前选中规格
    location_n: '',
    add_address: false,
    hasMore: false,
    dataNull: true,
    show_q: false,
    temp_code: 0,
    is_shop_id: 0,//门店id
    brand_list: [],//品牌
    cate_img: true,
    total_page: 1,
    cate_show: 0, //二级展开
    cate_hieght: 0,
    menuLeft: '',
    shouhide: "true",
    pageX: '',
    blockWidth: '',
    parentLeft: '',
    is_getUserProfile:false,
    catename: '分类'
  },
  onLoad: function (options) {
    var self = this;
    self.setData({
      temp_code: app.globalData.temp_idcode,
    })
    self.pagecache('cate_list');//分类缓存
    self.pagecache('order_list');//排序缓存
    self.pagecache('screen_list');//筛选缓存
    self.pagecache('brand_list');//品牌缓存
    var cate_hieght = self.data.cate_hieght;
    var cate_list = self.data.cate_list;
    for (var i in cate_list) {
      if (cate_list[0].id) {
        if (cate_list[0].child > 0) {
          cate_hieght = 1;
        } else {
          cate_hieght = 0;
        }
        self.setData({
          cate_hieght: cate_hieght
        })
      }
    }
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
    if (options.screen_list) {
      self.setData({
        screen_list: options.screen_list,
      })
    }
    if (wx.getUserProfile){
      self.setData({
        is_getUserProfile:true
      })
    }
    var animation = wx.createAnimation({
      duration: 500,
      transformOrigin: "50% 50%",
      timingFunction: 'ease',
    })
    this.animation = animation;
    app.getUserInfo(function (ret) {
      if (!app.globalData.catid) {
        self.get_list();
      }

    });
  },
  pagecache: function (fiedname, cachename) {
    var self = this;
    if (!cachename) cachename = 'catch_' + fiedname;
    var ret = app.HCgetStorage(cachename);
    if (ret) { self.setData({ [fiedname]: ret }); }
  },
  changeData: function (data) {
    var self = this;
    var param = self.data.param;
    if (data) {
      param.keyword = data;
      param.page = 1;
      self.setData({
        param: param,
        current_catid: 'search'
      })
      self.get_list();
    }
  },
  onShow: function () {
    var self = this;
    var location_n = app.globalData.location_n;
    if (location_n) {
      self.setData({
        location_n: location_n
      });
    }
    self.setData({
      is_shop_id: app.globalData.HCshopid
    })
    var search_keyword = app.globalData.search_keyword;
    if (search_keyword) {
      var param = self.data.param;
      param.keyword = search_keyword;
      param.page = 1;
      self.setData({
        param: param,
        current_catid: 'search'
      })
    }
    if (app.globalData.HCshopid == 0) {
      self.setData({ add_address: true })
    } else {
      self.setData({ add_address: false })
      if ($.is_empty(self.data.cate_list)) self.get_list();
    }
    var cate_id = app.globalData.catid;
    if (cate_id) {
      var param = self.data.param;
      var current_catid = cate_id;
      param.catid = cate_id;
      param.page = 1;
      self.setData({
        param: param,
        current_catid: current_catid
      })
      self.get_list();
      app.globalData.catid = 0;
    }
    var screen_id = app.globalData.screen_list;
    var param = self.data.param;
    param.screen_order = screen_id;
    if (screen_id) {
      self.setData({
        param: param,
      })
      app.globalData.screen_list = 0;
    }
    var ret = app.HCgetStorage('catch_screen_list')
    if (ret) {
      for (var i in ret) {
        if (ret[i].screen_order == screen_id) {
          ret[i].checks = true;
        } else {
          ret[i].checks = false;
        }
      }
      self.setData({
        screen_list: ret
      })
    }

  },
  tolocation: function () {
    app.HCnavigateTo('../../location/location');
  },
  showMenuTap: function (e) {
    var menuType = e.currentTarget.dataset.type;
    var thismenuType = this.data.menuType;
    var self = this;
    if (self.data.isVisible == true && thismenuType == menuType) {
      self.startAnimation(false, -200, 0, function () {
        setTimeout(function () {
          self.setData({
            menuType: 0
          })
        }, 300);
      });
      return;
    }
    self.setData({
      menuType: menuType
    })
    self.startAnimation(true, 0, menuType);
  },
  hideMenuTap: function () {
    var self = this;
    self.startAnimation(false, -200, 0, function () {
      setTimeout(function () {
        self.setData({
          menuType: 0
        })
      }, 300);
    });
  },
  startAnimation: function (isShow, offset, menuType, cb) {
    var that = this
    var offsetTem
    if (offset == 0) {
      offsetTem = offset
    } else {
      offsetTem = offset + 'rpx'
    }
    this.animation.translateY(offset).step()
    this.setData({
      animationData: this.animation.export(),
      isVisible: isShow,
    })
    typeof cb == "function" && cb(true);
  },
  //下拉刷新
  onPullDownRefresh: function () {
    var param = this.data.param;
    param.page = 1;
    this.setData({
      page: 1,
      param: param,
      list: [],
      hasMore: false,
      dataNull: false
    });
    this.get_list();
  },
  get_list: function (type) {
    var self = this;
    app.showLoading('加载中...');
    if (self.data.list && self.data.param.page == 1) {
      self.setData({ list: [], hasMore: false, dataNull: true });
    }
    var action = 'c=Takeout&a=index';
    var param = self.data.param;
    param = $.ObjectToStr(self.data.param);
    var HCshopid = app.globalData.HCshopid;
    app.ajaxRequest(action, 'GET', param, function (ret) {
      // if (HCshopid == 0 && app.globalData.HCshopid > 0) {
      //   self.get_list(); return;
      // }
      app.hideLoading();//手动隐藏弹窗
      app.HCstopPullDownRefresh();

      if (ret.status == 1) {
        if (ret.data) {
          if (ret.data.init_list == '') { ret.data.init_list = new Object; }
          self.setData({ current_goods: ret.data.init_list });
          var brand_list = self.data.brand_list
          if (brand_list) {
            brand_list = brand_list;
          } else { brand_list = ret.data.brand_list; }
          self.setData({ brand_list: brand_list, });

          if (ret.data.brand_list) {
            app.HCsetStorage('catch_brand_list', ret.data.brand_list)
          }
          var is_empty = true;
          //self.count_total();
          if (ret.data.goods_list) {
            $.init_page_list(self, ret.data.goods_list);
          } else {
            $.init_page_empty_list(self, ret.msg);
          }
          self.setData({
            count_total_num: ret.cart_info.cart_num,
            count_total: ret.cart_info.cart_total_price,
            is_empty: is_empty,
            goods_count: ret.data.goods_count,
            total_page: ret.data.totalpage,
            temp_code: ret.temp_id,
            is_sell: ret.data.is_sell,
            catename: ret.data.catename
          });
          if (ret.data.catid) {
            self.setData({
              current_catid: ret.data.catid,
            })
          }
          if (ret.data.child_id) {
            self.setData({
              current_childcatid: ret.data.child_id,
            })
          }
          // if (self.data.current_catid==0){
          //   self.setData({
          //     current_catid:ret.data.catid,
          //     current_childcatid: ret.data.child_id
          //   })
          // }
          app.globalData.search_keyword = '';
        }
      } else if (ret.status == 2) {
        self.setData({
          catename: ret.data.catename,
          total_page: 0
        });
        $.init_page_empty_list(self, ret.msg);
      }
    }, true);
  },
  get_goods_price: function () {
    var self = this;
    var goods_id = new Array;
    var goods_list = self.data.list
    for (var i in goods_list) {
      goods_id.push(goods_list[i].id);
    }
    var postdata = new Object;
    postdata.goods_ids = goods_id;
    var action = 'c=Takeout&a=get_goods_price';
    var HCshopid = app.globalData.HCshopid;
    postdata.shop_id = HCshopid
    app.ajaxRequest(action, 'POST', postdata, function (ret) {
      if (ret.status == 1) {
        var goods_price_info = ret.data;
        for (var i in goods_price_info) {
          for (var j in goods_list) {
            if (goods_list[j].id == goods_price_info[i].id) {
              goods_list[j].shop_price = goods_price_info[i].shop_price;
              goods_list[j].sprice = goods_price_info[i].sprice;
            }
          }
        }
        self.setData({
          list: goods_list,
        });
      }
    }, true)
  },
  onReachBottom: function () {
    var self = this;
    var param = self.data.param;
    param.page++;
    self.setData({
      param: param
    });
    self.get_list();
  },
  changecate: function (event) {
    var self = this;
    var catid = event.currentTarget.dataset.id;
    var inx = event.currentTarget.dataset.inx;
    var param = this.data.param;
    self.setData({
      menuLeft: '0px',
    })
    if (inx == "search") {
      catid = 0;
    } else {
      param.keyword = '';
    }
    param.page = 1;
    param.catid = catid;
    param.childcatid = 0;
    this.setData({
      param: param,
      current_catid: catid,
      current_childcatid: 0,
      childcatid: 0,
      hasMore: false,
      dataNull: true,
      isRuleTrue: false,
      shouhide: false,
    });

    app.HCgetStorage('catch_goods_list_' + catid, function (ret) {
      //console.log('getcatch_goods_list_' + catid);
      //console.log(ret);
      if (ret) {
        self.setData({
          list: ret,
        })
      }
      self.get_list();

    });
    //this.get_list();
    var cate_list = self.data.cate_list;
    var cate_hieght = self.data.cate_hieght;
    for (var i in cate_list) {
      if (catid == cate_list[i].id) {
        if (cate_list[i].child > 0) {
          cate_hieght = 1;
        } else {
          cate_hieght = 0;
          this.hideMenuTap();
        }
        self.setData({
          cate_hieght: cate_hieght
        })
      }
    }
    this.hideMenuTap();
  },
  navCenter: function (self, event) {
    //获取索引
    var inxVal = event.target.dataset.inx;
    //获取父级
    var query = wx.createSelectorQuery();
    query.select('.table_menu').boundingClientRect();
    query.selectViewport().scrollOffset()//这段代码的意思是获取页面滑动位置的查询请求
    query.exec(function (res) {
      if (res[0] && res[0].width) {
        self.setData({
          pageX: res[0].width
          //  parentLeft: res[0].left
        })
      }
    })
    query.selectViewport().scrollOffset(function (res) {
      self.setData({
        parentLeft: res.scrollLeft
      })
    })

    wx.createSelectorQuery().selectAll('.table_menu .listChild').boundingClientRect(function (rect) {
      if (rect[0] && rect[0].left) {
        var offsetLeftN = rect[inxVal].left - rect[0].left;
        var moveX = offsetLeftN + self.data.parentLeft;;
        var blockWidth = rect[inxVal].width;
        var pageXNew = self.data.pageX;
        var left = moveX - (pageXNew / 2) + (blockWidth / 2);
        self.setData({
          menuLeft: left + 'px',
        })
      }
    }).exec()
  },
  changechildcate: function (event) {
    var self = this;
    var catid = event.currentTarget.dataset.id;
    var inx = event.currentTarget.dataset.inx;
    var pid = event.currentTarget.dataset.pid;
    var param = this.data.param;
    param.childcatid = catid;
    param.catid = pid;

    self.setData({
      param: param,
      current_childcatid: catid,
      isRuleTrue: false,
      shouhide: false,
      cate_show: 0
    });
    //点击导航居中
    this.navCenter(self, event);
    this.get_list();
    this.hideMenuTap();
  },
  changeorder: function (event) {
    var order = event.currentTarget.dataset.id;
    var inx = event.currentTarget.dataset.inx;
    var param = this.data.param;
    param.order = order;
    this.setData({
      param: param,
      current_order: inx
    });
    this.hideMenuTap();
    this.get_list();
  },
  changescreen: function (event) {
    var current_screen = this.data.current_screen;
    var id = event.currentTarget.dataset.id;
    var screen_list = this.data.screen_list;
    if ($.inArray(id, current_screen)) {
      current_screen.splice($.inArrayS(id, current_screen), 1);
    } else {
      current_screen.push(id);
    }
    for (var i in screen_list) {
      if ($.inArray(screen_list[i].screen_order, current_screen)) {
        screen_list[i].checks = true;
      } else {
        screen_list[i].checks = false;
      }
    }
    this.setData({
      screen_list: screen_list
    });
  },
  changebrand: function (event) {
    var current_brand = this.data.current_brand;
    var id = event.currentTarget.dataset.id;
    var brand_list = this.data.brand_list;
    if ($.inArray(id, current_brand)) {
      current_brand.splice($.inArrayS(id, current_brand), 1);
    } else {
      current_brand.push(id);
    }
    for (var i in brand_list) {
      if ($.inArray(brand_list[i].id, current_brand)) {
        brand_list[i].checks = true;
      } else {
        brand_list[i].checks = false;
      }
    }
    this.setData({
      brand_list: brand_list
    });
  },
  sub_screen: function () {
    var param = this.data.param;
    var current_screen = this.data.current_screen;
    var current_brand = this.data.current_brand;
    this.hideMenuTap();
    if (current_screen && current_screen.length > 0) {
      param.screen_order = current_screen.join(",");
    } else {
      delete param.screen_order;
    }
    if (current_brand && current_brand.length > 0) {
      param.brand_order = current_brand.join(",");
    } else {
      delete param.brand_order;
    }
    this.setData({
      param: param
    });
    this.get_list();
  },
  cancel_screen: function (event) {
    this.hideMenuTap();
  },
  //显示隐藏二级分类
  show_childcate: function (event) {
    var cate_img = this.data.cate_img;
    if (cate_img == true) {
      cate_img = false;
      this.setData({ cate_show: 1, })
    } else {
      cate_img = true;
      this.setData({ cate_show: 0, })
    }
    this.setData({
      cate_img: cate_img,
    })

  },
  //显示隐藏二级分类
  show_childcatex: function (event) {
    var self = this;
    var cate_show = self.data.cate_show;
    if (cate_show) {
      self.setData({
        isRuleTrue: false,
        shouhide: false,
        cate_show: 0
      })
    } else {
      self.setData({
        isRuleTrue: true,
        shouhide: true,
        cate_show: 1
      })
    }

  },

  add_cart: function (event) {
    var dataset = event.currentTarget.dataset;
    var current_goods = this.data.current_goods;
    var goods = dataset.id;
    var goods_number = new Object;
    var num = 1;
    var is_add = 1;
    var data = new Object;
    if (dataset.type == '+') {
      is_add = 1;
    } else if (dataset.type == '-') {
      is_add = 0;
    } else if (dataset.type == '=') {
      var value = event.detail.value;
      if (isNaN(value) || value <= 0) {
        num = 1;
      } else {
        num = event.detail.value;
      }
    }
    if (num > parseInt(goods.stock.goods_number)) {
      app.HCerror('提示', '库存不足', false); return;
    }
    data.goods_id = goods.id;
    data.num = num;
    data.is_add = is_add;
    var self = this;
    app.showLoading('加载中...');
    var action = 'c=Takeout&a=add_carts';
    app.ajaxRequest(action, 'POST', data, function (ret) {
      if (ret.status == 1) {
        if (current_goods[goods.id]) {
          current_goods[goods.id].num = ret.cart_num;
        } else {
          current_goods[goods.id] = data;
        }
        if (current_goods[goods.id].num == 0) {
          delete current_goods[goods.id];
        }
        self.setData({
          current_goods: current_goods,
          count_total_num: ret.cart_info.cart_num,
          count_total: ret.cart_info.cart_total_price
        });
      } else {
        app.HCerror('提示', ret.info, false);
      }
    }, true);
  },
  changespec: function (event) {
    var self = this;
    var data = event.currentTarget.dataset.id;
    var current_goods_price_show = $.formatmoney(data.shop_price);
    self.setData({
      showspec: true,
      speclist: data.format_spec.newarr,
      current_goods_id: data.id,
      current_goods_price: data.shop_price,
      current_goods_price_show: current_goods_price_show,
      current_goods_num: 1,
      combination: JSON.parse(data.format_spec.combination),
      combinationpricenum: data.format_spec.combinationpricenum,
      combinationprice: JSON.parse(data.format_spec.combinationprice),
      stock: data.stock
    });
  },
  hidespec: function () {
    this.setData({
      showspec: false,
      optionslist: {},
      no_num: []
    });
  },
  setoptions: function (event) {
    var self = this;
    var no_num = self.data.no_num;
    var data = event.currentTarget.dataset;
    var optionslist = self.data.optionslist;
    if (data) {
      if (!no_num[data.id.id]) {
        var current_spec = new Object;
        if (optionslist[data.inx] && optionslist[data.inx].id == data.id.id) {
          delete optionslist[data.inx];
        } else {
          optionslist[data.inx] = data.id;
          current_spec[data.inx] = data.id;
        }
        self.setData({
          optionslist: optionslist,
          current_spec: current_spec
        });
        self.checkspec();//使规格变灰色不能选中的方法
        self.count_total_spec();//计算带规格商品的价格
      }
    }
  },
  checkspec: function () {
    var self = this;
    var combination = self.data.combination;
    var speclist = self.data.speclist;
    //当前已经选中的规格
    var current_spec = self.data.current_spec;
    var check = new Object;//除了当前选中的本身之外都需要校验
    for (var i in speclist) {
      for (var j in current_spec) {
        if (i != j) {
          if (!check[i]) {
            check[i] = speclist[i];
          }
        }
      }
    }
    var checkarr = new Array;
    for (var i in current_spec) {
      checkarr.push(current_spec[i].id);
    }
    var no_num = new Object;
    for (var i in check) {
      for (var j in check[i].options) {
        var temparr = checkarr;
        var tempthisarr = new Array;
        tempthisarr.push(check[i].options[j].id);
        temparr = temparr.concat(tempthisarr);
        //判断当前组合是否存在
        var ischeck = true;
        for (var k in combination) {
          if ($.isContained(combination[k], temparr)) {
            ischeck = false; break;
          }
        }
        if (ischeck) {
          no_num[check[i].options[j].id] = check[i].options[j].id;
        }
      }
    }
    self.setData({
      no_num: no_num,
    });
    self.change_goods_spec('no_num');
  },
  change_goods_spec: function (event) {
    var self = this;
    if (event == 'no_num') {
      var types = '';
    } else {
      var types = event.currentTarget.dataset.type;
    }
    var current_goods_num = self.data.current_goods_num;
    var spec_data = new Object;
    var is_add = 1;
    //规格数量
    if (types == '+') {
      is_add = 1;
      current_goods_num = parseInt(current_goods_num) + 1;
    } else if (types == '-') {
      is_add = 0;
      if (parseInt(current_goods_num) > 1) {
        current_goods_num = parseInt(current_goods_num) - 1;
      }
    } else if (types == '=') {
      var value = event.detail.value;
      if (isNaN(value)) {
        current_goods_num = 1;
      } else {
        current_goods_num = value;
      }
    }
    //规格价格
    var optionslist = self.data.optionslist;
    var combinationprice = self.data.combinationprice;
    var combinationpricenum = self.data.combinationpricenum;
    var current_goods = self.data.current_goods;
    var current_goods_id = self.data.current_goods_id;
    var current_goods_price = parseFloat(self.data.current_goods_price) * parseFloat(current_goods_num);
    var current_goods_price_init = parseFloat(self.data.current_goods_price);
    var keyarr = new Array;
    var name = '';
    for (var i in optionslist) {
      keyarr.push(optionslist[i].id);
      name += optionslist[i].optionsval + ' ';
    }
    if ((keyarr.length == parseInt(combinationpricenum)) && parseInt(combinationpricenum) > 0) {//选完所有的规格属性
      keyarr = keyarr.sort();
      var key_str = keyarr.join("_");
      if (!current_goods[key_str]) {
        current_goods[key_str] = new Object;
        current_goods[key_str].id = current_goods_id;//商品id
        current_goods[key_str].num = 0;
        var format = new Object;
        format.key = key_str;
        format.name = name;
        current_goods[key_str].spec_format = format;
        // current_goods[key_str].price = current_goods_price_init + parseFloat(combinationprice[key_str].attr_price);
        current_goods[key_str].price = combinationprice[key_str] ? combinationprice[key_str].attr_price : 0;
      }
      current_goods_price = parseFloat(current_goods[key_str].price) * current_goods_num
    }
    //验证库存
    var is_start = true;
    if ((keyarr.length == parseInt(combinationpricenum)) && parseInt(combinationpricenum) > 0) {
      var stock = self.data.stock;
      if ((current_goods_num + parseInt(current_goods[key_str].num)) > parseInt(stock.goods_stock_number[key_str]) || parseInt(stock.goods_stock_number) == 0) {
        app.HCerror('提示', '【' + name + '】库存不足', false); return;
      }
      is_start = false;
    }
    if (types == 'submit') {
      if (is_start) {
        app.HCerror('提示', '请选择属性规格', false); return;
      }
      self.hidespec();

      current_goods[key_str].num = current_goods_num;

      var data = new Object;
      if (current_goods[key_str].id == current_goods_id) {
        data = current_goods[key_str];
        data.goods_id = current_goods[key_str].id;
        data.goods_attr = JSON.stringify(this.data.current_goods[key_str].spec_format);
        data.is_add = is_add;
      }
      var self = this;
      app.showLoading('加载中...');
      var action = 'c=Takeout&a=add_carts';
      app.ajaxRequest(action, 'POST', data, function (ret) {
        if (ret.status == 1) {
          self.setData({
            current_goods: current_goods,
            count_total_num: ret.cart_info.cart_num,
            count_total: ret.cart_info.cart_total_price
          });
        } else {
          app.HCerror('提示', ret.info, false);
        }
      }, true);
    }
    //end
    var current_goods_price_show = $.formatmoney(current_goods_price);
    self.setData({
      current_goods_price_show: current_goods_price_show,
      current_goods_num: current_goods_num
    });
    //self.count_total();
  },
  count_total_spec: function () {

  },
  count_total: function () {
    var current_goods = this.data.current_goods;
    var count_total = 0;
    var count_total_num = 0;
    for (var i in current_goods) {//检查清空当前无效的数据
      if (i == "") {
        delete current_goods[i];
      }
    }
    for (var i in current_goods) {
      var thisnum = parseInt(current_goods[i].num);
      count_total = count_total + parseInt(current_goods[i].price) * thisnum;
      count_total_num = count_total_num + thisnum;
    }
    count_total = $.formatmoney(count_total);
    this.setData({
      count_total: count_total,
      count_total_num: count_total_num
    });
  },
  gotoaddress: function () {
    app.HCnavigateTo('../../userinfo/add_address/add_address');
  },
  GotoCont: function (event) {
    // app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);

    var pt_id = event.currentTarget.dataset.pt_id;
    var pt_price = event.currentTarget.dataset.pt_price;
    var is_overdue = event.currentTarget.dataset.is_overdue;
    var is_ptdue = event.currentTarget.dataset.is_ptdue;

    if (pt_id > 0 && pt_price > 0 && is_ptdue == 0) {
      app.HCnavigateTo('../../../spellgroup/pages/fightgroup/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
    } else {
      app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
    }
  },
  GotoSearch: function () {
    var keyword = this.data.param.keyword ? this.data.param.keyword : '';
    app.HCnavigateTo('../../search/index?keyword=' + keyword);
  },
  ClearKeyword: function () {
    var self = this;
    var param = self.data.param;
    var current_catid = self.data.current_catid;
    if (current_catid == 'search') {
      current_catid = 0;
    }
    param.keyword = '';
    self.setData({
      param: param,
      current_catid: current_catid
    })
    self.get_list();
  },
  onShareAppMessage: function () {
    return {
      title: '商品',
      desc: '选择您心仪的宝贝!',
      path: '/' + $.getCurrentPageUrl() + '?invite_key=' + app.globalData.init_invite_key
    }
  },
  gotoCart: function () {
    app.HCswitchTab('../../buycart/index/index');
  },
  //获取用户信息授权
  bindGetUserInfo: function (e) {
    var self = this;
    if (wx.getUserProfile){
      wx.getUserProfile({
        desc:'用于完善会员资料',
        success:function(res){
          app.HCsetStorage('profile_Users', res.userInfo);
          app.HCsetStorage('profile_iv', res.iv);
          app.HCsetStorage('profile_encryptedData', res.encryptedData);
          app.getUserInfo(function (ret) {  
            self.setData({
              show_q: false,
              info: ret,
            })
            if ($.is_empty(ret.mobile) && e.detail.userInfo) {
              app.HCnavigateTo('../../login_accredit/login_accredit');
            }
          })
        }
      })
    }else{
      app.getUserInfo(function (ret) {
        self.setData({
          show_q: false,
          info: ret,
        })
        if ($.is_empty(ret.mobile) && e.detail.userInfo) {
          app.HCnavigateTo('../../login_accredit/login_accredit');
        }
      })
    }
  },
  //打开透明层
  showRule: function () {
    this.setData({
      isRuleTrue: true,
      shouhide: true
    })
  },
  //关闭透明层
  hideRule: function () {
    this.setData({
      isRuleTrue: false,
      shouhide: false,
      cate_show: 0
    })
  },
})