search.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="search">
  3. <view class="search-item">
  4. <u-search v-model="search_text" :clearabled="true" @custom="handlerSearchBtn" />
  5. <!-- <button class="search-btn" @click="handlerSearchBtn">搜索</button> -->
  6. </view>
  7. <!-- 搜索历史 -->
  8. <view class="history">
  9. <view class="history-top">
  10. <hotCom>搜索历史</hotCom>
  11. <view class="history-right" @click="handlerAllSearchRecord">
  12. <u-icon name="trash" />
  13. <text>删除记录</text>
  14. </view>
  15. </view>
  16. <view class="label">
  17. <u-tag
  18. v-for="(item, index) of search_list"
  19. :key="index"
  20. :text="item.name"
  21. plain
  22. closable
  23. :show="close2"
  24. @close="handlerCloseSearchItem(item, index)"
  25. />
  26. </view>
  27. </view>
  28. <!-- 热门搜索 -->
  29. <view class="history">
  30. <view class="history-top">
  31. <text class="hotCom">热门搜索</text>
  32. </view>
  33. <view class="label">
  34. <u-tag
  35. v-for="(item, index) in favourite_list"
  36. :text="item.name"
  37. :key="index"
  38. class="label-item"
  39. @click="$Router.push(`/pages/client/clientPackage/storeDetail?id=${item.id}`)"
  40. />
  41. </view>
  42. </view>
  43. <u-divider text="猜你喜欢"></u-divider>
  44. <!-- 列表 -->
  45. <view class="popular-box">
  46. <view
  47. class="hot"
  48. v-for="(item, index) of popular_search_list"
  49. :key="index"
  50. @click="$Router.push(`/pages/client/clientPackage/storeDetail?id=${item.id}`)"
  51. >
  52. <Image src="https://cdn.uviewui.com/uview/album/1.jpg"></Image>
  53. <view>
  54. <view class="item-text">{{ item.name }}</view>
  55. <view class="item-flex">
  56. <view class="star">
  57. <u-rate :count="count" :value="item.score" readonly />
  58. <text class="line">|</text>
  59. </view>
  60. <view>{{ item.goodReview }}单</view>
  61. </view>
  62. <view class="address-flex">
  63. <view>{{ item.address }}</view>
  64. <view>2.7km</view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { listHotMerchant, likeMerchant } from '@/api/client/home.js';
  73. export default {
  74. data() {
  75. return {
  76. count: 5,
  77. value: 4,
  78. close2: true,
  79. radios: [
  80. {
  81. checked: true,
  82. },
  83. ],
  84. checkboxs: [
  85. {
  86. checked: true,
  87. },
  88. ],
  89. search_text: '', // 搜索text
  90. search_list: [], // 搜索列表
  91. popular_search_list: [], //热门搜索列表
  92. favourite_list: [], // 猜你喜欢列表
  93. };
  94. },
  95. onShow() {
  96. if (uni.getStorageSync('searchItem')) {
  97. this.search_list = uni.getStorageSync('searchItem');
  98. }
  99. },
  100. mounted() {
  101. this.handlerInitList();
  102. },
  103. methods: {
  104. // 初始化热门搜索 猜你喜欢列表
  105. handlerInitList() {
  106. listHotMerchant().then(res => {
  107. this.popular_search_list = res.data;
  108. });
  109. // 猜你喜欢列表
  110. likeMerchant().then(res => {
  111. this.favourite_list = res.data;
  112. });
  113. },
  114. // 点击搜索按钮
  115. handlerSearchBtn() {
  116. if (!this.search_text) {
  117. uni.showToast({
  118. title: '请输入您要搜索的关键字',
  119. icon: 'none',
  120. });
  121. return;
  122. } else {
  123. let params = {
  124. name: this.search_text,
  125. };
  126. this.search_list.push(params);
  127. uni.setStorageSync('searchItem', this.search_list);
  128. this.search_text = '';
  129. }
  130. },
  131. // 删除搜索记录按钮
  132. handlerCloseSearchItem(item, index) {
  133. this.search_list.splice(index, 1);
  134. uni.setStorageSync('searchItem', this.search_list);
  135. },
  136. // 删除所有搜索记录按钮
  137. handlerAllSearchRecord() {
  138. uni.removeStorageSync('searchItem');
  139. this.search_list = [];
  140. },
  141. },
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .search {
  146. min-height: 100vh;
  147. background-color: #fff;
  148. }
  149. /* 搜索样式 */
  150. .search-item {
  151. display: flex;
  152. justify-content: space-between;
  153. align-items: center;
  154. padding: 0 20rpx;
  155. height: 80rpx;
  156. line-height: 80rpx;
  157. background-color: #fff;
  158. margin-bottom: 10rpx;
  159. .search-btn {
  160. width: 160rpx;
  161. height: 70rpx;
  162. font-size: 28rpx;
  163. line-height: 70rpx;
  164. }
  165. }
  166. /* 搜索历史样式 */
  167. .history {
  168. padding: 30rpx;
  169. margin-bottom: 10rpx;
  170. .history-top {
  171. display: flex;
  172. justify-content: space-between;
  173. margin-bottom: 20rpx;
  174. .history-right {
  175. margin-top: 15rpx;
  176. display: flex;
  177. font-size: 12px;
  178. }
  179. hotCom {
  180. font-size: 15px;
  181. font-weight: bold;
  182. color: #404045;
  183. }
  184. }
  185. }
  186. .label {
  187. display: flex;
  188. flex-wrap: wrap;
  189. }
  190. // 列表
  191. .hot {
  192. height: 220rpx;
  193. background-color: #fff;
  194. padding: 0 20rpx;
  195. margin-bottom: 20rpx;
  196. display: flex;
  197. Image {
  198. width: 120px;
  199. height: calc(100% - 20rpx);
  200. margin: 10rpx 20rpx 10rpx 0;
  201. }
  202. .item-text {
  203. font-weight: bold;
  204. margin: 10rpx 0 10rpx;
  205. color: #333;
  206. }
  207. .item-flex {
  208. display: flex;
  209. justify-content: space-between;
  210. font-size: 14px;
  211. margin: 0 20rpx 30rpx 0;
  212. color: #0d0d0d66;
  213. .star {
  214. display: flex;
  215. .line {
  216. margin-left: 18rpx;
  217. margin-top: 5rpx;
  218. font-size: 24rpx;
  219. }
  220. }
  221. }
  222. .address-flex {
  223. display: flex;
  224. justify-content: space-between;
  225. font-size: 12px;
  226. color: #999;
  227. margin-right: 20rpx;
  228. }
  229. }
  230. ::v-deep view.data-v-1481d46d,
  231. scroll-view.data-v-1481d46d,
  232. swiper-item.data-v-1481d46d {
  233. margin: 0 4rpx;
  234. }
  235. </style>