<template>
  <div id="leave">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="main">
          <el-col :span="24" class="leaveBtn">
            <van-button round type="info" icon="smile" @click="onClickRight()">请假申请</van-button>
          </el-col>
          <el-col :span="24" class="leaveList">
            <leaveList :leaveList="leaveList"></leaveList>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topTitle.vue';
import leaveList from '@/layout/user/leaveList.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapLeave } = createNamespacedHelpers('leave');
export default {
  metaInfo: { title: '请假管理' },
  name: 'leave',
  props: {},
  components: {
    NavBar, //头部导航
    leaveList, //请假列表
  },
  data: () => ({
    leaveList: [],
    title: '',
    isleftarrow: '',
    transitionName: 'fade',
    navShow: true,
  }),
  created() {
    this.searchInfo();
  },
  computed: { ...mapState(['user']) },
  mounted() {
    this.title = this.$route.meta.title;
    this.isleftarrow = this.$route.meta.isleftarrow;
  },
  watch: {
    $route(to, from) {
      this.title = to.meta.title;
      this.isleftarrow = to.meta.isleftarrow;
    },
  },
  methods: {
    ...mapLeave(['query']),
    async searchInfo({ skip = 0, limit = 10, ...info } = {}) {
      if (this.user.type == 4) {
        let type = 0;
        let name = this.user.name;
        const res = await this.query({ skip, limit, type, name, ...info });
        this.$set(this, `leaveList`, res.data);
      } else {
        let type = 0;
        const res = await this.query({ skip, limit, type, ...info });
        this.$set(this, `leaveList`, res.data);
      }
    },
    // 跳转到请假
    onClickRight() {
      this.$router.push({ path: '/user/leaveDetail', query: { type: 0 } });
    },
  },
};
</script>

<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
}
.main {
  min-height: 570px;
}
.main .leaveBtn {
  text-align: center;
  padding: 15px 0;
}
</style>
