<!--
 * @Description: create
 * @Version: 1.0
 * @Autor: XuTongZhang
 * @Date: 2020-07-30 10:17:25
 * @LastEditors: XuTongZhang
 * @LastEditTime: 2020-08-17 15:57:05
-->
<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" @update="update"></v-table>
    <v-pager @page="callPage" :total="totalrecords"></v-pager>
    <!-- <resume :dialogFormVisible="dialogFormVisible" :close="close" :info="info" :searchForm="searchForm" :queryData="queryData"></resume> -->
    <el-dialog :visible.sync="dialogVisible" width="600px" :before-close="closeDia" :close-on-click-modal="false">
        <el-form :model="form" ref="uform" label-width="140px" :rules="rules" label-position="right">
            <el-form-item label="姓名" prop="delivererName">
                <el-input placeholder="请输入姓名" v-model="form.delivererName" maxlength="32" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="性别" prop="delivererSex">
                <el-select v-model="form.delivererSex" class="select" placeholder="请选择性别">
                    <el-option v-for="item in [{ value: 0, label: '女' }, { value: 1, label: '男' }]" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="简历投递职位" prop="positionApplied">
                <el-input placeholder="请输入投递职位" v-model="form.positionApplied" maxlength="32" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="工作年限" prop="delivererWorkExp">
                <el-input placeholder="请输入工作年限" v-model="form.delivererWorkExp" maxlength="200" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="学历" prop="delivererEducation">
                <el-select class="select" v-model="form.delivererEducation" placeholder="请选择学历">
                    <el-option v-for="item in ['大专', '本科', '研究生', '博士', '其他']" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="联系电话" prop="delivererPhone">
                <el-input placeholder="请输入联系电话" v-model.number="form.delivererPhone" maxlength="11" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="邮箱地址" prop="delivererMail">
                <el-input placeholder="请输入邮箱地址" v-model="form.delivererMail" maxlength="32" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="面试应聘职位" prop="desiredPositionId">
                <el-select class="select" v-model="form.desiredPositionId" placeholder="请选择应聘职位">
                    <el-option v-for="item in positionList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button @click="closeDia">取 消</el-button>
                <el-button type="primary" @click="submit">修 改</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</div>
</template>

<script>
export default {
  data () {
    let validator = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入手机号'))
      } else {
        if (!(/^1[3456789]\d{9}$/.test(value))) {
          callback(new Error('请输入正确的手机格式'))
        }
        callback()
      }
    }
    return {
      tableList: [],
      dialogFormVisible: false,
      dialogVisible: false,
      page: 1,
      totalrecords: 0,
      pickList: [],
      downList1: [],
      searchForm: {},
      form: {},
      rules: {
        delivererEducation: [{
          required: true,
          message: '请选择学历',
          trigger: 'change'
        }],
        delivererName: [{
          required: true,
          message: '请输入姓名',
          trigger: 'change'
        }],
        delivererPhone: [{
          required: true,
          validator,
          trigger: 'change'
        }],
        delivererMail: [{
          required: true,
          message: '请输入邮箱',
          trigger: 'change'
        }],
        delivererSex: [{
          required: true,
          message: '请选择性别',
          trigger: 'change'
        }],
        delivererWorkExp: [{
          required: true,
          message: '请填写工作经验',
          trigger: 'change'
        }],
        // desiredPositionId: [{
        //     required: true,
        //     message: '请选择应聘职位',
        //     trigger: 'change'
        // }],
        positionApplied: [{
          required: true,
          message: '请填写投递职位',
          trigger: 'change'
        }]
      },
      positionList: [],
      info: {},
      list: [{
        placeholder: '请输入关键字查询',
        props: 'condition'
      },
      {
        type: 'select',
        placeholder: '性别',
        props: 'delivererSex',
        options: [{
          label: '全部',
          value: null
        }, {
          label: '男',
          value: 1
        }, {
          label: '女',
          value: 0
        }]
      },
      {
        type: 'select',
        placeholder: '来源',
        props: 'resumeFrom',
        options: [{
          label: '全部',
          value: null
        },
        {
          label: '51job',
          value: 0
        },
        {
          label: '智联',
          value: 1
        },
        {
          label: '58同城',
          value: 2
        },
        {
          label: '平台',
          value: 3
        }
        ]
      }
      ],
      btn: [{
        name: '确定',
        type: 'primary',
        method: 'search'
      },
      {
        name: '导出',
        type: 'primary',
        method: 'exports'
      }
      ],
      table: {
        selection: true,
        column: [{
          label: '编号',
          props: 'id'
        },
        {
          label: '姓名',
          props: 'delivererName',
          width: 60
        },
        {
          label: '性别',
          props: 'delivererSex',
          options: ['女', '男'],
          width: 60
        },
        {
          label: '简历来源',
          props: 'resumeFrom',
          options: ['51job', '智联招聘', '58同城', '平台'],
          width: 80
        },
        {
          label: '招聘类型',
          props: 'recruitType',
          options: ['社招', '校招', '直接校招'],
          width: 80
        },
        {
          label: '简历投递职位',
          props: 'positionApplied'
        },
        {
          label: '简历状态',
          props: 'state'
        },
        {
          label: '工作年限',
          props: 'delivererWorkExp'
        },
        {
          label: '学历',
          props: 'delivererEducation'
        },
        {
          label: '联系电话',
          props: 'delivererPhone'
        },
        {
          label: '邮箱',
          props: 'delivererMail'
        },
        {
          label: '面试应聘职位',
          props: 'positionName'
        },
        {
          label: '通知面试时间',
          props: 'sendMailTime'
        },
        {
          label: '完成面试时间',
          props: 'confirmInterviewTime'
        },
        {
          label: '面试状态',
          props: 'interviewStatus',
          options: ['未面试', '已面试']
        },
        {
          label: '面试结果',
          props: 'interviewResult',
          options: ['未读', '已通过', '已淘汰']
        }
        ],
        // fixed: true,
        width: 200,
        handle: [{
          title: '修改信息',
          method: 'update',
          type: 'warning'
        }
        // {
        //   title: '查看简历',
        //   method: 'details',
        //   type: 'info'
        // }
        ]
      }
    }
  },
  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.delivererSex = item.delivererSex - 0 || 0
            item.desiredPositionId = item.desiredPositionId - 0 || null
            // 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.positionList = res.list.map((item) => ({
            value: item.id,
            label: item.positionName
          }))
          this.downList1 = res.list
        })
    },
    search (form) {
      this.queryData(form)
    },
    update (row) {
      this.openDia()
      console.log(row)
      this.form = Object.assign({}, row)
    },
    submit () {
      let a
      this.$refs['uform'].validate((valid) => {
        a = valid
      })
      if (!a) return
      let reqdata = this.form
      this.$api
        .post('/resumeInfo/updateResumeInfo', {
          reqdata
        })
        .then((res) => {
          this.$message({
            message: '修改成功！',
            type: 'success'
          })
          this.closeDia()
          this.queryData()
        })
    },
    details (row) {
      this.open()
      this.info = row
    },
    exports () {
      this.$api
        .post('/export/export2Web', {
          reqdata: this.searchForm
        })
        .then((res) => {
          console.log(res)
        })
    },
    openDia () {
      this.dialogVisible = true
    },
    closeDia () {
      this.dialogVisible = false
      this.form = {}
    },
    open () {
      this.dialogFormVisible = true
    },
    close () {
      this.dialogFormVisible = false
      this.form = {}
    },
    callPage (val) {
      this.page = val
      this.queryData(this.searchForm)
    }
  }
}
</script>
