brandSearch.js
2.29 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
import { getYHStorageSync } from '../../utils/util';
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
/**
* 组件的属性列表
* 用于组件自定义设置
*/
properties: {
all_list: {
type: Object,
value: {},
},
hotKeyword: {
type: Object,
value: {},
}
},
/**
* 私有数据,组件的初始数据
* 可用于模版渲染
*/
data: {
result: [],
showResult: false,
hasResult: false,
searchHistory: [],
},
ready: function () {
let searchHistory = getYHStorageSync('searchHistory', 'brandSearch') ? getYHStorageSync('searchHistory','brandSearch') : [];
this.setData({
searchHistory,
});
},
/**
* 组件的方法列表
* 更新属性和数据的方法与更新页面数据的方法类似
*/
methods: {
//搜索框文字改变
inputChanged: function (event) {
let text = event.detail.value;
text = text.toLowerCase();
if (text) {
let all_list = this.properties.all_list;
let hasResult = false;
let result = [];
for (let item of all_list) {
let list = item.list;
list && list.map((value, key) => {
let name = value.name.toLowerCase();
if (name.includes(text)) {
result.push(value);
hasResult = true;
}
})
}
this.setData({
hasResult,
showResult: true,
result,
})
}else {
this.setData({
hasResult: false,
showResult: false,
result: {},
})
}
},
brandItemTapped: function(event) {
let that = this;
let brandItem = event.currentTarget.dataset.brandItem;
wx.navigateTo({
url: './brandDetail?brandId=' + brandItem.id + '&brandName=' + brandItem.name,
success: function(res) {
that.triggerEvent('dismissSearchView', {});
}
})
},
//搜索框获取焦点焦点
focusChanged: function (event) {
// console.log('focusChanged')
},
//搜索框键盘点击确定
inputConfirmed: function (event) {
// console.log('inputConfirmed')
},
cancelSearch: function (event) {
},
}
})