<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="成交专利">
            <template #title>成交专利({{ total1 }})</template>
            <list-1 :list="list"></list-1>
          </van-tab>
          <van-tab title="交易信息">
            <template #title>交易信息({{ total2 }})</template>
            <list-2 :list="list" @toView="toView"></list-2>
          </van-tab>
        </van-tabs>
      </template>
    </admin-frame>
    <van-dialog class="dialog" v-model="dialog.show" :title="dialog.title" :show-confirm-button="false" show-cancel-button cancel-button-text="返回">
      <info-1 :info="info" v-if="dialog.type == '1'"></info-1>
    </van-dialog>
  </div>
</template>

<script>
import list1 from './parts/list-1.vue';
import list2 from '@/layout/trans/list-2.vue';
import info1 from '@/layout/trans/info-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,
    list2,
    info1,
  },
  data: function () {
    return {
      active: 0,
      limit: 5,
      total: 0,
      // 转让信息
      list: [],
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
      // 显示总数
      total1: 0,
      total2: 0,
    };
  },
  async created() {
    await this.search();
    await this.searchOther();
  },
  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: '5', ...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: '1', ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
          this.$set(this, `total`, res.total);
        }
      }
    },
    // 查看详情
    toView(data) {
      this.$set(this, `info`, data);
      let dialog = { show: true, title: '详细信息', type: '1' };
      this.$set(this, `dialog`, dialog);
    },
    // 选择类型
    changeActive(value) {
      this.$set(this, `active`, Number(value));
      this.search();
    },
    // 查询其他信息
    async searchOther() {
      let res = await this.query({ status: '5' });
      if (this.$checkRes(res)) this.$set(this, `total1`, res.total);
      res = await this.query({ status: '1' });
      if (this.$checkRes(res)) this.$set(this, `total2`, res.total);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.dialog {
  /deep/.van-dialog__content {
    max-height: 350px;
    overflow-y: auto;
  }
}
</style>
