From 36cf6c5a265d3300a286e2aff6058b82bca8227e Mon Sep 17 00:00:00 2001
From: GuLiMmo <2820890765@qq.com>
Date: Mon, 25 Dec 2023 10:29:43 +0800
Subject: [PATCH] 评优页面更新

---
 src/views/evaluate/evaluateTask.vue |  292 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 162 insertions(+), 130 deletions(-)

diff --git a/src/views/evaluate/evaluateTask.vue b/src/views/evaluate/evaluateTask.vue
index 15e5d19..47dafef 100644
--- a/src/views/evaluate/evaluateTask.vue
+++ b/src/views/evaluate/evaluateTask.vue
@@ -7,26 +7,18 @@
       @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>
     <!-- 发布弹窗 -->
@@ -46,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 {
@@ -76,7 +76,7 @@
       page: {
         pageSize: 10,
         currentPage: 1,
-        total: 0
+        total: 0,
       },
       selectionList: [],
       option: option,
@@ -84,7 +84,7 @@
       // 发布弹窗
       dialogVisible: false,
       publicForm: {
-        publicData: ""
+        publicData: '',
       },
       isAddDialogVisible: false,
       addParams: {},
@@ -96,38 +96,44 @@
         column: [
           {
             label: '个人评优',
-            prop: 0
+            prop: 0,
           },
           {
             label: '部门评优',
-            prop: 1
-          }
-        ]
-      }
+            prop: 1,
+          },
+        ],
+      },
+      // 新增候选人params
+      addCandidateParams: {},
+      // 信息预览弹窗
+      viewEvaluateDetailParams: {},
     };
   },
   watch: {
     defaultTaskType: {
       handler(n) {
-        this.query = {}
-        this.query['type'] = n
+        this.query = {};
+        this.query['type'] = n;
         let params = {
-          type: n
-        }
+          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() {
@@ -135,8 +141,8 @@
       this.selectionList.forEach(ele => {
         ids.push(ele.id);
       });
-      return ids.join(",");
-    }
+      return ids.join(',');
+    },
   },
   methods: {
     handleAdd() {
@@ -145,21 +151,24 @@
         title: '添加',
         isEdit: false,
         type: this.defaultTaskType,
-        addForm: {}
-      }
+        addForm: {},
+      };
     },
     rowSave(row, done, loading) {
-      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 = {
@@ -168,28 +177,37 @@
         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);
@@ -197,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);
@@ -218,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;
         });
@@ -264,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();
@@ -291,9 +310,7 @@
     onLoad(page, params = {}) {
       this.loading = true;
 
-      const {
-        taskName,
-      } = this.query;
+      const { taskName } = this.query;
 
       let values = {
         ...this.query,
@@ -310,47 +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
-    }
-  }
+      this.defaultTaskType = value.prop;
+    },
+  },
 };
 </script>
 

--
Gitblit v1.9.3