goods.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. goodsName: '',
  22. pageNo: 1,
  23. pageSize: 10,
  24. goodsList:[],
  25. status: 'loadmore',
  26. count: 0
  27. };
  28. },
  29. onLoad(opts) {
  30. this.goodsName = opts.name
  31. this.clsId = opts.goodsTypeNo
  32. this.goldLimit = opts.goldLimit
  33. uni.setNavigationBarTitle({
  34. title: this.goodsName
  35. })
  36. this.getGoods()
  37. },
  38. // 下拉刷新
  39. onPullDownRefresh() {
  40. console.log('refresh')
  41. this.pageNo = 1
  42. this.getGoods()
  43. setTimeout(function () {
  44. uni.stopPullDownRefresh()
  45. }, 200)
  46. },
  47. methods: {
  48. // 查询商品
  49. getGoods(item,index){
  50. getGoodsList({
  51. pageNo: this.pageNo,
  52. pageSize: this.pageSize,
  53. goodsTypeNo:this.clsId,
  54. }).then(res => {
  55. console.log(res,'goodsList')
  56. if(res.status == 200){
  57. this.count = res.data.count
  58. if(this.pageNo == 1){
  59. this.goodsList = res.data.list
  60. if(res.data.list.length == this.count){
  61. this.status = 'nomore'
  62. }else{
  63. this.status = 'loadmore'
  64. }
  65. }else{
  66. this.goodsList = this.goodsList.concat(res.data.list)
  67. this.goodsList.splice()
  68. this.status = 'loadmore'
  69. }
  70. }
  71. })
  72. },
  73. loadmore(){
  74. if(this.count <= this.goodsList.length) {
  75. this.status = 'nomore'
  76. }else{
  77. this.status = 'loading'
  78. this.pageNo = ++ this.pageNo
  79. this.getGoods()
  80. }
  81. }
  82. },
  83. onReachBottom() {
  84. this.loadmore()
  85. }
  86. }
  87. </script>
  88. <style lang="scss">
  89. .content {
  90. width: 100%;
  91. .goods{
  92. padding: 20upx 0;
  93. }
  94. .goods-list{
  95. display: flex;
  96. flex-wrap: wrap;
  97. justify-content: space-between;
  98. padding: 20upx 20upx 0;
  99. background: #FFFFFF;
  100. >view{
  101. margin-bottom: 20upx;
  102. }
  103. }
  104. .info{
  105. text-align: center;
  106. color: #DD524D;
  107. margin-bottom: 20upx;
  108. }
  109. .loadmore{
  110. padding: 20upx 0;
  111. }
  112. }
  113. </style>