diy_searchbox.js
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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);
},
}
})