From 0a8bebe2edbb55eab98e3559eedf5303a417b73c Mon Sep 17 00:00:00 2001
From: GuLiMmo <2820890765@qq.com>
Date: Thu, 22 Feb 2024 16:47:42 +0800
Subject: [PATCH] 更新权限配置批量导入数据
---
src/views/assessment/components/assessmentWeight.vue | 300 ++++++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 214 insertions(+), 86 deletions(-)
diff --git a/src/views/assessment/components/assessmentWeight.vue b/src/views/assessment/components/assessmentWeight.vue
index f9ed379..ef59a96 100644
--- a/src/views/assessment/components/assessmentWeight.vue
+++ b/src/views/assessment/components/assessmentWeight.vue
@@ -22,27 +22,50 @@
@current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
<template #menu-left>
<el-button type="primary" icon="el-icon-plus" @click="rowSave">添加考核人</el-button>
+ <el-button type="primary" icon="el-icon-plus" @click="configDialogShow = true">导入权重配置中的数据</el-button>
</template>
</avue-crud>
<add-weight :dialogParams="dialogParams" @refresh="onLoad"></add-weight>
+ <el-dialog title="权重配置数据" v-model="configDialogShow" @open="configDialogOpen">
+ <el-table v-loading="addLoading" :element-loading-text="addTipsText" :data="configUserList" @selection-change="handleSelectionChange" style="width: 100%" border
+ max-height="700" class="custom-table">
+ <el-table-column type="selection" width="38" />
+ <el-table-column prop="assessorUserName" label="考核人姓名" />
+ <el-table-column prop="assessorPostName" label="考核人职位" />
+ <el-table-column prop="assessorDeptName" label="考核人部门" />
+ <el-table-column prop="weight" label="权重" />
+ <el-table-column prop="rangeVal" label="范围" />
+ </el-table>
+ <template #footer>
+ <el-button type="primary" icon="el-icon-circle-check" @click="addConfigUsers">确认添加</el-button>
+ <el-button icon="el-icon-close" @click="configDialogShow = false">取消</el-button>
+ </template>
+ </el-dialog>
</div>
</template>
-
+
<script>
-import { getAssessorList, getAssessorDetail, removeAssessor, updateAssessor } from '@/api/assessment/assessmentSet.js'
-import addWeight from './addWeight.vue'
+import {
+ getAssessorList,
+ getAssessorDetail,
+ removeAssessor,
+ updateAssessor,
+} from '@/api/assessment/assessmentSet.js';
+import addWeight from './addWeight.vue';
+import { getAssessors as getExportExcelData } from '@/api/assessment/assessmentConfig';
+import { addAssessorList } from '@/api/assessment/assessmentSet';
export default {
props: {
params: {
type: Object,
default() {
- return {}
- }
- }
+ return {};
+ },
+ },
},
components: {
- addWeight
+ addWeight,
},
data() {
return {
@@ -67,9 +90,9 @@
labelWidth: 120,
column: [
{
- label: "考核人",
- prop: "userName",
- type: "select",
+ label: '考核人',
+ prop: 'userName',
+ type: 'select',
rules: [
{
required: true,
@@ -79,9 +102,9 @@
],
},
{
- label: "考核人部门",
- prop: "deptName",
- type: "input",
+ label: '考核人部门',
+ prop: 'deptName',
+ type: 'input',
disabled: true,
rules: [
{
@@ -92,9 +115,9 @@
],
},
{
- label: "考核人职务",
- prop: "postName",
- type: "input",
+ label: '考核人职务',
+ prop: 'postName',
+ type: 'input',
disabled: true,
// hide: true,
rules: [
@@ -106,19 +129,19 @@
],
},
{
- label: "权值",
- prop: "weight",
- type: "input",
+ label: '权值',
+ prop: 'weight',
+ type: 'input',
rules: [
{
validator: (rule, value, callback) => {
if (value === '') {
- callback(new Error('请输入权值'))
+ callback(new Error('请输入权值'));
} else {
if (value > this.weightRange) {
- callback(new Error('输入的权值不可超过' + this.weightRange))
+ callback(new Error('输入的权值不可超过' + this.weightRange));
} else {
- callback()
+ callback();
}
}
},
@@ -126,8 +149,20 @@
trigger: 'click',
},
],
+ },
+ {
+ label: '范围',
+ prop: 'rangeVal',
+ type: 'input',
+ rules: [
+ {
+ required: true,
+ message: '请填写范围',
+ trigger: 'click',
+ },
+ ],
}
- ]
+ ],
},
page: {
pageSize: 10,
@@ -136,104 +171,109 @@
},
selectList: [],
weightRange: 100,
- dialogParams: {}
- }
+ dialogParams: {},
+ configDialogShow: false,
+ configUserList: [],
+ checkedUsers: [],
+ addLoading: false,
+ addTipsText: ''
+ };
},
- watch: {
- },
+ watch: {},
methods: {
back() {
- this.$emit('changeIs', true)
+ this.$emit('changeIs', true);
},
rowSave() {
this.dialogParams = {
visible: true,
isDept: false,
taskParams: this.params,
- weightRange: this.weightRange
- }
+ weightRange: this.weightRange,
+ };
},
rowUpdate(row, index, done, loading) {
- updateAssessor(row).then(() => {
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!"
- });
- done();
- }, error => {
- loading();
- console.log(error);
- });
+ updateAssessor(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);
- return removeAssessor(row.id)
+ return removeAssessor(row.id);
})
.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);
- return removeAssessor(this.ids)
+ return removeAssessor(this.ids);
})
.then(() => {
this.onLoad(this.page);
this.$message({
- type: "success",
- message: "操作成功!"
+ type: 'success',
+ message: '操作成功!',
});
this.$refs.crud.toggleSelection();
});
},
handleExport() {
- let downloadUrl = `/assessmentTask/assessmentTask/export-assessmentTask?${this.website.tokenHeader}=${getToken()}`;
- const {
- } = this.query;
- let values = {
- };
- this.$confirm("是否导出数据?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
+ let downloadUrl = `/assessmentTask/assessmentTask/export-assessmentTask?${this.website.tokenHeader
+ }=${getToken()}`;
+ const { } = this.query;
+ let values = {};
+ 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)) {
getAssessorDetail(this.form.id).then(res => {
this.form = res.data.data;
});
- if (type === "edit") {
-
- this.weightRange += this.form.weight
- this.defaults.weight.placeholder = `请输入权重(输入的权值大于等于${this.weightRange})`
+ if (type === 'edit') {
+ this.weightRange += this.form.weight;
+ this.defaults.weight.placeholder = `请输入权重(输入的权值大于等于${this.weightRange})`;
}
}
done();
@@ -267,41 +307,130 @@
onLoad(page, params = {}) {
this.loading = true;
- const {
- } = this.query;
+ const { } = this.query;
- const { userId, deptId, type, id } = this.params
+ const { userId, deptId, type, id } = this.params;
let values = {
// userId: !type ? userId : deptId
- assessmentSetId: id
+ assessmentSetId: id,
};
getAssessorList(page.currentPage, page.pageSize, values).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.loading = false;
- this.setDefaultWeightRange(data.records)
+ this.setDefaultWeightRange(data.records);
this.selectionClear();
});
},
setDefaultWeightRange(data) {
- let weightrange = 100
+ let weightrange = 100;
data.forEach(item => {
- weightrange -= item.weight
- })
- this.weightRange = weightrange
- this.defaults.weight.placeholder = `请输入权重(当前权重最大不可超过${weightrange})`
+ weightrange -= item.weight;
+ });
+ this.weightRange = weightrange;
+ this.defaults.weight.placeholder = `请输入权重(当前权重最大不可超过${weightrange})`;
+ },
+ configDialogOpen() {
+ getExportExcelData(this.params.userId).then(excelRes => {
+ if (excelRes.data.code !== 200) return this.$message.error('获取相关配置失败!!');
+ const list = excelRes.data.data;
+ this.configUserList = list;
+ });
+ },
+ handleSelectionChange(value) {
+ this.checkedUsers = value;
+ },
+ addConfigUsers() {
+ if (this.checkedUsers.length === 0) {
+ this.$message.warning('暂未选取任何数据!!');
+ } else {
+ let currentAllWeight = 0;
+ this.checkedUsers.forEach(item => {
+ currentAllWeight += item.weight;
+ });
+ if (currentAllWeight > 100) {
+ return this.$message.warning('当前权重超过100,请重新选择或在权重配置中修改后重新选择');
+ }
+ this.addLoading = true
+
+ const dataList = this.checkedUsers.map(item => {
+ const {
+ assessorUserId,
+ assessorUserName,
+ assessorPostName,
+ assessorDeptId,
+ assessorDeptName,
+ weight,
+ rangeVal,
+ } = item;
+ return {
+ assessmentSetId: this.params.id,
+ deptId: assessorDeptId,
+ deptName: assessorDeptName,
+ postName: assessorPostName,
+ userId: assessorUserId,
+ userName: assessorUserName,
+ weight,
+ rangeVal,
+ }
+ });
+
+ const promiseArr = []
+ const createAssessorPromise = (data, userName) => {
+ return addAssessorList(data).then(res => {
+ this.addTipsText = `数据"${userName}"添加中...`
+ if (res.data.code !== 200) {
+ return `${userName}添加失败`;
+ }
+ return `${userName}添加成功`;
+ })
+ }
+
+ dataList.forEach(item => {
+ promiseArr.push(createAssessorPromise(item, item.userName))
+ })
+
+ Promise.allSettled(promiseArr).then((responses) => {
+ const message = responses.map(item => item.value).join('、')
+ this.$message.success(message)
+ this.addLoading = false
+ this.configDialogShow = false
+ this.refreshChange()
+ }, error => {
+ this.$message.error(error)
+ })
+ }
},
},
- mounted() {
- }
-}
+ mounted() { },
+};
</script>
-
+
<style lang="scss" scoped>
.header {
margin-bottom: 20px;
+}
+
+.table-search {
+ margin-bottom: 15px;
+ width: 250px;
+ float: right;
+}
+
+:deep() {
+ .custom-table {
+ .el-table__header {
+ thead {
+ color: black;
+
+ .el-table__cell {
+ background-color: #fafafa;
+ }
+ }
+ }
+ }
}
.info {
@@ -320,4 +449,3 @@
}
}
</style>
-
\ No newline at end of file
--
Gitblit v1.9.3