|
@@ -1,8 +1,12 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import { ref, reactive } from "vue";
|
|
|
|
|
|
+import { ref, reactive, watch } from "vue";
|
|
import { ElMessageBox, ElMessage } from "element-plus";
|
|
import { ElMessageBox, ElMessage } from "element-plus";
|
|
import { calculator } from "./evaluate";
|
|
import { calculator } from "./evaluate";
|
|
-import { getIndexInfo } from "@/api/templateInfo";
|
|
|
|
|
|
+import {
|
|
|
|
+ getIndexInfo,
|
|
|
|
+ postUpdate,
|
|
|
|
+ calculateScoreByConditionMoCondition
|
|
|
|
+} from "@/api/templateInfo";
|
|
import { conditionVerify } from "@/api/formula";
|
|
import { conditionVerify } from "@/api/formula";
|
|
import type { DrawerProps, FormItemProps, FormProps } from "element-plus";
|
|
import type { DrawerProps, FormItemProps, FormProps } from "element-plus";
|
|
// const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");
|
|
// const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");
|
|
@@ -44,9 +48,47 @@ const getIndexInfoApi = async id => {
|
|
if (code === 200) {
|
|
if (code === 200) {
|
|
Object.assign(params, data);
|
|
Object.assign(params, data);
|
|
if (isValidJSON(data.formula)) {
|
|
if (isValidJSON(data.formula)) {
|
|
- params.formula = JSON.parse(data.formula);
|
|
|
|
|
|
+ if (params.formulaType == 0) {
|
|
|
|
+ params.formula = JSON.parse(data.formula);
|
|
|
|
+ } else if (params.formulaType == 1) {
|
|
|
|
+ let aa = JSON.parse(data.formula);
|
|
|
|
+ let bb = JSON.parse(aa.noConditionFormula);
|
|
|
|
+ Object.assign(addmanyChange, bb);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!data.formula) {
|
|
|
|
+ params.formula = {
|
|
|
|
+ noConditionFormula: ""
|
|
|
|
+ };
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
|
|
+ if (!data.formulaType) {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ const { msg, code } = await postUpdate(params);
|
|
|
|
+ if (code === 200) {
|
|
|
|
+ ElMessage({
|
|
|
|
+ message: "编辑成功",
|
|
|
|
+ type: "success"
|
|
|
|
+ });
|
|
|
|
+ disabledValue.value = true;
|
|
|
|
+ editShow.value = true;
|
|
|
|
+ drawer.value = !drawer.value;
|
|
} else {
|
|
} else {
|
|
ElMessage.error(msg);
|
|
ElMessage.error(msg);
|
|
}
|
|
}
|
|
@@ -57,71 +99,105 @@ const formulaForm = ref([]);
|
|
const grade = ref();
|
|
const grade = ref();
|
|
const conditionVerifyApi = async () => {
|
|
const conditionVerifyApi = async () => {
|
|
dialogFormVisibleFormula.value = true;
|
|
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 = ["完成值", "目标值", "门槛值", "挑战值", "增幅", "降幅"];
|
|
const keywords = ["完成值", "目标值", "门槛值", "挑战值", "增幅", "降幅"];
|
|
let str = params.formula.noConditionFormula;
|
|
let str = params.formula.noConditionFormula;
|
|
// 创建一个正则表达式,匹配这些关键词
|
|
// 创建一个正则表达式,匹配这些关键词
|
|
const regex = new RegExp(keywords.join("|"), "g");
|
|
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 => {
|
|
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
|
|
// 判断是否为json
|
|
function isValidJSON(str) {
|
|
function isValidJSON(str) {
|
|
@@ -147,18 +223,44 @@ function cancelClick() {
|
|
editShow.value = true;
|
|
editShow.value = true;
|
|
}
|
|
}
|
|
function confirmClick() {
|
|
function confirmClick() {
|
|
- console.log(1111);
|
|
|
|
- disabledValue.value = true;
|
|
|
|
- editShow.value = true;
|
|
|
|
- drawer.value = !drawer.value;
|
|
|
|
- ElMessage({
|
|
|
|
- message: "保存成功",
|
|
|
|
- type: "success"
|
|
|
|
- });
|
|
|
|
|
|
+ postUpdateApi();
|
|
}
|
|
}
|
|
const open = row => {
|
|
const open = row => {
|
|
drawer.value = true;
|
|
drawer.value = true;
|
|
- // console.log("row", row.id);
|
|
|
|
|
|
+ Object.assign(params, {
|
|
|
|
+ id: "",
|
|
|
|
+ tpId: "",
|
|
|
|
+ dimId: "",
|
|
|
|
+ indId: "",
|
|
|
|
+ valueInput: "",
|
|
|
|
+ scoreStandard: 0,
|
|
|
|
+ remark: "",
|
|
|
|
+ scoreRule: "",
|
|
|
|
+ targetValue: "",
|
|
|
|
+ finalValue: "",
|
|
|
|
+ formulaType: 0,
|
|
|
|
+ challengeValue: "",
|
|
|
|
+ startValue: "",
|
|
|
|
+ datasoure: "",
|
|
|
|
+ weight: "",
|
|
|
|
+ scoreValue: "",
|
|
|
|
+ formula: {
|
|
|
|
+ noConditionFormula: ""
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ Object.assign(addmanyChange, {
|
|
|
|
+ outerConditionValue: "",
|
|
|
|
+ innerConditionExpression: [
|
|
|
|
+ {
|
|
|
|
+ startValue: null,
|
|
|
|
+ endValue: null,
|
|
|
|
+ select: null,
|
|
|
|
+ comparisonStart: null,
|
|
|
|
+ comparisonEnd: null,
|
|
|
|
+ scoreRuleMoreInnerVO: []
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
getIndexInfoApi(row.id);
|
|
getIndexInfoApi(row.id);
|
|
};
|
|
};
|
|
const editShow = ref(true);
|
|
const editShow = ref(true);
|
|
@@ -193,6 +295,14 @@ const rolesList = reactive({
|
|
value: "",
|
|
value: "",
|
|
num: null
|
|
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 => {
|
|
const lookRoles = item => {
|
|
bgColor.value = item.id;
|
|
bgColor.value = item.id;
|
|
params.formula.noConditionFormula =
|
|
params.formula.noConditionFormula =
|
|
@@ -229,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({
|
|
const addmanyChange = reactive({
|
|
outerConditionValue: "",
|
|
outerConditionValue: "",
|
|
innerConditionExpression: [
|
|
innerConditionExpression: [
|
|
@@ -298,19 +349,19 @@ const addmanyChange = reactive({
|
|
comparisonStart: null,
|
|
comparisonStart: null,
|
|
comparisonEnd: null,
|
|
comparisonEnd: null,
|
|
scoreRuleMoreInnerVO: [
|
|
scoreRuleMoreInnerVO: [
|
|
- {
|
|
|
|
- innerConditionValue: null,
|
|
|
|
- scoreRules: [
|
|
|
|
- {
|
|
|
|
- score: null,
|
|
|
|
- startValue: null,
|
|
|
|
- select: "",
|
|
|
|
- endValue: null,
|
|
|
|
- comparisonStart: null,
|
|
|
|
- comparisonEnd: null
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
|
|
+ // {
|
|
|
|
+ // innerConditionValue: null,
|
|
|
|
+ // scoreRules: [
|
|
|
|
+ // {
|
|
|
|
+ // score: null,
|
|
|
|
+ // startValue: null,
|
|
|
|
+ // select: "",
|
|
|
|
+ // endValue: null,
|
|
|
|
+ // comparisonStart: null,
|
|
|
|
+ // comparisonEnd: null
|
|
|
|
+ // }
|
|
|
|
+ // ]
|
|
|
|
+ // }
|
|
]
|
|
]
|
|
}
|
|
}
|
|
]
|
|
]
|
|
@@ -385,6 +436,22 @@ const addItemDataList = (
|
|
comparisonEnd: null
|
|
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>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
@@ -418,7 +485,11 @@ const addItemDataList = (
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<div v-if="params.scoreStandard === 1">
|
|
<div v-if="params.scoreStandard === 1">
|
|
<el-form-item label="公式类型" label-position="top">
|
|
<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
|
|
<el-option
|
|
v-for="item in compute"
|
|
v-for="item in compute"
|
|
:key="item.value"
|
|
:key="item.value"
|
|
@@ -623,7 +694,7 @@ const addItemDataList = (
|
|
<el-form-item v-else label="公式设置">
|
|
<el-form-item v-else label="公式设置">
|
|
<div class="w-full">
|
|
<div class="w-full">
|
|
<div class="flex items-center">
|
|
<div class="flex items-center">
|
|
- <el-text>条件填 = </el-text>
|
|
|
|
|
|
+ <el-text>条件值 = </el-text>
|
|
<el-input
|
|
<el-input
|
|
v-model="addmanyChange.outerConditionValue"
|
|
v-model="addmanyChange.outerConditionValue"
|
|
class="ml-2"
|
|
class="ml-2"
|
|
@@ -808,7 +879,7 @@ const addItemDataList = (
|
|
</el-text>
|
|
</el-text>
|
|
</div>
|
|
</div>
|
|
<div class="float-right mr-8">
|
|
<div class="float-right mr-8">
|
|
- <el-button type="primary" @click="conditionVerifyApi"
|
|
|
|
|
|
+ <el-button type="primary" @click="manyConditions"
|
|
>公式验证</el-button
|
|
>公式验证</el-button
|
|
>
|
|
>
|
|
</div>
|
|
</div>
|