guhongwei 3 年之前
父节点
当前提交
76fd590294
共有 2 个文件被更改,包括 44 次插入11 次删除
  1. 8 0
      src/store/customer.js
  2. 36 11
      src/views/customer/index.vue

+ 8 - 0
src/store/customer.js

@@ -14,6 +14,14 @@ const actions = {
     const res = await this.$axios.$get('/capi/getRecord', payload);
     return res;
   },
+  async chatRecord({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get('/capi/chatRecord', {
+      skip,
+      limit,
+      ...info,
+    });
+    return res;
+  },
   async createChat({ commit }, payload) {
     const res = await this.$axios.$post('/capi/chat', payload);
     return res;

+ 36 - 11
src/views/customer/index.vue

@@ -115,22 +115,23 @@ export default {
     this.channel();
   },
   methods: {
-    ...customer(['online', 'record', 'createChat']),
+    ...customer(['online', 'record', 'createChat', 'chatRecord']),
     search() {},
-    chatBtn(data) {
+    // 点击获取客户聊天列表
+    async chatBtn(data) {
       this.$set(this, `chatUserInfo`, data);
+      let arr = await this.chatRecord({ client_id: data.client_id, customer_id: data.customer_id });
+      if (this.$checkRes(arr)) {
+        this.$set(this, `chatList`, arr.data);
+        this.scrollToBottom();
+      }
+      this.chatChannel();
     },
     // 区分发言人
     isSender(data) {
-      return data.id != '客服';
-    },
-    //获取客户列表
-    async getClientList() {
-      const res = await this.record({ _tenant: this._tenant, customer_id: this.user.id });
-      if (this.$checkRes(res)) {
-        this.$set(this, `userList`, res.data);
-      }
+      return data.sender_id != this.user.id;
     },
+    // 查询客服列表
     channel() {
       this.$stomp({
         [`/exchange/${this._tenant}/customer.${this.user.id}`]: this.onMessage,
@@ -141,7 +142,12 @@ export default {
       console.log('receive a message: ', message.body);
       if (message.body === 'research') this.getClientList();
     },
-
+    async getClientList() {
+      const res = await this.record({ _tenant: this._tenant, customer_id: this.user.id });
+      if (this.$checkRes(res)) {
+        this.$set(this, `userList`, res.data);
+      }
+    },
     async toOnline() {
       console.log('in function:');
       const time = 5000; //1min 600000
@@ -181,6 +187,25 @@ export default {
         }
       }
     },
+    chatChannel() {
+      this.$stomp({
+        [`/exchange/${this._tenant}/customer.${this.chatUserInfo.client_id}.${this.chatUserInfo.customer_id}`]: this.chatMessage,
+      });
+    },
+    chatMessage(message) {
+      let body = _.get(message, 'body');
+      if (body) {
+        body = JSON.parse(body);
+        this.chatList.push(body);
+        this.scrollToBottom();
+      }
+    },
+    scrollToBottom: function() {
+      this.$nextTick(() => {
+        var container = this.$el.querySelector('.right_2');
+        container.scrollTop = container.scrollHeight;
+      });
+    },
   },
   computed: {
     ...mapState(['user', '_tenant']),