goods.vue 2.5 KB

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