all.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="app-container">
  3. <view class="top-container">
  4. <view class="tab">
  5. <view class="item" :class="screenType === 0 ? 'current':''" @tap="changeScreen(0)">综合</view>
  6. <view class="item" :class="screenType === 1 ? 'current':''" @tap="changeScreen(1)">销量</view>
  7. <view class="item" :class="screenType === 2 || screenType === 3 ? 'current':''" @tap="changeScreen(2)">价格
  8. <image src="@/static/icon/price_1.png" v-if="screenType === 2"></image>
  9. <image src="@/static/icon/price_2.png" v-if="screenType === 3"></image>
  10. <image src="@/static/icon/price_0.png" v-if="screenType != 2 && screenType != 3"></image>
  11. </view>
  12. <view class="item" :class="screenType === 4 ? 'current':''" @tap="changeScreen(4)">上架时间</view>
  13. </view>
  14. <view class="icon">
  15. <image src="@/static/icon/show_1.png" v-if="showType == 1" @tap="showType = 2"></image>
  16. <image src="@/static/icon/show_2.png" v-if="showType == 2" @tap="showType = 1"></image>
  17. </view>
  18. </view>
  19. <view class="goods-waterfall-list" v-show="showType == 1">
  20. <view class="left">
  21. <block v-for="(item, index) in goodsList" :key='index'>
  22. <view class="item" v-if="index%2==0" @tap="toGoodsDetail(item.goodsId)">
  23. <view class="image">
  24. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  25. <image :src="item.logo" mode="aspectFill" class="water" v-if="item.isShowWater"></image>
  26. </view>
  27. <view class="content">
  28. <view class="title ellipsis-2">{{item.goodsName}}</view>
  29. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  30. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{it}}</view>
  31. </view>
  32. <view class="price">
  33. <view class="price-1">¥{{item.goodsPrice | numToFixed}}</view>
  34. <view class="price-2">¥{{item.orgGoodsPrice | numToFixed}}</view>
  35. </view>
  36. <view class="tags2" v-if="item.tags2 && item.tags2.length > 0">
  37. <view class="it" v-for="(it, idx) in item.tags2" :key="idx">{{it}}</view>
  38. </view>
  39. <view class="text">销量:{{item.soldNum}}</view>
  40. </view>
  41. </view>
  42. </block>
  43. </view>
  44. <view class="right">
  45. <block v-for="(item, index) in goodsList" :key='index'>
  46. <view class="item" v-if="index%2==1" @tap="toGoodsDetail(item.goodsId)">
  47. <view class="image">
  48. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  49. <image :src="item.logo" mode="aspectFill" class="water" v-if="item.isShowWater"></image>
  50. </view>
  51. <view class="content">
  52. <view class="title ellipsis-2">{{item.goodsName}}</view>
  53. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  54. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{it}}</view>
  55. </view>
  56. <view class="price">
  57. <view class="price-1">¥{{item.goodsPrice | numToFixed}}</view>
  58. <view class="price-2">¥{{item.orgGoodsPrice | numToFixed}}</view>
  59. </view>
  60. <view class="tags2" v-if="item.tags2 && item.tags2.length > 0">
  61. <view class="it" v-for="(it, idx) in item.tags2" :key="idx">{{it}}</view>
  62. </view>
  63. <view class="text">销量:{{item.soldNum}}</view>
  64. </view>
  65. </view>
  66. </block>
  67. </view>
  68. </view>
  69. <view class="goods-row-list" v-show="showType == 2">
  70. <block v-for="(item, index) in goodsList" :key='index'>
  71. <view class="item" @tap="toGoodsDetail(item.goodsId)">
  72. <view class="image">
  73. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  74. <image :src="item.logo" mode="aspectFill" class="water" v-if="item.isShowWater"></image>
  75. </view>
  76. <view class="right">
  77. <view>
  78. <view class="title ellipsis-2">{{item.goodsName}}</view>
  79. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  80. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{it}}</view>
  81. </view>
  82. </view>
  83. <view>
  84. <view class="bottom">
  85. <view class="price">
  86. <view class="price-1">¥{{item.goodsPrice | numToFixed}}</view>
  87. <view class="price-2">¥{{item.orgGoodsPrice | numToFixed}}</view>
  88. </view>
  89. <view class="text">销量:{{item.soldNum}}</view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </block>
  95. </view>
  96. <no-data v-if="!goodsList.length" :showText="'暂无商品'"></no-data>
  97. <loading-text v-if="goodsList.length" :loading="loading" :noMore="noMore" ></loading-text>
  98. <drag-button :isDock="true" :customBar="true" ref="dragButton"></drag-button>
  99. </view>
  100. </template>
  101. <script>
  102. import dragButton from '@/components/drag-button.vue';
  103. export default {
  104. components:{
  105. dragButton
  106. },
  107. data() {
  108. return {
  109. screenType: '',
  110. goodsList: [],
  111. pageNum: 1,
  112. pageSize: 8,
  113. noMore: false,
  114. loading: false,
  115. showType: 1
  116. }
  117. },
  118. onShow() {
  119. this.$refs.dragButton.init();
  120. },
  121. onLoad() {
  122. this.getGoodsList();
  123. },
  124. // 下拉刷新
  125. onPullDownRefresh() {
  126. this.pageNum = 1;
  127. this.getGoodsList();
  128. },
  129. // 上拉加载
  130. onReachBottom() {
  131. this.getGoodsList(1);
  132. },
  133. methods: {
  134. // 切换筛选类型
  135. changeScreen(type) {
  136. if(type != 2) {
  137. if(this.screenType !== type) {
  138. this.screenType = type;
  139. }else {
  140. this.screenType = '';
  141. }
  142. }else {
  143. if(this.screenType != 2 && this.screenType != 3) {
  144. this.screenType = 2;
  145. }else if(this.screenType == 2) {
  146. this.screenType = 3;
  147. }else {
  148. this.screenType = '';
  149. }
  150. }
  151. this.pageNum = 1;
  152. this.getGoodsList();
  153. },
  154. // 获取商品列表
  155. getGoodsList(loadMore) {
  156. if(this.noMore && loadMore)return;
  157. this.noMore = false
  158. if(!loadMore){
  159. this.pageNum = 1;
  160. }else{
  161. this.loading = true;
  162. }
  163. this.$axios({
  164. url: '/goods/list/sort/page',
  165. method: 'get',
  166. params: {
  167. pageNum: this.pageNum,
  168. pageSize: this.pageSize,
  169. categoryId: '',
  170. sort: this.screenType
  171. },
  172. isLoading: !loadMore
  173. }).then(res => {
  174. res.data.records.forEach(item => {
  175. if(item.logo && item.logoStartTime) {
  176. item.isShowWater = this.$compareTime(item.logoStartTime, item.logoEndTime);
  177. }else {
  178. item.isShowWater = false;
  179. }
  180. })
  181. let _list = res.data.records;
  182. let pageTotal = res.data.pages;
  183. if(this.pageNum >= pageTotal){
  184. this.noMore = true;
  185. }
  186. if (_list.length) {
  187. this.pageNum += 1
  188. }
  189. if (loadMore) {
  190. this.goodsList = this.goodsList.concat(_list);
  191. this.loading = false;
  192. } else {
  193. this.goodsList = _list;
  194. }
  195. uni.stopPullDownRefresh();
  196. })
  197. },
  198. toGoodsDetail(id) {
  199. uni.navigateTo({
  200. url: '/packageGoods/pages/detail?id=' + id
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss">
  207. .app-container {
  208. background: #F4F2F2;
  209. padding-top: 88rpx;
  210. box-sizing: border-box;
  211. }
  212. .top-container {
  213. position: fixed;
  214. top: 0;
  215. left: 0;
  216. width: 100%;
  217. background: #FFFFFF;
  218. display: flex;
  219. padding: 0 20rpx;
  220. align-items: center;
  221. box-sizing: border-box;
  222. .tab {
  223. flex: 1;
  224. display: flex;
  225. padding: 0 80rpx 0 30rpx;
  226. box-sizing: border-box;
  227. justify-content: space-between;
  228. .item {
  229. height: 88rpx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. font-size: 30rpx;
  234. color: #666666;
  235. &.current {
  236. color: #FF3F42;
  237. }
  238. image {
  239. width: 18rpx;
  240. height: 30rpx;
  241. display: block;
  242. margin-left: 10rpx;
  243. }
  244. }
  245. }
  246. .icon {
  247. padding-right: 10rpx;
  248. image {
  249. width: 36rpx;
  250. height: 36rpx;
  251. display: block;
  252. }
  253. }
  254. }
  255. </style>