index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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" style="width: 100%;height: 350rpx;border-radius: 10rpx;" mode="scaleToFill">
  5. </image>
  6. </view>
  7. <u-empty v-if="data.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
  8. <u-loadmore v-if="page.total !== 0 && data.length != 0" :status="status" />
  9. </view>
  10. </template>
  11. <script>
  12. // import {
  13. // activityList
  14. // } from '@/api/tabBar/activity.js'
  15. import {
  16. shoppingCartList
  17. } from '@/api/shoppingCart/index.js'
  18. export default {
  19. data() {
  20. return {
  21. page: {
  22. current: 1,
  23. size: 10,
  24. total: 0,
  25. },
  26. data: [],
  27. status: 'loadmore',
  28. }
  29. },
  30. onLoad() {
  31. uni.showToast({
  32. title: "开发中",
  33. icon: "none",
  34. });
  35. // this.activityListfun()
  36. },
  37. onShow() {
  38. // this.getUpdate()
  39. this.getBadge()
  40. this.data = [];
  41. this.page.current = 1;
  42. size: this.page.size = 10;
  43. // this.activityListfun()
  44. },
  45. onReachBottom() {
  46. this.status = 'loading'
  47. if (this.data.length < this.page.total) {
  48. this.page.current++
  49. this.activityListfun()
  50. } else {
  51. this.status = 'nomore'
  52. }
  53. },
  54. methods: {
  55. getBadge() {
  56. shoppingCartList().then(res => {
  57. let num = res.data.length
  58. if (num) {
  59. uni.setTabBarBadge({
  60. index: 3, // tabIndex,tabBar的哪一项,从0开始
  61. text: num.toString() // 显示的文本,超过 99 显示成 “…”
  62. })
  63. } else {
  64. uni.removeTabBarBadge({
  65. index: 3, // tabIndex,tabBar的哪一项,从0开始
  66. })
  67. }
  68. })
  69. },
  70. // getUpdate() {
  71. // const updateManager = uni.getUpdateManager();
  72. // updateManager.onCheckForUpdate(function(res) {
  73. // // 请求完新版本信息的回调
  74. // if (res.hasUpdate) {
  75. // updateManager.onUpdateReady(function() {
  76. // uni.showModal({
  77. // title: '更新提示',
  78. // content: '新版本已经准备好,是否重启应用?',
  79. // success: function(res) {
  80. // if (res.confirm) {
  81. // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  82. // updateManager.applyUpdate();
  83. // }
  84. // }
  85. // });
  86. // });
  87. // updateManager.onUpdateFailed(function() {
  88. // // 新的版本下载失败
  89. // uni.showModal({
  90. // title: '已经有新版本了哟~',
  91. // content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  92. // });
  93. // });
  94. // }
  95. // });
  96. // },
  97. // 跳转详情
  98. jumpDetails(row) {
  99. uni.navigateTo({
  100. url: '/pages/tabBar/activity/details?id=' + row.id
  101. })
  102. },
  103. // 获取列表数据
  104. activityListfun() {
  105. uni.showLoading({
  106. title: '加载中',
  107. mask: true
  108. });
  109. activityList({
  110. current: this.page.current,
  111. size: this.page.size,
  112. status: 1
  113. }).then(res => {
  114. this.data = this.data.concat(res.data.records)
  115. this.page.total = res.data.total
  116. if (this.data.length == res.data.total) {
  117. this.status = 'nomore'
  118. }
  119. if (res.data.total) {
  120. uni.setTabBarBadge({
  121. index: 1, // tabIndex,tabBar的哪一项,从0开始
  122. text: res.data.total.toString() // 显示的文本,超过 99 显示成 “…”
  123. })
  124. } else {
  125. uni.removeTabBarBadge({
  126. index: 1, // tabIndex,tabBar的哪一项,从0开始
  127. })
  128. }
  129. uni.hideLoading();
  130. }).catch(err => {
  131. uni.hideLoading();
  132. })
  133. },
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .widthBox {
  139. background-color: #fff;
  140. padding: 32rpx;
  141. height: 100vh;
  142. }
  143. </style>