msg.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view class="page" style="background-color: #fff;">
  3. <view v-if="dataList.length == 0" class="empty-wrap"><u-empty text="暂无消息"></u-empty></view>
  4. <!-- 记录 -->
  5. <u-cell-group v-if="dataList.length > 0">
  6. <u-cell-item
  7. v-for="(item, index) in dataList"
  8. :key="index"
  9. :title="!item.body.content ? '点击查看内容' : item.body.content.length > 15 ? item.body.content.slice(0, 15) + '...' : item.body.content"
  10. :title-style="{ fontWeight: item.is_read ? '' : 'bold' }"
  11. :label="vk.pubfn.timeFormat(item._add_time, 'yyyy-MM-dd')"
  12. :value="item.is_read ? '已读' : '未读'"
  13. arrow
  14. @click="showDetailPopup(index)"
  15. ></u-cell-item>
  16. </u-cell-group>
  17. <!-- 消息详情 -->
  18. <u-popup v-model="detailPopupShow" mode="center" width="80%" height="480rpx" border-radius="20" closeable close-icon-color="#fff">
  19. <view class="bwin-popup">
  20. <view class="popup-header">消息详情</view>
  21. <view v-if="detailPopupShow" class="popup-body">
  22. <text class="content" v-if="dataList[currentItemIndex].type == 'text'">{{ dataList[currentItemIndex].body.content }}</text>
  23. <u-image v-if="dataList[currentItemIndex].type == 'image'" :src="dataList[currentItemIndex].body.files" mode="widthFix" width="100%"></u-image>
  24. <view class="from-info">
  25. <view class="nickname">{{ dataList[currentItemIndex].fromUserInfo.nickname }}</view>
  26. <view class="date">{{ dataList[currentItemIndex].fromUserInfo._add_time | date('yyyy-mm-dd hh:MM:ss') }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </u-popup>
  31. <u-loadmore
  32. v-if="dataList.length > 0"
  33. marginTop="20"
  34. :line="true"
  35. :status="loadmore.status"
  36. :loading-text="loadmore.loadingText"
  37. :loadmore-text="loadmore.defaultText"
  38. :nomore-text="loadmore.nomoreText"
  39. />
  40. </view>
  41. </template>
  42. <script>
  43. var that;
  44. export default {
  45. data() {
  46. return {
  47. dataList: [],
  48. detailPopupShow: false,
  49. currentItemIndex: 0,
  50. loadmore: {
  51. status: 'loadmore',
  52. loadingText: '努力加载中',
  53. defaultText: '轻轻上拉 查看更多',
  54. nomoreText: '实在没有了',
  55. currentPage: 1
  56. }
  57. };
  58. },
  59. onLoad() {
  60. that = this;
  61. vk.callFunction({
  62. url: 'client/agent/kh/getMsgList',
  63. title: '请求中...',
  64. needAlert: false
  65. }).then(res => {
  66. if (res.list.length < 10) {
  67. that.loadmore.status = 'nomore';
  68. }
  69. that.dataList = res.list;
  70. });
  71. },
  72. onReachBottom() {
  73. if (that.loadmore.status == 'nomore') {
  74. return;
  75. }
  76. that.loadmore.currentPage++;
  77. vk.callFunction({
  78. url: 'client/agent/kh/getMsgList',
  79. title: '请求中...',
  80. needAlert: false,
  81. data: {
  82. pageIndex: that.loadmore.currentPage
  83. }
  84. }).then(res => {
  85. if (res.list.length < 10) {
  86. that.loadmore.status = 'nomore';
  87. }
  88. that.dataList = that.dataList.concat(res.list);
  89. });
  90. },
  91. methods: {
  92. showDetailPopup(index) {
  93. that.currentItemIndex = index;
  94. that.detailPopupShow = true;
  95. if (!that.dataList[index].is_read) {
  96. vk.callFunction({
  97. url: 'client/agent/kh/updateMsgStatus',
  98. needAlert: false,
  99. data: {
  100. _id: that.dataList[index]._id
  101. }
  102. }).then(res => {
  103. that.dataList[index].is_read = true; // 标记已读
  104. });
  105. }
  106. }
  107. }
  108. };
  109. </script>
  110. <style lang="scss">
  111. .popup-body {
  112. .content {
  113. font-size: $u-p;
  114. display: flex;
  115. padding: 20rpx;
  116. background-color: $u-bg-color;
  117. border-radius: 10rpx;
  118. width: 100%;
  119. }
  120. .from-info {
  121. padding-top: 20rpx;
  122. width: 100%;
  123. display: flex;
  124. align-items: center;
  125. justify-content: space-between;
  126. font-size: $u-p1;
  127. .nickname {
  128. color: $u-main-color;
  129. }
  130. .date {
  131. color: $u-content-color;
  132. }
  133. }
  134. }
  135. </style>