<template>
  <div class="app-container">
    <el-form :model="ruleForm" :rules="rules" label-width="130px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="人员名称" prop="name" class="input-width">
            <el-input v-model="ruleForm.name" placeholder="请输入人员名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="身份证号" prop="cardId">
            <el-input v-model="ruleForm.cardId" placeholder="请输入身份证号"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="10px">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
              搜索
            </el-button>
            <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <el-table
      ref="multipleTable"
      :data="varList"
      :header-cell-style="{'font-weight': 'bold','color': '#000'}"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row>
      <el-table-column :selectable="handleSelectWithDifferentStatus" type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center"/>
      <el-table-column prop="username" label="用户名" align="center"/>
      <el-table-column prop="cardId" label="身份证号" align="center"/>
      <el-table-column prop="name" label="人员名称" align="center"/>
      <el-table-column prop="corpName" label="企业名称" align="center"/>
      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="{row}">
          <el-button type="primary" icon="el-icon-s-claim" size="mini" @click="doCheckIn([row])">入住</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList"/>
    </div>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive

export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      rules: {
        name: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        cardId: [{ required: true, message: '身份证号不能为空', trigger: 'blur' }]
      },
      ruleForm: { name: '', cardId: '' },
      config: config,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      varList: [],
      add: false,		// 新增按钮
      del: false,		// 删除按钮
      edit: false	// 修改按钮
    }
  },
  created() {
    // this.getDict()
    // this.getList()

  },
  methods: {
    handleSelectWithDifferentStatus(row, rowIndex) {
      return true
    },
    getQuery() {
      if (this.ruleForm.name === '') {
        this.$message.error('请填写人员名称')
        return false
      }
      if (this.ruleForm.cardId === '') {
        this.$message.error('请填写身份证号')
        return false
      }
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection()
      }
      this.listQuery = {
        page: 1,
        limit: 10
      }
      this.getList()
    },
    goKeyReset() {
      this.ruleForm.cardId = ''
      this.ruleForm.name = ''
      this.varList = []
    //  this.getQuery()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/coerce/getUserListByIdCardAndName?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          cardId: this.ruleForm.cardId,
          name: this.ruleForm.name,
          UN_EMPLOY_FLAG: '0'
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        if (this.varList.length === 0) {
          this.$message.error('没有相关人员信息')
        }
        this.total = data.page.totalResult
      })
        .catch((e) => {
          this.listLoading = false
        })
    },
    doCheckIn(row) {
      this.$confirm('确定要将  ' + row[0].name + '  拉入企业吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/coerce/doCoerceCheckIn',
          {
            userId: row[0].userId,
            corpinfoId: JSON.parse(sessionStorage.getItem('user')).CORPINFO_ID
          }
        ).then((e) => {
          console.log(e)
          if (e.msg === '1') {
            this.$message({
              message: '当前人员已经在企业中',
              type: 'warning'
            })
          } else {
            this.$message({
              message: '拉入成功',
              type: 'success'
            })
            this.getQuery()
          }
          this.listLoading = false
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {})
    }

  }
}
</script>

