goods.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. methods: {
  35. // 查询商品
  36. getGoods(item,index){
  37. getGoodsList({
  38. pageNo: this.pageNo,
  39. pageSize: this.pageSize,
  40. goodsTypeNo:this.clsId,
  41. }).then(res => {
  42. console.log(res,'goodsList')
  43. if(res.status == 200){
  44. this.count = res.data.count
  45. if(this.pageNo == 1){
  46. this.goodsList = res.data.list
  47. if(res.data.list.length == this.count){
  48. this.status = 'nomore'
  49. }else{
  50. this.status = 'loadmore'
  51. }
  52. }else{
  53. this.goodsList = this.goodsList.concat(res.data.list)
  54. this.goodsList.splice()
  55. this.status = 'loadmore'
  56. }
  57. }
  58. })
  59. },
  60. loadmore(){
  61. if(this.count <= this.goodsList.length) {
  62. this.status = 'nomore'
  63. }else{
  64. this.status = 'loading'
  65. this.pageNo = ++ this.pageNo
  66. this.getGoods()
  67. }
  68. }
  69. },
  70. onReachBottom() {
  71. this.loadmore()
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. .content {
  77. width: 100%;
  78. .goods{
  79. padding: 20upx 0;
  80. }
  81. .goods-list{
  82. display: flex;
  83. flex-wrap: wrap;
  84. justify-content: space-between;
  85. padding: 20upx 20upx 0;
  86. background: #FFFFFF;
  87. >view{
  88. margin-bottom: 20upx;
  89. }
  90. }
  91. .info{
  92. text-align: center;
  93. color: #DD524D;
  94. margin-bottom: 20upx;
  95. }
  96. .loadmore{
  97. padding: 20upx 0;
  98. }
  99. }
  100. </style>