<template>
  <div id="contextxx">
    <template v-if="view == 'room'">
      <rooms :list="list" @toChat="toChat"></rooms>
    </template>
    <template v-else>
      <chat :room="room"></chat>
    </template>
  </div>
</template>

<script>
import rooms from './parts/room.vue';
import chat from './parts/chat.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('personalroom');
export default {
  name: 'contextxx',
  props: {},
  components: { rooms, chat },
  data: () => {
    return {
      view: 'room',
      list: [],
      room: {},
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...mapActions(['query', 'fetch']),
    async search() {
      let res = await this.query({ seller_id: this.user.uid });
      if (this.$checkRes(res)) this.$set(this, `list`, res.data);
    },
    async toChat(data) {
      let res = await this.fetch(data.id);
      if (this.$checkRes(res)) {
        this.$set(this, `room`, res.data);
        this.view = 'chat';
      }
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped></style>
