// pages/search/search.js const apiServer = require('../../api/request'); Page({ /** * 页面的初始数据 */ data: { list: [], inputValue: null, resultList:[ // { // title:'AppL', // subtitle:"APPL INC", // Increase:"1.22", // digital:"33", // data:[52,56,355,444] // }, // { // title:'AppL', // subtitle:"APPL INC", // Increase:"1.22", // digital:"33", // data:[52,56,355,44554] // }, ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.hotSearch(); var _this = this; wx.getStorage({ key: 'historySearch', success(res) { _this.setData({ list: res.data }) } }) }, blur: function (e) { this.setData({ inputValue: e.detail.value }) this.search(); }, search:function(){ let data ={ searchParam:this.data.inputValue }; apiServer.getSearch(data).then((res) =>{ if(res.statusCode == 200){ this.setData({ resultList:res.data.data } ) }else{ wx.showToast({ title: '搜索失败', icon: 'none' }) } }) }, hotSearch: function(){ apiServer.hotSearch().then((res)=>{ if(res.statusCode == 200){ this.setData({ hotList:res.data.data }) } }) }, save: function () { var list = this.data.list; if (list.indexOf(this.data.inputValue) == -1 & this.data.inputValue != '') { list.push(this.data.inputValue); } this.setData({ list: list }) wx.setStorage({ key: 'historySearch', data: list }) }, searchName: function (e) { this.setData({ inputValue: e.currentTarget.dataset.value }) this.search(); }, hotName:function(e){ console.log(e); this.setData({ inputValue: e.currentTarget.dataset.value.plateName }) this.search(); }, remove: function () { var _this = this; wx.showModal({ title: '提示', content: '确认清空所有记录?', success(res) { if (res.confirm) { wx.removeStorage({ key: 'historySearch', success() { _this.setData({ list: [] }) } }) } else if (res.cancel) { console.log('用户点击取消') } } }) }, clean:function(){ var _this=this setTimeout(function () { _this.setData({ inputValue: '', }) },100) }, detail:function(e){ console.log(e); this.save(); wx.navigateTo({ url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row) }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, })