GuLiMmo
2023-12-25 36cf6c5a265d3300a286e2aff6058b82bca8227e
src/views/evaluate/evaluateTask.vue
@@ -1,31 +1,24 @@
<template>
  <basic-container>
    <avue-tabs :option="taskTypeList" @change="tabChange"></avue-tabs>
    <avue-crud :option="option" v-model:search="search" v-model:page="page" v-model="form" :table-loading="loading"
      :data="data" :permission="permissionList" :before-open="beforeOpen" ref="crud" @row-update="rowUpdate"
      @row-save="rowSave" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset"
      @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
      @refresh-change="refreshChange" @on-load="onLoad">
      <template #menu-left>
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">
          新增
        </el-button>
        <el-button type="danger" icon="el-icon-delete" plain v-if="permission.evaluateTask_delete" @click="handleDelete">
          删除
        </el-button>
        <el-button type="warning" plain icon="el-icon-download" @click="handleExport">
          导出
        </el-button>
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
        <el-button type="danger" icon="el-icon-delete" plain v-if="permission.evaluateTask_delete"
          @click="handleDelete">删除</el-button>
        <!-- <el-button type="warning" plain icon="el-icon-download" @click="handleExport">导出</el-button> -->
      </template>
      <template #menu="{ size, row, index }">
        <el-button type="primary" text plain icon="el-icon-edit" @click="editDialog(row)">
          编辑
        </el-button>
        <el-button type="primary" text plain icon="el-icon-position" @click="publicTimeBtn(row)">
          发布
        </el-button>
        <el-button type="primary" text plain icon="el-icon-download" @click="">
          导出
        </el-button>
        <el-button type="primary" text plain icon="el-icon-view" @click="viewDateilDialog(row)">详情</el-button>
        <el-button type="primary" text plain icon="el-icon-edit" @click="editDialog(row)">编辑</el-button>
        <el-button type="primary" text plain icon="el-icon-position" @click="publicTimeBtn(row)"
          v-if="row.candidateState === 2 && row.evaluateState === 0">发布</el-button>
        <el-button type="primary" v-if="row.type === 0 && row.candidateState === 0" text plain icon="el-icon-plus" @click="addCandidateHandle(row)">新增候选人</el-button>
        <!-- <el-button type="primary" text plain icon="el-icon-download">导出</el-button> -->
      </template>
    </avue-crud>
    <!-- 发布弹窗 -->
@@ -45,25 +38,33 @@
    </el-dialog>
    <!-- 新增编辑弹窗 -->
    <addDialog :params="addParams" @refreshTable="this.onLoad" />
    <!-- 新增候选人 -->
    <addCandidate :params="addCandidateParams" @refreshTable="this.onLoad" />
    <!-- 预览弹窗 -->
    <viewEvaluateDetail :params="viewEvaluateDetailParams" />
  </basic-container>
