<template>
  <div id="appointment">
    <el-row>
      <el-col :span="24">
        <appointment-detail
          :liebiaoList="liebiaoList"
          @query="search"
          @onsave="onsaveClick"
          :nextData="nextData"
          :nextTotal="nextTotal"
          :pastData="pastData"
          :pastTotal="pastTotal"
        ></appointment-detail>
      </el-col>
    </el-row>
  </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: 'appointment',
  props: {},
  components: {
    appointmentDetail,
  },
  data: () => ({
    liebiaoList: [
      { name: '基本信息' },
      { name: '消息管理' },
      { name: '我的发布' },
      { name: '事项管理' },
      { name: '展会管理' },
      //  // { name: '返回首页' },
      { name: '修改密码' },
      { name: '退出账号' },
    ],
    // 下期直播
    nextData: [],
    nextTotal: 0,
    // 以往直播
    pastData: [],
    pastTotal: 0,
  }),
  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, status: '0' });
      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, `nextData`, res.data);
      this.$set(this, `nextTotal`, res.total);
      res = await this.query({ skip, limit, status: '2' });
      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, `pastData`, res.data);
      this.$set(this, `pastTotal`, res.total);
    },
    // 切换菜单
    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();
      }
    },
  },
};
</script>

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