<template>
  <div id="recruit">
    <el-row>
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle"></topInfo>
      </el-col>
      <el-col :span="24" class="main">
        <enterpriseProduct
          :recruitInfo="recruitInfo"
          :total="total"
          @handleCurrentChange="handleCurrentChange"
          :forms="forms"
          @submit="submit"
          @handleDelete="handleDelete"
        ></enterpriseProduct>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/public/top.vue';
import enterpriseProduct from '@/layout/enterpriseProduct/enterpriseProduct.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: product } = createNamespacedHelpers('market');
export default {
  name: 'recruit',
  props: {},
  components: {
    topInfo,
    enterpriseProduct,
  },
  data: () => ({
    topTitle: '审核信息',
    recruitInfo: [],
    total: 1,
    skip: '',
    forms: {
      status: '3',
    },
  }),
  created() {
    this.search();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...product(['query', 'comquery', 'delete', 'fetch', 'update']),
    async submit() {
      this.search(this.forms.status);
    },
    async search({ skip = 0, limit = 10, ...info } = {}) {
      if (this.forms.status) {
        status = this.forms.status;
        skip = this.skip;
        let code = this.user.code;
        const arr = await this.comquery({ status, code, ...info });
        this.$set(this, `recruitInfo`, arr.res);
        this.$set(this, `total`, arr.res.length);
      } else {
        skip = this.skip;
        let code = this.user.code;
        const arr = await this.comquery({ status: 3, code, ...info });
        this.$set(this, `recruitInfo`, arr.res);
        this.$set(this, `total`, arr.res.length);
      }
    },
    // 删除
    async handleDelete(id) {
      const res = await this.delete(id);
      if (this.$checkRes(res)) {
        this.$message({
          message: '删除信息成功',
          type: 'success',
        });
        this.search();
      }
    },
    async handleCurrentChange({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.search();
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding: 20px;
  margin: 10px 20px;
  border: 1px solid #ccc;
  width: 96%;
}
</style>
