index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view>
  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-sousuo2'></text>
  7. <input type='text' :value='searchValue' :focus="focus" placeholder='点击搜索商品' placeholder-class='placeholder' @input="setValue"></input>
  8. </view>
  9. <view class='bnt' @tap='searchBut'>搜索</view>
  10. </view>
  11. <view class='title'>热门搜索</view>
  12. <view class='list acea-row'>
  13. <block v-for="(item,index) in hotSearchList" :key="index">
  14. <view class='item' @tap='setHotSearchValue(item.title)'>{{item.title}}</view>
  15. </block>
  16. </view>
  17. <view class='line'></view>
  18. <goodList :bastList="bastList" v-if="bastList.length > 0"></goodList>
  19. <view class='loadingicon acea-row row-center-wrapper' v-if="bastList.length > 0">
  20. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  21. </view>
  22. </view>
  23. <view class='noCommodity'>
  24. <view class='pictrue' v-if="bastList.length == 0 && isbastList">
  25. <image src='../../static/images/noSearch.png'></image>
  26. </view>
  27. <recommend :hostProduct='hostProduct' v-if="bastList.length == 0"></recommend>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. getSearchKeyword,
  34. getProductslist,
  35. getProductHot
  36. } from '@/api/store.js';
  37. import goodList from '@/components/goodList';
  38. import recommend from '@/components/recommend';
  39. export default {
  40. components: {
  41. goodList,
  42. recommend
  43. },
  44. data() {
  45. return {
  46. hostProduct: [],
  47. searchValue: '',
  48. focus: true,
  49. bastList: [],
  50. hotSearchList: [],
  51. first: 0,
  52. limit: 8,
  53. page: 1,
  54. loading: false,
  55. loadend: false,
  56. loadTitle: '加载更多',
  57. hotPage:1,
  58. isScroll:true,
  59. isbastList: false
  60. };
  61. },
  62. onShow: function() {
  63. this.getRoutineHotSearch();
  64. this.getHostProduct();
  65. },
  66. onReachBottom: function() {
  67. if(this.bastList.length>0){
  68. this.getProductList();
  69. }else{
  70. this.getHostProduct();
  71. }
  72. },
  73. methods: {
  74. getRoutineHotSearch: function() {
  75. let that = this;
  76. getSearchKeyword().then(res => {
  77. that.$set(that, 'hotSearchList', res.data);
  78. });
  79. },
  80. getProductList: function() {
  81. let that = this;
  82. if (that.loadend) return;
  83. if (that.loading) return;
  84. that.loading = true;
  85. that.loadTitle = '';
  86. getProductslist({
  87. keyword: that.searchValue,
  88. page: that.page,
  89. limit: that.limit
  90. }).then(res => {
  91. let list = res.data.list,
  92. loadend = list.length < that.limit;
  93. that.bastList = that.$util.SplitArray(list, that.bastList);
  94. that.$set(that,'bastList',that.bastList);
  95. that.loading = false;
  96. that.loadend = loadend;
  97. that.loadTitle = loadend ? "😕人家是有底线的~~" : "加载更多";
  98. that.page = that.page + 1;
  99. that.isbastList = true;
  100. }).catch(err => {
  101. that.loading = false,
  102. that.loadTitle = '加载更多'
  103. });
  104. },
  105. getHostProduct: function() {
  106. let that = this;
  107. if(!this.isScroll) return
  108. getProductHot(that.hotPage,that.limit).then(res => {
  109. that.isScroll = res.data.list.length>=that.limit
  110. that.hostProduct = that.hostProduct.concat(res.data.list)
  111. that.hotPage += 1;
  112. });
  113. },
  114. setHotSearchValue: function(event) {
  115. this.$set(this, 'searchValue', event);
  116. this.page = 1;
  117. this.loadend = false;
  118. this.$set(this, 'bastList', []);
  119. this.getProductList();
  120. },
  121. setValue: function(event) {
  122. this.$set(this, 'searchValue', event.detail.value);
  123. },
  124. searchBut: function() {
  125. let that = this;
  126. that.focus = false;
  127. if (that.searchValue.length > 0) {
  128. that.page = 1;
  129. that.loadend = false;
  130. that.$set(that, 'bastList', []);
  131. uni.showLoading({
  132. title: '正在搜索中'
  133. });
  134. that.getProductList();
  135. uni.hideLoading();
  136. } else {
  137. return this.$util.Tips({
  138. title: '请输入要搜索的商品',
  139. icon: 'none',
  140. duration: 1000,
  141. mask: true,
  142. });
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss">
  149. page {
  150. margin-top: var(--status-bar-height);
  151. background-color: #fff !important;
  152. }
  153. .searchGood .search {
  154. padding-left: 30rpx;
  155. background-color: #fff !important;
  156. }
  157. .searchGood .search {
  158. padding-top: 20rpx;
  159. }
  160. .searchGood .search .input {
  161. width: 598rpx;
  162. background-color: #f7f7f7;
  163. border-radius: 33rpx;
  164. padding: 0 35rpx;
  165. box-sizing: border-box;
  166. height: 66rpx;
  167. }
  168. .searchGood .search .input input {
  169. width: 472rpx;
  170. font-size: 26rpx;
  171. }
  172. .searchGood .search .input .placeholder {
  173. color: #bbb;
  174. }
  175. .searchGood .search .input .iconfont {
  176. color: #000;
  177. font-size: 35rpx;
  178. }
  179. .searchGood .search .bnt {
  180. width: 120rpx;
  181. text-align: center;
  182. height: 66rpx;
  183. line-height: 66rpx;
  184. font-size: 30rpx;
  185. color: #282828;
  186. }
  187. .searchGood .title {
  188. font-size: 28rpx;
  189. color: #999;
  190. margin: 50rpx 30rpx 25rpx 30rpx;
  191. }
  192. .searchGood .list {
  193. padding-left: 10rpx;
  194. }
  195. .searchGood .list .item {
  196. font-size: 26rpx;
  197. color: #454545;
  198. padding: 0 21rpx;
  199. height: 60rpx;
  200. border-radius: 30rpx;
  201. line-height: 60rpx;
  202. border: 1rpx solid #aaa;
  203. margin: 0 0 20rpx 20rpx;
  204. }
  205. .searchGood .line {
  206. border-bottom: 1rpx solid #eee;
  207. margin: 20rpx 30rpx 0 30rpx;
  208. }
  209. </style>