Search.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <home-base :show="false"><view class="div search-wrapper">
  3. <home-common-search :from="'search'" ref='header' :value="keywords"></home-common-search>
  4. <view class="div search-body">
  5. <view class="div list current-search" v-if='currenKeywords.length > 0'>
  6. <view class="div list-header">
  7. <text class="span">最近搜索</text>
  8. <image mode="aspectFit" class="img" src="../../../static/image/home/home-search-delete1.png" v-on:click='deleteCurrent()'>
  9. </view>
  10. <view class="ul">
  11. <view class="li item" v-for="(item, index) in currenKeywords" v-on:click='getKey(item)' :key="index">{{item}}</view>
  12. </view>
  13. </view>
  14. <view class="div list hot-wrapper" v-if="hotKeywords[0]">
  15. <view class="div list-header">
  16. <text class="span">热门搜索</text>
  17. </view>
  18. <view class="ul">
  19. <view class="li item" v-for='(item, index) in hotKeywords' :key='index' v-on:click='getKey(item)'>{{ item}}</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view></home-base>
  24. </template>
  25. <script>
  26. import {getFontSize} from '@/util/common'
  27. import HomeBase from '../HomeBase'
  28. import { mapState, mapMutations } from 'vuex'
  29. import HomeCommonSearch from '../common/HomeCommonSearch'
  30. import { searchKeywordList } from '../../../api/homesearch'
  31. export default {
  32. data () {
  33. return {
  34. hotKeywords: [],
  35. keywords: this.$store.state.homesearch.currentKey ? this.$store.state.homesearch.currentKey : ''
  36. }
  37. },
  38. components:{
  39. HomeBase,
  40. HomeCommonSearch
  41. },
  42. computed:{
  43. fontSize(){
  44. return getFontSize()
  45. },
  46. ...mapState({
  47. currentKey: state => state.homesearch.currentKey,
  48. currenKeywords: state => state.homesearch.currenKeywords
  49. })
  50. },
  51. created () {
  52. this.getHotKeywords()
  53. },
  54. methods: {
  55. ...mapMutations({
  56. 'changeKey': 'changeKey',
  57. 'saveKeywords': 'saveKeywords'
  58. }),
  59. getHotKeywords () {
  60. searchKeywordList().then(res => {
  61. this.hotKeywords = Object.assign([], res.result.list, this.hotKeywords)
  62. })
  63. },
  64. getKey (item) {
  65. if (item.content) {
  66. this.keywords = item.content
  67. } else {
  68. this.keywords = item
  69. }
  70. this.changeKey(this.keywords)
  71. this.$refs.header.goSearch(this.keywords)
  72. },
  73. deleteCurrent () {
  74. this.saveKeywords([])
  75. },
  76. }
  77. }
  78. </script>
  79. <style lang='scss' scoped>
  80. .search-wrapper{
  81. height: auto;
  82. width: auto;
  83. .search-body {
  84. .div.list {
  85. padding-top: 0.75rem;
  86. padding-bottom: 0.75rem;
  87. padding-left: $pageSpace;
  88. padding-right: $pageSpace;
  89. background-color: #fff;
  90. .list-header {
  91. display: flex;
  92. justify-content: space-between;
  93. align-content: center;
  94. align-items: center;
  95. .span {
  96. color: #333;
  97. font-size: $h3;
  98. background: url('../../../static/image/home/home-search-history.png') no-repeat left center;
  99. background-size: 0.8rem;
  100. padding-left: 1.25rem;
  101. align-self: flex-end;
  102. }
  103. .img {
  104. width: 1rem;
  105. height:1rem;
  106. cursor: pointer;
  107. }
  108. }
  109. .ul {
  110. display: flex;
  111. padding-top: 0.65rem;
  112. flex-wrap: wrap;
  113. .li {
  114. padding: 0.4rem;
  115. background-color: #F4F4F4;
  116. color: $descTextColor;
  117. font-size: $fontSize;
  118. margin-right: 0.8rem;
  119. margin-bottom: 0.8rem;
  120. border-radius:.2rem;
  121. }
  122. }
  123. }
  124. .div.hot-wrapper {
  125. .list-header{
  126. .span{
  127. background: url('../../../static/image/home/home-search-hot.png') no-repeat left center;
  128. background-size: 0.8rem;
  129. }
  130. }
  131. }
  132. }
  133. }
  134. </style>