// pages/module_consult/consultsearch/consultsearch.js Page({ /** * 页面的初始数据 */ data: { focus: false, placeholder: '搜索', value: '', histroy: [], hotTopic: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, clearInput() { // @ts-ignore this.setData({ value: '', focus: true, result: [] }); // @ts-ignore this.triggerEvent('clear'); }, // @ts-ignore inputFocus(e) { // this.setData({ // searchState: true // }) // @ts-ignore this.triggerEvent('focus', e.detail); }, // @ts-ignore inputBlur(e) { this.setData({ focus: false }); this.triggerEvent('blur', e.detail); }, // @ts-ignore inputChange(e) { this.setData({ value: e.detail.value }); this.triggerEvent('input', e.detail); // if (Date.now() - this.lastSearch < this.data.throttle) { // return; // } if (typeof this.data.search !== 'function') { return; } this.lastSearch = Date.now(); this.timerId = setTimeout(() => { if (Date.now() - this.lastSearch < this.data.throttle) { return; } this.data.search(e.detail.value).then(json => { this.setData({ result: json }); }).catch(err => { console.error('search error', err); }); }, this.data.throttle); }, })