<template>
  <div id="adviserList">
    <look-detail
      :liebiaoList="liebiaoList"
      @deleteRow="deleteRow"
      @success="success"
      @shibai="shibai"
      :resultTable="resultTable"
      @onsave="onsaveClick"
      :limit="limit"
      :total="total"
      @handleCurrentChange="handleCurrentChange"
      :pageSize="pageSize"
      :display="display"
    ></look-detail>
  </div>
</template>

<script>
import lookDetail from '@/components/enterprise/look.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: apply } = createNamespacedHelpers('apply');
const { mapActions: login } = createNamespacedHelpers('login');
export default {
  name: 'adviserList',
  props: {},
  components: {
    lookDetail,
  },
  data: () => ({
    total: 0,
    limit: 4,
    display: 'list',
    pageSize: 4,
    info: {},
    liebiaoList: [
      { name: '基本信息' },
      { name: '消息管理' },
      { name: '我的发布' },
      { name: '事项管理' },
      { name: '展会管理' },
      // { name: '返回首页' },
      { name: '修改密码' },
      { name: '退出账号' },
    ],
    resultTable: [],
    form: {},
  }),
  created() {
    this.search();
  },
  computed: {
    data() {
      return this.$route.query.data;
    },
    ...mapState(['user']),
  },
  methods: {
    ...apply(['query', 'delete', 'update']),
    ...login({ logout: 'logout', transactiondtetle: 'delete' }),
    //查询
    async search({ skip = 0, limit = 4, currentPage } = { skip: 0, limit: 10 }) {
      console.log(this.data);
      console.log(this.data.apply.length);
      this.$set(this, `total`, this.data.apply.length);

      console.log();
      const newProducts = [];
      for (let index = skip; index < skip + limit; index++) {
        if (this.data.apply[index]) {
          newProducts.push(this.data.apply[index]);
        }
      }
      console.log(newProducts);

      this.$set(this, `resultTable`, newProducts);
    },

    handleCurrentChange({ currentPage }) {
      this.search({ skip: (currentPage - 1) * this.pageSize, limit: this.pageSize, currentPage });
      console.log(currentPage);
    },

    async onsaveClick({ id }) {
      console.log(id);
      if (id === '基本信息') {
        this.$router.push({ path: '/enterprise/enterprisejb' });
      } else if (id === '消息管理') {
        this.$router.push({ path: '/enterprise/enterprisexx' });
      } else if (id === '我的发布') {
        this.$router.push({ path: '/enterprise/enterprisefabu' });
      } else if (id === '事项管理') {
        this.$router.push({ path: '/enterprise/enterprisedg' });
      } else if (id === '展会管理') {
        this.$router.push({ path: '/enterprise/appointment' });
      } else if (id === '修改密码') {
        this.$router.push({ path: '/enterprise/xiugai' });
      } else if (id === '返回首页') {
        this.$router.push({ path: '/home' });
      } else if (id === '退出账号') {
        this.logout();
        this.$message({
          message: '注销成功',
          type: 'success',
        });
        this.toLogin();
      }
    },

    async toLogin() {
      this.$router.push({ path: '/platlive' });
    },
    async success(row) {
      row.status = '1';
      row.dock_id = this.data.id;
      row.id = data._id;
      console.log(row);
      let res = await this.update(row);
      this.$checkRes(res, '通过审核', '添加失败');
    },
    async shibai(row) {
      row.status = '2';
      row.dock_id = this.data.id;
      row.id = data._id;
      console.log(row);
      let res = await this.update(row);
      this.$checkRes(res, '审核拒绝', '添加失败');
    },
    async deleteRow(id) {
      const res = await this.delete(id);
      if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
    },
  },
};
</script>

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