// pages/search/search.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { searchKeys: wx.getStorageSync('searchKeys') || [], loading: false, loadding: false, scrollTop: 0, current: 0, pages: null, picTitle: "", userInfo: wx.getStorageSync('userInfo'), goodsList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ searchKeys: wx.getStorageSync('searchKeys') || [], }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, asyncValue(e) { this.setData({ ["" + e.target.dataset.name]: e.detail.value }) }, async getGoodsList() { if (this.data.pages != null && this.data.current >= this.data.pages) { return; } this.setData({ current: this.data.current + 1, loadding: true }); try { let { data } = await app.ajax.get({ url: "/admin/bxdprod/browsePage", data: { picTitle: this.data.picTitle, mini: 1, current: this.data.current, size: 20, virtualInventoryId: wx.getStorageSync('virtualInventoryId') } }); let goodsList = this.data.goodsList.concat(data.data.records); goodsList = goodsList.map(v => { v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png'; return v; }); this.setData({ goodsList: goodsList, pages: data.data.pages || null, loadding: false }) } catch (e) { this.setData({ loadding: false }) } }, searchGoods(e) { let keys = e.currentTarget.dataset.name1 || this.data.picTitle; if (!keys) { return; } if (e.currentTarget.dataset.index == undefined) { let searchKeys = wx.getStorageSync('searchKeys') || []; if (keys.length <= 20) { searchKeys.push(keys); searchKeys = Array.from(new Set(searchKeys)) wx.setStorageSync('searchKeys', searchKeys); this.setData({ searchKeys: searchKeys }) } } this.setData({ picTitle: keys, goodsList: [], current: 0, pages: null, loading: true }) this.getGoodsList(); }, delHistory() { if (this.data.searchKeys.length == 0) { return; } let that = this; wx.showModal({ title: '提示', content: '您确定要删除搜索记录吗?', success(res) { if (res.confirm) { that.setData({ searchKeys: [] }) wx.setStorageSync('searchKeys', []) } else if (res.cancel) {} } }) }, cancelSearch() { this.setData({ picTitle: "", goodsList: [], current: 0, loading: false, pages: null }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() { } })