|
@@ -162,6 +162,8 @@ const dialogFormVisibleFormula = ref(false);
|
|
|
const formulaForm = ref([]);
|
|
|
const grade = ref();
|
|
|
const conditionVerifyApi = async () => {
|
|
|
+ grade.value = null;
|
|
|
+ formulaForm.value = [];
|
|
|
dialogFormVisibleFormula.value = true;
|
|
|
try {
|
|
|
formulaForm.value = [];
|
|
@@ -223,6 +225,33 @@ function reverseReplace(oldValue, dataObject) {
|
|
|
});
|
|
|
return dataObject;
|
|
|
}
|
|
|
+function calculateScore(inputString) {
|
|
|
+ // 将 formulaForm.value 转换为一个键值对映射,方便替换
|
|
|
+ const valueMap = formulaForm.value.reduce((map, item) => {
|
|
|
+ map[item.name] = item.value !== null ? item.value : 0; // 用 0 替代 null
|
|
|
+ return map;
|
|
|
+ }, {});
|
|
|
+
|
|
|
+ // 替换字符串中的关键字为对应的 value 值
|
|
|
+ let formula = inputString;
|
|
|
+ for (const [key, value] of Object.entries(valueMap)) {
|
|
|
+ if (formula.includes(key)) {
|
|
|
+ // 使用正则替换所有匹配的关键字
|
|
|
+ const regex = new RegExp(key, "g");
|
|
|
+ formula = formula.replace(regex, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用 eval 计算公式
|
|
|
+ const result = eval(formula);
|
|
|
+ return result;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("公式计算出错:", error);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const countComputed = async () => {
|
|
|
try {
|
|
|
if (params.formulaType == 0) {
|
|
@@ -269,14 +298,58 @@ const countComputed = async () => {
|
|
|
});
|
|
|
}
|
|
|
} else if (params.formulaType == 1) {
|
|
|
- let oldValue = {};
|
|
|
- Object.assign(oldValue, addmanyChange);
|
|
|
- let formListNum = formulaForm.value;
|
|
|
- let newValue = reverseReplace(formListNum, oldValue);
|
|
|
- const { code, msg, data } =
|
|
|
- await calculateScoreByConditionMoCondition(newValue);
|
|
|
- if (code == 200) {
|
|
|
- grade.value = data;
|
|
|
+ let oldValue = JSON.parse(JSON.stringify(addmanyChange));
|
|
|
+ // Object.assign(oldValue, addmanyChange);
|
|
|
+ const formulaPar = JSON.stringify(oldValue);
|
|
|
+ const res = await conditionVerify({
|
|
|
+ formulaType: params.formulaType,
|
|
|
+ formula: formulaPar
|
|
|
+ });
|
|
|
+ if (res.code == 200) {
|
|
|
+ if (oldValue.outerConditionValue) {
|
|
|
+ oldValue.outerConditionValue = calculateScore(
|
|
|
+ oldValue.outerConditionValue
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (oldValue.innerConditionExpression.length > 0) {
|
|
|
+ oldValue.innerConditionExpression.map(itEx => {
|
|
|
+ if (itEx.startValue) {
|
|
|
+ itEx.startValue = calculateScore(itEx.startValue);
|
|
|
+ }
|
|
|
+ if (itEx.endValue) {
|
|
|
+ itEx.endValue = calculateScore(itEx.endValue);
|
|
|
+ }
|
|
|
+ if (itEx.innerScore) {
|
|
|
+ itEx.innerScore = calculateScore(itEx.innerScore);
|
|
|
+ }
|
|
|
+ if (itEx?.scoreRuleMoreInnerVO[0]?.innerConditionValue) {
|
|
|
+ itEx.scoreRuleMoreInnerVO[0].innerConditionValue = calculateScore(
|
|
|
+ itEx.scoreRuleMoreInnerVO[0].innerConditionValue
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (itEx?.scoreRuleMoreInnerVO[0]?.scoreRules.length > 0) {
|
|
|
+ itEx.scoreRuleMoreInnerVO[0].scoreRules.map(itRule => {
|
|
|
+ if (itRule.score) {
|
|
|
+ itRule.score = calculateScore(itRule.score);
|
|
|
+ }
|
|
|
+ if (itRule.startValue) {
|
|
|
+ itRule.startValue = calculateScore(itRule.startValue);
|
|
|
+ }
|
|
|
+ if (itRule.endValue) {
|
|
|
+ itRule.endValue = calculateScore(itRule.endValue);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ console.log("计算后的数据oldValue", oldValue);
|
|
|
+ console.log("计算后的数据addmanyChange", addmanyChange);
|
|
|
+ // let newValue = reverseReplace(formListNum, oldValue);
|
|
|
+ const { code, msg, data } =
|
|
|
+ await calculateScoreByConditionMoCondition(oldValue);
|
|
|
+ if (code == 200) {
|
|
|
+ grade.value = data;
|
|
|
+ }
|
|
|
} else {
|
|
|
ElMessageBox.confirm(
|
|
|
"如果不修改将无法计算得分",
|
|
@@ -384,6 +457,7 @@ const open = row => {
|
|
|
]
|
|
|
});
|
|
|
getIndexInfoApi(row.id);
|
|
|
+ calculatorShow.value = true;
|
|
|
};
|
|
|
const editShow = ref(true);
|
|
|
defineExpose({
|
|
@@ -523,19 +597,23 @@ const addItemFormulaList = (item, index) => {
|
|
|
}
|
|
|
];
|
|
|
addmanyChange.innerConditionExpression[index].innerScore = "";
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
|
|
|
const deleteItem = index => {
|
|
|
addmanyChange.innerConditionExpression.splice(index, 1);
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const dataleListItem = (index, indexList) => {
|
|
|
addmanyChange.innerConditionExpression[
|
|
|
index
|
|
|
].scoreRuleMoreInnerVO[0].scoreRules.splice(indexList, 1);
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
// 条件变量
|
|
|
const dataleListItemAll = (item, index) => {
|
|
|
item.scoreRuleMoreInnerVO = [];
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const addNewItem = () => {
|
|
|
addmanyChange.innerConditionExpression.push({
|
|
@@ -546,6 +624,7 @@ const addNewItem = () => {
|
|
|
comparisonEnd: null,
|
|
|
scoreRuleMoreInnerVO: []
|
|
|
});
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const addNewItemOldValue = item => {
|
|
|
addmanyChange.innerConditionExpression.push({
|
|
@@ -556,6 +635,7 @@ const addNewItemOldValue = item => {
|
|
|
comparisonEnd: null,
|
|
|
scoreRuleMoreInnerVO: []
|
|
|
});
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const addItemDataList = (
|
|
|
index: number,
|
|
@@ -575,9 +655,10 @@ const addItemDataList = (
|
|
|
comparisonEnd: null
|
|
|
});
|
|
|
addmanyChange.innerConditionExpression[index].innerScore = "";
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
// 多条件公式验证
|
|
|
-const keywords = ["目标值", "完成值", "挑战值", "增幅", "降幅"];
|
|
|
+const keywords = ["目标值", "完成值", "挑战值", "门槛值", "增幅", "降幅"];
|
|
|
// 处理字符串,提取关键词
|
|
|
function extractKeywords(value) {
|
|
|
// 如果是字符串,处理包含的关键词
|
|
@@ -613,21 +694,76 @@ function traverseObject(obj) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+function extractKeywordsAndPush(keywordsList, inputString) {
|
|
|
+ keywords.forEach(keyword => {
|
|
|
+ if (
|
|
|
+ inputString?.includes(keyword) && // 检查字符串是否包含关键字
|
|
|
+ !formulaForm.value.some(item => item.name === keyword) // 确保没有重复
|
|
|
+ ) {
|
|
|
+ // 如果包含且未重复,构造对象并push到formulaForm.value
|
|
|
+ formulaForm.value.push({
|
|
|
+ name: keyword,
|
|
|
+ value: null // 根据需求赋值
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return formulaForm;
|
|
|
+}
|
|
|
const manyConditions = () => {
|
|
|
+ grade.value = null;
|
|
|
dialogFormVisibleFormula.value = true;
|
|
|
formulaForm.value = [];
|
|
|
// 提取 addmanyChange 对象中的条件值
|
|
|
- const oldValue = addmanyChange;
|
|
|
- traverseObject(oldValue);
|
|
|
+ let oldValue = addmanyChange;
|
|
|
+ if (oldValue.outerConditionValue) {
|
|
|
+ extractKeywordsAndPush(keywords, oldValue.outerConditionValue);
|
|
|
+ }
|
|
|
+ if (oldValue.innerConditionExpression.length > 0) {
|
|
|
+ oldValue.innerConditionExpression.map(itemExp => {
|
|
|
+ if (itemExp.startValue) {
|
|
|
+ extractKeywordsAndPush(keywords, itemExp.startValue);
|
|
|
+ }
|
|
|
+ if (itemExp.endValue) {
|
|
|
+ extractKeywordsAndPush(keywords, itemExp.endValue);
|
|
|
+ }
|
|
|
+ if (itemExp.innerScore) {
|
|
|
+ extractKeywordsAndPush(keywords, itemExp.innerScore);
|
|
|
+ }
|
|
|
+ if (itemExp?.scoreRuleMoreInnerVO[0]?.innerConditionValue) {
|
|
|
+ extractKeywordsAndPush(
|
|
|
+ keywords,
|
|
|
+ itemExp.scoreRuleMoreInnerVO[0].innerConditionValue
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (itemExp?.scoreRuleMoreInnerVO.length > 0) {
|
|
|
+ if (itemExp?.scoreRuleMoreInnerVO[0]?.scoreRules.length > 0) {
|
|
|
+ itemExp?.scoreRuleMoreInnerVO[0]?.scoreRules.map(itSc => {
|
|
|
+ if (itSc.score) {
|
|
|
+ extractKeywordsAndPush(keywords, itSc.score);
|
|
|
+ }
|
|
|
+ if (itSc.startValue) {
|
|
|
+ extractKeywordsAndPush(keywords, itSc.startValue);
|
|
|
+ }
|
|
|
+ if (itSc.endValue) {
|
|
|
+ extractKeywordsAndPush(keywords, itSc.endValue);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
// 计算器
|
|
|
const jishuanqiRef = ref();
|
|
|
const countNoConditionFormula = item => {
|
|
|
addmanyChange.outerConditionValue = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const jishuanqiRef1 = ref();
|
|
|
const countNoConditionFormula1 = (item, index) => {
|
|
|
addmanyChange.innerConditionExpression[index].endValue = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const jishuanqiRef2 = ref();
|
|
|
const countNoConditionFormula2 = (item, index) => {
|
|
@@ -635,20 +771,24 @@ const countNoConditionFormula2 = (item, index) => {
|
|
|
addmanyChange.innerConditionExpression[
|
|
|
index
|
|
|
].scoreRuleMoreInnerVO[0].innerConditionValue = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const jishuanqiRef3 = ref();
|
|
|
const countNoConditionFormula3 = (item, index, indexList) => {
|
|
|
addmanyChange.innerConditionExpression[
|
|
|
index
|
|
|
].scoreRuleMoreInnerVO[0].scoreRules[indexList].endValue = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const countNoConditionFormula4 = (item, index, indexList) => {
|
|
|
addmanyChange.innerConditionExpression[
|
|
|
index
|
|
|
].scoreRuleMoreInnerVO[0].scoreRules[indexList].score = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
const countNoConditionFormulaInnerScore = (item, index, indexList) => {
|
|
|
addmanyChange.innerConditionExpression[index].innerScore = item;
|
|
|
+ changeAddMay();
|
|
|
};
|
|
|
|
|
|
// 转换函数 --- 人员
|
|
@@ -675,6 +815,60 @@ const handleRreeSelect = () => {
|
|
|
});
|
|
|
params.designatedPersonnel = arr.map(item => item.value).join(",");
|
|
|
};
|
|
|
+// 取消计算
|
|
|
+const quxiaoCmputed = () => {
|
|
|
+ formulaForm.value = [];
|
|
|
+ dialogFormVisibleFormula.value = false;
|
|
|
+};
|
|
|
+// 监听数据变化
|
|
|
+const changeAddMay = () => {
|
|
|
+ let addmanyChangeOldVal = JSON.parse(JSON.stringify(addmanyChange));
|
|
|
+ addmanyChange.innerConditionExpression.forEach((item, index, arr) => {
|
|
|
+ if (index + 1 <= arr.length) {
|
|
|
+ console.log("12312", addmanyChangeOldVal.innerConditionExpression);
|
|
|
+ if (item.endValue) {
|
|
|
+ if (addmanyChangeOldVal.innerConditionExpression.length > 1) {
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[index + 1].startValue =
|
|
|
+ item?.endValue;
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[index + 1].startExpress =
|
|
|
+ item?.endExpress;
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[
|
|
|
+ index + 1
|
|
|
+ ].comparisonStart = item?.comparisonEnd == "≥" ? ">" : "≥";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.scoreRuleMoreInnerVO.length > 0) {
|
|
|
+ if (item.scoreRuleMoreInnerVO[0].scoreRules.length > 0) {
|
|
|
+ item.scoreRuleMoreInnerVO[0].scoreRules.map((it, id, arrChild) => {
|
|
|
+ if (id + 1 <= arrChild.length) {
|
|
|
+ if (it.endValue) {
|
|
|
+ // if (
|
|
|
+ // addmanyChangeOldVal.innerConditionExpression[index + 1]
|
|
|
+ // .scoreRuleMoreInnerVO.length > 0
|
|
|
+ // ) {
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[
|
|
|
+ index
|
|
|
+ ].scoreRuleMoreInnerVO[0].scoreRules[id + 1].startValue =
|
|
|
+ it?.endValue;
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[
|
|
|
+ index
|
|
|
+ ].scoreRuleMoreInnerVO[0].scoreRules[id + 1].startExpress =
|
|
|
+ it?.startExpress;
|
|
|
+ addmanyChangeOldVal.innerConditionExpression[
|
|
|
+ index
|
|
|
+ ].scoreRuleMoreInnerVO[0].scoreRules[id + 1].comparisonStart =
|
|
|
+ it?.comparisonEnd;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Object.assign(addmanyChange, addmanyChangeOldVal);
|
|
|
+};
|
|
|
+// { deep: true };
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -1264,7 +1458,12 @@ const handleRreeSelect = () => {
|
|
|
</template>
|
|
|
</el-drawer>
|
|
|
<!-- 公式验证 -->
|
|
|
- <el-dialog v-model="dialogFormVisibleFormula" title="完成值" width="500">
|
|
|
+ <el-dialog
|
|
|
+ v-model="dialogFormVisibleFormula"
|
|
|
+ title="完成值"
|
|
|
+ width="500"
|
|
|
+ :before-close="quxiaoCmputed"
|
|
|
+ >
|
|
|
<el-form :model="formulaForm">
|
|
|
<div v-for="(itemF, indexF) in formulaForm" :key="indexF">
|
|
|
<el-form-item :label="itemF.name">
|
|
@@ -1277,7 +1476,7 @@ const handleRreeSelect = () => {
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
|
- <el-button @click="dialogFormVisibleFormula = false">取消</el-button>
|
|
|
+ <el-button @click="quxiaoCmputed">取消</el-button>
|
|
|
<el-button type="primary" @click="countComputed"> 计算 </el-button>
|
|
|
</div>
|
|
|
</template>
|