index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Page({
  2. data: {
  3. },
  4. onLoad: function (options) {
  5. this.setData({
  6. list: wx.getStorageSync('searchHis')
  7. })
  8. },
  9. onShow: function () {
  10. },
  11. search(e) {
  12. this.setData({
  13. inputVal: e.detail
  14. })
  15. if (e.detail) {
  16. let searchHis = wx.getStorageSync('searchHis')
  17. if (!searchHis) {
  18. searchHis = [e.detail]
  19. }
  20. if (!searchHis.includes(e.detail)) {
  21. searchHis.push(e.detail)
  22. }
  23. wx.setStorageSync('searchHis', searchHis)
  24. this.setData({
  25. list: searchHis
  26. })
  27. }
  28. wx.redirectTo({
  29. url: '/pages/goods/list?name=' + this.data.inputVal,
  30. })
  31. },
  32. onClose(e) {
  33. const idx = e.currentTarget.dataset.idx
  34. const searchHis = this.data.list
  35. searchHis.splice(idx, 1)
  36. wx.setStorageSync('searchHis', searchHis)
  37. this.setData({
  38. list: searchHis
  39. })
  40. },
  41. go(e) {
  42. const idx = e.currentTarget.dataset.idx
  43. const keywords = this.data.list[idx]
  44. wx.redirectTo({
  45. url: '/pages/goods/list?name=' + keywords,
  46. })
  47. }
  48. })