|
@@ -37,7 +37,7 @@
|
|
|
<el-input v-model="content"></el-input>
|
|
|
</el-col>
|
|
|
<el-col :span="4" class="two_2">
|
|
|
- <el-button type="primary">发送</el-button>
|
|
|
+ <el-button type="primary" @click="send">发送</el-button>
|
|
|
</el-col>
|
|
|
</el-col>
|
|
|
</el-col>
|
|
@@ -47,46 +47,80 @@
|
|
|
|
|
|
<script>
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: clientApply } = createNamespacedHelpers('clientApply');
|
|
|
+const { mapActions: mapChat } = createNamespacedHelpers('chat');
|
|
|
export default {
|
|
|
name: 'chat',
|
|
|
- props: {},
|
|
|
+ props: {
|
|
|
+ userInfo: { type: Object },
|
|
|
+ },
|
|
|
components: {},
|
|
|
data: function () {
|
|
|
return {
|
|
|
content: '',
|
|
|
- list: [
|
|
|
- {
|
|
|
- id: '客服',
|
|
|
- sender_name: '客服',
|
|
|
- content: '信息内容1',
|
|
|
- },
|
|
|
- {
|
|
|
- id: '用户',
|
|
|
- sender_name: '用户',
|
|
|
- content: '信息内容2',
|
|
|
- },
|
|
|
- {
|
|
|
- id: '客服',
|
|
|
- sender_name: '客服',
|
|
|
- content: '信息内容3',
|
|
|
- },
|
|
|
- {
|
|
|
- id: '用户',
|
|
|
- sender_name: '用户',
|
|
|
- content: '信息内容4',
|
|
|
- },
|
|
|
- ],
|
|
|
+ list: [],
|
|
|
// 客服头像
|
|
|
leftIcon: require('@a/leftIcon.png'),
|
|
|
// 用户头像
|
|
|
rightIcon: require('@a/rightIcon.png'),
|
|
|
+ // 请求客服
|
|
|
+ customer: {},
|
|
|
};
|
|
|
},
|
|
|
- created() {},
|
|
|
+ created() {
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ ...clientApply(['query']),
|
|
|
+ ...mapChat(['create']),
|
|
|
+ async search() {
|
|
|
+ let res = await this.query({ ...this.userInfo });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `customer`, res.data);
|
|
|
+ this.channel();
|
|
|
+ }
|
|
|
+ },
|
|
|
// 区分发言人
|
|
|
isSender(data) {
|
|
|
- return data.id == '客服';
|
|
|
+ return data.customer_id != this.customer.customer_id;
|
|
|
+ },
|
|
|
+ // 发言
|
|
|
+ async send() {
|
|
|
+ if (!this.content) {
|
|
|
+ this.$message({
|
|
|
+ message: '发言内容不能为空',
|
|
|
+ type: 'warning',
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ let data = {
|
|
|
+ _tenant: this.customer._tenant,
|
|
|
+ client_id: this.customer.client_id,
|
|
|
+ customer_id: this.customer.customer_id,
|
|
|
+ sender_id: this.customer.client_id,
|
|
|
+ sender_name: this.customer.client_name,
|
|
|
+ content: this.content,
|
|
|
+ };
|
|
|
+ let res = await this.create(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$message({
|
|
|
+ message: '消息发送成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ this.content = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ channel() {
|
|
|
+ this.$stomp({
|
|
|
+ [`/exchange/platform/customer.${this.customer.client_id}.${this.customer.customer_id}`]: this.onMessage,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onMessage(message) {
|
|
|
+ let body = _.get(message, 'body');
|
|
|
+ if (body) {
|
|
|
+ body = JSON.parse(body);
|
|
|
+ this.list.push(body);
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
computed: {
|