messageList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="message-list">
  3. <view
  4. v-for="(item, index) in typeList"
  5. :key="index"
  6. class="list-item"
  7. @click="handleToDetail(item)">
  8. <image :src="$static(item.icon)" class="type-icon" />
  9. <view class="list-item-body">
  10. <view class="top">
  11. <view class="type-name">
  12. {{ item.label }}
  13. </view>
  14. <view
  15. v-if="item.firstData"
  16. class="type-time">
  17. {{ item.firstData | formatTime }}
  18. </view>
  19. </view>
  20. <view class="content">
  21. <view class="type-content">
  22. {{ item.desc }}
  23. </view>
  24. <view v-if="item.num && item.num > 0" class="num">
  25. {{ item.num > 99 ? '99+' : item.num }}
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { QueryUnreadCount, QueryMessageList } from 'API/admin'
  34. import config from './message.js'
  35. import { deepCopy } from '@/utils/lib.js'
  36. import moment from 'moment'
  37. import { mapActions } from 'vuex'
  38. export default {
  39. name: 'MessageList',
  40. filters: {
  41. formatTime(firstData) {
  42. if (!firstData.createTime) return '--'
  43. return moment(firstData.createTime).format('yyyy-MM-DD')
  44. }
  45. },
  46. data() {
  47. return {
  48. loading: false,
  49. typeList: deepCopy(config.typeList)
  50. }
  51. },
  52. mounted() {
  53. this.getMessage()
  54. },
  55. wkActivated() {
  56. this.getMessage()
  57. },
  58. methods: {
  59. ...mapActions({
  60. setBacklogNum: 'base/setBacklogNum'
  61. }),
  62. getMessage() {
  63. if (this.loading) return
  64. this.loading = true
  65. QueryUnreadCount().then(res => {
  66. this.typeList.forEach((item, index) => {
  67. if (res.hasOwnProperty(item.field)) {
  68. item.num = res[item.field] || 0
  69. if (item.num > 0) {
  70. this.getFirstMessage(index)
  71. this.$set(this.typeList, index, item)
  72. } else {
  73. item.desc = '暂无新消息'
  74. this.$set(this.typeList, index, item)
  75. }
  76. }
  77. })
  78. this.setBacklogNum(res)
  79. this.loading = false
  80. }).catch(() => {
  81. this.loading = false
  82. })
  83. },
  84. getFirstMessage(index) {
  85. QueryMessageList({
  86. label: this.typeList[index].value,
  87. page: 1,
  88. limit: 1,
  89. isRead: 0
  90. }).then(res => {
  91. this.typeList[index].firstData = res.list[0]
  92. this.typeList[index].desc = config.getMsgStr(res.list[0]).join('')
  93. this.$set(this.typeList, index, this.typeList[index])
  94. }).catch()
  95. },
  96. handleToDetail(item) {
  97. this.$Router.navigateTo({
  98. url: '/pages_message/messageDetail',
  99. query: {
  100. type: item.value
  101. }
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped lang="scss">
  108. .message-list {
  109. width: 100%;
  110. height: 100%;
  111. overflow: auto;
  112. padding-top: 20rpx;
  113. .list-item {
  114. width: 100%;
  115. background-color: white;
  116. padding: 20rpx 32rpx;
  117. border-bottom: 1rpx solid $border-color;
  118. @include left;
  119. &:last-child {
  120. border-bottom: 0 none;
  121. }
  122. .type-icon {
  123. width: 80rpx;
  124. height: 80rpx;
  125. border-radius: 50%;
  126. margin-right: 20rpx;
  127. }
  128. .list-item-body {
  129. flex: 1;
  130. overflow: hidden;
  131. .top {
  132. @include left;
  133. .type-name {
  134. flex: 1;
  135. font-weight: 500;
  136. font-size: $wk-font-medium;
  137. margin-right: 20rpx;
  138. @include ellipsis;
  139. }
  140. .type-time {
  141. color: $light;
  142. font-size: $wk-font-sm;
  143. }
  144. }
  145. .content {
  146. width: 100%;
  147. margin-top: 10rpx;
  148. @include left;
  149. .type-content {
  150. flex: 1;
  151. font-size: $wk-font-base;
  152. color: $gray;
  153. margin-right: 20rpx;
  154. @include ellipsis;
  155. }
  156. .num {
  157. min-width: 36rpx;
  158. height: 36rpx;
  159. line-height: 36rpx;
  160. font-size: 24rpx;
  161. padding: 0 5rpx;
  162. color: white;
  163. border-radius: 36rpx;
  164. background-color: $error;
  165. @include center;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. </style>