contextxx.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div id="contextxx">
  3. <template v-if="view == 'room'">
  4. <rooms :list="list" @toChat="toChat"></rooms>
  5. </template>
  6. <template v-else>
  7. <chat :room="room" @toRoom="toRoom"></chat>
  8. </template>
  9. </div>
  10. </template>
  11. <script>
  12. import _ from 'lodash';
  13. import rooms from './parts/room.vue';
  14. import chat from './parts/chat.vue';
  15. import { mapState, createNamespacedHelpers } from 'vuex';
  16. const { mapActions } = createNamespacedHelpers('personalroom');
  17. const { mapActions: personalChat } = createNamespacedHelpers('personalchat');
  18. export default {
  19. name: 'contextxx',
  20. props: {},
  21. components: { rooms, chat },
  22. data: () => {
  23. return {
  24. view: 'room',
  25. list: [],
  26. room: {},
  27. };
  28. },
  29. created() {
  30. this.search();
  31. },
  32. mounted() {
  33. this.channel();
  34. },
  35. methods: {
  36. ...mapActions(['query', 'fetch']),
  37. ...personalChat({ getChatList: 'query' }),
  38. async search() {
  39. let res = await this.query({ seller_id: this.user.uid });
  40. if (this.$checkRes(res)) {
  41. this.$set(this, `list`, res.data);
  42. this.onMessage();
  43. }
  44. },
  45. async toChat(data) {
  46. let res = await this.fetch(data.id);
  47. if (this.$checkRes(res)) {
  48. this.$set(this, `room`, res.data);
  49. this.view = 'chat';
  50. }
  51. },
  52. toRoom() {
  53. this.view = 'room';
  54. this.onMessage();
  55. },
  56. channel() {
  57. this.$stomp({
  58. [`/exchange/chat_message/${this.user.uid}`]: this.onMessage,
  59. });
  60. },
  61. async onMessage(message) {
  62. let res = await this.getChatList({ status: 0, receiver_id: this.user.uid });
  63. if (this.$checkRes(res)) {
  64. let arr = this.list.map(i => {
  65. i.needRead ? '' : (i.needRead = 0);
  66. let findRes = res.data.filter(f => i.buyer_id == f.sender_id);
  67. i.needRead = findRes.length || 0;
  68. return i;
  69. });
  70. this.$set(this, `list`, arr);
  71. }
  72. },
  73. },
  74. computed: {
  75. ...mapState(['user']),
  76. pageTitle() {
  77. return `${this.$route.meta.title}`;
  78. },
  79. },
  80. metaInfo() {
  81. return { title: this.$route.meta.title };
  82. },
  83. };
  84. </script>
  85. <style lang="less" scoped></style>