index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="home-page">
  3. <van-empty description="暂无数据" :image="require('@/static/empty.png')" v-if="list.length===0&&!loading"/>
  4. <template v-else>
  5. <view class="message-box flex white-wrap" @click="handleGONext(item.SourceType)" v-for="item in list" :key="item.SourceType">
  6. <image class="icon" :src="item.img" mode="aspectFill"></image>
  7. <text style="flex: 1;margin-right: 5px;" class="van-ellipsis">{{item.Message}}</text>
  8. <van-tag round type="danger" color="#FF4444" v-if="item.Total>0">{{item.Total}}</van-tag>
  9. </view>
  10. </template>
  11. </view>
  12. </template>
  13. <script>
  14. import {apiMessageCount} from '@/api/message.js'
  15. import {shareData} from '@/utils/config.js'
  16. export default {
  17. data() {
  18. return {
  19. list:[],
  20. loading:false
  21. }
  22. },
  23. onShow() {
  24. this.getMessage()
  25. },
  26. onPullDownRefresh() {
  27. this.getMessage()
  28. setTimeout(()=>{
  29. uni.stopPullDownRefresh()
  30. }, 500);
  31. },
  32. onShareAppMessage() {
  33. return shareData
  34. },
  35. methods: {
  36. // 跳转消息列表
  37. handleGONext(e){
  38. uni.navigateTo({
  39. url:'../../pages-todomessages/list/list?type='+e
  40. })
  41. },
  42. //获取消息数据
  43. async getMessage(){
  44. this.loading=true
  45. const res=await apiMessageCount()
  46. this.loading=false
  47. if(res.code===200){
  48. const imgMap = {
  49. 1: require('../../static/icon-1.png'),
  50. 2: require('../../static/icon-2.png'),
  51. 3: require('../../static/icon-3.png'),
  52. 5: require('../../static/icon-question.png'),
  53. 6: require('../../static/icon-comment.png'),
  54. 10:require('../../static/icon-7.png'),
  55. }
  56. this.list=res.data&&res.data.map(item=>{
  57. let img=imgMap[item.SourceType]
  58. return {
  59. ...item,
  60. img
  61. }
  62. })
  63. }
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss">
  69. .message-box{
  70. padding: 20rpx 34rpx;
  71. align-items: center;
  72. border-bottom: 1rpx solid #f5f5f5;
  73. font-size: 16px;
  74. .icon{
  75. width: 102rpx;
  76. height: 102rpx;
  77. margin-right: 34rpx;
  78. flex-shrink: 0;
  79. }
  80. }
  81. </style>