index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='searchGood'>
  4. <view class='search acea-row row-between-wrapper'>
  5. <view class='input acea-row row-between-wrapper'>
  6. <text class='iconfont icon-sousuo'></text>
  7. <input type='text' v-model='searchValue' @confirm="inputConfirm" confirm-type="search" focus placeholder='点击搜索商品'
  8. placeholder-class='placeholder' @input="setValue"></input>
  9. </view>
  10. <view class='bnt' @tap='searchBut'>搜索</view>
  11. </view>
  12. <template v-if="history.length">
  13. <view class='title acea-row row-between-wrapper'>
  14. <view>搜索历史</view>
  15. <view class="iconfont icon-shanchu" @click="clear"></view>
  16. </view>
  17. <view class='list acea-row'>
  18. <block v-for="(item,index) in history" :key="index">
  19. <view class='item history-item line1' @tap='setHotSearchValue(item.keyword)' v-if="item.keyword">{{item.keyword}}</view>
  20. </block>
  21. </view>
  22. </template>
  23. <template v-if="hotSearchList.length">
  24. <view class='title'>热门搜索</view>
  25. <view class='list acea-row'>
  26. <block v-for="(item,index) in hotSearchList" :key="index">
  27. <view class='item line1' @tap='setHotSearchValue(item.val)' v-if="item.val">{{item.val}}</view>
  28. </block>
  29. </view>
  30. </template>
  31. </view>
  32. <home v-if="navigation"></home>
  33. </view>
  34. </template>
  35. <script>
  36. import home from '@/components/home/index.vue'
  37. import {
  38. searchList,
  39. clearSearch
  40. } from '@/api/api.js';
  41. import colors from "@/mixins/color";
  42. export default {
  43. components: {
  44. home
  45. },
  46. mixins: [colors],
  47. data() {
  48. return {
  49. searchValue: '',
  50. focus: true,
  51. hotSearchList: [],
  52. history: [],
  53. };
  54. },
  55. onShow: function() {
  56. uni.removeStorageSync('form_type_cart');
  57. this.searchList();
  58. try {
  59. this.hotSearchList = uni.getStorageSync('hotList');
  60. } catch (err) {}
  61. },
  62. methods: {
  63. searchList() {
  64. searchList({
  65. page: 1,
  66. limit: 10
  67. }).then(res => {
  68. this.history = res.data;
  69. });
  70. },
  71. clear() {
  72. let that = this;
  73. clearSearch().then(res => {
  74. uni.showToast({
  75. title: res.msg,
  76. success() {
  77. that.history = [];
  78. }
  79. });
  80. });
  81. },
  82. inputConfirm: function(event) {
  83. if (event.detail.value) {
  84. uni.hideKeyboard();
  85. this.setHotSearchValue(event.detail.value);
  86. }
  87. },
  88. setHotSearchValue: function(event) {
  89. uni.navigateTo({
  90. url: '/pages/goods/goods_list/index?title=默认&searchValue='+encodeURIComponent(event)
  91. });
  92. },
  93. setValue: function(event) {
  94. this.$set(this, 'searchValue', event.detail.value);
  95. },
  96. searchBut: function() {
  97. let that = this;
  98. that.focus = false;
  99. if (that.searchValue.length > 0) {
  100. uni.navigateTo({
  101. url:'/pages/goods/goods_list/index?title=默认&searchValue='+encodeURIComponent(that.searchValue)
  102. });
  103. } else {
  104. return this.$util.Tips({
  105. title: '请输入要搜索的商品',
  106. icon: 'none',
  107. duration: 1000,
  108. mask: true,
  109. });
  110. }
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. page {
  117. background-color: #fff !important;
  118. }
  119. .noCommodity{
  120. border-top-width: 0;
  121. }
  122. .searchGood .search {
  123. padding-left: 30rpx;
  124. }
  125. .searchGood .search {
  126. margin-top: 20rpx;
  127. }
  128. .searchGood .search .input {
  129. width: 598rpx;
  130. background-color: #f7f7f7;
  131. border-radius: 33rpx;
  132. padding: 0 35rpx;
  133. box-sizing: border-box;
  134. height: 66rpx;
  135. }
  136. .searchGood .search .input input {
  137. width: 472rpx;
  138. font-size: 28rpx;
  139. }
  140. .searchGood .search .input .placeholder {
  141. color: #999;
  142. }
  143. .searchGood .search .input .iconfont {
  144. color: #555;
  145. font-size: 35rpx;
  146. }
  147. .searchGood .search .bnt {
  148. width: 120rpx;
  149. text-align: center;
  150. height: 66rpx;
  151. line-height: 66rpx;
  152. font-size: 30rpx;
  153. color: #282828;
  154. }
  155. .searchGood .title {
  156. font-size: 28rpx;
  157. color: #999;
  158. margin: 50rpx 30rpx 25rpx 30rpx;
  159. }
  160. .searchGood .title .iconfont {
  161. font-size: 28rpx;
  162. }
  163. .searchGood .list {
  164. padding-left: 10rpx;
  165. }
  166. .searchGood .list .item {
  167. font-size: 26rpx;
  168. color: #454545;
  169. padding: 0 21rpx;
  170. height: 60rpx;
  171. border-radius: 3rpx;
  172. line-height: 60rpx;
  173. border: 1rpx solid #aaa;
  174. margin: 0 0 20rpx 20rpx;
  175. }
  176. .searchGood .list .item.history-item {
  177. height: 50rpx;
  178. border: none;
  179. border-radius: 25rpx;
  180. background-color: #F7F7F7;
  181. line-height: 50rpx;
  182. }
  183. .searchGood .line {
  184. border-bottom: 1rpx solid #eee;
  185. margin: 20rpx 30rpx 0 30rpx;
  186. }
  187. </style>