<template>
  <div id="index">
    <admin-frame @search="search" :limit="limit" :total="total" topType="3" @back="back" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <list-1 :list="list" @detail="detail"></list-1>
      </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>
    </van-dialog>
  </div>
</template>

<script>
import list1 from './parts/list-1.vue';
import info1 from './parts/info-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
  },
  data: function () {
    return {
      limit: 5,
      total: 0,
      list: [],
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    if (this.id) await this.search();
  },
  methods: {
    ...patentinfo(['query']),
    async search({ skip = 0, limit = this.limit, searchName, ...info } = {}) {
      info.user_id = this.id;
      if (searchName) info.name = searchName;
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查询详情
    detail(data) {
      this.$set(this, `info`, data);
      this.dialog = { show: true, title: '详细信息', type: '1' };
    },
    // 返回
    back() {
      this.$router.push({ path: '/account/users/index' });
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  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>
