<!--
 * @Description: create
 * @Version: 1.0
 * @Autor: XuTongZhang
 * @Date: 2020-07-30 10:17:25
 * @LastEditors: XuTongZhang
 * @LastEditTime: 2020-08-12 17:59:30
-->
<template>
  <div class="indexPage">
    <v-input :btn="btn" :list="list" @search="search" @exports="exports"></v-input>
    <v-table
      :table="table"
      :tableList="tableList"
      :sortType="true"
      :queryData="queryData"
      :form="searchForm"
      @details="details"
    ></v-table>
    <v-pager @page="callPage" :total="totalrecords"></v-pager>
    <resume :dialogFormVisible="dialogFormVisible" :close="close" :info="info" :searchForm="searchForm" :queryData="queryData"></resume>
  </div>
</template>

<script>
import resume from './resume'
export default {
  data () {
    return {
      tableList: [],
      dialogFormVisible: false,
      page: 1,
      totalrecords: 0,
      pickList: [],
      downList1: [],
      searchForm: {},
      info: {},
      list: [
        {
          placeholder: '请输入关键字查询',
          props: 'condition'
        },
        {
          type: 'select',
          placeholder: '性别',
          props: 'delivererSex',
          options: [{ label: '男', value: 1 }, { label: '女', value: 0 }]
        },
        {
          type: 'select',
          placeholder: '来源',
          props: 'resumeFrom',
          options: [{ label: '51job', value: 0 }, { label: '智联', value: 1 }, { label: '58同城', value: 2 }]
        },
        {
          placeholder: '请输入投递职位',
          props: 'positionApplied'
        },
        {
          type: 'select',
          placeholder: '应聘职位',
          props: 'desiredPositionId',
          options: []
        }
      ],
      btn: [
        {
          name: '确定',
          type: 'primary',
          method: 'search'
        },
        {
          name: '导出',
          type: 'primary',
          method: 'exports'
        }
      ],
      table: {
        selection: true,
        column: [
          {
            label: '编号',
            props: 'id'
          },
          {
            label: '姓名',
            props: 'delivererName'
          },
          {
            label: '性别',
            props: 'delivererSex',
            options: ['女', '男']
          },
          {
            label: '简历来源',
            props: 'resumeFrom',
            options: ['51job', '智联招聘', '58同城']
          },
          {
            label: '招聘类型',
            props: 'recruitType',
            options: ['社招', '校招', '直接校招']
          },
          {
            label: '简历投递职位',
            props: 'positionApplied'
          },
          {
            label: '简历状态',
            props: 'state'
          },
          {
            label: '工作年限',
            props: 'delivererWorkExp'
          },
          {
            label: '学历',
            props: 'delivererEducation'
          },
          {
            label: '联系电话',
            props: 'delivererPhone'
          },
          {
            label: '面试应聘职位',
            props: 'desiredPositionId'
          },
          {
            label: '通知面试时间',
            props: 'sendMailTime'
          },
          {
            label: '完成面试时间',
            props: 'confirmInterviewTime'
          },
          {
            label: '面试状态',
            props: 'interviewStatus',
            options: ['未面试', '已面试']
          },
          {
            label: '面试结果',
            props: 'interviewResult',
            options: ['未通过', '已通过', '已淘汰']
          }
        ],
        fixed: true,
        width: 100,
        handle: [
          {
            title: '查看简历',
            method: 'details',
            type: 'info'
          }
        ]
      }
    }
  },
  components: {
    resume
  },
  mounted () {
    this.queryData()
    this.queryDownList()
  },
  methods: {
    queryData (form = {}) {
      let page = this.page
      this.searchForm = form
      let reqdata = form
      this.$api
        .post('/resumeInfo/queryTalentPoolList', {
          reqdata,
          page
        })
        .then((res) => {
          this.totalrecords = res.totalrecords
          this.tableList = res.list.map(item => {
            item.desiredPositionId = item.desiredPositionId ? this.downList1.some(i => i.id === item.desiredPositionId) ? this.downList1.find(i => i.id === item.desiredPositionId).positionName : '' : ''
            item.state = item.interviewResult ? ['', '已通过', '未通过'][item.interviewResult] : item.isSendInviteMail ? '已通知' : ['未通过', '已通过', '已淘汰', '待定'][item.isPass]
            return item
          })
        })
    },
    queryDownList () {
      this.$api
        .post('/position/queryPositionList', {
          reqdata: {}
        })
        .then((res) => {
          this.list[4].options = res.list.map((item) => ({
            value: item.id,
            label: item.positionName
          }))
          this.downList1 = res.list
        })
    },
    search (form) {
      this.queryData(form)
    },
    details (row) {
      this.open()
      this.info = row
    },
    exports () {
      this.$api
        .post('/export/export2Web', {
          reqdata: this.searchForm
        })
        .then((res) => {
          console.log(res)
        })
    },
    open () {
      this.dialogFormVisible = true
    },
    close () {
      this.dialogFormVisible = false
      this.form = {}
    },
    callPage (val) {
      this.page = val
      this.queryData(this.searchForm)
    }
  }
}
</script>
