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

<script>
import appointmentDetail from '@/components/enterprise/appointment.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: dock } = createNamespacedHelpers('dock');
const { mapActions: apply } = createNamespacedHelpers('apply');
const { mapActions: login } = createNamespacedHelpers('login');
const { mapActions: place } = createNamespacedHelpers('place');

export default {
  name: 'adviserList',
  props: {},
  components: {
    appointmentDetail,
  },
  data: () => ({
    total: 0,
    limit: 4,
    pageSize: 4,
    info: {},
    datas: {},
    display: 'list',
    liebiaoList: [
      { name: '基本信息' },
      { name: '消息管理' },
      { name: '我的发布' },
      { name: '事项管理' },
      { name: '展会管理' },
      //  // { name: '返回首页' },
      { name: '修改密码' },
      { name: '退出账号' },
    ],
    resultTable: [],
    form: {},
  }),
  created() {
    this.search();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...dock(['query', 'delete', 'update']),
    ...apply({ applyupdate: 'update' }),
    ...login({ logout: 'logout', transactiondtetle: 'delete' }),
    ...place({ palcequery: 'query', palcefetch: 'fetch' }),
    //查询
    async search({ skip = 0, limit = 0 } = { skip: 0, limit: 0 }) {
      let res = await this.query({ skip, limit });
      for (const val of res.data) {
        let parent = val.province;
        let places = val.place;
        let reslte = await this.palcequery({ level: 1, parent });
        let resltes = await this.palcequery({ level: 2, parent });
        var arr = reslte.data.filter(item => item.code === parent);
        var cre = resltes.data.filter(item => item.code === places);
        for (const shi of cre) {
          val.shi = shi.name;
        }
        for (const sheng of arr) {
          val.sheng = sheng.name;
        }
      }
      this.$set(this, `resultTable`, res.data);
      this.$set(this, `total`, res.total);
    },

    //查询
    async searchinfo({ skip = 0, limit = 0, currentPage } = { skip: 0, limit: 0 }) {
      this.display = 'dadad';
      this.$set(this, `total`, this.datas.apply.length);
      const newProducts = [];
      for (let index = skip; index < skip + limit; index++) {
        if (this.datas.apply[index]) {
          newProducts.push(this.datas.apply[index]);
        }
      }
      this.$set(this, `resultTable`, newProducts);
    },

    look(row) {
      this.display = 'dadad';
      this.$set(this, `datas`, row);
      this.searchinfo();
    },
    async onsaveClick({ 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' });
    },
    handleCurrentChange({ currentPage }) {
      this.searchinfo({ skip: (currentPage - 1) * this.pageSize, limit: this.pageSize, currentPage });
    },
    async success(row) {
      row.status = '1';
      row.dock_id = this.datas.id;
      row.id = row._id;
      let res = await this.applyupdate(row);
      this.$checkRes(res, '通过审核', '添加失败');
    },
    async shibai(row) {
      row.status = '2';
      row.dock_id = this.datas.id;
      row.id = row._id;
      let res = await this.applyupdate(row);
      this.$checkRes(res, '审核拒绝', '添加失败');
    },
  },
};
</script>

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