message.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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" @modify="handleModify">
  9. </ItemMessage>
  10. </z-paging>
  11. </template>
  12. <script>
  13. import {
  14. getMsgCountUrl,
  15. getMessageListUrl,
  16. modifyMsgUrl
  17. } from '@/common/config/api.js'
  18. import ItemMessage from '@/components/ItemMessage.vue'
  19. export default {
  20. components: {
  21. ItemMessage
  22. },
  23. data() {
  24. return {
  25. dataList: []
  26. }
  27. },
  28. onShow() {
  29. this.getMsgCount();
  30. },
  31. computed: {
  32. computeNavHeight() {
  33. console.log(uni.$u.sys());
  34. return uni.$u.sys().statusBarHeight + 44 + 'px'
  35. }
  36. },
  37. methods: {
  38. handleModify(id) {
  39. modifyMsgUrl({
  40. params: {
  41. id
  42. }
  43. })
  44. .then(res => {
  45. console.log('阅读消息', res);
  46. this.$refs.msgpPging.reload();
  47. this.getMsgCount()
  48. })
  49. .catch(err => {
  50. console.log(err);
  51. })
  52. },
  53. // 获取未读消息数量
  54. getMsgCount() {
  55. getMsgCountUrl({
  56. params: {
  57. userId: this.vuex_user.id
  58. }
  59. })
  60. .then(res => {
  61. console.log('未读消息数', res);
  62. this.$refs.msgpPging.reload();
  63. const count = parseInt(res);
  64. if (count > 0) {
  65. uni.setTabBarBadge({
  66. index: 1,
  67. text: count > 99 ? '99+' : res
  68. })
  69. } else {
  70. uni.removeTabBarBadge({
  71. index: 1
  72. })
  73. }
  74. })
  75. .catch(err => {
  76. console.log(err);
  77. })
  78. },
  79. queryList(pageNo, pageSize) {
  80. // this.$refs.msgpPging.complete([1, 2, 3, 4, 5]);
  81. getMessageListUrl({
  82. pageNum: pageNo,
  83. pageSize: pageSize,
  84. userId: this.vuex_user.id
  85. })
  86. .then(res => {
  87. console.log('消息列表: ', res);
  88. this.$refs.msgpPging.complete(res.records);
  89. })
  90. .catch(err => {
  91. console.log('err: ', err);
  92. this.$refs.msgpPging.complete(false);
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. page {
  100. background-color: #F6F8FD;
  101. }
  102. .nav-header {
  103. background-image: url('@/static/images/nav-bg.png');
  104. background-size: cover;
  105. background-position: center;
  106. }
  107. </style>