<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-input
          v-model="queryParams.applier"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请部门" prop="applyDept">
        <el-input
          v-model="queryParams.applyDept"
          placeholder="请输入申请部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目id" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          placeholder="请输入项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请日期" prop="applyDate">
        <el-date-picker clearable
          v-model="queryParams.applyDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="岗位名称" prop="postName">
        <el-input
          v-model="queryParams.postName"
          placeholder="请输入岗位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位人数" prop="postNumber">
        <el-input
          v-model="queryParams.postNumber"
          placeholder="请输入岗位人数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位职责" prop="duty">
        <el-input
          v-model="queryParams.duty"
          placeholder="请输入岗位职责"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任职资格" prop="qualification">
        <el-input
          v-model="queryParams.qualification"
          placeholder="请输入任职资格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="薪酬待遇" prop="wage">
        <el-input
          v-model="queryParams.wage"
          placeholder="请输入薪酬待遇"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门意见" prop="deptComment">
        <el-input
          v-model="queryParams.deptComment"
          placeholder="请输入部门意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门负责人" prop="deptLeader">
        <el-input
          v-model="queryParams.deptLeader"
          placeholder="请输入部门负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门审批时间" prop="deptTime">
        <el-date-picker clearable
          v-model="queryParams.deptTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择部门审批时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="分管领导意见" prop="managerComment">
        <el-input
          v-model="queryParams.managerComment"
          placeholder="请输入分管领导意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分管领导" prop="managerLeader">
        <el-input
          v-model="queryParams.managerLeader"
          placeholder="请输入分管领导"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分管领导审批时间" prop="managerTime">
        <el-date-picker clearable
          v-model="queryParams.managerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择分管领导审批时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="总经理意见" prop="zjlComment">
        <el-input
          v-model="queryParams.zjlComment"
          placeholder="请输入总经理意见"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总经理" prop="zjlLeader">
        <el-input
          v-model="queryParams.zjlLeader"
          placeholder="请输入总经理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总经理审批时间" prop="zjlTime">
        <el-date-picker clearable
          v-model="queryParams.zjlTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择总经理审批时间">
        </el-date-picker>
      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['oa:recruit:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['oa:recruit:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oa:recruit:remove']"
        >删除</el-button>
      </el-col>
      <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="招聘申请id" align="center" prop="recruitId" />
      <el-table-column label="申请人" align="center" prop="applier" />
      <el-table-column label="申请部门" align="center" prop="applyDept" />
      <el-table-column label="项目id" align="center" prop="projectId" />
      <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="duty" />
      <el-table-column label="任职资格" align="center" prop="qualification" />
      <el-table-column label="薪酬待遇" align="center" prop="wage" />
      <el-table-column label="部门意见" align="center" prop="deptComment" />
      <el-table-column label="部门负责人" align="center" prop="deptLeader" />
      <el-table-column label="部门审批时间" align="center" prop="deptTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deptTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分管领导意见" align="center" prop="managerComment" />
      <el-table-column label="分管领导" align="center" prop="managerLeader" />
      <el-table-column label="分管领导审批时间" align="center" prop="managerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.managerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总经理意见" align="center" prop="zjlComment" />
      <el-table-column label="总经理" align="center" prop="zjlLeader" />
      <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-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oa:recruit:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['oa:recruit:remove']"
          >删除</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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="申请人" prop="applier">
          <el-input v-model="form.applier" placeholder="请输入申请人" />
        </el-form-item>
        <el-form-item label="申请部门" prop="applyDept">
          <el-input v-model="form.applyDept" placeholder="请输入申请部门" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="申请日期" prop="applyDate">
          <el-date-picker clearable
            v-model="form.applyDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="岗位名称" prop="postName">
          <el-input v-model="form.postName" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="岗位人数" prop="postNumber">
          <el-input v-model="form.postNumber" placeholder="请输入岗位人数" />
        </el-form-item>
        <el-form-item label="岗位职责" prop="duty">
          <el-input v-model="form.duty" placeholder="请输入岗位职责" />
        </el-form-item>
        <el-form-item label="任职资格" prop="qualification">
          <el-input v-model="form.qualification" placeholder="请输入任职资格" />
        </el-form-item>
        <el-form-item label="薪酬待遇" prop="wage">
          <el-input v-model="form.wage" placeholder="请输入薪酬待遇" />
        </el-form-item>
        <el-form-item label="部门意见" prop="deptComment">
          <el-input v-model="form.deptComment" placeholder="请输入部门意见" />
        </el-form-item>
        <el-form-item label="部门负责人" prop="deptLeader">
          <el-input v-model="form.deptLeader" placeholder="请输入部门负责人" />
        </el-form-item>
        <el-form-item label="部门审批时间" prop="deptTime">
          <el-date-picker clearable
            v-model="form.deptTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择部门审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分管领导意见" prop="managerComment">
          <el-input v-model="form.managerComment" placeholder="请输入分管领导意见" />
        </el-form-item>
        <el-form-item label="分管领导" prop="managerLeader">
          <el-input v-model="form.managerLeader" placeholder="请输入分管领导" />
        </el-form-item>
        <el-form-item label="分管领导审批时间" prop="managerTime">
          <el-date-picker clearable
            v-model="form.managerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择分管领导审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总经理意见" prop="zjlComment">
          <el-input v-model="form.zjlComment" placeholder="请输入总经理意见" />
        </el-form-item>
        <el-form-item label="总经理" prop="zjlLeader">
          <el-input v-model="form.zjlLeader" placeholder="请输入总经理" />
        </el-form-item>
        <el-form-item label="总经理审批时间" prop="zjlTime">
          <el-date-picker clearable
            v-model="form.zjlTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择总经理审批时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecruit, getRecruit, delRecruit, addRecruit, updateRecruit } from "@/api/oa/recruit/recruit";

export default {
  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: {
      }
    };
  },
  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
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加cmc招聘申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recruitId = row.recruitId || this.ids
      getRecruit(recruitId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改cmc招聘申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recruitId != null) {
            updateRecruit(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecruit(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recruitIds = row.recruitId || this.ids;
      this.$modal.confirm('是否确认删除cmc招聘申请编号为"' + recruitIds + '"的数据项？').then(function() {
        return delRecruit(recruitIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/recruit/export', {
        ...this.queryParams
      }, `recruit_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
