<template>
  <div id="index">
    <admin-frame
      @search="search"
      :limit="limit"
      :total="total"
      topType="2"
      :usePage="active == '0' ? false : true"
      @back="back"
      :rightArrow="false"
      :useNav="false"
    >
      <template v-slot:info>
        <van-tabs v-model="active">
          <van-tab title="审批单">
            <form-2 :apply_id="apply_id"></form-2>
          </van-tab>
          <van-tab title="已申请">
            <list-1 :list="list" @toView="toView" @toResult="toResult" @toHeavy="toHeavy" @toGzj="toGzj"></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 :info="info" v-if="dialog.type == '1'"></info-1>
      <result-1 :info="info" v-else-if="dialog.type == '2'"></result-1>
    </van-dialog>
  </div>
</template>

<script>
import form2 from '@/layout/apply/form-2.vue';
import list1 from '@/layout/apply/list-1.vue';
import info1 from '@/layout/apply/info-1.vue';
import result1 from '@/layout/apply/result-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentapply } = createNamespacedHelpers('patentapply');
export default {
  name: 'index',
  props: {},
  components: { adminFrame, form2, list1, info1, result1 },
  data: function () {
    return {
      active: 0,
      // 列表
      list: [],
      limit: 4,
      total: 0,
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
      // 重申数据id
      apply_id: '',
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patentapply(['query', 'fetch', 'create', 'update']),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, user_id: this.user._id, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查看信息
    async toView(data) {
      let res = await this.fetch(data.id);
      if (this.$checkRes(res)) {
        if (res.data.questions == undefined) res.data.questions = {};
        this.$set(this, `info`, res.data);
        this.dialog = { show: true, title: '详细信息', type: '1' };
      }
    },
    // 查看审核结果
    toResult(data) {
      this.$set(this, `info`, data);
      this.dialog = { show: true, title: '审核结果', type: '2' };
    },
    // 用户重申
    toHeavy(data) {
      this.$set(this, `apply_id`, data.id);
      this.$set(this, `active`, 0);
    },
    // 国知局反馈信息
    toGzj(data) {
      this.$router.push({ path: '/patent/user/apply/apply/gzjDetail', query: { name: data.name, create_number: data.create_number } });
    },
    // 返回
    back() {
      this.$router.push({ path: '/patent/index' });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    active: {
      deep: true,
      immediate: true,
      handler(val) {
        this.search();
      },
    },
  },
};
</script>

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