<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="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业院校" prop="graduateCollege">
        <el-input
          v-model="queryParams.graduateCollege"
          placeholder="请输入毕业院校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职意向" prop="jobObjective">
        <el-input
          v-model="queryParams.jobObjective"
          placeholder="请输入求职意向"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="导入人" prop="createUserName">
        <el-input
          v-model="queryParams.createUserName"
          placeholder="请输入导入人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="导入开始时间" prop="startTime">
        <el-date-picker
          clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择导入开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="导入结束时间" prop="endTime">
        <el-date-picker
          clearable
          v-model="queryParams.endTime"
          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="['system:resume: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="['system:resume: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="['system:resume: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="['system:resume:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="resumeList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="基本信息"
        width="300"
        align="center"
        prop="resumeId"
      >
        <template slot-scope="scope">
          <span
            >{{ scope.row.userName }}|{{
              parseTime(scope.row.birthday, "{y}-{m}-{d}")
            }}|{{ scope.row.gender }} |{{ scope.row.experience }}|{{
              scope.row.degree
            }}|{{ scope.row.graduateCollege }} |{{ scope.row.major }}|{{
              scope.row.jobObjective
            }}|{{ scope.row.residence }} |{{ scope.row.mobile }}|{{
              scope.row.email
            }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="职位"
        align="center"
        prop="position"
        width="100"
      />
      <el-table-column
        label="导入时间"
        align="center"
        prop="createDate"
        width="150"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="导入人"
        align="center"
        prop="createUserName"
        width="100"
      />
      <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="['system:resume:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:resume: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"
    />

    <!-- 添加或修改简历管理对话框 -->
    <!-- <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="userName">
          <el-input v-model="form.userName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="简历附件" prop="resumeFile">
          <file-upload v-model="form.resumeFile" />
        </el-form-item>
        <el-form-item label="工作地" prop="workingPlace">
          <el-input v-model="form.workingPlace" placeholder="请输入工作地" />
        </el-form-item>
        <el-form-item label="学历" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="居住地" prop="residence">
          <el-input v-model="form.residence" placeholder="请输入居住地" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="行业经验" prop="industryExperience">
          <el-input v-model="form.industryExperience" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="毕业院校" prop="graduateCollege">
          <el-input v-model="form.graduateCollege" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="岗位" prop="position">
          <el-input v-model="form.position" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="语言能力" prop="languageAbility">
          <el-input v-model="form.languageAbility" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="证书" prop="certificate">
          <el-input v-model="form.certificate" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-date-picker clearable
                          v-model="form.birthday"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作年限" prop="experience">
          <el-input v-model="form.experience" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="期望薪资" prop="exceptedSalary">
          <el-input v-model="form.exceptedSalary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="最近工作公司" prop="lastCompany">
          <el-input v-model="form.lastCompany" placeholder="请输入最近工作公司" />
        </el-form-item>
        <el-form-item label="最近工作行业" prop="lastIndustry">
          <el-input v-model="form.lastIndustry" placeholder="请输入最近工作行业" />
        </el-form-item>
        <el-form-item label="最近工作职位" prop="lastPosition">
          <el-input v-model="form.lastPosition" placeholder="请输入最近工作职位" />
        </el-form-item>
        <el-form-item label="专业技能" prop="keyWords">
          <el-input v-model="form.keyWords" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="自我评价" prop="selfEvaluation">
          <el-input v-model="form.selfEvaluation" type="textarea" placeholder="请输入内容" />
        </el-form-item>

        <el-form-item label="工作履历" prop="resumeWork">
          <el-input v-model="form.resumeWork" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="项目经验" prop="resumeProject">
          <el-input v-model="form.resumeProject" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="教育经历" prop="resumeEducation">
          <el-input v-model="form.resumeEducation" type="textarea" placeholder="请输入内容" />
        </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 {
  listResume,
  getResume,
  delResume,
  addResume,
  updateResume,
} from "@/api/system/resume";

export default {
  name: "Resume",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 简历管理表格数据
      resumeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        resumeName: null,
        userName: null,
        gender: null,
        birthday: null,
        age: null,
        degree: null,
        experience: null,
        mobile: null,
        cardNo: null,
        email: null,
        isMarryed: null,
        residence: null,
        origin: null,
        nationality: null,
        graduateCollege: null,
        major: null,
        lanuage: null,
        graduateDate: null,
        positionRating: null,
        keyWords: null,
        jobObjective: null,
        salary: null,
        selfIntroduce: null,
        userId: null,
        headUrl: null,
        isPrivate: null,
        isDeleted: null,
        createDate: null,
        createUserName: null,
        updateUserId: null,
        updateDate: null,
        resumeDownloadUrl: null,
        status: null,
        currentCompany: null,
        industry: null,
        workingPlace: null,
        certificate: null,
        languageAbility: null,
        industryExperience: null,
        workExperience: null,
        post: null,
        lastCompany: null,
        lastIndustry: null,
        lastPosition: null,
        position: null,
        selfEvaluation: null,
        exceptedSalary: null,
        isEnabled: null,
        startTime: null,
        endTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询简历管理列表 */
    getList() {
      this.loading = true;
      listResume(this.queryParams).then((response) => {
        this.resumeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        resumeId: null,
        resumeName: null,
        userName: null,
        gender: null,
        birthday: null,
        age: null,
        degree: null,
        experience: null,
        mobile: null,
        cardNo: null,
        email: null,
        isMarryed: null,
        residence: null,
        origin: null,
        nationality: null,
        graduateCollege: null,
        major: null,
        lanuage: null,
        graduateDate: null,
        positionRating: null,
        keyWords: null,
        jobObjective: null,
        salary: null,
        selfIntroduce: null,
        userId: null,
        headUrl: null,
        isPrivate: null,
        isDeleted: null,
        createDate: null,
        createUserName: null,
        updateUserId: null,
        updateDate: null,
        resumeDownloadUrl: null,
        status: null,
        currentCompany: null,
        industry: null,
        workingPlace: null,
        certificate: null,
        languageAbility: null,
        industryExperience: null,
        workExperience: null,
        post: null,
        lastCompany: null,
        lastIndustry: null,
        lastPosition: null,
        position: null,
        selfEvaluation: null,
        exceptedSalary: null,
        isEnabled: null,
        startTime: null,
        endTime: 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.resumeId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({ path: "/system/resume/add" });
      // this.reset();
      // this.open = true;
      // this.title = "添加简历管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const resumeId = row.resumeId || this.ids;
      getResume(resumeId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改简历管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.resumeId != null) {
            updateResume(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addResume(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const resumeIds = row.resumeId || this.ids;
      this.$modal
        .confirm('是否确认删除简历管理编号为"' + resumeIds + '"的数据项？')
        .then(function () {
          return delResume(resumeIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/resume/export",
        {
          ...this.queryParams,
        },
        `resume_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
