海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
  1. <template>
  2. <view>
  3. <view class="lf-p-t-30 lf-p-r-30 lf-flex lf-w-100 lf-bg-white">
  4. <u-icon name="search" class="search-icon"></u-icon>
  5. <input class="rom-search" type="text" v-model="searchContent" @confirm="setSearch()" placeholder="请输入商品名称"/>
  6. </view>
  7. <view class="history-card" v-if="historySearch != ''">
  8. <view class="lf-font-28 lf-color-gray lf-p-b-30 lf-p-l-30">
  9. 历史搜索
  10. </view>
  11. <view class="lf-flex lf-flex-wrap lf-p-l-20 lf-p-r-20">
  12. <view class="search-tag" v-for="(i,index) of historySearch" :key="index" @click="gosearch(i)">{{i}}</view>
  13. </view>
  14. </view>
  15. <view class="history-card" v-else>
  16. <view class="lf-font-28 lf-color-gray lf-p-b-30 lf-p-l-30">
  17. 历史搜索
  18. </view>
  19. <view class="lf-flex lf-flex-wrap lf-p-l-30 lf-p-r-20">
  20. 暂无历史搜索记录
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. let list = []
  27. export default {
  28. data() {
  29. return {
  30. historySearch: [],
  31. searchContent: ''
  32. }
  33. },
  34. methods: {
  35. gosearch(i) {
  36. uni.navigateTo({
  37. url: '/pages/search/searchList?serach_content=' + i
  38. })
  39. },
  40. setSearch() {
  41. list.push(this.searchContent);
  42. list = [...new Set(list)];
  43. uni.navigateTo({
  44. url: '/pages/search/searchList?serach_content=' + this.searchContent
  45. })
  46. setTimeout(() => {
  47. this.historySearch = list
  48. uni.setStorageSync('historySearch',this.historySearch)
  49. },1000)
  50. }
  51. },
  52. onShow() {
  53. this.historySearch = uni.getStorageSync('historySearch') || [];
  54. console.log('初始',this.historySearch)
  55. }
  56. }
  57. </script>
  58. <style>
  59. page {
  60. background-color: #F8F8F8;
  61. }
  62. </style>
  63. <style lang="scss" scoped>
  64. .history-card {
  65. background-color: white;
  66. width: 100%;
  67. height: 100%;
  68. padding: 30rpx 0;
  69. }
  70. .search-tag {
  71. padding: 10rpx 20rpx;
  72. border-radius: 30rpx;
  73. background: #f5f5f5;
  74. color: #222;
  75. display: flex;
  76. align-items: center;
  77. text-align: center;
  78. width: max-content;
  79. height: max-content;
  80. font-size: 28rpx;
  81. margin-right: 20rpx;
  82. &:nth-child(5n) {
  83. margin-right: 0;
  84. }
  85. &:nth-child(n + 6) {
  86. margin-top: 20rpx;
  87. }
  88. }
  89. .search-icon {
  90. position: relative;
  91. bottom: 0;
  92. left: 54rpx;
  93. }
  94. /deep/.input-placeholder{
  95. color: #777;
  96. font-size: 28rpx;
  97. }
  98. .rom-search {
  99. width: 686rpx;
  100. height: 60rpx;
  101. background: #f5f5f5;
  102. border-radius: 30rpx;
  103. padding-left: 74rpx;
  104. font-size: 28rpx;
  105. }
  106. </style>