index.js 1.9 KB

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