index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if (id == 'all') {
  40. id = null
  41. content = "是否清除全部记录"
  42. } else {
  43. content = "是否清除选中记录"
  44. }
  45. wx.showModal({
  46. title: title,
  47. content: content,
  48. success: (res) => {
  49. if (res.confirm) {
  50. wx.removeStorageSync("searchKey");
  51. showToast("删除成功");
  52. wx.navigateBack();
  53. }
  54. }
  55. })
  56. },
  57. // 搜索框输入值
  58. bindKeyInput(e) {
  59. this.data.searchVal = e.detail.value;
  60. },
  61. // 点击搜索记录
  62. selectMsg(e) {
  63. this.data.searchVal = e.currentTarget.dataset.value
  64. this.toSearchPage(1);
  65. },
  66. //搜索
  67. toSearchPage(type) {
  68. if (!this.data.searchVal) {
  69. showToast("请输入搜索内容");
  70. return;
  71. }
  72. if (type == 1) {
  73. } else {
  74. var key = {};
  75. key.id = this.data.searchKey.length;
  76. key.searchVal = this.data.searchVal;
  77. let searchKey = this.data.searchKey
  78. searchKey.push(key);
  79. wx.setStorageSync("searchKey", searchKey);
  80. }
  81. wx.navigateTo({
  82. url: '../search-result/search-result?searchVal=' + this.data.searchVal,
  83. })
  84. },
  85. })