<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 name="有效">
            <template #title>有效({{ total1 }}) </template>
            <list-1 :list="list" @toView="toView"></list-1>
          </van-tab>
          <van-tab name="审中">
            <template #title>审中({{ total2 }})</template>
            <list-1 :list="list" @toView="toView"></list-1>
          </van-tab>
          <van-tab name="失效">
            <template #title>失效({{ total3 }}) </template>
            <list-1 :list="list" @toView="toView"></list-1>
          </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 v-if="dialog.type == '1'" :info="info"></info-1>
    </van-dialog>
  </div>
</template>

<script>
import list1 from '@/layout/patentInfo/list-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: patentinfo } = createNamespacedHelpers('patentinfo');
const { mapActions: personal } = createNamespacedHelpers('personal');
const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
  },
  data: function () {
    return {
      // 选项
      active: '有效',
      list: [],
      limit: 4,
      total: 0,
      // 专利总数
      total1: 0,
      total2: 0,
      total3: 0,
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    await this.searchOther();
    await this.search({ term: '有效' });
  },
  methods: {
    ...patentinfo(['query', 'queryByOrg', 'fetch']),
    ...personal({ personalFetch: 'fetch' }),
    ...adminLogin({ adminQuery: 'query' }),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      info.term = this.active ? this.active : '有效';
      info.first_apply = this.user.deptname;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        console.log(res);
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 选择标签
    change(value) {
      this.$set(this, `active`, value);
      this.search({ term: value });
    },
    // 查看信息
    async toView(data) {
      let res = await this.fetch(data.id);
      if (this.$checkRes(res)) {
        this.$set(this, `info`, res.data);
        this.dialog = { show: true, title: '详细信息', type: '1' };
      }
    },
    // 查询总数a
    async searchOther({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, term: '有效', first_apply: this.user.deptname, ...info });
      if (this.$checkRes(res)) this.$set(this, `total1`, res.total);
      res = await this.query({ skip, limit, term: '审中', first_apply: this.user.deptname, ...info });
      if (this.$checkRes(res)) this.$set(this, `total2`, res.total);
      res = await this.query({ skip, limit, term: '失效', first_apply: this.user.deptname, ...info });
      if (this.$checkRes(res)) this.$set(this, `total3`, res.total);
    }, // 返回
    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>
