message.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="container">
  3. <view class="massage" v-for="(item, index) in list">
  4. <view class="time">
  5. {{ item.createTime }}
  6. </view>
  7. <uni-badge
  8. class="uni-badge-left-margin"
  9. :is-dot="true"
  10. :text="item.status == 0"
  11. absolute="rightTop"
  12. size="small"
  13. :offset="[5, 5]"
  14. >
  15. <view class="info" @click="clickMassage(item)">
  16. <view class="title">
  17. {{ item.title }}
  18. </view>
  19. <view class="text">
  20. {{ item.content }}
  21. </view>
  22. </view>
  23. </uni-badge>
  24. </view>
  25. <uni-load-more
  26. v-if="list.length > 0"
  27. :status="loadMore"
  28. @clickLoadMore="load"
  29. :contentText="contentText"
  30. ></uni-load-more>
  31. <noData v-else />
  32. </view>
  33. </template>
  34. <script>
  35. import noData from '@/component/noData.vue'
  36. import { messageListApi, messageReadApi } from '@/api/message.js'
  37. export default {
  38. components: {
  39. noData,
  40. },
  41. data() {
  42. return {
  43. value: 1,
  44. // more/loading/noMore
  45. loadMore: 'more',
  46. contentText: {
  47. contentdown: '点击加载更多',
  48. },
  49. params: {
  50. limit: 10,
  51. page: 1,
  52. },
  53. list: [],
  54. }
  55. },
  56. onShow() {
  57. this.getList()
  58. },
  59. methods: {
  60. load() {
  61. if (this.loadMore == 'more') {
  62. this.params.page += 1
  63. this.getList()
  64. }
  65. },
  66. getList() {
  67. this.loadMore = 'loading'
  68. messageListApi(this.params).then(res => {
  69. this.list.push(...res.data.list)
  70. // 判断是否还有更多数据
  71. let listNum = this.params.limit * this.params.page
  72. let total = res.data.total
  73. if (total > listNum) {
  74. this.loadMore = 'more'
  75. } else {
  76. this.loadMore = 'noMore'
  77. }
  78. })
  79. },
  80. clickMassage(value) {
  81. // 设置成已读
  82. let params = [value.id]
  83. value.status = 1
  84. messageReadApi(params).then(res => {
  85. // this.list = []
  86. // this.getList()
  87. })
  88. // 判断点击消息类型进行后续业务
  89. },
  90. },
  91. }
  92. </script>
  93. <style scoped lang="scss">
  94. .container {
  95. height: 100vh;
  96. .massage {
  97. margin: 5px 10px;
  98. .time {
  99. font-size: 12px;
  100. padding: 6px 0;
  101. text-align: center;
  102. }
  103. .info {
  104. background: #fff;
  105. border-radius: 5px;
  106. padding: 10px;
  107. .title {
  108. font-size: 16px;
  109. font-weight: 600;
  110. padding: 5px 0;
  111. }
  112. .text {
  113. font-size: 12px;
  114. color: #9999;
  115. }
  116. }
  117. }
  118. }
  119. </style>