search.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="app-container">
  3. <view class="search-container">
  4. <view class="search">
  5. <image src="/static/icon/search.png" class=""></image>
  6. <input type="text" confirm-type="search" placeholder="搜索商品名称或型号" v-model="keyword" @confirm="searchSubmit">
  7. </view>
  8. </view>
  9. <view class="list-container">
  10. <block v-for="(item, index) in goodsList" :key='index'>
  11. <view class="item" @tap="toGoodsDetail(item.goodsId)">
  12. <view class="image">
  13. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  14. <image
  15. :src="item.logo"
  16. mode="aspectFill"
  17. class="water"
  18. v-if="item.isShowWater"
  19. ></image>
  20. </view>
  21. <view class="content">
  22. <view class="title ellipsis-2">{{item.goodsName}}</view>
  23. <view class="bottom">
  24. <view class="price">
  25. <view class="price-1">¥{{item.goodsPrice | numToFixed}}</view>
  26. <view class="price-2">¥{{item.orgGoodsPrice | numToFixed}}</view>
  27. </view>
  28. <view class="btn"><image src="@/static/icon/cart.png" mode="aspectFill"></image></view>
  29. </view>
  30. </view>
  31. </view>
  32. </block>
  33. </view>
  34. <no-data v-if="!goodsList.length" :showText="'暂无商品'"></no-data>
  35. <loading-text v-if="goodsList.length" :loading="loading" :noMore="noMore" ></loading-text>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. keyword: '',
  43. goodsList: [],
  44. pageNum: 1,
  45. pageSize: 8,
  46. noMore: false,
  47. loading: false,
  48. }
  49. },
  50. onLoad({keyword}) {
  51. this.keyword = keyword;
  52. this.getGoodsList();
  53. },
  54. // 下拉刷新
  55. onPullDownRefresh() {
  56. this.pageNum = 1;
  57. this.getGoodsList();
  58. },
  59. // 上拉加载
  60. onReachBottom() {
  61. this.getGoodsList(1);
  62. },
  63. methods: {
  64. // 获取商品列表
  65. getGoodsList(loadMore) {
  66. if(this.noMore && loadMore)return;
  67. this.noMore = false
  68. if(!loadMore){
  69. this.pageNum = 1;
  70. }else{
  71. this.loading = true;
  72. }
  73. this.$axios({
  74. url: '/goods/list/sort/page',
  75. method: 'get',
  76. params: {
  77. pageNum: this.pageNum,
  78. pageSize: this.pageSize,
  79. keyword: this.keyword,
  80. },
  81. isLoading: !loadMore
  82. }).then(res => {
  83. res.data.records.forEach((item) => {
  84. if (item.logo && item.logoStartTime) {
  85. item.isShowWater = this.$compareTime(
  86. item.logoStartTime,
  87. item.logoEndTime
  88. );
  89. } else {
  90. item.isShowWater = false;
  91. }
  92. });
  93. let _list = res.data.records;
  94. let pageTotal = res.data.pages;
  95. if(this.pageNum >= pageTotal){
  96. this.noMore = true;
  97. }
  98. if (_list.length) {
  99. this.pageNum += 1
  100. }
  101. if (loadMore) {
  102. this.goodsList = this.goodsList.concat(_list);
  103. this.loading = false;
  104. } else {
  105. this.goodsList = _list;
  106. }
  107. uni.stopPullDownRefresh();
  108. })
  109. },
  110. searchSubmit() {
  111. this.getGoodsList();
  112. },
  113. toGoodsDetail(id) {
  114. uni.navigateTo({
  115. url:'/packageGoods/pages/detail?id=' + id
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .app-container {
  123. background: #F4F2F2;
  124. box-sizing: border-box;
  125. padding-top: 90rpx;
  126. }
  127. .search-container {
  128. background: #FFFFFF;
  129. padding: 12rpx 20rpx;
  130. border-bottom: 1px solid #F4F2F2;
  131. position: fixed;
  132. top: 0;
  133. left: 0;
  134. width: 100%;
  135. box-sizing: border-box;
  136. .search {
  137. height: 64rpx;
  138. display: flex;
  139. align-items: center;
  140. background: #F0F0F0;
  141. border-radius: 64rpx;
  142. padding: 0 20rpx;
  143. image {
  144. width: 28rpx;
  145. height: 28rpx;
  146. }
  147. input {
  148. width: 100%;
  149. padding-left: 15rpx;
  150. }
  151. }
  152. }
  153. .list-container {
  154. display: flex;
  155. flex-wrap: wrap;
  156. padding: 20rpx;
  157. .item {
  158. width: 348rpx;
  159. background: #FFFFFF;
  160. margin-right: 14rpx;
  161. margin-bottom: 20rpx;
  162. border-radius: 20rpx;
  163. overflow: hidden;
  164. &:nth-child(2n) {
  165. margin-right: 0;
  166. }
  167. // image {
  168. // width: 348rpx;
  169. // height: 348rpx;
  170. // }
  171. .image {
  172. width: 348rpx;
  173. height: 348rpx;
  174. flex-shrink: 0;
  175. position: relative;
  176. .img {
  177. width: 348rpx;
  178. height: 348rpx;
  179. display: block;
  180. }
  181. .water {
  182. width: 348rpx;
  183. height: 348rpx;
  184. display: block;
  185. position: absolute;
  186. left: 0;
  187. top: 0;
  188. z-index: 1;
  189. }
  190. }
  191. .content {
  192. padding: 15rpx 20rpx;
  193. .title {
  194. font-size: 30rpx;
  195. color: #333333;
  196. line-height: 36rpx;
  197. font-weight: 600;
  198. height: 72rpx;
  199. }
  200. .bottom {
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. margin-top: 10rpx;
  205. .price {
  206. display: flex;
  207. flex-direction: column;
  208. }
  209. .price-1 {
  210. font-size: 32rpx;
  211. color: #FF3F42;
  212. line-height: 36rpx;
  213. }
  214. .price-2 {
  215. font-size: 26rpx;
  216. color: #666666;
  217. line-height: 30rpx;
  218. text-decoration: line-through;
  219. }
  220. .btn {
  221. width: 60rpx;
  222. height: 60rpx;
  223. background: #FE781F;
  224. border-radius: 50%;
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. image {
  229. width: 41rpx;
  230. height: 36rpx;
  231. display: block;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>