index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view :data-theme="theme">
  3. <view class='searchGood'>
  4. <view class='search acea-row row-between-wrapper'>
  5. <!-- #ifndef MP -->
  6. <view class='input acea-row row-between-wrapper'>
  7. <text class='iconfont icon-sousuo2'></text>
  8. <input type='text' :value='searchValue'
  9. :focus="focus" placeholder='点击搜索商品'
  10. confirm-type='search' @confirm="searchBut"
  11. placeholder-class='placeholder' @input="setValue"
  12. maxlength="20"></input>
  13. </view>
  14. <view class='bnt' @tap='searchBut'>搜索</view>
  15. <!-- #endif -->
  16. <!-- #ifdef MP -->
  17. <searchBox :searchValue="searchValue" class="searchBox" @searchChange="searchBut"></searchBox>
  18. <!-- #endif -->
  19. </view>
  20. <!-- #ifdef MP -->
  21. <view class='title' :style="{'margin-top':searchTop+60+'px'}">热门搜索</view>
  22. <!-- #endif -->
  23. <!-- #ifndef MP -->
  24. <view class='title'>热门搜索</view>
  25. <!-- #endif -->
  26. <view class='list acea-row'>
  27. <block v-for="(item,index) in hotSearchList" :key="index">
  28. <view class='item' @tap='setHotSearchValue(item.title)'>{{item.title}}</view>
  29. </block>
  30. </view>
  31. <view class='line'></view>
  32. </view>
  33. <recommend ref="recommend"></recommend>
  34. </view>
  35. </template>
  36. <script>
  37. // +----------------------------------------------------------------------
  38. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  39. // +----------------------------------------------------------------------
  40. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  41. // +----------------------------------------------------------------------
  42. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  43. // +----------------------------------------------------------------------
  44. // | Author: CRMEB Team <admin@crmeb.com>
  45. // +----------------------------------------------------------------------
  46. import {
  47. getSearchKeyword,
  48. } from '@/api/product.js';
  49. import recommend from "@/components/base/recommend.vue";
  50. // #ifdef MP
  51. import searchBox from "@/components/searchBox.vue";
  52. // #endif
  53. let app = getApp();
  54. export default {
  55. components: {
  56. recommend,
  57. // #ifdef MP
  58. searchBox
  59. // #endif
  60. },
  61. data() {
  62. return {
  63. hostProduct: [],
  64. searchValue: '',
  65. focus: true,
  66. bastList: [],
  67. hotSearchList: [],
  68. first: 0,
  69. limit: 8,
  70. page: 1,
  71. loading: false,
  72. loadend: false,
  73. loadTitle: '加载更多',
  74. hotPage:1,
  75. isScroll:true,
  76. theme:app.globalData.theme,
  77. searchTop:''
  78. };
  79. },
  80. // 滚动监听
  81. onPageScroll(e) {
  82. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  83. uni.$emit('scroll');
  84. },
  85. onShow: function() {
  86. this.getRoutineHotSearch();
  87. },
  88. onLoad(e){
  89. // #ifdef MP
  90. this.searchTop=uni.getMenuButtonBoundingClientRect().top
  91. // #endif
  92. if(e.searchVal) this.searchValue = e.searchVal;
  93. },
  94. methods: {
  95. getRoutineHotSearch: function() {
  96. let that = this;
  97. getSearchKeyword().then(res => {
  98. that.$set(that, 'hotSearchList', res.data);
  99. });
  100. },
  101. setHotSearchValue: function(event) {
  102. this.$set(this, 'searchValue', event);
  103. this.page = 1;
  104. this.loadend = false;
  105. this.$set(this, 'bastList', []);
  106. uni.navigateTo({
  107. url: `/pages/goods/goods_list/index?searchValue=${this.searchValue}`
  108. })
  109. },
  110. setValue: function(event) {
  111. this.$set(this, 'searchValue', event.detail.value);
  112. },
  113. searchBut: function(e) {
  114. let that = this;
  115. let val = '';
  116. that.focus = false;
  117. if(e.detail.value){
  118. val =e.detail.value
  119. }
  120. if (that.searchValue.length > 0||val) {
  121. uni.navigateTo({
  122. url: `/pages/goods/goods_list/index?searchValue=${val?val:that.searchValue}`
  123. })
  124. } else {
  125. return this.$util.Tips({
  126. title: '请输入要搜索的商品',
  127. icon: 'none',
  128. duration: 1000,
  129. mask: true,
  130. });
  131. }
  132. }
  133. },
  134. onReachBottom() {
  135. this.$refs.recommend.get_host_product();
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. page {
  141. background-color: #f5f5f5 !important;
  142. }
  143. .searchGood .search {
  144. padding-left: 30rpx;
  145. background-color: #fff !important;
  146. }
  147. .searchGood .search {
  148. /* #ifndef MP */
  149. padding-top: 20rpx;
  150. padding-bottom: 20rpx;
  151. /* #endif */
  152. /* #ifdef MP */
  153. position: fixed;
  154. width: 100%;
  155. z-index: 9999;
  156. top: 0;
  157. /* #endif */
  158. }
  159. .searchGood .search .input {
  160. width: 598rpx;
  161. background-color: #f7f7f7;
  162. border-radius: 33rpx;
  163. padding: 0 35rpx;
  164. box-sizing: border-box;
  165. height: 66rpx;
  166. }
  167. .searchGood .search .input input {
  168. width: 472rpx;
  169. font-size: 26rpx;
  170. }
  171. .searchGood .search .input .placeholder {
  172. color: #bbb;
  173. }
  174. .searchGood .search .input .iconfont {
  175. color: #000;
  176. font-size: 35rpx;
  177. }
  178. .searchGood .search .bnt {
  179. width: 120rpx;
  180. text-align: center;
  181. height: 66rpx;
  182. line-height: 66rpx;
  183. font-size: 30rpx;
  184. color: #282828;
  185. }
  186. .searchGood .title {
  187. font-weight: 500;
  188. font-family: PingFang SC, PingFang SC;
  189. font-size: 28rpx;
  190. color: #333;
  191. margin: 50rpx 30rpx 25rpx 30rpx;
  192. }
  193. .searchGood .list {
  194. padding-left: 10rpx;
  195. }
  196. .searchGood .list .item {
  197. font-size: 26rpx;
  198. color: #454545;
  199. padding: 0 21rpx;
  200. height: 60rpx;
  201. border-radius: 30rpx;
  202. line-height: 60rpx;
  203. border: 1rpx solid #aaa;
  204. margin: 0 0 20rpx 20rpx;
  205. }
  206. .searchGood .line {
  207. margin: 20rpx 30rpx 0 30rpx;
  208. }
  209. .searchBox{
  210. width: 100%;
  211. }
  212. </style>