index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="widthBox">
  3. <view class="cardBox" v-for="item in data" :key="item.id" @click.stop="jumpDetails(item)">
  4. <view class="cardBox-img">
  5. <image style="width: 100%;height: 100%;" :src="item.url" mode=""></image>
  6. </view>
  7. <view class="cardBox-text">
  8. <view class="cardBox-textTitle">{{item.activityName}}</view>
  9. <view class="cardBox-textText">
  10. <u--text :lines="2" :text="item.activityDescription"></u--text>
  11. </view>
  12. </view>
  13. </view>
  14. <u-empty v-if="data.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
  15. <u-loadmore v-if="page.total !== 0 && data.length != 0" :status="status" />
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. activityList
  21. } from '@/api/tabBar/activity.js'
  22. import {
  23. shoppingCartList
  24. } from '@/api/tabBar/shoppingCart.js'
  25. export default {
  26. data() {
  27. return {
  28. page: {
  29. current: 1,
  30. size: 10,
  31. total: 0,
  32. },
  33. data: [],
  34. status: 'loadmore',
  35. }
  36. },
  37. onLoad() {
  38. // this.activityListfun()
  39. },
  40. onShow() {
  41. shoppingCartList().then(res => {
  42. let num=0
  43. res.data.forEach(e=>{
  44. console.log(e.list)
  45. num=num+e.list.length
  46. })
  47. uni.setTabBarBadge({
  48. index: 3, // tabIndex,tabBar的哪一项,从0开始
  49. text: num.toString()// 显示的文本,超过 99 显示成 “…”
  50. })
  51. })
  52. this.data = [];
  53. this.page.current = 1;
  54. size: this.page.size = 10;
  55. this.activityListfun()
  56. },
  57. onReachBottom() {
  58. this.status = 'loading'
  59. if (this.data.length < this.page.total) {
  60. this.page.current++
  61. this.activityListfun()
  62. } else {
  63. this.status = 'nomore'
  64. }
  65. },
  66. methods: {
  67. // 跳转详情
  68. jumpDetails(row) {
  69. uni.navigateTo({
  70. url: '/pages/tabBar/activity/details?id=' + row.id
  71. })
  72. },
  73. // 获取列表数据
  74. activityListfun() {
  75. uni.showLoading({
  76. title: '加载中',
  77. mask: true
  78. });
  79. activityList({
  80. current: this.page.current,
  81. size: this.page.size,
  82. status: 1
  83. }).then(res => {
  84. this.data = this.data.concat(res.data.records)
  85. this.page.total = res.data.total
  86. if (this.data.length == res.data.total) {
  87. this.status = 'nomore'
  88. }
  89. uni.setTabBarBadge({
  90. index: 2, // tabIndex,tabBar的哪一项,从0开始
  91. text: res.data.total.toString() // 显示的文本,超过 99 显示成 “…”
  92. })
  93. uni.hideLoading();
  94. }).catch(err => {
  95. uni.hideLoading();
  96. })
  97. },
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .widthBox {
  103. width: 94%;
  104. margin: 20rpx auto;
  105. }
  106. .cardBox {
  107. background: #fff;
  108. border-radius: 10rpx;
  109. padding: 20rpx;
  110. box-sizing: border-box;
  111. display: flex;
  112. .cardBox-img {
  113. flex: 1;
  114. width: 200rpx;
  115. height: 180rpx;
  116. }
  117. .cardBox-text {
  118. flex: 2;
  119. margin-left: 10rpx;
  120. .cardBox-textTitle {
  121. font-size: 36rpx;
  122. font-weight: bold;
  123. margin-bottom: 10rpx;
  124. }
  125. .cardBox-textText {
  126. font-size: 30rpx;
  127. color: #8b8b8b;
  128. }
  129. }
  130. }
  131. </style>