index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  55. this.list=res.data&&res.data.map(item=>{
  56. let img=imgMap[item.SourceType]
  57. return {
  58. ...item,
  59. img
  60. }
  61. })
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss">
  68. .message-box{
  69. padding: 20rpx 34rpx;
  70. align-items: center;
  71. border-bottom: 1rpx solid #f5f5f5;
  72. font-size: 16px;
  73. .icon{
  74. width: 102rpx;
  75. height: 102rpx;
  76. margin-right: 34rpx;
  77. flex-shrink: 0;
  78. }
  79. }
  80. </style>