index.js 2.0 KB

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