<template>
  <div id="index">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" @back="back" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <van-tabs v-model="active" @change="change">
          <van-tab :title="`专利信息(${oneTotal})`" name="1">
            <list-1 :list="oneList" @toView="oneView"></list-1>
          </van-tab>
          <van-tab :title="`交易公告(${twoTotal})`" name="2">
            <list-2 :list="twoList"></list-2>
          </van-tab>
          <!-- <van-tab :title="`专利转让(${thrTotal})`" name="3">
            <list-3 :list="thrList" @toView="toView"></list-3>
          </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-3 :info="info" v-if="dialog.type == '1'"></info-3>
      <info-1 :info="info" v-else-if="dialog.type == '2'"></info-1>
    </van-dialog>
  </div>
</template>

<script>
import list1 from '@/layout/patentInfo/list-2.vue';
import list2 from './parts/list-2.vue';
import list3 from '@/layout/trans/list-2.vue';
import info3 from '@/layout/trans/info-1.vue';
import info1 from '@/layout/patentInfo/info-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
const { mapActions: patenttrans } = createNamespacedHelpers('patenttrans');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
    list2,
    // list3,
    info3,
  },
  data: function () {
    return {
      adminInfo: {},
      active: '1',
      limit: 5,
      total: 0,
      // 专利信息
      oneList: [],
      // 交易公告
      twoList: [],
      // 转让交易
      thrList: [],
      oneTotal: 0,
      twoTotal: 0,
      thrTotal: 0,
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    await this.searchOther();
    await this.searchTotal();
    await this.search();
  },
  methods: {
    ...adminLogin({ adminLoginQuery: 'query' }),
    ...patentinfo(['query', 'fetch']),
    ...patenttrans({ transQuery: 'query' }),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      if (this.active == '1') {
        let res = await this.query({ skip, limit, first_apply: this.adminInfo.deptname, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `oneList`, res.data);
          this.$set(this, `total`, res.total);
        }
      } else if (this.active == '2') {
        let res = await this.transQuery({ skip, limit, status: '2', ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `twoList`, res.data);
          this.$set(this, `total`, res.total);
        }
      }
      // else if (this.active == '3') {
      //   let res = await this.transQuery({ skip, limit, status: '1', ...info });
      //   if (this.$checkRes(res)) {
      //     this.$set(this, `thrList`, res.data);
      //     this.$set(this, `total`, res.total);
      //   }
      // }
    },
    // 查询总数
    async searchTotal({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, first_apply: this.adminInfo.deptname, ...info });
      if (this.$checkRes(res)) this.$set(this, `oneTotal`, res.total);
      res = await this.transQuery({ ...info });
      let p1 = res.data.filter((i) => i.status == '2');
      if (p1) this.$set(this, `twoTotal`, p1.length);
      // let p2 = res.data.filter((i) => i.status == '1');
      // if (p2) this.$set(this, `thrTotal`, p2.length);
    },
    // 专利详情
    async oneView(data) {
      let res = await this.fetch(data.id);
      if (this.$checkRes(res)) {
        this.$set(this, `info`, res.data);
        this.dialog = { show: true, title: '详细信息', type: '2' };
      }
    },
    // 交易详情
    twoDetail(data) {
      this.$router.push({ path: '/patent/market/transDetail', query: { id: data._id } });
    },
    change(name) {
      this.$set(this, `active`, name);
      this.search();
    },
    // 转让信息
    // 详细信息
    toView(data) {
      this.$set(this, `info`, data);
      this.dialog = { show: true, title: '详细信息', type: '1' };
    },
    // 查询其他信息
    async searchOther() {
      let res = await this.adminLoginQuery({ code: this.user.code });
      if (this.$checkRes(res)) {
        this.$set(this, `adminInfo`, res.data[0]);
      }
    },
    // 返回
    back() {
      this.$router.push({ path: '/patent/index' });
    },
  },
  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>
