index.js 1.9 KB

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