guhongwei 3 years ago
parent
commit
1a5c75b9c4
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/components/chat.vue

+ 10 - 1
src/components/chat.vue

@@ -71,6 +71,7 @@ export default {
   created() {
     this.search();
   },
+  mounted() {},
   methods: {
     ...clientApply(['query']),
     ...mapChat(['create']),
@@ -84,11 +85,12 @@ export default {
       let arr = await this.chatQuery({ client_id: this.customer.client_id, customer_id: this.customer.customer_id });
       if (this.$checkRes(arr)) {
         this.$set(this, `list`, arr.data);
+        this.scrollToBottom();
       }
     },
     // 区分发言人
     isSender(data) {
-      return data.customer_id != this.customer.customer_id;
+      return data.sender_id == this.customer.customer_id;
     },
     // 发言
     async send() {
@@ -126,8 +128,15 @@ export default {
       if (body) {
         body = JSON.parse(body);
         this.list.push(body);
+        this.scrollToBottom();
       }
     },
+    scrollToBottom: function () {
+      this.$nextTick(() => {
+        var container = this.$el.querySelector('.one');
+        container.scrollTop = container.scrollHeight;
+      });
+    },
   },
   computed: {
     ...mapState(['user']),