</template>
<script>
import { getList, getDetail, add, update, remove } from "@/api/evaluate/evaluateTask";
import option from "@/option/evaluate/evaluateTask";
import { mapGetters } from "vuex";
import { exportBlob } from "@/api/common";
import { getList, getDetail, add, update, remove } from '@/api/evaluate/evaluateTask';
import { option, sectionOption } from '@/option/evaluate/evaluateTask';
import { mapGetters } from 'vuex';
import { exportBlob } from '@/api/common';
import { getToken } from '@/utils/auth';
import { downloadXls } from "@/utils/util";
import { dateNow } from "@/utils/date";
import { downloadXls } from '@/utils/util';
import { dateNow } from '@/utils/date';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import addDialog from "./components/addDialog.vue";
import addDialog from './components/addDialog.vue';
import addCandidate from './components/addCandidate.vue';
import viewEvaluateDetail from './components/viewEvaluateDetail.vue';
import { getDeptTree } from '@/api/system/dept';
export default {
  components: {
    addDialog
    addDialog,
    addCandidate,
    viewEvaluateDetail
  },
  data() {
    return {
@@ -75,7 +76,7 @@
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
        total: 0,
      },
      selectionList: [],
      option: option,
@@ -83,22 +84,56 @@
      // 发布弹窗
      dialogVisible: false,
      publicForm: {
        publicData: ""
        publicData: '',
      },
      isAddDialogVisible: false,
      addParams: {},
      viewParams: {},
      depts: []
      depts: [],
      // 考核结果参数
      defaultTaskType: 0,
      taskTypeList: {
        column: [
          {
            label: '个人评优',
            prop: 0,
          },
          {
            label: '部门评优',
            prop: 1,
          },
        ],
      },
      // 新增候选人params
      addCandidateParams: {},
      // 信息预览弹窗
      viewEvaluateDetailParams: {},
    };
  },
  watch: {
    defaultTaskType: {
      handler(n) {
        this.query = {};
        this.query['type'] = n;
        let params = {
          type: n,
        };
        // 更改option
        !n ? (this.option = option) : (this.option = sectionOption)
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
      },
      immediate: true,
    },
  },
  computed: {
    ...mapGetters(["permission"]),
    ...mapGetters(['permission']),
    permissionList() {
      return {
        addBtn: this.validData(this.permission.evaluateTask_add, false),
        viewBtn: this.validData(this.permission.evaluateTask_view, false),
        delBtn: this.validData(this.permission.evaluateTask_delete, false),
        editBtn: this.validData(this.permission.evaluateTask_edit, false)
        editBtn: this.validData(this.permission.evaluateTask_edit, false),
      };
    },
    ids() {
@@ -106,8 +141,8 @@
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
      return ids.join(',');
    },
  },
  methods: {
    handleAdd() {
@@ -115,51 +150,64 @@
        visible: true,
        title: '添加',
        isEdit: false,
        addForm: {}
      }
        type: this.defaultTaskType,
        addForm: {},
      };
    },
    rowSave(row, done, loading) {
      console.log(row);
      add(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        window.console.log(error);
      });
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          loading();
          window.console.log(error);
        }
      );
    },
    editDialog(row) {
      this.addParams = {
        visible: true,
        title: '编辑',
        isEdit: true,
        type: this.defaultTaskType,
        addForm: {
          ...row
        }
          ...row,
        },
      };
    },
    viewDateilDialog(row) {
      this.viewEvaluateDetailParams = {
        visible: true,
        data: row
      }
    },
    rowUpdate(row, index, done, loading) {
      update(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        console.log(error);
      });
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        error => {
          loading();
          console.log(error);
        }
      );
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
@@ -167,20 +215,20 @@
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(this.ids);
@@ -188,44 +236,42 @@
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            type: 'success',
            message: '操作成功!',
          });
          this.$refs.crud.toggleSelection();
        });
    },
    handleExport() {
      let downloadUrl = `/evaluateTask/evaluateTask/export-evaluateTask?${this.website.tokenHeader}=${getToken()}`;
      const {
        taskName,
      } = this.query;
      let downloadUrl = `/evaluateTask/evaluateTask/export-evaluateTask?${this.website.tokenHeader
        }=${getToken()}`;
      const { taskName } = this.query;
      let values = {
        taskName_like: taskName,
      };
      this.$confirm("是否导出数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      this.$confirm('是否导出数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        NProgress.start();
        exportBlob(downloadUrl, values).then(res => {
          downloadXls(res.data, `评优任务表${dateNow()}.xlsx`);
          NProgress.done();
        })
        });
      });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then(res => {
          if (type === 'view') {
            this.deptData().then(deptRes => {
              const candidates = []
              res.data.data.candidateNum.forEach(item => {
                const value = deptRes.find(dept => dept.id === item.deptId)
                candidates.push(`${value.title}: ${item.val}人`)
              })
              this.form.candidateNum = candidates.join('、')
            const candidates = [];
            res.data.data.candidateNum.forEach(item => {
              const users = []
              item.users.forEach(item => users.push(item.name))
              candidates.push(`${item.deptName}(${item.val || 0}人): ${users.join('、')}`);
            })
            this.form.candidateNum = candidates.join('\n');
          }
          this.form = res.data.data;
        });
@@ -234,10 +280,13 @@
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
      this.onLoad(this.page, { type: this.defaultTaskType });
    },
    searchChange(params, done) {
      this.query = params;
      this.query = {
        ...params,
        type: this.defaultTaskType,
      };
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
@@ -261,14 +310,13 @@
    onLoad(page, params = {}) {
      this.loading = true;
      const {
        taskName,
      } = this.query;
      const { taskName } = this.query;
      let values = {
        ...this.query,
        ...params,
        taskName_like: taskName,
      };
      getList(page.currentPage, page.pageSize, values).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
@@ -279,44 +327,62 @@
    },
    deptData() {
      return getDeptTree(this.website.tenantId).then(deptResult => {
        const result = deptResult.data.data
        let deptList = []
        const result = deptResult.data.data;
        let deptList = [];
        result.forEach(dept => {
          if (dept.children) {
            deptList = result.concat(dept.children)
            delete dept.children
            deptList = result.concat(dept.children);
            delete dept.children;
          } else {
            deptList.push(dept)
            deptList.push(dept);
          }
        })
        return deptList
        });
        return deptList;
      });
    },
    publicTimeBtn(row) {
      this.rowData = row
      this.dialogVisible = true
      this.rowData = row;
      this.dialogVisible = true;
    },
    // 发布
    timeSubmit() {
      const { id } = this.rowData
      const { id } = this.rowData;
      const params = {
        id,
        evaluateCutoffTime: this.publicForm.publicData
        // candidateState: 1,
        evaluateState: 1,
        evaluateCutoffTime: this.publicForm.publicData,
      };
      update(params).then(
        res => {
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.refreshChange();
        },
        error => {
          this.$message({
            type: 'success',
            message: error,
          });
        }
      );
      this.dialogVisible = false;
    },
    addCandidateHandle(row) {
      this.addCandidateParams = {
        visible: true,
        type: 0,
        data: {
          ...row
        }
      }
      add(params).then(res => {
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        this.refreshChange()
      }, error => {
        this.$message({
          type: "success",
          message: error
        });
      })
      this.dialogVisible = false
    }
  }
    },
    tabChange(value) {
      this.defaultTaskType = value.prop;
    },
  },
};
</script>