index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view>
  3. <navbar :iSimmersive="false" :placeholder="true" title="搜索"></navbar>
  4. <view class="search-wrap">
  5. <form @submit="onSubmit">
  6. <view class="field-box iconfont">
  7. <input type="text" class="uni-input" name="key" :value="value" placeholder="请输入关键字" />
  8. </view>
  9. <view class="field-btn">
  10. <button :disabled="isSubmit" plain form-type="submit">搜索</button>
  11. </view>
  12. </form>
  13. </view>
  14. <view class="search-host-list clear">
  15. <view class="host-list clear">
  16. <view class="title">热门搜索</view>
  17. <view class="list">
  18. <text v-for="(item,i) in keywords" :key="i" @click="onSearch(item)">{{ item }}</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import navbar from "@/components/navbar/navbar";
  26. export default {
  27. components: {
  28. navbar
  29. },
  30. data() {
  31. return {
  32. value:"",
  33. keywords:[],
  34. isSubmit: false
  35. };
  36. },
  37. onLoad() {
  38. this.$http.getSearchKeywords().then((result)=>{
  39. if(result.status){
  40. this.keywords = result.data;
  41. }
  42. });
  43. },
  44. methods: {
  45. onSubmit(e){
  46. let formData = e.detail.value;
  47. uni.navigateTo({
  48. url: `/pages/search/list?keywords=${formData.key}`
  49. });
  50. },
  51. onSearch(val){
  52. if(typeof val == 'string'){
  53. this.value = val;
  54. }
  55. uni.navigateTo({
  56. url: `/pages/search/list?keywords=${val}`
  57. });
  58. }
  59. },
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .search-wrap{
  64. width: 100%;
  65. height: 90rpx;
  66. border-top: 1px solid #ddd;
  67. background: #fff;
  68. .field-box {
  69. position: relative;
  70. z-index: 1;
  71. input{
  72. width: 610rpx;
  73. float: left;
  74. height: 64rpx;
  75. line-height: 64rpx;
  76. border:1px solid #bfbfbf;
  77. border-radius: 15rpx;
  78. background-color: #fff;
  79. position: relative;
  80. top: 12rpx;
  81. left: 20rpx;
  82. text-indent: 70rpx;
  83. font-size: 26rpx;
  84. color: #333;
  85. }
  86. &::before {
  87. z-index: 10;
  88. position: absolute;
  89. content: "\e629";
  90. left: 40rpx;
  91. top: 25rpx;
  92. font-size: 38rpx;
  93. color: #aaa;
  94. }
  95. }
  96. .field-btn {
  97. button {
  98. float: right;
  99. background-color: #fff;
  100. border: none;
  101. font-size: 28rpx;
  102. width: 110rpx;
  103. height: 64rpx;
  104. line-height: 64rpx;
  105. position: relative;
  106. top: 12rpx;
  107. }
  108. }
  109. }
  110. .search-host-list {
  111. width: 100%; margin-top: 10px;
  112. height: auto !important;
  113. height: 100px; min-height: 100px;
  114. padding: 10px 0;
  115. background-color: #fff;
  116. .host-list{
  117. .title{
  118. float: left;
  119. color: #666;
  120. font-size: 16px;
  121. width: 100%;
  122. height: 45px;
  123. line-height: 45px;
  124. text-indent: 10px;
  125. }
  126. .list{
  127. text {
  128. font-size: 14px;
  129. padding: 5px 10px;
  130. background-color: #f1f1f1;
  131. color: #333;
  132. margin: 5px 10px;
  133. border-radius: 10px;
  134. float: left;
  135. }
  136. }
  137. }
  138. }
  139. </style>