<template>
  <div id="index">
    <mobileMain :useNav="false" @search="search" :total="total" :limit="limit">
      <template v-slot:info>
        <van-tabs v-model="active" @click="changeActive">
          <van-tab title="嘉宾访谈" name="0">
            <one-frame :list="list"></one-frame>
          </van-tab>
          <van-tab title="技能培训" name="1">
            <two-frame :list="list"></two-frame>
          </van-tab>
        </van-tabs>
      </template>
    </mobileMain>
  </div>
</template>

<script>
import oneFrame from '../parts/list_4.vue';
import twoFrame from '../parts/list_5.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: interview } = createNamespacedHelpers('interview');
const { mapActions: trainLive } = createNamespacedHelpers('trainLive');
export default {
  name: 'index',
  props: {},
  components: {
    oneFrame,
    twoFrame,
  },
  data: function() {
    return {
      active: 0,
      list: [],
      total: 0,
      limit: 10,
    };
  },
  created() {
    this.changeActive();
  },
  methods: {
    ...interview(['query']),
    ...trainLive({ getTrainlive: 'query' }),
    async search({ skip = 0, limit = this.limit, searchName, ...info } = {}) {
      if (searchName) info.title = searchName;
      if (this.active == 0) {
        let res = await this.query({ skip, limit, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
          this.$set(this, `total`, res.total);
        }
      } else if (this.active == 1) {
        let res = await this.getTrainlive({ skip, limit, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
          this.$set(this, `total`, res.total);
        }
      }
    },
    changeActive(name) {
      this.$set(this, `active`, name || 0);
      this.search();
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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