|
@@ -4,16 +4,18 @@
|
|
|
<rooms :list="list" @toChat="toChat"></rooms>
|
|
|
</template>
|
|
|
<template v-else>
|
|
|
- <chat :room="room" @toRoom="view = 'room'"></chat>
|
|
|
+ <chat :room="room" @toRoom="toRoom"></chat>
|
|
|
</template>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import _ from 'lodash';
|
|
|
import rooms from './parts/room.vue';
|
|
|
import chat from './parts/chat.vue';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
const { mapActions } = createNamespacedHelpers('personalroom');
|
|
|
+const { mapActions: personalChat } = createNamespacedHelpers('personalchat');
|
|
|
export default {
|
|
|
name: 'contextxx',
|
|
|
props: {},
|
|
@@ -33,9 +35,13 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
...mapActions(['query', 'fetch']),
|
|
|
+ ...personalChat({ getChatList: 'query' }),
|
|
|
async search() {
|
|
|
let res = await this.query({ seller_id: this.user.uid });
|
|
|
- if (this.$checkRes(res)) this.$set(this, `list`, res.data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
+ this.onMessage();
|
|
|
+ }
|
|
|
},
|
|
|
async toChat(data) {
|
|
|
let res = await this.fetch(data.id);
|
|
@@ -44,13 +50,26 @@ export default {
|
|
|
this.view = 'chat';
|
|
|
}
|
|
|
},
|
|
|
+ toRoom() {
|
|
|
+ this.view = 'room';
|
|
|
+ this.onMessage();
|
|
|
+ },
|
|
|
channel() {
|
|
|
this.$stomp({
|
|
|
[`/exchange/chat_message/${this.user.uid}`]: this.onMessage,
|
|
|
});
|
|
|
},
|
|
|
- onMessage(message) {
|
|
|
- console.log(message);
|
|
|
+ async onMessage(message) {
|
|
|
+ let res = await this.getChatList({ status: 0, receiver_id: this.user.uid });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ let arr = this.list.map(i => {
|
|
|
+ i.needRead ? '' : (i.needRead = 0);
|
|
|
+ let findRes = res.data.filter(f => i.buyer_id == f.sender_id);
|
|
|
+ i.needRead = findRes.length || 0;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ this.$set(this, `list`, arr);
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
computed: {
|