|
@@ -1,8 +1,12 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive } from "vue";
|
|
|
+import { ref, reactive, watch } from "vue";
|
|
|
import { ElMessageBox, ElMessage } from "element-plus";
|
|
|
import { calculator } from "./evaluate";
|
|
|
-import { getIndexInfo, postUpdate } from "@/api/templateInfo";
|
|
|
+import {
|
|
|
+ getIndexInfo,
|
|
|
+ postUpdate,
|
|
|
+ calculateScoreByConditionMoCondition
|
|
|
+} from "@/api/templateInfo";
|
|
|
import { conditionVerify } from "@/api/formula";
|
|
|
import type { DrawerProps, FormItemProps, FormProps } from "element-plus";
|
|
|
// const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");
|
|
@@ -52,37 +56,27 @@ const getIndexInfoApi = async id => {
|
|
|
Object.assign(addmanyChange, bb);
|
|
|
}
|
|
|
}
|
|
|
- if (data.formula) {
|
|
|
- } else {
|
|
|
- Object.assign(params.formula, {
|
|
|
+ if (!data.formula) {
|
|
|
+ params.formula = {
|
|
|
noConditionFormula: ""
|
|
|
- });
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ if (!data.formulaType) {
|
|
|
+ params.formulaType = 0;
|
|
|
}
|
|
|
- console.log("params", params);
|
|
|
} else {
|
|
|
ElMessage.error(msg);
|
|
|
}
|
|
|
};
|
|
|
-// 指标信息
|
|
|
-// const getIndInfoApi = async id => {
|
|
|
-// const { data, code, msg } = await getIndInfo(id);
|
|
|
-// // console.log("1111", data);
|
|
|
-// if (code === 200) {
|
|
|
-// Object.assign(params, data);
|
|
|
-// if (isValidJSON(data.formula)) {
|
|
|
-// if (params.formulaType == 0) {
|
|
|
-// }
|
|
|
-// }
|
|
|
-// console.log("params", params);
|
|
|
-// } else {
|
|
|
-// ElMessage.error(msg);
|
|
|
-// }
|
|
|
-// };
|
|
|
// 更新指标
|
|
|
const postUpdateApi = async () => {
|
|
|
if (params.formulaType == 0) {
|
|
|
params.formula = JSON.stringify(params.formula);
|
|
|
} else {
|
|
|
+ params.formula = {
|
|
|
+ noConditionFormula: ""
|
|
|
+ };
|
|
|
params.formula.noConditionFormula = JSON.stringify(addmanyChange);
|
|
|
params.formula = JSON.stringify(params.formula);
|
|
|
}
|
|
@@ -105,71 +99,105 @@ const formulaForm = ref([]);
|
|
|
const grade = ref();
|
|
|
const conditionVerifyApi = async () => {
|
|
|
dialogFormVisibleFormula.value = true;
|
|
|
- formulaForm.value = [];
|
|
|
- grade.value = "";
|
|
|
- console.log("params", params);
|
|
|
-
|
|
|
- const keywords = ["完成值", "目标值", "门槛值", "挑战值", "增幅", "降幅"];
|
|
|
- let str = params.formula.noConditionFormula;
|
|
|
- // 创建一个正则表达式,匹配这些关键词
|
|
|
- const regex = new RegExp(keywords.join("|"), "g");
|
|
|
- // 提取字符串中的所有关键词
|
|
|
- let matches = str.match(regex);
|
|
|
- console.log("匹配到的关键词:", matches);
|
|
|
- matches.forEach(matchItem => {
|
|
|
- formulaForm.value.push({
|
|
|
- name: matchItem,
|
|
|
- value: ""
|
|
|
- });
|
|
|
- });
|
|
|
- let result = str.replace(regex, match => {
|
|
|
- return `${match}`;
|
|
|
- });
|
|
|
- console.log("formula", formulaForm.value);
|
|
|
+ try {
|
|
|
+ formulaForm.value = [];
|
|
|
+ grade.value = "";
|
|
|
+ console.log("params", params);
|
|
|
|
|
|
- // let formula = JSON.stringify(params.formula);
|
|
|
- // const { code, msg } = await conditionVerify({
|
|
|
- // formulaType: params.formulaType,
|
|
|
- // formula
|
|
|
- // });
|
|
|
-};
|
|
|
-// 计算
|
|
|
-const countComputed = async () => {
|
|
|
- const formula = JSON.stringify(params.formula);
|
|
|
- const { code, msg } = await conditionVerify({
|
|
|
- formulaType: params.formulaType,
|
|
|
- formula
|
|
|
- });
|
|
|
- if (code == 200) {
|
|
|
const keywords = ["完成值", "目标值", "门槛值", "挑战值", "增幅", "降幅"];
|
|
|
let str = params.formula.noConditionFormula;
|
|
|
// 创建一个正则表达式,匹配这些关键词
|
|
|
const regex = new RegExp(keywords.join("|"), "g");
|
|
|
+ // 提取字符串中的所有关键词
|
|
|
+ let matches = str.match(regex);
|
|
|
+ console.log("匹配到的关键词:", matches);
|
|
|
+ matches.forEach(matchItem => {
|
|
|
+ formulaForm.value.push({
|
|
|
+ name: matchItem,
|
|
|
+ value: ""
|
|
|
+ });
|
|
|
+ });
|
|
|
let result = str.replace(regex, match => {
|
|
|
- // 在 formulaForm.value 中查找匹配的项
|
|
|
- let matchedItem = formulaForm.value.find(item => item.name === match);
|
|
|
+ return `${match}`;
|
|
|
+ });
|
|
|
+ } catch (err) {}
|
|
|
+};
|
|
|
+// 计算
|
|
|
+const countComputed = async () => {
|
|
|
+ try {
|
|
|
+ if (params.formulaType == 0) {
|
|
|
+ const formula = JSON.stringify(params.formula);
|
|
|
+ const { code, msg } = await conditionVerify({
|
|
|
+ formulaType: params.formulaType,
|
|
|
+ formula
|
|
|
+ });
|
|
|
+ if (code == 200) {
|
|
|
+ const keywords = [
|
|
|
+ "完成值",
|
|
|
+ "目标值",
|
|
|
+ "门槛值",
|
|
|
+ "挑战值",
|
|
|
+ "增幅",
|
|
|
+ "降幅"
|
|
|
+ ];
|
|
|
+ let str = params.formula.noConditionFormula;
|
|
|
+ // 创建一个正则表达式,匹配这些关键词
|
|
|
+ const regex = new RegExp(keywords.join("|"), "g");
|
|
|
+ let result = str.replace(regex, match => {
|
|
|
+ // 在 formulaForm.value 中查找匹配的项
|
|
|
+ let matchedItem = formulaForm.value.find(item => item.name === match);
|
|
|
|
|
|
- // 如果找到匹配项,返回其 value,否则返回原始匹配值
|
|
|
- if (matchedItem) {
|
|
|
- return matchedItem.value; // 替换为对应的值
|
|
|
+ // 如果找到匹配项,返回其 value,否则返回原始匹配值
|
|
|
+ if (matchedItem) {
|
|
|
+ return matchedItem.value; // 替换为对应的值
|
|
|
+ }
|
|
|
+ return match; // 如果没有匹配项,返回原始匹配值
|
|
|
+ });
|
|
|
+ calculator.calculate(result);
|
|
|
+ grade.value = calculator.get();
|
|
|
+ } else {
|
|
|
+ ElMessageBox.confirm(
|
|
|
+ "如果不修改将无法计算得分",
|
|
|
+ "公式计算错误,修改后确认",
|
|
|
+ {
|
|
|
+ type: "warning"
|
|
|
+ }
|
|
|
+ ).then(() => {
|
|
|
+ dialogFormVisibleFormula.value = false;
|
|
|
+ });
|
|
|
}
|
|
|
- return match; // 如果没有匹配项,返回原始匹配值
|
|
|
- });
|
|
|
- calculator.calculate(result);
|
|
|
- grade.value = calculator.get();
|
|
|
- } else {
|
|
|
- ElMessageBox.confirm("配置项未保存,确认关闭", {
|
|
|
- type: "warning"
|
|
|
- }).then(() => {
|
|
|
- dialogFormVisibleFormula.value = false;
|
|
|
- });
|
|
|
+ } else if (params.formulaType == 1) {
|
|
|
+ let aa = JSON.parse(JSON.stringify(addmanyChange));
|
|
|
+ aa.outerConditionValue = formulaForm.value[0].value;
|
|
|
+ formulaForm.value.map((item, index) => {
|
|
|
+ console.log("item", aa);
|
|
|
+ if (index > 0) {
|
|
|
+ delete aa.innerConditionExpression[index - 1].select;
|
|
|
+ aa.innerConditionExpression[
|
|
|
+ index - 1
|
|
|
+ ].scoreRuleMoreInnerVO[0].innerConditionValue = item.value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const { code, msg, data } =
|
|
|
+ await calculateScoreByConditionMoCondition(aa);
|
|
|
+ console.log("aaa", aa);
|
|
|
+ if (code == 200) {
|
|
|
+ grade.value = data;
|
|
|
+ } else {
|
|
|
+ ElMessageBox.confirm(
|
|
|
+ "如果不修改将无法计算得分",
|
|
|
+ "公式计算错误,修改后确认",
|
|
|
+ {
|
|
|
+ type: "warning"
|
|
|
+ }
|
|
|
+ ).then(() => {
|
|
|
+ dialogFormVisibleFormula.value = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.log(err);
|
|
|
}
|
|
|
- // ElMessageBox.confirm("配置项未保存,确认关闭", {
|
|
|
- // type: "warning"
|
|
|
- // }).then(() => {
|
|
|
-
|
|
|
- // })
|
|
|
- // console.log();
|
|
|
};
|
|
|
// 判断是否为json
|
|
|
function isValidJSON(str) {
|
|
@@ -199,7 +227,6 @@ function confirmClick() {
|
|
|
}
|
|
|
const open = row => {
|
|
|
drawer.value = true;
|
|
|
- // console.log("row", row.id);
|
|
|
Object.assign(params, {
|
|
|
id: "",
|
|
|
tpId: "",
|
|
@@ -268,6 +295,14 @@ const rolesList = reactive({
|
|
|
value: "",
|
|
|
num: null
|
|
|
});
|
|
|
+// 监听formulaType变化
|
|
|
+const watchFormulaType = value => {
|
|
|
+ if (value == 0 && typeof params.formula == "string") {
|
|
|
+ let aa = JSON.parse(params.formula);
|
|
|
+ params.formula = aa;
|
|
|
+ params.formula.noConditionFormula = "";
|
|
|
+ }
|
|
|
+};
|
|
|
const lookRoles = item => {
|
|
|
bgColor.value = item.id;
|
|
|
params.formula.noConditionFormula =
|
|
@@ -304,65 +339,6 @@ const count = item => {
|
|
|
}
|
|
|
};
|
|
|
// 多条件公式
|
|
|
-const manyChange = reactive({
|
|
|
- newData: "",
|
|
|
- dataList: [
|
|
|
- {
|
|
|
- compare: "0", // 比较符号
|
|
|
- compareList: [
|
|
|
- {
|
|
|
- value: "0",
|
|
|
- label: ">"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "1",
|
|
|
- label: "≥"
|
|
|
- }
|
|
|
- ],
|
|
|
- formula: "0",
|
|
|
- formulaList: [
|
|
|
- {
|
|
|
- value: "0",
|
|
|
- label: "数值"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "1",
|
|
|
- label: "公式"
|
|
|
- }
|
|
|
- ],
|
|
|
- value: "",
|
|
|
- newData: "",
|
|
|
- dataList: [
|
|
|
- {
|
|
|
- compare: "0", // 比较符号
|
|
|
- compareList: [
|
|
|
- {
|
|
|
- value: "0",
|
|
|
- label: ">"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "1",
|
|
|
- label: "≥"
|
|
|
- }
|
|
|
- ],
|
|
|
- formula: "0",
|
|
|
- formulaList: [
|
|
|
- {
|
|
|
- value: "0",
|
|
|
- label: "数值"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "1",
|
|
|
- label: "公式"
|
|
|
- }
|
|
|
- ],
|
|
|
- value: "",
|
|
|
- grade: ""
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
-});
|
|
|
const addmanyChange = reactive({
|
|
|
outerConditionValue: "",
|
|
|
innerConditionExpression: [
|
|
@@ -460,6 +436,22 @@ const addItemDataList = (
|
|
|
comparisonEnd: null
|
|
|
});
|
|
|
};
|
|
|
+// 多条件公式验证
|
|
|
+const manyConditions = () => {
|
|
|
+ // outerConditionValue
|
|
|
+ dialogFormVisibleFormula.value = true;
|
|
|
+ formulaForm.value = [];
|
|
|
+ formulaForm.value.push({
|
|
|
+ name: addmanyChange.outerConditionValue,
|
|
|
+ value: null
|
|
|
+ });
|
|
|
+ addmanyChange.innerConditionExpression.map((item, index) => {
|
|
|
+ formulaForm.value.push({
|
|
|
+ name: item.scoreRuleMoreInnerVO[0].innerConditionValue,
|
|
|
+ value: null
|
|
|
+ });
|
|
|
+ });
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -493,7 +485,11 @@ const addItemDataList = (
|
|
|
</el-form-item>
|
|
|
<div v-if="params.scoreStandard === 1">
|
|
|
<el-form-item label="公式类型" label-position="top">
|
|
|
- <el-select v-model="params.formulaType" placeholder="请选择">
|
|
|
+ <el-select
|
|
|
+ v-model="params.formulaType"
|
|
|
+ placeholder="请选择"
|
|
|
+ @change="watchFormulaType"
|
|
|
+ >
|
|
|
<el-option
|
|
|
v-for="item in compute"
|
|
|
:key="item.value"
|
|
@@ -698,7 +694,7 @@ const addItemDataList = (
|
|
|
<el-form-item v-else label="公式设置">
|
|
|
<div class="w-full">
|
|
|
<div class="flex items-center">
|
|
|
- <el-text>条件填 = </el-text>
|
|
|
+ <el-text>条件值 = </el-text>
|
|
|
<el-input
|
|
|
v-model="addmanyChange.outerConditionValue"
|
|
|
class="ml-2"
|
|
@@ -883,7 +879,7 @@ const addItemDataList = (
|
|
|
</el-text>
|
|
|
</div>
|
|
|
<div class="float-right mr-8">
|
|
|
- <el-button type="primary" @click="conditionVerifyApi"
|
|
|
+ <el-button type="primary" @click="manyConditions"
|
|
|
>公式验证</el-button
|
|
|
>
|
|
|
</div>
|