<template>
  <div id="index">
    <trial-detail
      :info="info"
      :nativeList="nativeList"
      @onsave="nativeClick"
      :display="display"
      :userInfos="userInfos"
      :userList="userList"
      :userListTotal="userListTotal"
      :adminList="adminList"
      :adminListTotal="adminListTotal"
      :alreadyList="alreadyList"
      :alreadyListTotal="alreadyListTotal"
      :notList="notList"
      :notListTotal="notListTotal"
      :JiaoyiList="JiaoyiList"
      :JiaoyiTotal="JiaoyiTotal"
      :alreadyTwoList="alreadyTwoList"
      :alreadyTwoListTotal="alreadyTwoListTotal"
      :notTwoList="notTwoList"
      :notTwoListTotal="notTwoListTotal"
      :JiaoyiTwoList="JiaoyiTwoList"
      :JiaoyiTwoListTotal="JiaoyiTwoListTotal"
      @deletes="deleteAlready"
      @delete="deleteAdmin"
    ></trial-detail>
  </div>
</template>

<script>
import trialDetail from '@/components/trial/index.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapSite } = createNamespacedHelpers('site');
const { mapActions: mapProduct } = createNamespacedHelpers('enterpriseproject');
const { mapActions: mapMarketUser } = createNamespacedHelpers('market');
export default {
  name: 'index',
  props: {},
  components: {
    trialDetail,
  },
  data: () => ({
    info: {},
    nativeList: [
      {
        name: '基本信息',
      },
      {
        name: '用户管理',
      },
      {
        name: '我的审核',
      },
      {
        name: '统计信息',
      },
      {
        name: '注销账号',
      },
    ],
    display: 'first',
    // 基本信息
    userInfos: {
      name: '外审管理员',
      cardnumber: '220182199603257019',
      addr: '吉林省长春市朝阳区力旺广场B座16楼1608',
    },
    userList: [],
    userListTotal: 1,
    adminList: [],
    adminListTotal: 1,
    alreadyList: [],
    alreadyListTotal: 1,
    notList: [],
    notListTotal: 1,
    JiaoyiList: [],
    JiaoyiTotal: 1,
    alreadyTwoList: [],
    alreadyTwoListTotal: 1,
    notTwoList: [],
    notTwoListTotal: 1,
    JiaoyiTwoList: [],
    JiaoyiTwoListTotal: 1,
  }),
  created() {
    this.searchSite();
    this.searchInfo();
    this.searchUser();
  },
  computed: {},
  methods: {
    ...mapSite(['showInfo']),
    ...mapProduct({ ProductQuery: 'query', ProductFetch: 'fetch', ProductDelete: 'delete' }),
    ...mapMarketUser({ userQuery: 'query', userFetch: 'fetch', userDelete: 'delete' }),
    // 查询站点信息
    async searchSite() {
      let res = await this.showInfo();
      let object = JSON.parse(JSON.stringify(res.data));
      if (object) {
        this.$set(this, `info`, res.data);
      } else {
        this.$message.error(res.errmsg ? res.errmsg : 'error');
      }
    },
    async nativeClick({ name }) {
      if (name === '基本信息') {
        this.display = 'first';
      } else if (name === '用户管理') {
        this.display = 'second';
      } else if (name === '我的审核') {
        this.display = 'third';
      } else if (name === '统计信息') {
        this.display = 'fourth';
      } else {
        this.display = 'fivth';
      }
    },
    async searchInfo({ skip = 0, limit = 3, ...info } = {}) {
      const res = await this.ProductQuery({ skip, limit, ...info });
      this.$set(this, `alreadyList`, res.data);
      this.$set(this, `alreadyListTotal`, res.total);
      this.$set(this, `notList`, res.data);
      this.$set(this, `notListTotal`, res.total);
      this.$set(this, `JiaoyiList`, res.data);
      this.$set(this, `JiaoyiTotal`, res.total);
      this.$set(this, `alreadyTwoList`, res.data);
      this.$set(this, `alreadyTwoListTotal`, res.total);
      this.$set(this, `notTwoList`, res.data);
      this.$set(this, `notTwoListTotal`, res.total);
      this.$set(this, `JiaoyiTwoList`, res.data);
      this.$set(this, `JiaoyiTwoListTotal`, res.total);
    },
    async deleteAlready({ item }) {
      const res = await this.ProductDelete(item.id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchInfo();
    },
    async searchUser({ skip = 0, limit = 3, ...info } = {}) {
      const res = await this.userQuery({ skip, limit, ...info });
      this.$set(this, `userList`, res.data);
      this.$set(this, `userListTotal`, res.total);
      this.$set(this, `adminList`, res.data);
      this.$set(this, `adminListTotal`, res.total);
    },
    async deleteAdmin({ id }) {
      const res = await this.userDelete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.searchUser();
    },
  },
};
</script>

<style lang="less" scoped></style>
