<template>
  <div id="index" class="animate__animated animate__backInRight">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" :useTop="false" :useNav="false">
      <template v-slot:info>
        <van-col :span="24" class="one">
          <van-button type="info" size="small" @click="toSearch">查询条件</van-button>
          <span class="total">({{ total }})</span>
        </van-col>
        <van-col :span="24" class="two">
          <list-2 :list="list" @toView="toView"></list-2>
        </van-col>
      </template>
    </admin-frame>
    <van-dialog class="dialog" v-model="dialog.show" :title="dialog.title" :show-confirm-button="false" show-cancel-button cancel-button-text="返回">
      <search-1 v-if="dialog.type == '1'" :searchForm="searchForm" @reseat="reseat" @onSubmit="onSubmit"></search-1>
      <info-1 v-else-if="dialog.type == '2'" :info="info"></info-1>
    </van-dialog>
  </div>
</template>

<script>
import search1 from '@/layout/patentInfo/search-1.vue';
import list2 from '@/layout/patentInfo/list-2.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,
    list2,
    search1,
    info1,
  },
  data: function () {
    return {
      list: [],
      limit: 4,
      total: 0,
      // 弹框
      dialog: { show: false, title: '查询条件', type: '1' },
      // 查询条件
      searchForm: {},
      // 详情
      info: {},
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patentinfo(['query', 'fetch']),
    ...personal({ personalFetch: 'fetch' }),
    ...adminLogin({ adminQuery: 'query' }),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, ...this.searchForm, ...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)) {
        this.$set(this, `info`, res.data);
        this.dialog = { show: true, title: '详细信息', type: '2' };
      }
    },
    // 查询
    toSearch() {
      let dialog = { show: true, title: '查询条件', type: '1' };
      this.$set(this, `dialog`, dialog);
    },
    // 重置条件
    reseat() {
      this.searchForm = {};
      this.search();
    },
    // 提交查询
    onSubmit({ data }) {
      this.search(data);
      let dialog = { show: false, title: '查询条件', type: '1' };
      this.$set(this, `dialog`, dialog);
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  background-color: #fff;
  padding: 10px 0;
  text-align: center;
  .total {
    color: #000;
    font-weight: bold;
    position: relative;
    top: 5px;
    left: 10px;
  }
}
.dialog {
  /deep/.van-dialog__content {
    max-height: 350px;
    overflow-y: auto;
  }
}
</style>
