|
@@ -1,5 +1,5 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, watch, computed, onMounted } from "vue";
|
|
|
+import { ref, reactive, watch, computed, onMounted, nextTick } from "vue";
|
|
|
import { ElMessageBox, ElMessage } from "element-plus";
|
|
|
import { useRoute } from "vue-router";
|
|
|
import {
|
|
@@ -17,6 +17,11 @@ const dalongTitle = ref("");
|
|
|
const direction = ref<DrawerProps["direction"]>("rtl");
|
|
|
const ruleFormRef = ref();
|
|
|
const dimWeight = ref(false);
|
|
|
+const oldIndexList = reactive({
|
|
|
+ // 分数
|
|
|
+ indLimitScore: []
|
|
|
+});
|
|
|
+// 分数
|
|
|
const formLabelAlign = reactive({
|
|
|
id: "",
|
|
|
list: [
|
|
@@ -44,14 +49,10 @@ const formLabelAlign = reactive({
|
|
|
});
|
|
|
// 存储指标变量,修改指标最高值时使用
|
|
|
const changeIndexList = ref([]);
|
|
|
-const newAddItem = ref();
|
|
|
-const handleClose = (done: () => void) => {
|
|
|
- done();
|
|
|
+const handleClose = () => {
|
|
|
+ Object.assign(formLabelAlign, {});
|
|
|
drawer.value = false;
|
|
|
};
|
|
|
-function cancelClick() {
|
|
|
- drawer.value = false;
|
|
|
-}
|
|
|
function confirmClick() {
|
|
|
ruleFormRef.value.validate((valid: boolean) => {
|
|
|
if (valid) {
|
|
@@ -67,7 +68,8 @@ function confirmClick() {
|
|
|
const titleName = ref("");
|
|
|
const indexList = ref([]);
|
|
|
const open = (row: any, title: string, order: number) => {
|
|
|
- console.log("编辑", row, title);
|
|
|
+ Object.assign(formLabelAlign, {});
|
|
|
+ oldIndexList.indLimitScore = [];
|
|
|
dalongTitle.value = title;
|
|
|
if (title == "新建") {
|
|
|
titleName.value = "新建考核维度";
|
|
@@ -91,15 +93,25 @@ const open = (row: any, title: string, order: number) => {
|
|
|
}
|
|
|
if (title == "编辑") {
|
|
|
titleName.value = "编辑考核维度";
|
|
|
- Object.assign(formLabelAlign, {
|
|
|
- ...row,
|
|
|
- order
|
|
|
- });
|
|
|
+ // 深拷贝对象防止父子通信的双向绑定
|
|
|
+ Object.assign(
|
|
|
+ formLabelAlign,
|
|
|
+ JSON.parse(
|
|
|
+ JSON.stringify({
|
|
|
+ ...row,
|
|
|
+ order
|
|
|
+ })
|
|
|
+ )
|
|
|
+ );
|
|
|
formLabelAlign.tableData.map(item => {
|
|
|
item["indNameIndex"] = item.indName;
|
|
|
});
|
|
|
changeIndexList.value = formLabelAlign.tableData;
|
|
|
indexList.value = formLabelAlign.tableData.reduce((acc, current) => {
|
|
|
+ // 检查 current.indLimitScore 是否为空,如果为空则跳过
|
|
|
+ if (!current.indLimitScore) {
|
|
|
+ return acc; // 直接返回当前的结果数组,不做任何操作
|
|
|
+ }
|
|
|
// 找到当前项的 indLimitScore 是否已经存在于结果数组中
|
|
|
let found = acc.find(
|
|
|
group => group[0].indLimitScore === current.indLimitScore
|
|
@@ -111,14 +123,11 @@ const open = (row: any, title: string, order: number) => {
|
|
|
// 如果没有找到,创建一个新的数组并将当前项加入
|
|
|
acc.push([current]);
|
|
|
}
|
|
|
-
|
|
|
return acc;
|
|
|
}, []);
|
|
|
- // indexList.value.map(item => {
|
|
|
- // item.map(it => {
|
|
|
- // it["indNameIndex"] = "";
|
|
|
- // });
|
|
|
- // });
|
|
|
+ indexList.value.map(item => {
|
|
|
+ oldIndexList.indLimitScore.push(item[0].indLimitScore);
|
|
|
+ });
|
|
|
watchTableData();
|
|
|
}
|
|
|
drawer.value = true;
|
|
@@ -180,7 +189,6 @@ const remarkValueValue = computed({
|
|
|
// 分割————————————————————————————————————————————
|
|
|
// 新建维度
|
|
|
const postAddDimensionApi = async () => {
|
|
|
- console.log("新建维度", formLabelAlign);
|
|
|
const { code, msg } = await postAddDimension(formLabelAlign);
|
|
|
if (code === 200) {
|
|
|
ElMessage({
|
|
@@ -200,12 +208,12 @@ const postAddDimensionApi = async () => {
|
|
|
const postUpdateDeptApi = async () => {
|
|
|
const { code, msg } = await postUpdateDept(formLabelAlign);
|
|
|
if (code === 200) {
|
|
|
- ElMessage({
|
|
|
- message: "更新成功",
|
|
|
- type: "success"
|
|
|
- });
|
|
|
- $emit("handClick", formLabelAlign.tpId);
|
|
|
- drawer.value = false;
|
|
|
+ // ElMessage({
|
|
|
+ // message: "更新成功",
|
|
|
+ // type: "success"
|
|
|
+ // });
|
|
|
+ // $emit("handClick", formLabelAlign.tpId);
|
|
|
+ // drawer.value = false;
|
|
|
} else {
|
|
|
ElMessage({
|
|
|
message: msg,
|
|
@@ -214,29 +222,44 @@ const postUpdateDeptApi = async () => {
|
|
|
}
|
|
|
};
|
|
|
const handClose = (indName, ind, indId) => {
|
|
|
- // console.log("item", ind, indId);
|
|
|
- indexList.value[ind].splice(indId, 1);
|
|
|
- if (indexList.value[ind].length == 0) {
|
|
|
- indexList.value.splice(ind, 1);
|
|
|
- }
|
|
|
let newIndName = indName;
|
|
|
newIndName.indLimitScore = null;
|
|
|
- formLabelAlign.tableData.push(newIndName);
|
|
|
+ nextTick(() => {
|
|
|
+ formLabelAlign.tableData.push(newIndName);
|
|
|
+ indexList.value[ind].splice(indId, 1);
|
|
|
+ if (indexList.value[ind].length == 0) {
|
|
|
+ console.log("oldIndexList", oldIndexList.indLimitScore);
|
|
|
+ oldIndexList.indLimitScore[ind] = 1;
|
|
|
+ indexList.value.splice(ind, 1);
|
|
|
+ console.log("newold", oldIndexList.indLimitScore);
|
|
|
+ }
|
|
|
+ if (indexList.value[ind]?.length > 0 && !indexList.value[ind][0].id) {
|
|
|
+ indexList.value[ind].splice(0, 1);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
const delteIndex = (index, item) => {
|
|
|
- indexList.value[index].map(it => {
|
|
|
- it.indLimitScore = null;
|
|
|
- formLabelAlign.tableData.push(it);
|
|
|
+ nextTick(() => {
|
|
|
+ indexList.value[index].map(it => {
|
|
|
+ if (it.id) {
|
|
|
+ it.indLimitScore = null;
|
|
|
+ formLabelAlign.tableData.push(it);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ indexList.value.splice(index, 1);
|
|
|
+ oldIndexList.indLimitScore.splice(index, 1);
|
|
|
});
|
|
|
- indexList.value.splice(index, 1);
|
|
|
};
|
|
|
const addIndex = () => {
|
|
|
- indexList.value.push([
|
|
|
- {
|
|
|
- indNameIndex: "",
|
|
|
- indLimitScore: null
|
|
|
- }
|
|
|
- ]);
|
|
|
+ nextTick(() => {
|
|
|
+ indexList.value.push([
|
|
|
+ {
|
|
|
+ indNameIndex: "",
|
|
|
+ indLimitScore: null
|
|
|
+ }
|
|
|
+ ]);
|
|
|
+ oldIndexList.indLimitScore.push(1);
|
|
|
+ });
|
|
|
};
|
|
|
const watchTableData = () => {
|
|
|
const idsToDelete = new Set();
|
|
@@ -251,32 +274,63 @@ const watchTableData = () => {
|
|
|
item => !idsToDelete.has(item.id)
|
|
|
);
|
|
|
formLabelAlign.tableData = filteredTableData;
|
|
|
- console.log("tableDatatableData", filteredTableData);
|
|
|
};
|
|
|
const handChangeIndex = (ind, val) => {
|
|
|
- changeIndexList.value.map(item => {
|
|
|
- if (item.id == val) {
|
|
|
- formLabelAlign.tableData;
|
|
|
- indexList.value[ind].push(item);
|
|
|
- watchTableData();
|
|
|
- }
|
|
|
+ // <!--select使用交互有bug,响应式数据加载慢-- >
|
|
|
+ // changeIndexList.value.map(item => {
|
|
|
+ // if (item.id == val) {
|
|
|
+ // nextTick(() => {
|
|
|
+ // indexList.value[ind].push(item);
|
|
|
+ // watchTableData();
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ nextTick(() => {
|
|
|
+ indexList.value[ind].push(val);
|
|
|
+ watchTableData();
|
|
|
});
|
|
|
};
|
|
|
const postUpdateApi = async () => {
|
|
|
- indexList.value.map(item => {
|
|
|
+ let codeList = [];
|
|
|
+ let successList = [];
|
|
|
+ console.log("数据", indexList.value);
|
|
|
+ indexList.value.map((item, index) => {
|
|
|
item.map(async (item1, index1, arr1) => {
|
|
|
if (item1.id) {
|
|
|
- item1.indLimitScore = arr1[item.length - 1].indLimitScore;
|
|
|
+ item1.indLimitScore = oldIndexList.indLimitScore[index];
|
|
|
const { code } = await postUpdate(item1);
|
|
|
+ codeList.push(item1.id);
|
|
|
+ if (code == 200) {
|
|
|
+ successList.push(code);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
+ if (successList.length == codeList.length) {
|
|
|
+ ElMessage({
|
|
|
+ message: "更新成功",
|
|
|
+ type: "success"
|
|
|
+ });
|
|
|
+ $emit("handClick", formLabelAlign.tpId);
|
|
|
+ drawer.value = false;
|
|
|
+ }
|
|
|
console.log("indexList", indexList.value);
|
|
|
};
|
|
|
defineExpose({
|
|
|
open
|
|
|
});
|
|
|
-const value = ref("");
|
|
|
+// 输入验证方法
|
|
|
+const validateInput = ind => {
|
|
|
+ // 转换输入为数字
|
|
|
+ console.log("ind", ind);
|
|
|
+ const num = parseFloat(oldIndexList.indLimitScore[ind]);
|
|
|
+
|
|
|
+ // 如果输入不是有效的数字,或者小于等于0,清空输入框
|
|
|
+ if (isNaN(num) || num <= 0) {
|
|
|
+ ElMessage.error("请输入大于0的数字,且不能为空");
|
|
|
+ oldIndexList.indLimitScore[ind] = 1;
|
|
|
+ }
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -339,30 +393,66 @@ const value = ref("");
|
|
|
class="mx-1"
|
|
|
type="danger"
|
|
|
@click="delteIndex(ind, int)"
|
|
|
- ><el-icon> <Delete /> </el-icon
|
|
|
- ></el-text>
|
|
|
+ >
|
|
|
+ <el-icon>
|
|
|
+ <Delete />
|
|
|
+ </el-icon>
|
|
|
+ </el-text>
|
|
|
<el-text class="mx-1">不超过</el-text>
|
|
|
+ <!-- <el-input v-model="int[int.length - 1].indLimitScore" size="small" style="width: 45px" /> -->
|
|
|
<el-input
|
|
|
- v-model="int[int.length - 1].indLimitScore"
|
|
|
+ v-model="oldIndexList.indLimitScore[ind]"
|
|
|
size="small"
|
|
|
- style="width: 30px"
|
|
|
+ style="width: 45px"
|
|
|
+ @input="validateInput(ind)"
|
|
|
/>
|
|
|
<el-text class="mx-1">分</el-text>
|
|
|
- <!-- <el-select v-model="int[int.length - 1].indNameIndex" placeholder="Select" style="width: 140px" -->
|
|
|
- <el-select
|
|
|
- v-model="int[int.length - 1].indNameIndex"
|
|
|
- placeholder="Select"
|
|
|
- style="width: 140px"
|
|
|
- filterable
|
|
|
- @change="handChangeIndex(ind, $event)"
|
|
|
- >
|
|
|
- <el-option
|
|
|
- v-for="item in formLabelAlign.tableData"
|
|
|
- :key="item.id"
|
|
|
- :label="item.indName"
|
|
|
- :value="item.id"
|
|
|
- />
|
|
|
- </el-select>
|
|
|
+ <!-- select使用交互有bug,响应式数据加载慢,拿不到最新数据 -->
|
|
|
+ <!-- <el-select v-model="int[int.length - 1].indNameIndex" placeholder="请选择指标" style="width: 140px"
|
|
|
+ filterable @change="handChangeIndex(ind, $event)">
|
|
|
+ <el-option v-for="item in formLabelAlign.tableData" :key="item.id" :label="item.indNameIndex"
|
|
|
+ :value="item.id" />
|
|
|
+ </el-select> -->
|
|
|
+ <el-dropdown trigger="click" placement="bottom-start">
|
|
|
+ <span class="el-dropdown-link">
|
|
|
+ <el-input
|
|
|
+ v-model="int[int.length - 1].indNameIndex"
|
|
|
+ style="width: 140px"
|
|
|
+ />
|
|
|
+ </span>
|
|
|
+ <template #dropdown>
|
|
|
+ <el-dropdown-menu>
|
|
|
+ <div
|
|
|
+ v-if="formLabelAlign.tableData.length > 0"
|
|
|
+ style="max-height: 300px"
|
|
|
+ >
|
|
|
+ <el-scrollbar>
|
|
|
+ <div
|
|
|
+ v-if="formLabelAlign.tableData.length > 0"
|
|
|
+ class="p-2"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ v-for="item in formLabelAlign.tableData"
|
|
|
+ :key="item.id"
|
|
|
+ class="w-full h-8 flex items-center justify-center text-center cursor-pointer hoverBlue p-2"
|
|
|
+ @click="handChangeIndex(ind, item)"
|
|
|
+ >
|
|
|
+ <!-- <el-text class="mx-1" type="info"> -->
|
|
|
+ {{ item.indName }}
|
|
|
+ <!-- </el-text> -->
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-scrollbar>
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ v-else
|
|
|
+ class="w-[150px] h-10 flex items-center justify-center"
|
|
|
+ >
|
|
|
+ <el-text class="mx-1" type="info">暂无数据</el-text>
|
|
|
+ </div>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </template>
|
|
|
+ </el-dropdown>
|
|
|
<span v-for="(indName, indId) in int" :key="indId">
|
|
|
<el-tag
|
|
|
v-if="indName.indName"
|
|
@@ -375,11 +465,6 @@ const value = ref("");
|
|
|
</el-tag>
|
|
|
</span>
|
|
|
</div>
|
|
|
- <!-- <el-text size="large" type="primary">
|
|
|
- <el-icon>
|
|
|
- <Plus />
|
|
|
- </el-icon>
|
|
|
- </el-text> -->
|
|
|
<el-tag type="primary" @click="addIndex">
|
|
|
<el-icon> <Plus /> </el-icon>添加
|
|
|
</el-tag>
|
|
@@ -428,10 +513,24 @@ const value = ref("");
|
|
|
</template>
|
|
|
<template #footer>
|
|
|
<div>
|
|
|
- <el-button @click="cancelClick">取消</el-button>
|
|
|
+ <el-button @click="handleClose">取消</el-button>
|
|
|
<el-button type="primary" @click="confirmClick">确认</el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-drawer>
|
|
|
</div>
|
|
|
</template>
|
|
|
+<style scoped lang="scss">
|
|
|
+.hoverBlue {
|
|
|
+ overflow: hidden;
|
|
|
+ font-size: 14px;
|
|
|
+ color: #999;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ white-space: nowrap;
|
|
|
+}
|
|
|
+
|
|
|
+.hoverBlue:hover {
|
|
|
+ color: #4285f4 !important;
|
|
|
+ background-color: #99999912;
|
|
|
+}
|
|
|
+</style>
|