var t = getApp(),
 o = t.globalData.setting;


Component({
  properties: {
    // 这里定义了innerText属性，属性值可以在组件使用时指定
    object: {
      type: Object,
      value: null,
    },
    transparent: {
      type: Number,
      value: 0,
    },
    nav_backgroundColor: {
      type: String,
      value: '',
    },
  },
  data: {
    // 这里是一些组件内部数据
    yc:false,
    imghost: o.imghost,
    someData: {},
	first:1,
	inputShowed:1,
	inputval:'请输入商品关键字',
	keyword:'',
	
	searchRecord: [],
  },
  ready: function() {
	var th=this;  
    getApp().getConfig2(function(e) {
		//看有没有热搜
		if(e.hot_keywords)
		   th.setData({keyword:e.hot_keywords});
	})
	
	var arr=wx.getStorageSync('searchRecord') || [] //若无存储则为空
	
	this.setData({
	  searchRecord: arr
	});
	
  },
  
  
  pageLifetimes:{
    //要处理一下，游客登录后的界面的变化,主要还该是改变会员
    show: function () {
	   var th=this;
	   var arr=wx.getStorageSync('searchRecord') || [] //若无存储则为空	
       this.setData({
         searchRecord: arr,inputval:'',first:1,is_his:0
       });
    }
  },
  
  methods: {
    //智能跳转
    go_url:function (e) {
       var url=e.currentTarget.dataset.url;
       getApp().goto(url);
    },	
	click_sear:function(){
	  //如果搜索的单词为空的时候，就要跳到搜索页	
	  if(this.data.keyword!=''){
		  getApp().goto("/packageG/pages/goods/search/search");
		  return false;
	  }			
	  this.setData({first:0,inputShowed:1,inputval:''});
	   
	},		
	inputFocus:function(){	
		if(this.data.is_init) return false;
		this.setData({is_his:1,})
	},
	
	onblur:function(){		
		var th=this;
		setTimeout(function(){
			if(th.data.click_sear) return false;
			var val=th.data.inputval;
			if(val==''){
				th.setData({first:1,});
			}
			th.setData({is_his:0,})
		},300)	
	},	
	set_input:function(e){
		var val=e.detail.value;
		this.setData({inputval:val});
	},	
	sear:function(){
		var url="/packageG/pages/goods/search/search?s_key="+this.data.inputval;
		getApp().goto(url);
	},
	
	del_his:function(){
		this.setData({
		  searchRecord: []
		});		
		wx.setStorage({ key: 'searchRecord', data:[]});
	},
	
	sear_key:function(e){
		this.data.click_sear=1;
		var str=e.currentTarget.dataset.item;	
		var url="/packageG/pages/goods/search/search?s_key="+str;
		this.data.click_sear=0;
		getApp().goto(url);
		
	},
	
  }
})