goodSearch.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="search">
  3. <uv-navbar title="搜索" placeholder @leftClick="goBack"></uv-navbar>
  4. <div class="search-box">
  5. <div class="search-wap">
  6. <text class="iconfont search-icon">&#xe618;</text>
  7. <input type="text" focus class="sput" placeholder-style="color: #999999;" confirm-type="search" v-model="inputValue" placeholder="请输入搜索内容" @confirm="goSearchConfirm" />
  8. </div>
  9. <div class="word" @click="goSearchConfirm">搜索</div>
  10. </div>
  11. <view class="record" v-if="recordList.length>0">
  12. <view class="record-top"> 历史记录 </view>
  13. <view class="record-flex">
  14. <view class="record-item" v-for="(item,index) in recordList" :key="index" @click="goProductList(item)">
  15. {{ item }}
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <view class="find">
  20. <view class="find-top"> 搜索发现 </view>
  21. <view class="find-flex">
  22. <view class="find-item" v-for="(item,index) in findList" :key="index" @click="goProductList(item.key_word)">
  23. {{ item.key_word }}
  24. </view>
  25. </view>
  26. </view> -->
  27. </view>
  28. </template>
  29. <script setup>
  30. import { ref } from 'vue'
  31. import { onShow } from '@dcloudio/uni-app'
  32. const recordList = ref([]);
  33. const inputValue = ref('');
  34. const goBack = () => {
  35. uni.navigateBack()
  36. }
  37. const historyRecored = () => {
  38. let word = inputValue.value;
  39. if (word != '') {
  40. let history = uni.getStorageSync("history");
  41. if (!history) {
  42. uni.setStorageSync("history", [word]);
  43. } else {
  44. let arr = uni.getStorageSync("history");
  45. let isHad = false;
  46. for (var i = 0; i < arr.length; i++) {
  47. if (arr[i] == word) {
  48. isHad = true;
  49. break;
  50. }
  51. }
  52. if (!isHad) {
  53. if (arr.length > 10) {
  54. arr.splice(9, 1);
  55. let pp = arr.concat([word]);
  56. uni.setStorageSync("history", pp);
  57. } else {
  58. history = history.concat([word]);
  59. uni.setStorageSync("history", history);
  60. }
  61. recordList.value = uni.getStorageSync("history").reverse();
  62. }
  63. }
  64. }
  65. }
  66. const goProductList = (text) => {
  67. // historyRecored()
  68. uni.navigateTo({
  69. url: "/pages/shop/goodsList?keyword=" + text,
  70. });
  71. }
  72. const goSearchConfirm = () => {
  73. uni.navigateTo({
  74. url: "/pages/shop/goodsList?keyword=" + inputValue.value,
  75. });
  76. }
  77. onShow(() => {
  78. if (uni.getStorageSync("history")) {
  79. recordList.value = uni.getStorageSync("history").reverse();
  80. }
  81. })
  82. </script>
  83. <style lang='scss' scoped>
  84. ::v-deep.hx-navbar__content__main_search_hxicon {
  85. span {
  86. font-size: 30rpx;
  87. }
  88. }
  89. .search-box {
  90. height: 85rpx;
  91. padding: 0 30rpx;
  92. // width: 100%;
  93. background-color: #fff;
  94. display: flex;
  95. // align-items: center;
  96. .search-wap {
  97. width: 600rpx;
  98. height: 60rpx;
  99. display: flex;
  100. align-items: center;
  101. background: #fff;
  102. border: 1px solid rgba(0, 0, 0, 0.42);
  103. border-radius: 30rpx;
  104. position: relative;
  105. ::v-deep .uni-input-input {
  106. color: #333333 !important;
  107. font-size: 26rpx;
  108. }
  109. .search-icon {
  110. font-size: 18px;
  111. margin-left: 30rpx;
  112. }
  113. .sput {
  114. margin-left: 25rpx;
  115. font-size: 22rpx;
  116. // color: #ffffff;
  117. width: 100%;
  118. }
  119. }
  120. .word {
  121. font-size: 28rpx;
  122. margin-left: 24rpx;
  123. line-height: 60rpx;
  124. }
  125. }
  126. .find {
  127. margin: 10rpx 30rpx 0 30rpx;
  128. .find-top {
  129. color: #1a1a1a;
  130. font-size: 32rpx;
  131. font-weight: 700;
  132. line-height: 28rpx;
  133. }
  134. .find-flex {
  135. display: flex;
  136. flex-wrap: wrap;
  137. margin-top: 20rpx;
  138. .find-item {
  139. color: #999999;
  140. font-size: 24rpx;
  141. font-weight: 400;
  142. line-height: 24rpx;
  143. padding: 18rpx 30rpx;
  144. background-color: #f5f5f5;
  145. border-radius: 36rpx;
  146. margin: 0 22rpx 32rpx 0;
  147. }
  148. }
  149. }
  150. .record {
  151. margin: 30rpx;
  152. .record-top {
  153. font-size: 32rpx;
  154. font-weight: 700;
  155. color: #1a1a1a;
  156. }
  157. .record-flex {
  158. display: flex;
  159. flex-wrap: wrap;
  160. margin-top: 30rpx;
  161. .record-item {
  162. margin: 0 22rpx 30rpx 0;
  163. padding: 20rpx 30rpx;
  164. color: #999999;
  165. font-size: 24rpx;
  166. font-weight: 400;
  167. background-color: #f5f5f5;
  168. line-height: 24rpx;
  169. border-radius: 36rpx;
  170. }
  171. }
  172. }
  173. </style>