index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {
  2. searchHistory,
  3. deleteHistory,
  4. getIndexList
  5. } from '../../services/index.js'
  6. import {
  7. showToast
  8. } from '../../utils/tips.js'
  9. import {
  10. updataStorageData
  11. } from '../../utils/storage.js'
  12. Page({
  13. data: {
  14. historyList: [],
  15. searchVal: '',
  16. searchKey: [],
  17. },
  18. onLoad: function(options) {
  19. },
  20. onShow: function() {
  21. this.fetchData()
  22. },
  23. //获取历史记录
  24. fetchData() {
  25. var searchKey = wx.getStorageSync("searchKey");
  26. console.log("ll", searchKey);
  27. if (searchKey) {
  28. this.setData({
  29. searchKey: searchKey
  30. })
  31. }
  32. },
  33. //删除历史记录
  34. delHistory(e) {
  35. console.log(e)
  36. let id = e.currentTarget.dataset.id
  37. let title = "删除提示"
  38. let content = "";
  39. content = "是否清除历史记录"
  40. wx.showModal({
  41. title: title,
  42. content: content,
  43. success: (res) => {
  44. if (res.confirm) {
  45. wx.removeStorageSync("searchKey");
  46. showToast("删除成功");
  47. this.onShow();
  48. }
  49. }
  50. })
  51. },
  52. // 搜索框输入值
  53. bindKeyInput(e) {
  54. this.data.searchVal = e.detail.value;
  55. },
  56. // 点击搜索记录
  57. selectMsg(e) {
  58. this.data.searchVal = e.currentTarget.dataset.value
  59. this.toSearchPage(1);
  60. },
  61. //搜索
  62. toSearchPage(type) {
  63. if (!this.data.searchVal) {
  64. showToast("请输入搜索内容");
  65. return;
  66. }
  67. if (type == 1) {
  68. } else {
  69. var key = {};
  70. key.id = this.data.searchKey.length;
  71. key.searchVal = this.data.searchVal;
  72. let searchKey = this.data.searchKey
  73. searchKey.push(key);
  74. wx.setStorageSync("searchKey", searchKey);
  75. }
  76. wx.navigateTo({
  77. url: '../search-result/search-result?searchVal=' + this.data.searchVal,
  78. })
  79. },
  80. })