// components/diy_top_nav/diy_top_nav.js
const app = getApp();
var os = app.globalData.setting;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    nav_type:{
      type:Number,
      value:0,
    },
    istop:{
      type:Number,
      value:0,
    },
    nav_title:{
      type:String,
      value:'首页',
    },
    nav_frontColor:{
      type:String,
      value:'#000',
    },
    nav_backgroundColor:{
      type:String,
      value:'#ffffff',
    },
    is_share:{
      type:Boolean,
      value:true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imghots: os.imghost,
    nav_h:0, //导航胶囊上面状态栏的高度
    mentButt_h:0,//导航胶囊高度
    navleft_pb:0, //导航左边的自定义内容的左右内边距
    nav_left_w:281,  // 导航左边自定义的内容宽度
    navleft_w:0,   //左边胶囊宽度
    nav_pb:0,  // 导航的下内边距  
    show_menu:false,//详情页导航下拉菜单显示
    men_list:[
      {
        name:'首页',
        img:'miniapp/js_img/goods_info/home.png?v=3',
        url:'/pages/index/index/index' 
      },
      {
        name:'我的订单',
         img:'miniapp/js_img/goods_info/order.png?v=3',
        url:'/pages/user/order_list/order_list' 
      },
      {
        name:'我的收藏',
         img:'miniapp/js_img/goods_info/collect.png?v=3',
        url:'/packageB/pages/user/collect_list/collect_list' 
      },
      // {
      //   name:'浏览足迹',
      //   img:'',
      //   url:'' 
      // },
    ],
    is_pc:0
  },
  lifetimes:{
    attached:function(){

       var is_pc=getApp().globalData.is_pc;
       if(!is_pc) {

        //满屏顶部导航参数获取-----------
        try {
          let systemInfo = wx.getSystemInfoSync()
          let mentButt = wx.getMenuButtonBoundingClientRect()
          let nav_pb = mentButt.top - systemInfo.statusBarHeight
          let navleft_pb = systemInfo.windowWidth - mentButt.right

          let user_no = '';
          if (getApp().globalData.userInfo) {
            user_no = getApp().globalData.userInfo.erpvipno
          }

          this.setData({
            nav_h: mentButt.top,
            mentButt_h: mentButt.height,
            nav_left_w: mentButt.left,
            navleft_pb,
            nav_pb,
            navleft_w: mentButt.width * 0.9,
            user_no
          })
        } catch (e) {
          console.error(e);
          wx.showToast({
            title: '系统参数获取失败',
            icon: 'none',
            duration: 2000
          })
          // this.setData({
          //   is_full_screen_navigation:false
          // })
          // Do something when catch error
        }
      }else{
          this.setData({is_pc:1});
       }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    nav_menu(e){
      let url=e.currentTarget.dataset.url
      getApp().goto(url)
    },
    show_menu_fn(){
      this.setData({
        show_menu:!this.data.show_menu
      })
    },
    hide_menu_fn(){
      this.setData({
        show_menu:false
      })
    },
    //分享
    fenx_fn(){
      this.triggerEvent('clickShare')
    },
    call_back(){
      wx.navigateBack({
        delta:1,
        fail:()=>{
          wx.reLaunch({
            url: '/pages/index/index/index',
          })
        }
      })
    },
    nav_search(){
      getApp().goto('/packageG/pages/goods/search/search')
    }
  }
})
