// components/dkbase/dk-navbar/dk-navbar.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
      navbarTitle:{
        type: String,
        value: 'dk自定义头部导航'
      },
      leftArrow:{
        type: Boolean,
        value: true
      },
      operateShow:{
        type: Boolean,
        value: true
      },
      navigationStyle: {
        type: String,
        value: ''
      },
      titleFontColor: {
        type: String,
        value: '#000000'
      },
      fixed:{
        type: Boolean,
        value: false
      },
      operateUrl:{
        type: String,
        value: ''
      },
      customStyle:{
        type: String,
        value: ''
      }
    },

    /**
     * 组件的初始数据
     */
    data: {
      paddingTopNum: wx.getSystemInfoSync().statusBarHeight+7
    },
    lifetimes: {
      attached: function() {
        // 在组件实例进入页面节点树时执行
        this.getHeight()
      },
      detached: function() {
        // 在组件实例被从页面节点树移除时执行
      },
    },
    /**
     * 组件的方法列表
     */
    methods: {
      /**
       * 获取自定义组件高度并向上抛出
       * @author 刘尧
       */
      getHeight(){
        let that = this
        let query = wx.createSelectorQuery().in(this);
        query.select('.van-nav-bar').boundingClientRect(function (rect) {
          that.triggerEvent('getNavbarHeight', rect);
        }).exec()
      },
      clickLeft(e){
        this.triggerEvent('clickBack', {
          value: e
        })
      },
      operateClick(e){
        let url = this.data.operateUrl
        let toUrl = null;
        if (url) {
          // 看下是否包括http,http就跳转到product页面
          if (url.indexOf('http') >= 0) {
            toUrl = '/pages/product/product'
          } else {
            // 说明是跳本产品
            toUrl = url;
          }
          wx.navigateTo({
            url: toUrl,
            success: function (res) {
              res.eventChannel.emit('url', url);
            }
          })
        }
      }
    }
})