<!--
 * @Description: create
 * @Version: 1.0
 * @Autor: XuTongZhang
 * @Date: 2020-07-28 15:25:06
 * @LastEditors: XuTongZhang
 * @LastEditTime: 2020-08-02 16:48:59
-->
<template>
  <div class="indexPage">
    <v-input :btn="btn" :list="list" @del="delAll" @search="search"></v-input>
    <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
      <el-radio-button :label="1">已通过候选人</el-radio-button>
      <el-radio-button :label="2">已淘汰候选人</el-radio-button>
    </el-radio-group>
    <v-table
      :key="isCollapse"
      :table="table"
      :tableList="tableList"
      :sortType="true"
      :queryData="queryData"
      :form="form"
      @details="details"
      @update="update"
      @selection-change="selection"
      id=""
    ></v-table>
    <v-pager @page="callPage" :total="totalrecords"></v-pager>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableList: [],
      page: 1,
      sortRule: {},
      isCollapse: 1,
      totalrecords: 0,
      pickList: [],
      form: {},
      list: [
        {
          placeholder: '请输入关键字查询',
          props: ''
        },
        {
          type: 'select',
          placeholder: '性别',
          props: '',
          options: [{ label: '男', value: 1 }, { label: '女', value: 0 }]
        },
        {
          type: 'select',
          placeholder: '来源',
          props: '',
          options: []
        },
        {
          type: 'select',
          placeholder: '投递职位',
          props: '',
          options: []
        },
        {
          type: 'select',
          placeholder: '应聘职位',
          props: '',
          options: []
        },
        {
          type: 'date'
        }
      ],
      btn: [
        {
          name: '确定',
          type: 'primary',
          method: ''
        }
      ],
      table: {
        selection: true,
        column: [
          {
            label: '编号',
            props: ''
          },
          {
            label: '姓名',
            props: ''
          },
          {
            label: '简历来源',
            props: ''
          },
          {
            label: '简历投递时间',
            props: ''
          },
          {
            label: '简历投递职位',
            props: ''
          },
          {
            label: '工作年限',
            props: ''
          },
          {
            label: '学历',
            props: ''
          },
          {
            label: '联系电话',
            props: ''
          }
        ],
        handle: [
          {
            title: '查看简历',
            method: '',
            type: 'info'
          },
          {
            title: '通知面试',
            method: '',
            type: 'info'
          },
          {
            title: '标记通过',
            method: '',
            type: 'info'
          },
          {
            title: '标记淘汰',
            method: '',
            type: 'warning'
          }
        ]
      }
    }
  },
  mounted () {
    // this.queryData()
  },
  methods: {
    queryData (form = { conditions: '' }, sort = {}) {
      let page = this.page
      this.sortRule = sort
      this.form = form
      let reqdata = Object.assign({}, form, sort)
      this.$api
        .post('', {
          reqdata,
          page
        })
        .then((res) => {
          this.totalrecords = res.totalrecords
          this.tableList = res.list.map((item) => {
            item.ctx = item.infoContent
              ? item.infoContent.length > 15
                ? item.infoContent.replace(/<[^>]+>/g, '').slice(0, 15) + '...'
                : item.infoContent.replace(/<[^>]+>/g, '').slice(0, 15)
              : ''
            return item
          })
        })
    },
    search (form, sortRule) {
      this.queryData(form, sortRule)
    },
    details (row) {
      this.dialogVisible = true
      this.querydetail(row.infoId)
    },
    update (row) {
      this.type = 1
      this.querydetail(row.infoId)
      this.openDiaLog()
    },
    querydetail (infoId) {
      this.$api
        .post('/platform/information/platformGetInformation', {
          reqdata: {
            infoId
          }
        })
        .then((res) => {
          let obj = res.object
          // obj.createtime = this.$utils.format(res.object.createtime)
          this.info = obj
        })
    },
    del (row, type = false) {
      let id = type ? row : [row.infoId]
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$api
            .post('/platform/information/platformDeleteInformation', {
              reqdata: {
                id
              }
            })
            .then((res) => {
              this.queryData(this.form, this.sortRule)
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    delAll () {
      this.pickList.length
        ? this.del(this.pickList, true)
        : this.$message({ type: 'info', message: '请选择需要删除的内容' })
    },
    selection (val) {
      this.pickList = val
    },
    callPage (val) {
      this.page = val
      this.queryData(this.form, this.sortRule)
    }
  }
}
</script>
