index.vue 2.3 KB

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