message.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <z-paging ref="msgpPging" v-model="dataList" @query="queryList" loading-more-no-more-text="没有更多消息了">
  3. <template v-slot:top>
  4. <up-navbar title="消息" bgColor="transparent" leftIcon='' :title-style="{fontWeight:'bold'}">
  5. </up-navbar>
  6. <div class="nav-header" :style="{height:computeNavHeight}"></div>
  7. </template>
  8. <ItemMessage v-for="(item,index) in dataList" :item="item" :index="index" :key="item.notice_user_id"
  9. @modify="handleModify">
  10. </ItemMessage>
  11. </z-paging>
  12. </template>
  13. <script>
  14. import {
  15. getMsgCountUrl,
  16. // getMessageListUrl,
  17. modifyMsgUrl
  18. } from '@/common/config/api.js'
  19. import ItemMessage from '@/components/ItemMessage.vue'
  20. export default {
  21. components: {
  22. ItemMessage
  23. },
  24. data() {
  25. return {
  26. dataList: []
  27. }
  28. },
  29. onShow() {
  30. this.getMsgCount();
  31. },
  32. computed: {
  33. computeNavHeight() {
  34. console.log(uni.$u.sys());
  35. return uni.$u.sys().statusBarHeight + 44 + 'px'
  36. }
  37. },
  38. methods: {
  39. handleModify(id) {
  40. modifyMsgUrl({
  41. noticeUserId: id
  42. })
  43. .then(res => {
  44. console.log('阅读消息', res);
  45. this.$refs.msgpPging.reload();
  46. this.getMsgCount()
  47. })
  48. .catch(err => {
  49. console.log(err);
  50. })
  51. },
  52. // 获取未读消息数量
  53. getMsgCount() {
  54. getMsgCountUrl({
  55. params: {
  56. pageNum: 1,
  57. pageSize: 1,
  58. userId: this.vuex_user.id,
  59. status: 0
  60. },
  61. custom: {
  62. catch: true
  63. }
  64. })
  65. .then(res => {
  66. console.log('未读消息数', res);
  67. this.$refs.msgpPging.reload();
  68. if (res.code === 200) {
  69. const count = String(res.total);
  70. if (count > 0) {
  71. uni.setTabBarBadge({
  72. index: 1,
  73. text: count > 99 ? '99+' : count
  74. })
  75. } else {
  76. uni.removeTabBarBadge({
  77. index: 1
  78. })
  79. }
  80. } else {
  81. uni.removeTabBarBadge({
  82. index: 1
  83. })
  84. }
  85. })
  86. .catch(err => {
  87. console.log(err);
  88. })
  89. },
  90. queryList(pageNo, pageSize) {
  91. // this.$refs.msgpPging.complete([1, 2, 3, 4, 5]);
  92. getMsgCountUrl({
  93. params: {
  94. pageNum: 1,
  95. pageSize: 1,
  96. userId: this.vuex_user.id,
  97. status: 0
  98. },
  99. })
  100. .then(res => {
  101. console.log('消息列表: ', res);
  102. this.$refs.msgpPging.complete(res);
  103. })
  104. .catch(err => {
  105. console.log('err: ', err);
  106. this.$refs.msgpPging.complete(false);
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. page {
  114. background-color: #F6F8FD;
  115. }
  116. .nav-header {
  117. background-image: url('@/static/images/nav-bg.png');
  118. background-size: cover;
  119. background-position: center;
  120. }
  121. </style>