goods.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 :hasLogin="hasLogin" :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. import {checkLogin} from '@/api/login.js'
  17. export default {
  18. data() {
  19. return {
  20. clsId: '',
  21. goldLimit:0,
  22. goodsName: '',
  23. pageNo: 1,
  24. pageSize: 10,
  25. goodsList:[],
  26. status: 'loadmore',
  27. count: 0,
  28. dragPic: '/static/cart.png', // 购物车图标
  29. hasLogin: false
  30. };
  31. },
  32. onLoad(opts) {
  33. this.goodsName = opts.name
  34. this.clsId = opts.goodsTypeNo
  35. this.goldLimit = opts.goldLimit
  36. uni.setNavigationBarTitle({
  37. title: this.goodsName
  38. })
  39. this.getGoods()
  40. // 开启分享
  41. uni.showShareMenu({
  42. withShareTicket: true,
  43. menus: ['shareAppMessage', 'shareTimeline']
  44. })
  45. },
  46. // 下拉刷新
  47. onPullDownRefresh() {
  48. console.log('refresh')
  49. this.pageNo = 1
  50. this.getGoods()
  51. setTimeout(function () {
  52. uni.stopPullDownRefresh()
  53. }, 200)
  54. },
  55. onShow() {
  56. // 是否登录
  57. checkLogin().then(res => {
  58. this.hasLogin = res.status == 200
  59. })
  60. },
  61. methods: {
  62. // 查询商品
  63. getGoods(item,index){
  64. getGoodsList({
  65. pageNo: this.pageNo,
  66. pageSize: this.pageSize,
  67. goodsTypeNo:this.clsId,
  68. }).then(res => {
  69. console.log(res,'goodsList')
  70. if(res.status == 200){
  71. this.count = res.data.count
  72. if(this.pageNo == 1){
  73. this.goodsList = res.data.list
  74. if(res.data.list.length == this.count){
  75. this.status = 'nomore'
  76. }else{
  77. this.status = 'loadmore'
  78. }
  79. }else{
  80. this.goodsList = this.goodsList.concat(res.data.list)
  81. this.goodsList.splice()
  82. this.status = 'loadmore'
  83. }
  84. }
  85. })
  86. },
  87. loadmore(){
  88. if(this.count <= this.goodsList.length) {
  89. this.status = 'nomore'
  90. }else{
  91. this.status = 'loading'
  92. this.pageNo = ++ this.pageNo
  93. this.getGoods()
  94. }
  95. }
  96. },
  97. onReachBottom() {
  98. this.loadmore()
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. .content {
  104. width: 100%;
  105. .goods{
  106. padding: 20upx 0;
  107. }
  108. .goods-list{
  109. display: flex;
  110. flex-wrap: wrap;
  111. justify-content: space-between;
  112. padding: 20upx 20upx 0;
  113. background: #FFFFFF;
  114. >view{
  115. margin-bottom: 20upx;
  116. }
  117. }
  118. .info{
  119. text-align: center;
  120. color: #DD524D;
  121. margin-bottom: 20upx;
  122. }
  123. .loadmore{
  124. padding: 20upx 0;
  125. }
  126. }
  127. </style>