<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="reporter">
        <el-select v-model="queryParams.reporter" 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="reportDept">
        <el-select v-model="queryParams.reportDept" 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="zhTime">
        <el-date-picker clearable
          v-model="queryParams.zhTime"
          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="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['oa:performance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="performanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="绩效审批id" align="center" prop="performanceId" /> -->
      <el-table-column label="上报人" align="center" prop="reporter">
        <template slot-scope="scope">
          {{ getUserName(scope.row.reporter) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="附件" align="center" prop="document" /> -->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="上报日期" align="center" prop="reportTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="分管审核人" align="center" prop="managerUserId" /> -->
      <el-table-column label="分管审核意见" align="center" prop="managerComment" />
      <!-- <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="zjlUserId" /> -->
      <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" prop="zhUserId" />
      <el-table-column label="制单日期" align="center" prop="zhTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zhTime, '{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)"
            v-hasPermi="['oa:performance:query']"
          >查看</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="65%" append-to-body>
      <performance-form :taskForm="taskForm" :taskName="''" :isFlow="false"></performance-form>
    </el-dialog>
  </div>
</template>

<script>
import { listPerformance, getPerformance, delPerformance, addPerformance, updatePerformance } from "@/api/oa/performance/performance";
import performanceForm from '../../flowable/form/performance/performanceForm.vue';

export default {  
  components: { performanceForm },
  name: "Performance",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 绩效审批表格数据
      performanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reporter: null,
        document: null,
        reportTime: null,
        managerUserId: null,
        managerComment: null,
        managerTime: null,
        zjlUserId: null,
        zjlComment: null,
        zjlTime: null,
        zhUserId: null,
        zhTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      taskForm: {
        formId: ''
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询绩效审批列表 */
    getList() {
      this.loading = true;
      listPerformance(this.queryParams).then(response => {
        this.performanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        performanceId: null,
        reporter: null,
        document: null,
        remark: null,
        reportTime: null,
        managerUserId: null,
        managerComment: null,
        managerTime: null,
        zjlUserId: null,
        zjlComment: null,
        zjlTime: null,
        zhUserId: null,
        zhTime: 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.performanceId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加绩效审批";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const performanceId = row.performanceId || this.ids
      getPerformance(performanceId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改绩效审批";
      });
    },
    handleView(row) {
      this.open = true;
      this.taskForm.formId = row.performanceId;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.performanceId != null) {
            updatePerformance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerformance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const performanceIds = row.performanceId || this.ids;
      this.$modal.confirm('是否确认删除绩效审批编号为"' + performanceIds + '"的数据项？').then(function() {
        return delPerformance(performanceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/performance/export', {
        ...this.queryParams
      }, `performance_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
