index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. this.getUpdate()
  36. shoppingCartList({ whetherIntegral: '0'}).then(res => {
  37. let num=0
  38. res.data.forEach(e=>{
  39. console.log(e.list)
  40. num=num+e.list.length
  41. })
  42. uni.setTabBarBadge({
  43. index: 3, // tabIndex,tabBar的哪一项,从0开始
  44. text: num.toString()// 显示的文本,超过 99 显示成 “…”
  45. })
  46. })
  47. this.data = [];
  48. this.page.current = 1;
  49. size: this.page.size = 10;
  50. this.activityListfun()
  51. },
  52. onReachBottom() {
  53. this.status = 'loading'
  54. if (this.data.length < this.page.total) {
  55. this.page.current++
  56. this.activityListfun()
  57. } else {
  58. this.status = 'nomore'
  59. }
  60. },
  61. methods: {
  62. getUpdate() {
  63. const updateManager = uni.getUpdateManager();
  64. updateManager.onCheckForUpdate(function(res) {
  65. // 请求完新版本信息的回调
  66. if (res.hasUpdate) {
  67. updateManager.onUpdateReady(function() {
  68. uni.showModal({
  69. title: '更新提示',
  70. content: '新版本已经准备好,是否重启应用?',
  71. success: function(res) {
  72. if (res.confirm) {
  73. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  74. updateManager.applyUpdate();
  75. }
  76. }
  77. });
  78. });
  79. updateManager.onUpdateFailed(function() {
  80. // 新的版本下载失败
  81. uni.showModal({
  82. title: '已经有新版本了哟~',
  83. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  84. });
  85. });
  86. }
  87. });
  88. },
  89. // 跳转详情
  90. jumpDetails(row) {
  91. uni.navigateTo({
  92. url: '/pages/tabBar/activity/details?id=' + row.id
  93. })
  94. },
  95. // 获取列表数据
  96. activityListfun() {
  97. uni.showLoading({
  98. title: '加载中',
  99. mask: true
  100. });
  101. activityList({
  102. current: this.page.current,
  103. size: this.page.size,
  104. status: 1
  105. }).then(res => {
  106. this.data = this.data.concat(res.data.records)
  107. this.page.total = res.data.total
  108. if (this.data.length == res.data.total) {
  109. this.status = 'nomore'
  110. }
  111. uni.setTabBarBadge({
  112. index: 1, // tabIndex,tabBar的哪一项,从0开始
  113. text: res.data.total.toString() // 显示的文本,超过 99 显示成 “…”
  114. })
  115. uni.hideLoading();
  116. }).catch(err => {
  117. uni.hideLoading();
  118. })
  119. },
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .widthBox {
  125. background-color: #fff;
  126. padding: 32rpx;
  127. height: 100vh;
  128. }
  129. </style>