<template>
  <div id="index">
    <list-tab :tab="tabsTitle">
      <template v-slot:title>
        投递简历
      </template>
      <template v-slot:main1>
        <list type="0" :list="list0" :totalRow="totalRow0" @changePage="search" @selectInfo="selectInfo" @changeStatus="changeStatus"></list>
      </template>
      <template v-slot:main2>
        <list type="1" :list="list1" :totalRow="totalRow1" @changePage="search" @selectInfo="selectInfo" @changeStatus="changeStatus"></list>
      </template>
      <template v-slot:main3>
        <list type="2" :list="list2" :totalRow="totalRow2" @changePage="search" @selectInfo="selectInfo" @changeStatus="changeStatus"></list>
      </template>
    </list-tab>
  </div>
</template>

<script>
import list from './list.vue';
import listTab from '@/layout/list-tab.vue';
import { mapActions, mapState } from 'vuex';
export default {
  name: 'rindex',
  props: {},
  components: {
    listTab,
    list,
  },
  data: () => ({
    tabsTitle: ['未处理', '纳入考虑', '暂不考虑'],
    searchName: '',
    list: [],
    info: {},
    list0: [],
    list1: [],
    list2: [],
    totalRow0: 0,
    totalRow1: 0,
    totalRow2: 0,
  }),
  created() {
    this.search({ type: '0' });
    this.search({ type: '1' });
    this.search({ type: '2' });
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...mapActions(['lettersOperation']),
    async search({ type, currentPage, searchInfo }) {
      let skip = 0;
      if (currentPage) {
        skip = (currentPage - 1) * this.$limit;
      }
      let result = await this.lettersOperation({
        type: 'list',
        data: { post_id: this.$route.query.id, status: type, skip: skip, limit: this.$limit, corpname: this.user.corpname, ...searchInfo },
      });
      if (`${result.errcode}` === '0') {
        this.$set(this, `list${type}`, result.data);
        this.$set(this, `totalRow${type}`, result.total);
      } else {
        this.$message.error(result.errmsg ? result.errmsg : 'error');
      }
    },
    async searchInfo(id) {
      let result = await this.lettersOperation({ type: 'search', data: { id: id } });
      if (`${result.errcode}` === '0') {
        this.$set(this, `info`, result.data);
      }
    },
    async changeStatus({ id, status }) {
      let result = await this.lettersOperation({ type: 'update', data: { id: id, status: status } });
      if (`${result.errcode}` === '0') {
        this.$message.success('操作成功');
      } else {
        this.$message.error(result.errmsg || 'error');
      }
    },
    changePage({ type, currentPage }) {
      //type=>哪个标签页
      //currentPage=>标签页的当前页,用来计算skip的
      console.log(type, currentPage);
      //根据type查询对应的数据
    },
    selectInfo({ type, ids }) {
      //type=>哪个标签页
      //ids,选择的id
      console.log(type, ids);
      //缓存在本组件中(this.$set在本组件中),为之后的批量操作使用
    },
  },
};
</script>

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