<template>
  <div id="index">
    <admin-frame @search="search" :limit="limit" :total="total" :useNav="false">
      <template v-slot:info>
        <van-tabs v-model="active" @change="changeActive">
          <van-tab title="成交专利">
            <list-1 :list="list" @detail="detail"></list-1>
          </van-tab>
          <van-tab title="转让信息">
            <list-1 :list="list" @detail="detail"></list-1>
          </van-tab>
        </van-tabs>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import list1 from './parts/list-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patenttrans } = createNamespacedHelpers('patenttrans');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
  },
  data: function () {
    return {
      active: 0,
      limit: 5,
      total: 0,
      // 转让信息
      list: [],
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patenttrans(['query']),
    async search({ skip = 0, limit = this.limit, searchName, ...info } = {}) {
      if (searchName) info.patent_name = searchName;
      if (this.active == 0) {
        let res = await this.query({ skip, limit, status: '4', ...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.query({ skip, limit, status: '0', ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
          this.$set(this, `total`, res.total);
        }
      }
    },
    // 详情
    detail(data) {
      if (this.active == '1') {
        this.$router.push({ path: '/market/transfer/detail', query: { id: data.id } });
      }
    },
    // 选择类型
    changeActive(value) {
      this.$set(this, `active`, Number(value));
      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>
