index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view :style="colorStyle">
  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-sousuo'></text>
  7. <input type='text' v-model='searchValue' @confirm="inputConfirm" confirm-type="search" focus placeholder='点击搜索商品'
  8. placeholder-class='placeholder' @input="setValue"></input>
  9. </view>
  10. <view class='bnt' @tap='searchBut'>搜索</view>
  11. </view>
  12. <template v-if="history.length">
  13. <view class='title acea-row row-between-wrapper'>
  14. <view>搜索历史</view>
  15. <view class="iconfont icon-shanchu" @click="clear"></view>
  16. </view>
  17. <view class='list acea-row'>
  18. <block v-for="(item,index) in history" :key="index">
  19. <view class='item history-item line1' @tap='setHotSearchValue(item.keyword)' v-if="item.keyword">{{item.keyword}}</view>
  20. </block>
  21. </view>
  22. </template>
  23. <view class='title'>热门搜索</view>
  24. <view class='list acea-row'>
  25. <block v-for="(item,index) in hotSearchList" :key="index">
  26. <view class='item line1' @tap='setHotSearchValue(item.val)' v-if="item.val">{{item.val}}</view>
  27. </block>
  28. </view>
  29. <view class='line' v-if='bastList.length'></view>
  30. <goodList :bastList="bastList" v-if="bastList.length > 0"></goodList>
  31. <view class='loadingicon acea-row row-center-wrapper' v-if="bastList.length > 0">
  32. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  33. </view>
  34. </view>
  35. <view class='noCommodity'>
  36. <view class='pictrue' v-if="bastList.length == 0">
  37. <!-- <image src='../../static/images/noSearch.png'></image> -->
  38. <image :src="imgHost + '/statics/images/noSearch.png'"></image>
  39. </view>
  40. <recommend :hostProduct='hostProduct' v-if="bastList.length == 0 && page > 1"></recommend>
  41. </view>
  42. <home v-if="navigation"></home>
  43. </view>
  44. </template>
  45. <script>
  46. import home from '@/components/home/index.vue'
  47. import {
  48. getSearchKeyword,
  49. getProductslist,
  50. getProductHot
  51. } from '@/api/store.js';
  52. import {
  53. searchList,
  54. clearSearch
  55. } from '@/api/api.js';
  56. import goodList from '@/components/goodList';
  57. import recommend from '@/components/recommend';
  58. import colors from "@/mixins/color";
  59. import {HTTP_REQUEST_URL} from '@/config/app.js';
  60. export default {
  61. components: {
  62. goodList,
  63. recommend,
  64. home
  65. },
  66. mixins: [colors],
  67. data() {
  68. return {
  69. hostProduct: [],
  70. searchValue: '',
  71. focus: true,
  72. bastList: [],
  73. hotSearchList: [],
  74. first: 0,
  75. limit: 8,
  76. page: 1,
  77. loading: false,
  78. loadend: false,
  79. loadTitle: '加载更多',
  80. hotPage: 1,
  81. isScroll: true,
  82. history: [],
  83. imgHost:HTTP_REQUEST_URL
  84. };
  85. },
  86. onShow: function() {
  87. uni.removeStorageSync('form_type_cart');
  88. // this.getRoutineHotSearch();
  89. this.getHostProduct();
  90. this.searchList();
  91. try {
  92. this.hotSearchList = uni.getStorageSync('hotList');
  93. } catch (err) {}
  94. },
  95. onReachBottom: function() {
  96. if (this.bastList.length > 0) {
  97. this.getProductList();
  98. } else {
  99. this.getHostProduct();
  100. }
  101. },
  102. methods: {
  103. searchList() {
  104. searchList({
  105. page: 1,
  106. limit: 10
  107. }).then(res => {
  108. this.history = res.data;
  109. });
  110. },
  111. clear() {
  112. let that = this;
  113. clearSearch().then(res => {
  114. uni.showToast({
  115. title: res.msg,
  116. success() {
  117. that.history = [];
  118. }
  119. });
  120. });
  121. },
  122. inputConfirm: function(event) {
  123. if (event.detail.value) {
  124. uni.hideKeyboard();
  125. this.setHotSearchValue(event.detail.value);
  126. }
  127. },
  128. getRoutineHotSearch: function() {
  129. let that = this;
  130. getSearchKeyword().then(res => {
  131. that.$set(that, 'hotSearchList', res.data);
  132. });
  133. },
  134. getProductList: function() {
  135. let that = this;
  136. if (that.loadend) return;
  137. if (that.loading) return;
  138. that.loading = true;
  139. that.loadTitle = '';
  140. getProductslist({
  141. keyword: that.searchValue,
  142. page: that.page,
  143. limit: that.limit
  144. }).then(res => {
  145. let list = res.data,
  146. loadend = list.length < that.limit;
  147. that.bastList = that.$util.SplitArray(list, that.bastList);
  148. that.$set(that, 'bastList', that.bastList);
  149. that.loading = false;
  150. that.loadend = loadend;
  151. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  152. that.page = that.page + 1;
  153. }).catch(err => {
  154. that.loading = false,
  155. that.loadTitle = '加载更多'
  156. });
  157. },
  158. getHostProduct: function() {
  159. let that = this;
  160. if (!this.isScroll) return
  161. getProductHot(that.hotPage, that.limit).then(res => {
  162. that.isScroll = res.data.length >= that.limit
  163. that.hostProduct = that.hostProduct.concat(res.data)
  164. that.hotPage += 1;
  165. });
  166. },
  167. setHotSearchValue: function(event) {
  168. this.$set(this, 'searchValue', event);
  169. this.page = 1;
  170. this.loadend = false;
  171. this.$set(this, 'bastList', []);
  172. this.getProductList();
  173. },
  174. setValue: function(event) {
  175. this.$set(this, 'searchValue', event.detail.value);
  176. },
  177. searchBut: function() {
  178. let that = this;
  179. that.focus = false;
  180. if (that.searchValue.length > 0) {
  181. that.page = 1;
  182. that.loadend = false;
  183. that.$set(that, 'bastList', []);
  184. uni.showLoading({
  185. title: '正在搜索中'
  186. });
  187. that.getProductList();
  188. uni.hideLoading();
  189. } else {
  190. return this.$util.Tips({
  191. title: '请输入要搜索的商品',
  192. icon: 'none',
  193. duration: 1000,
  194. mask: true,
  195. });
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. page {
  203. background-color: #fff !important;
  204. }
  205. .noCommodity{
  206. border-top-width: 0;
  207. }
  208. .searchGood .search {
  209. padding-left: 30rpx;
  210. }
  211. .searchGood .search {
  212. margin-top: 20rpx;
  213. }
  214. .searchGood .search .input {
  215. width: 598rpx;
  216. background-color: #f7f7f7;
  217. border-radius: 33rpx;
  218. padding: 0 35rpx;
  219. box-sizing: border-box;
  220. height: 66rpx;
  221. }
  222. .searchGood .search .input input {
  223. width: 472rpx;
  224. font-size: 28rpx;
  225. }
  226. .searchGood .search .input .placeholder {
  227. color: #999;
  228. }
  229. .searchGood .search .input .iconfont {
  230. color: #555;
  231. font-size: 35rpx;
  232. }
  233. .searchGood .search .bnt {
  234. width: 120rpx;
  235. text-align: center;
  236. height: 66rpx;
  237. line-height: 66rpx;
  238. font-size: 30rpx;
  239. color: #282828;
  240. }
  241. .searchGood .title {
  242. font-size: 28rpx;
  243. color: #999;
  244. margin: 50rpx 30rpx 25rpx 30rpx;
  245. }
  246. .searchGood .title .iconfont {
  247. font-size: 28rpx;
  248. }
  249. .searchGood .list {
  250. padding-left: 10rpx;
  251. }
  252. .searchGood .list .item {
  253. font-size: 26rpx;
  254. color: #454545;
  255. padding: 0 21rpx;
  256. height: 60rpx;
  257. border-radius: 3rpx;
  258. line-height: 60rpx;
  259. border: 1rpx solid #aaa;
  260. margin: 0 0 20rpx 20rpx;
  261. }
  262. .searchGood .list .item.history-item {
  263. height: 50rpx;
  264. border: none;
  265. border-radius: 25rpx;
  266. background-color: #F7F7F7;
  267. line-height: 50rpx;
  268. }
  269. .searchGood .line {
  270. border-bottom: 1rpx solid #eee;
  271. margin: 20rpx 30rpx 0 30rpx;
  272. }
  273. </style>