You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
5.9 KiB

3 months ago
  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. <goodList :bastList="bastList" v-if="bastList.length > 0"></goodList>
  33. <view class='loadingicon acea-row row-center-wrapper' v-if="bastList.length > 0">
  34. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  35. </view>
  36. </view>
  37. <view class='noCommodity'>
  38. <view class='pictrue' v-if="bastList.length == 0 && isbastList">
  39. <image :src="urlDomain+'crmebimage/perset/staticImg/noSearch.png'"></image>
  40. </view>
  41. <recommend ref="recommendIndex" v-if="bastList.length == 0"></recommend>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. getSearchKeyword,
  48. getProductslist
  49. } from '@/api/store.js';
  50. import goodList from '@/components/goodList';
  51. import recommend from '@/components/recommend';
  52. // #ifdef MP
  53. import searchBox from "@/components/searchBox.vue";
  54. // #endif
  55. let app = getApp();
  56. export default {
  57. components: {
  58. goodList,
  59. recommend,
  60. // #ifdef MP
  61. searchBox
  62. // #endif
  63. },
  64. data() {
  65. return {
  66. urlDomain: this.$Cache.get("imgHost"),
  67. searchValue: '',
  68. focus: true,
  69. bastList: [],
  70. hotSearchList: [],
  71. first: 0,
  72. limit: 8,
  73. page: 1,
  74. loading: false,
  75. loadend: false,
  76. loadTitle: '加载更多',
  77. isbastList: false,
  78. theme:app.globalData.theme,
  79. searchTop:''
  80. };
  81. },
  82. onLoad(e){
  83. // #ifdef MP
  84. this.searchTop=uni.getMenuButtonBoundingClientRect().top
  85. // #endif
  86. },
  87. onShow: function() {
  88. this.getRoutineHotSearch();
  89. },
  90. onReachBottom: function() {
  91. if(this.bastList.length>0){
  92. this.getProductList();
  93. }else{
  94. this.$refs.recommendIndex.get_host_product();
  95. }
  96. },
  97. methods: {
  98. getRoutineHotSearch: function() {
  99. let that = this;
  100. getSearchKeyword().then(res => {
  101. that.$set(that, 'hotSearchList', res.data);
  102. });
  103. },
  104. getProductList: function() {
  105. let that = this;
  106. if (that.loadend) return;
  107. if (that.loading) return;
  108. that.loading = true;
  109. that.loadTitle = '';
  110. getProductslist({
  111. keyword: that.searchValue,
  112. page: that.page,
  113. limit: that.limit
  114. }).then(res => {
  115. let list = res.data.list,
  116. loadend = list.length < that.limit;
  117. that.bastList = that.$util.SplitArray(list, that.bastList);
  118. that.$set(that,'bastList',that.bastList);
  119. that.loading = false;
  120. that.loadend = loadend;
  121. that.loadTitle = loadend ? "我也是有底线的~" : "加载更多";
  122. that.page = that.page + 1;
  123. that.isbastList = true;
  124. }).catch(err => {
  125. that.loading = false,
  126. that.loadTitle = '加载更多'
  127. });
  128. },
  129. setHotSearchValue: function(event) {
  130. this.$set(this, 'searchValue', event);
  131. this.page = 1;
  132. this.loadend = false;
  133. this.$set(this, 'bastList', []);
  134. this.getProductList();
  135. },
  136. setValue: function(event) {
  137. this.$set(this, 'searchValue', event.detail.value);
  138. },
  139. searchBut: function(e) {
  140. let that = this;
  141. that.focus = false;
  142. if(e.detail.value){
  143. this.searchValue =e.detail.value
  144. }
  145. if (that.searchValue.length > 0||val) {
  146. that.page = 1;
  147. that.loadend = false;
  148. that.$set(that, 'bastList', []);
  149. uni.showLoading({
  150. title: '正在搜索中'
  151. });
  152. that.getProductList();
  153. uni.hideLoading();
  154. } else {
  155. return this.$util.Tips({
  156. title: '请输入要搜索的商品',
  157. icon: 'none',
  158. duration: 1000,
  159. mask: true,
  160. });
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. page {
  168. background-color: #fff !important;
  169. }
  170. .searchGood .search {
  171. padding-left: 30rpx;
  172. background-color: #fff !important;
  173. }
  174. .searchGood .search {
  175. /* #ifndef MP */
  176. padding-top: 20rpx;
  177. padding-bottom: 20rpx;
  178. /* #endif */
  179. /* #ifdef MP */
  180. position: fixed;
  181. width: 100%;
  182. z-index: 9999;
  183. top: 0;
  184. /* #endif */
  185. }
  186. .searchGood .search .input {
  187. width: 598rpx;
  188. background-color: #f7f7f7;
  189. border-radius: 33rpx;
  190. padding: 0 35rpx;
  191. box-sizing: border-box;
  192. height: 66rpx;
  193. }
  194. .searchGood .search .input input {
  195. width: 472rpx;
  196. font-size: 26rpx;
  197. }
  198. .searchGood .search .input .placeholder {
  199. color: #bbb;
  200. }
  201. .searchGood .search .input .iconfont {
  202. color: #000;
  203. font-size: 35rpx;
  204. }
  205. .searchGood .search .bnt {
  206. width: 120rpx;
  207. text-align: center;
  208. height: 66rpx;
  209. line-height: 66rpx;
  210. font-size: 30rpx;
  211. color: #282828;
  212. }
  213. .searchGood .title {
  214. font-weight: 500;
  215. font-family: PingFang SC, PingFang SC;
  216. font-size: 28rpx;
  217. color: #333;
  218. margin: 50rpx 30rpx 25rpx 30rpx;
  219. }
  220. .searchGood .list {
  221. padding-left: 10rpx;
  222. }
  223. .searchGood .list .item {
  224. font-size: 26rpx;
  225. color: #454545;
  226. padding: 0 21rpx;
  227. height: 60rpx;
  228. border-radius: 30rpx;
  229. line-height: 60rpx;
  230. border: 1rpx solid #aaa;
  231. margin: 0 0 20rpx 20rpx;
  232. }
  233. .searchGood .line {
  234. border-bottom: 1rpx solid #eee;
  235. margin: 20rpx 30rpx 0 30rpx;
  236. }
  237. .searchBox{
  238. width: 100%;
  239. }
  240. </style>