message.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view>
  3. <uni-list v-for="(item,index) in list" :key="index">
  4. <!-- 头像显示圆点 -->
  5. <uni-list-chat clickable="true" :title="item.msgTitle" avatar="/static/avatar-msg.png" :note="item.msgContent" :time="item.datetime" :badge-positon="item.position" badge-text="dot" @click="gotoDetail(item)"></uni-list-chat>
  6. </uni-list>
  7. </view>
  8. </template>
  9. <script>
  10. import badgeMix from '@/mixins/tabbar-badge.js'
  11. export default {
  12. mixins: [badgeMix],
  13. data() {
  14. return {
  15. list: [],
  16. // 查询对象
  17. queryObject: {
  18. pageNum: 1,
  19. pageSize: 15
  20. },
  21. total: 0,
  22. isLoading: false
  23. };
  24. },
  25. onShow() {
  26. this.queryObject.pageNum = 1
  27. this.queryObject.pageSize = 15
  28. this.list = []
  29. this.getMsgList()
  30. },
  31. methods: {
  32. async getMsgList(cb) {
  33. // 打开节流阀
  34. this.isLoading = true
  35. const params = {
  36. pageNum: this.queryObject.pageNum,
  37. pageSize: this.queryObject.pageSize
  38. }
  39. const { data: result } = await uni.$http.get('/education/mp-inner-msg/queryMsg', params)
  40. this.isLoading = false
  41. // 加载完数据执行
  42. cb && cb()
  43. if (result.data.list !== undefined) {
  44. this.list = [...this.list, ...result.data.list]
  45. this.total = result.data.count
  46. }
  47. },
  48. gotoDetail(item) {
  49. // item.position = 'none'
  50. uni.navigateTo({
  51. url: '/subpkg/my/message/my_message_detail?item='+encodeURIComponent(JSON.stringify(item))
  52. })
  53. },
  54. // 触底事件
  55. onReachBottom() {
  56. // 判断是否有下一页的数据
  57. if (this.queryObject.pageNum * this.queryObject.pageSize >= this.total) return uni.$showMsg('数据加载完毕!')
  58. // 判断是否正在请求其他数据
  59. if (this.isLoading) return
  60. this.queryObject.pageNum += 1
  61. // 重新获取数据
  62. this.getMsgList()
  63. },
  64. // 下拉刷新事件
  65. onPullDownRefresh() {
  66. // 1. 重置关键数据
  67. this.queryObject.pageNum = 1
  68. this.total = 0
  69. this.list = []
  70. // 2.重新发起请求
  71. this.getMsgList(() => uni.stopPullDownRefresh())
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. </style>