<template>
  <div id="patent-1">
    <el-row>
      <el-col :span="24" class="main">
        <list-2 :list="list" @toView="toView"></list-2>
      </el-col>
    </el-row>
    <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 list2 from '@/layout/patentInfo/list-2.vue';
import info1 from '@/layout/patentInfo/info-1.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
export default {
  name: 'patent-1',
  props: {},
  components: {
    list2,
    info1,
  },
  data: function () {
    return {
      adminInfo: {},
      list: [],
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    await this.searchOther();
    await this.search();
  },
  methods: {
    ...adminLogin({ adminLoginQuery: 'query' }),
    ...patentinfo(['query', 'fetch']),
    async search({ skip = 0, limit = 4, searchName, ...info } = {}) {
      info.first_apply = this.adminInfo.deptname;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
      }
    },
    // 查看信息
    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' };
      }
    },
    // 查询其他信息
    async searchOther() {
      let res = await this.adminLoginQuery({ code: this.user.code });
      if (this.$checkRes(res)) {
        this.$set(this, `adminInfo`, res.data[0]);
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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