goods.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="content">
  3. <view class="info">该类商品需购满{{goldLimit}}乐豆才能下单哦!</view>
  4. <view v-if="goodsList.length">
  5. <uni-coods :list="goodsList"></uni-coods>
  6. <view class="loadmore"><u-loadmore @loadmore="loadmore" :status="status" /></view>
  7. </view>
  8. <!-- 购物车 -->
  9. <uni-cart-fix></uni-cart-fix>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. getGoodsList
  15. } from '@/api/goods.js'
  16. export default {
  17. data() {
  18. return {
  19. clsId: '',
  20. goldLimit:0,
  21. pageNo: 1,
  22. pageSize: 10,
  23. goodsList:[],
  24. status: 'loadmore',
  25. count: 0
  26. };
  27. },
  28. onLoad(opts) {
  29. console.log(opts)
  30. this.clsId = opts.goodsTypeNo
  31. this.goldLimit = opts.goldLimit
  32. this.getGoods()
  33. },
  34. // 下拉刷新
  35. onPullDownRefresh() {
  36. console.log('refresh')
  37. this.pageNo = 1
  38. this.getGoods()
  39. setTimeout(function () {
  40. uni.stopPullDownRefresh()
  41. }, 200)
  42. },
  43. methods: {
  44. // 查询商品
  45. getGoods(item,index){
  46. getGoodsList({
  47. pageNo: this.pageNo,
  48. pageSize: this.pageSize,
  49. goodsTypeNo:this.clsId,
  50. }).then(res => {
  51. console.log(res,'goodsList')
  52. if(res.status == 200){
  53. this.count = res.data.count
  54. if(this.pageNo == 1){
  55. this.goodsList = res.data.list
  56. if(res.data.list.length == this.count){
  57. this.status = 'nomore'
  58. }else{
  59. this.status = 'loadmore'
  60. }
  61. }else{
  62. this.goodsList = this.goodsList.concat(res.data.list)
  63. this.goodsList.splice()
  64. this.status = 'loadmore'
  65. }
  66. }
  67. })
  68. },
  69. loadmore(){
  70. if(this.count <= this.goodsList.length) {
  71. this.status = 'nomore'
  72. }else{
  73. this.status = 'loading'
  74. this.pageNo = ++ this.pageNo
  75. this.getGoods()
  76. }
  77. }
  78. },
  79. onReachBottom() {
  80. this.loadmore()
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .content {
  86. width: 100%;
  87. .goods{
  88. padding: 20upx 0;
  89. }
  90. .goods-list{
  91. display: flex;
  92. flex-wrap: wrap;
  93. justify-content: space-between;
  94. padding: 20upx 20upx 0;
  95. background: #FFFFFF;
  96. >view{
  97. margin-bottom: 20upx;
  98. }
  99. }
  100. .info{
  101. text-align: center;
  102. color: #DD524D;
  103. margin-bottom: 20upx;
  104. }
  105. .loadmore{
  106. padding: 20upx 0;
  107. }
  108. }
  109. </style>