chatItem.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="item u-border-bottom" :class="value.isTop? 'bg_view' : ''" hover-class="message-hover-class" @tap="linkTo(value)">
  3. <img-cache :src="value.avatar|| value.imgUrl"></img-cache>
  4. <u-badge v-if="value.unreadNumber" :count="value.unreadNumber" type="error" class="badge" :offset="offset"></u-badge>
  5. <view class="right title-wrap">
  6. <view class="right_top">
  7. <view class="right_top_name u-line-1">{{ value.chatName || value.nickName}}</view>
  8. <view class="right_top_time ">{{value.lastOperTime || value.lastOpenTime | format}}</view>
  9. </view>
  10. <view class="right_btm ">
  11. <view class="u-line-1" >{{value.msgType==0?value.content:message[value.msgType]}}</view>
  12. <view>
  13. <u-tag v-if="value.traderFlag == 1" style="margin-left: 10rpx;" text="粮商" size ="mini"type="info" mode="plain"/>
  14. <u-tag v-if="value.farmerFlag == 1" style="margin-left: 10rpx;" text="粮农" size ="mini"type="info" mode="plain"/>
  15. <u-tag v-if="value.driverFlag == 1" style="margin-left: 10rpx;" text="物流" size ="mini"type="info" mode="plain"/>
  16. </view>
  17. <!-- <view class="" v-show="voiceIcon">
  18. <u-icon color="#c4c7cf" v-if="index%2==0" name="bell" size="22"></u-icon>
  19. </view> -->
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import ImgCache from '@/components/img-cache/img-cache.vue';
  26. export default {
  27. name: 'u-chatItem',
  28. components:{
  29. ImgCache
  30. },
  31. props: {
  32. value: {
  33. type: Object,
  34. default() {
  35. return {};
  36. }
  37. },
  38. index: {
  39. type: Number,
  40. default: -1
  41. },
  42. voiceIcon:{
  43. type: Boolean,
  44. default () {
  45. return false;
  46. }
  47. }
  48. },
  49. data() {
  50. return {
  51. offset:[10, 620],
  52. message:['文字', '图片', '表情', '语音', '视频',
  53. '签到', '已撤销一条消息', '发红包', '抢红包'],
  54. $url:''
  55. };
  56. },
  57. filters: {
  58. format: function (e) {
  59. // 获取js 时间戳
  60. let time = new Date().getTime();
  61. // 去掉 js 时间戳后三位
  62. time = parseInt((time - e) / 1000);
  63. // 存储转换值
  64. let s;
  65. if (time < 60 * 10) {
  66. // 十分钟内
  67. return '刚刚';
  68. } else if (time < 60 * 60 && time >= 60 * 10) {
  69. // 超过十分钟少于1小时
  70. s = Math.floor(time / 60);
  71. return s + '分钟前';
  72. } else if (time < 60 * 60 * 24 && time >= 60 * 60) {
  73. // 超过1小时少于24小时
  74. s = Math.floor(time / 60 / 60);
  75. return s + '小时前';
  76. } else if (time < 60 * 60 * 24 * 3 && time >= 60 * 60 * 24) {
  77. // 超过1天少于3天内
  78. s = Math.floor(time / 60 / 60 / 24);
  79. return s + '天前';
  80. } else {
  81. // 超过3天
  82. var date = new Date(e);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  83. var Y = date.getFullYear() + '-';
  84. var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  85. var D = date.getDate() + ' ';
  86. var h = date.getHours() + ':';
  87. var m = date.getMinutes() + ':';
  88. var ss = date.getSeconds();
  89. return h+m+ss;
  90. }
  91. }
  92. },
  93. methods:{
  94. linkTo(item) {
  95. this.$emit('linkTo',item)
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .item {
  102. width: 750rpx;
  103. height: 160rpx;
  104. display: flex;
  105. align-items: center;
  106. image {
  107. width: 96rpx;
  108. height: 96rpx;
  109. margin: 20rpx;
  110. border-radius: 12rpx;
  111. flex: 0 0 96rpx;
  112. }
  113. .right {
  114. overflow: hidden;
  115. flex: 1 0;
  116. padding: 20rpx 20rpx 40rpx 0;
  117. &_top {
  118. display: flex;
  119. justify-content: space-between;
  120. &_name {
  121. font-size: 28rpx;
  122. font-weight: 800;
  123. color: $u-main-color;
  124. flex: 0 0 450rpx;
  125. overflow: hidden;
  126. }
  127. &_time {
  128. font-size: 22rpx;
  129. color: $u-light-color;
  130. }
  131. }
  132. &_btm {
  133. display: flex;
  134. justify-content: space-between;
  135. align-items: center;
  136. font-size: 22rpx;
  137. color: $u-tips-color;
  138. padding-top: 10rpx;
  139. }
  140. }
  141. }
  142. .bg_view {
  143. background-color: #fafafa;
  144. }
  145. .slot-wrap {
  146. display: flex;
  147. align-items: center;
  148. padding: 0 30rpx;
  149. }
  150. </style>