index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.setData({
  48. searchKey: []
  49. })
  50. }
  51. }
  52. })
  53. },
  54. // 搜索框输入值
  55. bindKeyInput(e) {
  56. this.data.searchVal = e.detail.value;
  57. },
  58. // 点击搜索记录
  59. selectMsg(e) {
  60. this.data.searchVal = e.currentTarget.dataset.value
  61. this.toSearchPage(1);
  62. },
  63. //搜索
  64. toSearchPage(type) {
  65. if (!this.data.searchVal) {
  66. showToast("请输入搜索内容");
  67. return;
  68. }
  69. if (type == 1) {
  70. } else {
  71. var key = {};
  72. key.id = this.data.searchKey.length;
  73. key.searchVal = this.data.searchVal;
  74. let searchKey = this.data.searchKey
  75. searchKey.push(key);
  76. wx.setStorageSync("searchKey", searchKey);
  77. }
  78. wx.navigateTo({
  79. url: '../search-result/search-result?searchVal=' + this.data.searchVal,
  80. })
  81. },
  82. })