index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="search">
  3. <page-navbar bgColor="#fff" title="门店搜索"></page-navbar>
  4. <view class="search-item">
  5. <u-search
  6. v-model="search_text"
  7. :clearabled="true"
  8. @custom="handlerSearchBtn"
  9. @search="handlerSearchBtn"
  10. :actionStyle="{ color: '#215EBE' }"
  11. />
  12. </view>
  13. <!-- 搜索历史 -->
  14. <view class="history" v-show="search_list.length != 0">
  15. <view class="history-top">
  16. <view class="title">搜索历史</view>
  17. <view class="history-right" @click="handlerAllSearchRecord">
  18. <u-icon name="trash" />
  19. </view>
  20. </view>
  21. <view class="label">
  22. <u-tag
  23. v-for="(item, index) of search_list"
  24. :key="index"
  25. :text="item.name"
  26. plain
  27. closable
  28. borderColor="#F5F6F8"
  29. :show="close2"
  30. color="#0C1223"
  31. bgColor="#F5F6F8"
  32. :closable="false"
  33. @close="handlerCloseSearchItem(item, index)"
  34. @click="handlerSelctHistItem(item)"
  35. />
  36. </view>
  37. </view>
  38. <!-- 热门搜索 -->
  39. <view class="history">
  40. <view class="history-top">
  41. <view class="title">热门搜索</view>
  42. </view>
  43. <view class="label">
  44. <u-tag
  45. v-for="(item, index) in popular_search_list"
  46. :text="item.name"
  47. :key="index"
  48. borderColor="#F5F6F8"
  49. :show="close2"
  50. :color="
  51. index == 0
  52. ? '#EB1010'
  53. : index == 1
  54. ? '#FF5219'
  55. : index == 2
  56. ? '#FDA50C'
  57. : '#0C1223'
  58. "
  59. bgColor="#F5F6F8"
  60. :closable="false"
  61. class="label-item"
  62. v-if="index < 8"
  63. @click="$u.route(`/pagesHome/marketer/index?id=${item.id}`)"
  64. />
  65. </view>
  66. </view>
  67. <view class="u-p-l-100 u-p-r-100">
  68. <u-divider text="猜你喜欢"></u-divider>
  69. </view>
  70. <!-- 列表 -->
  71. <view style="padding: 0 32rpx">
  72. <base-list
  73. :list="favorite_list"
  74. :boxShadow="boxShadow"
  75. @click="handleFavorite"
  76. ></base-list>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import { listHotMerchant, likeMerchant } from '@/api/client/home.js';
  82. import { mapGetters } from 'vuex';
  83. export default {
  84. data() {
  85. return {
  86. close2: true,
  87. boxShadow: '0rpx 0rpx 16rpx 0rpx rgba(0,0,0,0.12)',
  88. search_text: '', // 搜索text
  89. search_list: [], // 搜索列表
  90. popular_search_list: [], //热门搜索列表
  91. favorite_list: [], // 猜你喜欢列表
  92. };
  93. },
  94. computed: {
  95. ...mapGetters(['location']),
  96. },
  97. watch: {
  98. // 搜索历史 > 8 删除最后一项
  99. search_list(newValue) {
  100. if (newValue.length > 8) {
  101. this.search_list.splice(newValue.length - 1, 1);
  102. uni.setStorageSync('searchItem', this.search_list);
  103. }
  104. },
  105. },
  106. onShow() {
  107. this.search_text = '';
  108. if (uni.getStorageSync('searchItem')) {
  109. this.search_list = uni.getStorageSync('searchItem');
  110. }
  111. },
  112. mounted() {
  113. this.handlerInitList();
  114. },
  115. methods: {
  116. // 初始化热门搜索 猜你喜欢列表
  117. handlerInitList() {
  118. listHotMerchant({ ...this.location }).then(res => {
  119. this.popular_search_list = res.data;
  120. });
  121. // 猜你喜欢列表
  122. likeMerchant({ ...this.location }).then(res => {
  123. this.favorite_list = res.data;
  124. });
  125. },
  126. // 点击搜索按钮
  127. handlerSearchBtn() {
  128. let params = {
  129. name: this.search_text,
  130. };
  131. this.search_list.unshift(params);
  132. uni.setStorageSync('searchItem', this.search_list);
  133. uni.navigateTo({
  134. url: `/pagesHome/storeList/index?keyword=${this.search_text}`,
  135. });
  136. },
  137. // 删除搜索记录按钮
  138. handlerCloseSearchItem(item, index) {
  139. this.search_list.splice(index, 1);
  140. uni.setStorageSync('searchItem', this.search_list);
  141. },
  142. // 点击搜索历史按钮
  143. handlerSelctHistItem(item) {
  144. this.search_text = item.name;
  145. uni.navigateTo({
  146. url: `/pagesHome/storeList/index?keyword=${this.search_text}`,
  147. });
  148. },
  149. // 删除所有搜索记录按钮
  150. handlerAllSearchRecord() {
  151. uni.removeStorageSync('searchItem');
  152. this.search_list = [];
  153. },
  154. handleFavorite(item) {
  155. uni.$u.route(`/pagesHome/marketer/index?id=${item.id}`);
  156. },
  157. },
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .search {
  162. min-height: 100vh;
  163. background-color: #fff;
  164. }
  165. /* 搜索样式 */
  166. .search-item {
  167. display: flex;
  168. justify-content: space-between;
  169. align-items: center;
  170. padding: 0 20rpx;
  171. height: 80rpx;
  172. line-height: 80rpx;
  173. background-color: #fff;
  174. margin-bottom: 10rpx;
  175. .search-btn {
  176. width: 160rpx;
  177. height: 70rpx;
  178. font-size: 28rpx;
  179. line-height: 70rpx;
  180. }
  181. }
  182. /* 搜索历史样式 */
  183. .history {
  184. padding: 20rpx 30rpx;
  185. .history-top {
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. margin-bottom: 20rpx;
  190. .title {
  191. color: #0c1223;
  192. font-size: 30rpx;
  193. font-weight: bold;
  194. }
  195. .history-right {
  196. margin-top: 15rpx;
  197. display: flex;
  198. font-size: 12px;
  199. }
  200. }
  201. }
  202. .label {
  203. display: flex;
  204. flex-wrap: wrap;
  205. }
  206. .label-item {
  207. margin-bottom: 20rpx;
  208. }
  209. ::v-deep view.data-v-1481d46d,
  210. scroll-view.data-v-1481d46d,
  211. swiper-item.data-v-1481d46d {
  212. margin: 0 4rpx;
  213. }
  214. ::v-deep view.data-v-39e33bf2,
  215. scroll-view.data-v-39e33bf2,
  216. swiper-item.data-v-39e33bf2 {
  217. margin-bottom: 10rpx !important;
  218. }
  219. </style>