message.vue 2.2 KB

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