index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="">
  3. <view v-if="chatList.length" class="content ">
  4. <!-- {{userId == item.userId,userId,item.userId}} -->
  5. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)"
  6. v-for="(item,index) in chatList" :key='index' >
  7. <view class="flex padding-tb " v-if="userId == item.userId">
  8. <view>
  9. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.shopCover"></u-image>
  10. </view>
  11. <view class="flex-sub margin-left-sm">
  12. <view class="flex justify-between">
  13. <view style="width: 50%;">{{item.shopName}}</view>
  14. <view class="text-grey">{{item.createTime}}</view>
  15. </view>
  16. <view class="flex justify-between">
  17. <view class="text-grey">{{ item.messageType == 1? item.content : '[图片]'}}</view>
  18. <view v-if="item.userUnread"
  19. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  20. {{item.userUnread}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="flex padding-tb" v-else>
  26. <view>
  27. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.shopCover"></u-image>
  28. </view>
  29. <view class="flex-sub margin-left-sm">
  30. <view class="flex justify-between">
  31. <view style="width: 50%;">{{item.shopName}}</view>
  32. <view class="text-grey">{{item.createTime}}</view>
  33. </view>
  34. <view class="flex justify-between">
  35. <view class="text-grey">{{ item.messageType == 1? item.content : '[图片]'}}</view>
  36. <view v-if="item.userUnread"
  37. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  38. {{item.userUnread}}
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <empty v-if="!chatList.length && !msgList.length" content='暂无消息'></empty>
  46. </view>
  47. </template>
  48. <script>
  49. import empty from '../../components/empty.vue'
  50. export default {
  51. components: {
  52. empty
  53. },
  54. data() {
  55. return {
  56. page: 1,
  57. limit: 20,
  58. chatList: [],
  59. userId: '',
  60. msgList: [],
  61. time: '',
  62. count: 0,
  63. messageCount: 0
  64. }
  65. },
  66. onLoad() {
  67. this.getChatList()
  68. let that = this
  69. if (that.userId) {
  70. that.time = setInterval(function() {
  71. that.getChatList()
  72. // that.getMsgList()
  73. that.$nextTick(function() {
  74. that.messageCount = uni.getStorageSync('messageCount')
  75. })
  76. }, 3000)
  77. } else {
  78. that.chatList = []
  79. that.msgList = []
  80. }
  81. },
  82. onShow() {
  83. let that = this
  84. that.userId = uni.getStorageSync('userId')
  85. if (that.userId) {
  86. that.page = 1;
  87. // that.chatList = []
  88. that.msgList = []
  89. that.getChatList();
  90. } else {
  91. that.chatList = []
  92. that.msgList = []
  93. }
  94. },
  95. onHide() {
  96. clearInterval(this.time)
  97. },
  98. methods: {
  99. getChatList() {
  100. this.$Request.get("/app/ordersChat/selectOrdersChatPageUser", {
  101. page: this.page,
  102. limit: this.limit,
  103. }).then(res => {
  104. if (res.code == 0) {
  105. if (this.page == 1) {
  106. this.chatList = [];
  107. }
  108. res.data.list.forEach(d => {
  109. this.chatList.push(d);
  110. });
  111. this.count = res.data.totalCount;
  112. // this.chatList = res.data.list
  113. }
  114. });
  115. },
  116. // getMsgList() {
  117. // this.$Request.get("/app/message/selectMessageByUserIdLimit1").then(res => {
  118. // if (res.code == 0) {
  119. // this.msgList = res.data.list
  120. // }
  121. // });
  122. // },
  123. goIM(e) {
  124. let userId = this.$queue.getData('userId');
  125. if (e.userId == userId) {
  126. userId = e.byUserId
  127. } else {
  128. userId = e.userId
  129. }
  130. uni.navigateTo({
  131. url: '/pages/index/shop/im?ordersId=' + e.ordersId
  132. })
  133. // uni.navigateTo({
  134. // url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId
  135. // })
  136. },
  137. goMsg() {
  138. uni.navigateTo({
  139. url: '/pages/msg/message'
  140. })
  141. }
  142. },
  143. onReachBottom: function() {
  144. if (this.chatList.length == this.count) {
  145. uni.showToast({
  146. title: '已经到底了',
  147. icon: 'none'
  148. })
  149. } else {
  150. this.page = this.page + 1;
  151. this.getChatList();
  152. }
  153. },
  154. }
  155. </script>
  156. <style>
  157. page {
  158. background-color: #F7F7F7;
  159. }
  160. .bg {
  161. background: #FFFFFF;
  162. }
  163. </style>