message.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="message-page custom_status_bar">
  3. <view class="nav">
  4. <view class="back" @click="back">
  5. <uni-icons type="back" size="20"></uni-icons>
  6. </view>
  7. <view class="title">消息</view>
  8. <template>
  9. <view @click="clickRight" class="nav-right" v-if="status===0">
  10. <image class="icon" src="/static/message/nav1.png" mode="widthFix"></image>
  11. <text>清除未读</text>
  12. </view>
  13. <view class="nav-right read" v-else>
  14. <image class="icon" src="/static/message/nav2.png" mode="widthFix"></image>
  15. <text>全部已读</text>
  16. </view>
  17. </template>
  18. </view>
  19. <view class="container">
  20. <view class="message-box" v-for="(item,index) in items" :key="index">
  21. <uni-swipe-action>
  22. <uni-swipe-action-item :right-options="options"
  23. :left-options="options"
  24. @click="onClick($event,item)"
  25. @change="swipeChange">
  26. <uni-list-chat
  27. :avatar-circle="true"
  28. :title="item.msgFrName||'发件人'"
  29. :avatar="item.msgFrAvatar||defaultAvatar"
  30. badge-positon="left" :badge-text="item.isRead===0?'dot':''"
  31. :note="item.msgContent"
  32. :clickable="true"
  33. @click="handleMessage(item)"
  34. >
  35. <view class="chat-custom-right">
  36. <text class="chat-custom-text">{{formateDate(item.msgTime)}}</text>
  37. <!-- <view class="badge-box">
  38. <uni-badge class="uni-badge-left-margin" :text="1" />
  39. </view> -->
  40. </view>
  41. </uni-list-chat>
  42. </uni-swipe-action-item>
  43. </uni-swipe-action>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import{
  50. parseTime,
  51. MessageTimeFormat
  52. } from '@/libs/index.js'
  53. import { putAllReadStatus, getMsgReceivedByPage, deleteMsgById, putReadStatus, getMsgById } from '@/api/system/msgApi'
  54. export default {
  55. data() {
  56. return {
  57. status:0,
  58. conditions: {
  59. page: 1,
  60. limit: 10
  61. },
  62. total:0,
  63. defaultAvatar:"/static/components/avatar.png",
  64. items:[],
  65. options:[
  66. {
  67. id:"1",
  68. text: '取消',
  69. style: {
  70. backgroundColor: '#007aff'
  71. }
  72. }, {
  73. id:"2",
  74. text: '删除',
  75. style: {
  76. backgroundColor: '#dd524d'
  77. }
  78. }
  79. ]
  80. }
  81. },
  82. onShow() {
  83. this.getData()
  84. },
  85. methods: {
  86. back(){
  87. uni.navigateBack()
  88. },
  89. clickRight(){
  90. putAllReadStatus().then(() => {
  91. this.status=1
  92. this.conditions.page=1
  93. this.conditions.limit=10
  94. this.total=0
  95. this.items=[]
  96. this.getData()
  97. })
  98. },
  99. getData(){
  100. let items=JSON.parse(JSON.stringify(this.items))
  101. getMsgReceivedByPage(this.conditions).then((res)=>{
  102. this.items=items.concat(res.data)
  103. this.total=res.total
  104. })
  105. },
  106. handleMessage(item){
  107. if (item.isRead === 0) {
  108. putReadStatus(item.msgId).then(() => {
  109. item.isRead=1
  110. uni.showToast({
  111. icon:"none",
  112. title:"已读"
  113. })
  114. })
  115. }
  116. },
  117. onClick(e,data){
  118. deleteMsgById(data.msgId).then(() => {
  119. this.conditions.page=1
  120. this.conditions.limit=10
  121. this.total=0
  122. this.items=[]
  123. this.getData()
  124. })
  125. },
  126. // swipeChange(e,index){
  127. // console.log('当前状态:'+ e +',下标:' + index)
  128. // },
  129. formateDate(val){
  130. return MessageTimeFormat(parseTime(val))
  131. }
  132. },
  133. onReachBottom() {
  134. if(this.total>=this.conditions.page*this.conditions.limit){
  135. this.conditions.page++
  136. this.getData()
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .message-page{
  143. /* #ifdef MP-WEIXIN */
  144. padding-top: 30px;
  145. /* #endif */
  146. background-color: rgba(243, 244, 247, 1);
  147. box-sizing: border-box;
  148. min-height: 100vh;
  149. padding-bottom: 50rpx;
  150. box-sizing: border-box;
  151. .nav{
  152. height: 44px;
  153. display: flex;
  154. align-items: center;
  155. padding: 0 10px;
  156. height: 44px;
  157. font-size: 12px;
  158. color: rgb(51, 51, 51);
  159. background-color: rgb(255, 255, 255);
  160. .back{
  161. width: 140rpx;
  162. }
  163. .title{
  164. flex: 1;
  165. text-align: center;
  166. font-size: 14px;
  167. overflow: hidden;
  168. white-space: nowrap;
  169. text-overflow: ellipsis;
  170. }
  171. .nav-right{
  172. display: flex;
  173. justify-items: center;
  174. align-items: center;
  175. color: rgba(151, 151, 151, 1);
  176. &.read{
  177. color: rgba(42, 91, 238, 1);
  178. }
  179. .icon{
  180. width: 44rpx;
  181. }
  182. }
  183. }
  184. .container{
  185. margin-top: 16rpx;
  186. .chat-custom-text{
  187. font-size: 26rpx;
  188. color: rgba(151, 151, 151, 1);
  189. }
  190. .badge-box{
  191. text-align: right;
  192. }
  193. }
  194. }
  195. </style>