message.vue 5.7 KB

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