list.vue 7.0 KB

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