<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
<!--      <el-form-item label="投票id" prop="voteId">
        <el-input
          v-model="queryParams.voteId"
          placeholder="请输入投票id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="评分主题" prop="voteTitle">
        <el-input
          v-model="queryParams.voteTitle"
          placeholder="请输入评分主题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="职工id" prop="empId">
        <el-input
          v-model="queryParams.empId"
          placeholder="请输入职工id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="被考核对象" prop="empName">
        <el-input
          v-model="queryParams.empName"
          placeholder="请输入被考核对象"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="当前投票数" prop="voteNum">
        <el-input
          v-model="queryParams.voteNum"
          placeholder="请输入当前投票数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前投票分数" prop="voteScore">
        <el-input
          v-model="queryParams.voteScore"
          placeholder="请输入当前投票分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="['kaohe:vote_emp: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="['kaohe:vote_emp: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="['kaohe:vote_emp: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="['kaohe:vote_emp:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

<!--    <el-table v-loading="loading" :data="vote_empList" @selection-change="handleSelectionChange">-->
    <el-table v-loading="loading" :data="vote_empList">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键" align="center" prop="id" />-->
<!--      <el-table-column label="投票id" align="center" prop="voteId" />-->
      <el-table-column label="评分主题" align="center" prop="voteTitle" />
<!--      <el-table-column label="职工id" align="center" prop="empId" />-->
      <el-table-column label="被考核对象" align="center" prop="bumen" />
      <el-table-column label="选项内容" align="center" prop="content" />
      <el-table-column label="评分人数" align="center" prop="voteNum" />
      <el-table-column label="评分均值" align="center" prop="votezz" />
      <el-table-column label="评分总分" align="center" prop="voteScore" />
      <el-table-column label="备注" align="center" prop="remark" />
<!--      <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="['kaohe:vote_emp:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kaohe:vote_emp: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="投票id" prop="voteId">
          <el-input v-model="form.voteId" placeholder="请输入投票id" />
        </el-form-item>
        <el-form-item label="评分主题" prop="voteTitle">
          <el-input v-model="form.voteTitle" placeholder="请输入评分主题" />
        </el-form-item>
        <el-form-item label="职工id" prop="empId">
          <el-input v-model="form.empId" placeholder="请输入职工id" />
        </el-form-item>
        <el-form-item label="被考核对象" prop="empName">
          <el-input v-model="form.empName" placeholder="请输入被考核对象" />
        </el-form-item>
        <el-form-item label="选项内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="当前投票数" prop="voteNum">
          <el-input v-model="form.voteNum" placeholder="请输入当前投票数" />
        </el-form-item>
        <el-form-item label="当前投票分数" prop="voteScore">
          <el-input v-model="form.voteScore" placeholder="请输入当前投票分数" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" 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 { listVote_emp, getVote_emp, delVote_emp, addVote_emp, updateVote_emp } from "@/api/kaohe/vote_emp"

export default {
  name: "Vote_emp",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投票选项表格数据
      vote_empList: [
        {
          bumen: '生命科学系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '海洋学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '历史文化与法学系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '物理科学与技术学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '教育学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '资源管理系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '马克思主义学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '美术学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '计算机科学技术系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '化学系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '数学与计算科学学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '继续教育学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '外国语学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '体育系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '文学院',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        },
        {
          bumen: '音乐系',
          voteTitle: '政治建设评分',
          content: '',
          voteNum: '10',
          votezz: '98',
          remark: '',
          voteScore: '980'
        }
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        voteId: null,
        voteTitle: null,
        empId: null,
        empName: null,
        content: null,
        voteNum: null,
        voteScore: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        voteId: [
          { required: true, message: "投票id不能为空", trigger: "blur" }
        ],
        empId: [
          { required: true, message: "职工id不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    // this.queryParams.voteId=this.$route.query.id
    // this.getList();
  },
  methods: {
    /** 查询投票选项列表 */
    getList() {
      this.loading = true
      listVote_emp(this.queryParams).then(response => {
        this.vote_empList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        voteId: null,
        voteTitle: null,
        empId: null,
        empName: null,
        content: null,
        voteNum: null,
        voteScore: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加投票选项"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getVote_emp(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改投票选项"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateVote_emp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addVote_emp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除投票选项编号为"' + ids + '"的数据项？').then(function() {
        return delVote_emp(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kaohe/vote_emp/export', {
        ...this.queryParams
      }, `vote_emp_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
