message.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="main">
  3. <view class="padding-lr">
  4. <view v-for="(item,index) in messageList" @click="gotoliaotian(item)" :key="index" class="padding-lr-sm padding-tb-sm bg-white margin-top-sm fade-in"
  5. :style="'border-radius: 16rpx;box-shadow: 0 0 50rpx 0 rgba(0, 0, 0, 0.1);'+'opacity:'+opacity+';'+'transform: scale('+scale+');'">
  6. <view class="flex justify-start align-center">
  7. <u-icon name="order"></u-icon>
  8. <text class="text-lg margin-left-xs">{{
  9. item.type==1?'医生确认接单':item.type==2?'医生确认结束':item.type==3?'系统通知':item.type==4?'下单成功':item.type==5?'服务包下单成功':item.type==6?'服务包到期':item.type==7?'充值成功':item.type==8?'余额付款成功':item.type==9?'修改密码':item.type==10?'修改绑定电话':item.type==11?'修改支付密码':item.type==12?'社区端通知':item.type==13?'后台通知':item.type==99?'医生消息':'订单通知'
  10. }}</text>
  11. <view class="cu-tag badge text-xs margin-left-sm" v-if="item.type==99&&item.unread" style="position: static;">{{item.unread}}</view>
  12. </view>
  13. <view class="margin-top-sm text-cut">
  14. {{item.type==99?'最新消息:'+item.content:item.content}}
  15. </view>
  16. <view class="text-right" style="position: relative">
  17. <!-- <u-badge size="mini" :absolute="false" type="error" v-if="item.status==1" :is-dot="true"></u-badge>
  18. <text class="margin-left-xs" v-if="item.status==1">未读</text>
  19. <text class="margin-left-xs" v-if="item.status==2">已读</text> -->
  20. </view>
  21. </view>
  22. </view>
  23. <u-empty text="暂无数据" mode="order" :show="show" margin-top="250"></u-empty>
  24. <view class="cu-tabbar-height"></view>
  25. <view class="cu-tabbar-height"></view>
  26. <u-no-network></u-no-network>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. onLoad(options) {
  32. },
  33. onShow() {
  34. this.pageindex = 1
  35. this.messageList = []
  36. this.getMessage()
  37. // if (getApp().globalData.imService == null) {
  38. // let user = uni.getStorageSync('user')
  39. // getApp().globalData.imService = new IMService();
  40. // let loginResult = getApp().globalData.imService.login({
  41. // flag: user.flag,
  42. // nickname: user.nickname,
  43. // avatar: user.avatar
  44. // });
  45. // if (loginResult) {
  46. // //连接IM
  47. // getApp().globalData.imService.connectIM();
  48. // }
  49. // }
  50. this.imService = getApp().globalData.imService;
  51. this.imService.onConversationsUpdate = (conversations) => {
  52. this.conversations = conversations;
  53. // this.setUnreadAmount();
  54. };
  55. var promise = this.imService.latestConversations();
  56. promise.then(res => {
  57. this.conversations = res.content;
  58. console.log("conversations load successfully")
  59. // this.setUnreadAmount();
  60. console.log(this.conversations)
  61. uni.hideLoading();
  62. }).catch(e => {
  63. console.log(e)
  64. });
  65. },
  66. mounted() {
  67. setTimeout(() => {
  68. this.handleScroll()
  69. }, 800)
  70. },
  71. data() {
  72. return {
  73. messageList: [],
  74. pageindex: 1,
  75. show: false,
  76. conversations: {
  77. unreadTotal: 0,
  78. conversations: []
  79. },
  80. imService: null,
  81. opacity: 0,
  82. scale: 0.8
  83. }
  84. },
  85. onReachBottom() {
  86. this.getMessage()
  87. },
  88. methods: {
  89. getNodes(item) {
  90. return (item.top + 200) < uni.getSystemInfoSync().windowHeight && item.bottom >= 0
  91. },
  92. handleScroll() {
  93. let query = uni.createSelectorQuery().selectAll('.fade-in').boundingClientRect((res) => {
  94. res.forEach(item => {
  95. if (this.getNodes(item)) {
  96. this.opacity = 1
  97. this.scale = 1
  98. }
  99. })
  100. }).exec()
  101. },
  102. getMessage: async function() {
  103. let res = await this.$request.post("/api/v1/user/userMessageList", {
  104. page: this.pageindex
  105. })
  106. console.log(res)
  107. if (res.status == 0) {
  108. if (this.pageindex > res.data.last_page) {
  109. uni.showToast({
  110. title: "没有更多了",
  111. icon: "none"
  112. })
  113. } else {
  114. this.messageList = this.messageList.concat(res.data.data)
  115. this.pageindex++
  116. }
  117. }
  118. if (this.messageList.length == 0) {
  119. this.show = true
  120. } else {
  121. this.show = false
  122. }
  123. this.conversations.conversations.reverse()
  124. this.conversations.conversations.forEach(item => {
  125. let obj = {
  126. type: 99,
  127. content: item.lastMessage.type == 'text' ? item.lastMessage.payload.text : item.lastMessage.type == 'audio' ?
  128. '[语音消息]' : '[图片消息]',
  129. unread: item.unread,
  130. docter_id: item.userId.split('_')[1],
  131. }
  132. this.messageList.unshift(obj)
  133. })
  134. },
  135. gotoliaotian(item) {
  136. // this.getNodes()
  137. console.log(item)
  138. if (item.type == 1 || item.type == 4) {
  139. uni.navigateTo({
  140. url: "../common_tools/my_consulting/consultingInfo?id=" + item.relation_id
  141. })
  142. } else if (item.type == 2 && item.product_type == 1 || item.type == 2 && item.product_type == 2) {
  143. uni.navigateTo({
  144. url: "../common_tools/my_consulting/opinionInfo?id=" + item.relation_id
  145. })
  146. } else if (item.type == 5 || item.type == 6) {
  147. uni.navigateTo({
  148. url: "../service_box/box_details"
  149. })
  150. } else if (item.type == 99) {
  151. this.$request.post("/api/v1/docter/docterDetail", {
  152. docter_id: item.docter_id
  153. }).then(res => {
  154. let obj = {
  155. id: res.id,
  156. name: res.name,
  157. avatar: res.avatar
  158. }
  159. uni.navigateTo({
  160. url: "../common_tools/my_consulting/conversation?doctor=" + JSON.stringify(obj) + "&doctorstatus=" + 3
  161. })
  162. })
  163. }
  164. }
  165. }
  166. };
  167. </script>
  168. <style scoped lang="scss">
  169. .main {}
  170. .fade-in {
  171. transition: 0.3s all ease-out;
  172. box-sizing: border-box;
  173. }
  174. </style>