<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请人" prop="applier">
        <el-select v-model="queryParams.applier" filterable clearable @change="handleQuery">
          <el-option v-for="item in $store.state.user.userList" :key="item.userId" :label="item.nickName"
            :value="item.userId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请部门" prop="applyDept">
        <el-select v-model="queryParams.applyDept" filterable clearable @change="handleQuery">
          <el-option v-for="item in $store.state.user.deptList" :key="item.deptId" :label="item.deptName"
            :value="item.deptId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目编号" prop="projectId">
        <el-select v-model="queryParams.projectId" clearable filterable remote reserve-keyword placeholder="请输入项目编号"
          :remote-method="remoteMethod" :loading="loading" style="width: 400px;">
          <el-option v-for="project in projectList" :key="project.projectId"
            :label="project.projectNumber + '-' + project.projectName" :value="project.projectId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['oa:recruit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recruitList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请人" align="center" prop="applier" >
         <template slot-scope="scope">
          {{ getUserName(scope.row.applier) }}
        </template>
      </el-table-column>
      <el-table-column label="申请部门" align="center" prop="applyDept" >
        <template slot-scope="scope">
          {{ getDeptName(scope.row.applyDept) }}
        </template>
      </el-table-column>
      <el-table-column label="项目编号" align="center" prop="projectNumber" >
        <template slot-scope="scope">
          <span>{{ scope.row.project ? scope.row.project.projectNumber : "" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" >
        <template slot-scope="scope">
          <span>{{ scope.row.project ? scope.row.project.projectName : "" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请日期" align="center" prop="applyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="岗位名称" align="center" prop="postName" />
      <el-table-column label="岗位人数" align="center" prop="postNumber" />
      <el-table-column label="薪酬待遇" align="center" prop="wage" />
      <el-table-column label="总经理意见" align="center" prop="zjlComment" />
      <el-table-column label="总经理审批时间" align="center" prop="zjlTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zjlTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改cmc招聘申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="65%" append-to-body>
      <recruit-tab :taskForm="taskForm"></recruit-tab>
    </el-dialog>
  </div>
</template>

<script>
import { listRecruit, getRecruit, delRecruit, addRecruit, updateRecruit } from "@/api/oa/recruit/recruit";
import { listProject } from '@/api/oa/project/project';
import RecruitTab from './recruitTab.vue'

export default {
  components: { RecruitTab },
  name: "Recruit",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // cmc招聘申请表格数据
      recruitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applier: null,
        applyDept: null,
        projectId: null,
        applyDate: null,
        postName: null,
        postNumber: null,
        duty: null,
        qualification: null,
        wage: null,
        deptComment: null,
        deptLeader: null,
        deptTime: null,
        managerComment: null,
        managerLeader: null,
        managerTime: null,
        zjlComment: null,
        zjlLeader: null,
        zjlTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      taskForm: {
        formId: ''
      },
      projectList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询cmc招聘申请列表 */
    getList() {
      this.loading = true;
      listRecruit(this.queryParams).then(response => {
        this.recruitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recruitId: null,
        applier: null,
        applyDept: null,
        projectId: null,
        applyDate: null,
        postName: null,
        postNumber: null,
        duty: null,
        qualification: null,
        wage: null,
        deptComment: null,
        deptLeader: null,
        deptTime: null,
        managerComment: null,
        managerLeader: null,
        managerTime: null,
        zjlComment: null,
        zjlLeader: null,
        zjlTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recruitId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    goBack() {
      this.$emit('goBack')
    },
    remoteMethod(val) {
      listProject({
        pageNum: 1,
        pageSize: 20,
        projectNumber: val
      }).then(res => {
        this.projectList = res.rows;
      })
    },
    handleView(row){
      this.taskForm.formId = row.recruitId;
      this.open = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/recruit/export', {
        ...this.queryParams
      }, `recruit_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
