<template>
  <div id="index">
    <list-tab :tab="tabsTitle">
      <template v-slot:title>
        简历筛选
      </template>
      <template v-slot:main1>
        <list
          type="0"
          :info="info"
          :dataList="dataList0"
          :totalRow="totalRow0"
          @changePage="search"
          @selectInfo="selectInfo"
          @searchInfo="searchInfo"
          @update="update"
        ></list>
      </template>
      <template v-slot:main2>
        <list
          type="1"
          :info="info"
          :dataList="dataList1"
          :totalRow="totalRow1"
          @changePage="search"
          @selectInfo="selectInfo"
          @searchInfo="searchInfo"
          @update="update"
        ></list>
      </template>
      <template v-slot:main3>
        <list
          type="2"
          :info="info"
          :dataList="dataList2"
          :totalRow="totalRow2"
          @changePage="search"
          @selectInfo="selectInfo"
          @searchInfo="searchInfo"
          @update="update"
        ></list>
      </template>
    </list-tab>
    <el-dialog title="简历详情" center :visible.sync="resumeDialog" :fullscreen="true">
      <resumeJob :info="info" @update="update"></resumeJob>
    </el-dialog>
  </div>
</template>

<script>
import resumeJob from '@publics/src/views/resumeJob.vue';
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,
    resumeJob,
  },
  data: () => ({
    testList: [{ label: 'test', value: 1 }, { label: 'name', value: 2 }, { label: 'lock', value: 3 }, { label: 'not', value: 4 }],
    tabsTitle: ['未处理', '纳入考虑', '暂不考虑'], //简历库
    info: {},
    dataList0: [],
    totalRow0: 20,
    dataList1: [],
    totalRow1: 10,
    dataList2: [],
    totalRow2: 50,
    resumeDialog: false,
  }),
  created() {
    this.initSearch();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...mapActions(['lettersOperation', 'resumesOperation']),
    initSearch() {
      this.search({ type: '0' });
      this.search({ type: '1' });
      this.search({ type: '2' });
    },
    async search({ type, currentPage, searchInfo }) {
      let skip = 0;
      if (currentPage) {
        skip = (currentPage - 1) * this.$limit;
      }
      //1直接拿着参数发送请求
      let result = await this.lettersOperation({
        type: 'list',
        data: { status: type, skip: skip, limit: this.$limit, corpname: this.user.corpname, ...searchInfo },
      });
      let arr = [];
      result.data.forEach(async val => {
        let result = await this.resumesOperation({ type: 'search', data: { id: val.resume_id } });
        let object = { ...val, skill: result.data.skill };
        arr.push(object);
      });
      if (`${result.errcode}` === '0') {
        //给this=>vue的实例下在中的list属性，赋予result。data的值
        this.$set(this, `dataList${type}`, arr);
        this.$set(this, `totalRow${type}`, result.total);
      } else {
        this.$message.error(result.errmsg ? result.errmsg : 'error');
      }
    },

    async searchInfo({ resumeid, letterid }) {
      let result = await this.resumesOperation({ type: 'search', data: { id: resumeid } });
      if (`${result.errcode}` === '0') {
        result.data.letterid = letterid;
        this.$set(this, `info`, result.data);
        console.log(this.info);
        this.resumeDialog = true;
      }
    },
    selectInfo({ type, ids }) {
      //type=>哪个标签页
      //ids,选择的id
      console.log(type, ids);
      //缓存在本组件中(this.$set在本组件中),为之后的批量操作使用
    },
    async update(data) {
      let result = await this.lettersOperation({ type: 'update', data: data });
      if (`${result.errcode}` === `0`) {
        this.$message.success('操作成功');
      } else {
        this.$message.error(result.errmsg || '操作失败');
      }
      this.initSearch();
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-dialog__headerbtn {
  top: 20px;
  right: 20%;
}
/deep/.el-dialog__headerbtn .el-dialog__close {
  color: #333;
  font-size: 30px;
  font-weight: 700;
}
</style>
