<template>
  <div id="index">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" @back="back" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <list-4 :list="list" @toDel="toDel"></list-4>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import list4 from './parts/list-4.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentearly } = createNamespacedHelpers('patentearly');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list4,
  },
  data: function () {
    return {
      limit: 5,
      total: 0,
      list: [],
    };
  },
  async created() {
    this.search();
  },
  methods: {
    ...patentearly(['query', 'delete']),
    async search({ skip = 0, limit = this.limit, searchName, ...info } = {}) {
      info.searchName = searchName;
      info.user_id = this.user.id;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 删除信息
    async toDel(data) {
      let res = await this.delete(data.id);
      if (this.$checkRes(res)) {
        this.$toast({ type: 'success', message: '删除信息成功' });
        this.search();
      }
    },
    // 返回
    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></style>
