<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="type">
        <el-select v-model="queryParams.type" clearable placeholder="请选择职称类型" @change="handleQuery">
          <el-option label="工程技术类" value="工程技术类"></el-option>
          <el-option label="工程经济类" value="工程经济类"></el-option>
          <el-option label="其他" value="其他"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="职称级别" prop="level">
        <el-select v-model="queryParams.level" clearable placeholder="请选择职称级别" @change="handleQuery">
          <el-option label="正高级" value="正高级"></el-option>
          <el-option label="副高级" value="副高级"></el-option>
          <el-option label="高级" value="高级"></el-option>
          <el-option label="中级" value="中级"></el-option>
          <el-option label="初级" value="初级"></el-option>
          <el-option label="员级" value="员级"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="userId">
        <el-select v-model="queryParams.userId" 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>
        <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:eval: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:eval: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:eval: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:eval:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="evalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请人" align="center" prop="userId">
        <template slot-scope="scope">
          {{ getUserName(scope.row.userId) }}
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="applyTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="评审年度" align="center" prop="annual" />
      <el-table-column label="评审单位" align="center" prop="institude" />
      <el-table-column label="职称类型" align="center" prop="type" />
      <el-table-column label="职称级别" align="center" prop="level" />
      <el-table-column label="职称专业名称" align="center" prop="titleProfession" />
      <el-table-column label="审核意见" align="center" prop="titleComment" />
      <el-table-column label="审核时间" align="center" prop="titleTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.titleTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称管理员" align="center" prop="titleUserId">
        <template slot-scope="scope">
          {{ getUserName(scope.row.titleUserId) }}
        </template>
      </el-table-column>
      <el-table-column label="确认时间" align="center" prop="confirmTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="确认状态" align="center" prop="confirmStatus" />
      <el-table-column label="是否通过" align="center" prop="isApproved" />
      <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:eval:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['oa:eval: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="userId">
          <el-input v-model="form.userId" placeholder="请输入申请人" />
        </el-form-item>
        <el-form-item label="评审年度" prop="annual">
          <el-input v-model="form.annual" placeholder="请输入评审年度" />
        </el-form-item>
        <el-form-item label="评审单位" prop="institude">
          <el-input v-model="form.institude" placeholder="请输入评审单位" />
        </el-form-item>
        <el-form-item label="职称级别" prop="level">
          <el-input v-model="form.level" placeholder="请输入职称级别" />
        </el-form-item>
        <el-form-item label="职称专业名称" prop="titleProfession">
          <el-input v-model="form.titleProfession" placeholder="请输入职称专业名称" />
        </el-form-item>
        <el-form-item label="评审表" prop="sheet">
          <el-input v-model="form.sheet" placeholder="请输入评审表" />
        </el-form-item>
        <el-form-item label="评审表" prop="sheetStamp">
          <el-input v-model="form.sheetStamp" placeholder="请输入评审表" />
        </el-form-item>
        <el-form-item label="其他材料" prop="material">
          <el-input v-model="form.material" placeholder="请输入其他材料" />
        </el-form-item>
        <el-form-item label="是否通过" prop="isApproved">
          <el-input v-model="form.isApproved" placeholder="请输入是否通过" />
        </el-form-item>
        <el-form-item label="公示红头文件" prop="publicityFile">
          <file-upload v-model="form.publicityFile" />
        </el-form-item>
        <el-form-item label="证书扫描件" prop="scanFile">
          <file-upload v-model="form.scanFile" />
        </el-form-item>
        <el-form-item label="证书取得时间" prop="obtainTime">
          <el-date-picker clearable v-model="form.obtainTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择证书取得时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申请时间" prop="applyTime">
          <el-date-picker clearable v-model="form.applyTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="职称管理员" prop="titleUserId">
          <el-input v-model="form.titleUserId" placeholder="请输入职称管理员" />
        </el-form-item>
        <el-form-item label="职称管理员审核时间" prop="titleTime">
          <el-date-picker clearable v-model="form.titleTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择职称管理员审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="职称管理员审核意见" prop="titleComment">
          <el-input v-model="form.titleComment" placeholder="请输入职称管理员审核意见" />
        </el-form-item>
        <el-form-item label="盖章材料上传时间" prop="materialUploadTime">
          <el-date-picker clearable v-model="form.materialUploadTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择盖章材料上传时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="确认人" prop="confirmer">
          <el-input v-model="form.confirmer" placeholder="请输入确认人" />
        </el-form-item>
        <el-form-item label="确认时间" prop="confirmTime">
          <el-date-picker clearable v-model="form.confirmTime" 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 { listEval, getEval, delEval, addEval, updateEval } from "@/api/oa/titles/titles";

export default {
  name: "Eval",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职称评审表格数据
      evalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        annual: null,
        institude: null,
        type: null,
        level: null,
        titleProfession: null,
        sheet: null,
        sheetStamp: null,
        material: null,
        isApproved: null,
        publicityFile: null,
        scanFile: null,
        obtainTime: null,
        applyTime: null,
        titleUserId: null,
        titleTime: null,
        titleComment: null,
        materialUploadTime: null,
        confirmer: null,
        confirmTime: null,
        confirmStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询职称评审列表 */
    getList() {
      this.loading = true;
      listEval(this.queryParams).then(response => {
        this.evalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        titleEvalId: null,
        userId: null,
        annual: null,
        institude: null,
        type: null,
        level: null,
        titleProfession: null,
        sheet: null,
        sheetStamp: null,
        material: null,
        isApproved: null,
        publicityFile: null,
        scanFile: null,
        obtainTime: null,
        applyTime: null,
        titleUserId: null,
        titleTime: null,
        titleComment: null,
        materialUploadTime: null,
        confirmer: null,
        confirmTime: null,
        confirmStatus: 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.titleEvalId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加职称评审";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const titleEvalId = row.titleEvalId || this.ids
      getEval(titleEvalId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改职称评审";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.titleEvalId != null) {
            updateEval(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEval(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const titleEvalIds = row.titleEvalId || this.ids;
      this.$modal.confirm('是否确认删除职称评审编号为"' + titleEvalIds + '"的数据项？').then(function () {
        return delEval(titleEvalIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/eval/export', {
        ...this.queryParams
      }, `eval_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
