liaotian.vue 5.4 KB

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