goods.vue 2.4 KB

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