瀏覽代碼

💊 修改计分统计未设置上限问题

快乐的梦鱼 1 月之前
父節點
當前提交
5e3f0fd880

+ 41 - 0
src/pages/collect/assessment/components/EvaluationFormBlock.vue

@@ -75,6 +75,14 @@
     </FlexCol>
   </FlexCol>
 
+  <FlexCol>
+    <Divider />
+    <FlexRow justify="space-between" align="center">
+      <H3>自评总分</H3>
+      <Text fontConfig="subTitleText" color="text.primary" :text="`${totalPoints} 分`" />
+    </FlexRow>
+  </FlexCol>
+
   <DynamicForm
     ref="formRef2"
     :model="currentForm"
@@ -391,6 +399,39 @@ async function reloadAllAnnexList() {
   await Promise.all(itemIds.map(loadAnnexListByItem));
 }
 
+const checkItemMap = computed(() => {
+  const m = new Map<number, CheckItemInfo & { parent?: CheckItemInfo }>();
+  for (const n of props.checkItemList) {
+    m.set(n.id, n);
+    if (n.children?.length) {
+      for (const child of n.children) {
+        (child as any).parent = n;
+        m.set(child.id, child as CheckItemInfo & { parent?: CheckItemInfo });
+      }
+    }
+  }
+  return m;
+});
+
+const totalPoints = computed(() => {
+  const groupMap = new Map<number, number>();
+  for (const item of props.currentFormCheckItems) {
+    const checkItem = checkItemMap.value.get(item.id);
+    if (!checkItem || !checkItem.parent)
+      continue;
+    const parentId = checkItem.parent.id;
+    const score = (item.points ?? 0) * (item.count ?? 1);
+    groupMap.set(parentId, (groupMap.get(parentId) ?? 0) + score);
+  }
+  let total = 0;
+  for (const [parentId, groupScore] of groupMap) {
+    const parent = checkItemMap.value.get(parentId);
+    const maxPoints = parent?.points ?? Infinity;
+    total += Math.min(groupScore, maxPoints);
+  }
+  return total;
+});
+
 async function validate() {
   if (props.readonly)
     return;

+ 0 - 32
src/pages/collect/assessment/components/SelfAssessmentFormDisplay.vue

@@ -9,11 +9,6 @@
       :current-form-check-items="currentFormCheckItems"
       :readonly="readonly"
     />
-    <Divider />
-    <FlexRow align="flex-end" justify="space-between">
-      <H3>自评总分</H3>
-      <Text fontSize="50rpx" color="#315816" fontFamily="HUNdin1451" :text="`${totalPoints}分`" />
-    </FlexRow>
   </FlexCol>
 </template>
 
@@ -23,10 +18,6 @@ import type { CheckItemInfo, SelfAssessmentCheckItemAnswer, SelfAssessmentDetail
 import type { IDynamicFormOptions } from '@/components/dynamic';
 import EvaluationFormBlock from './EvaluationFormBlock.vue';
 import FlexCol from '@/components/layout/FlexCol.vue';
-import Divider from '@/components/display/Divider.vue';
-import FlexRow from '@/components/layout/FlexRow.vue';
-import H3 from '@/components/typography/H3.vue';
-import Text from '@/components/basic/Text.vue';
 
 const props = withDefaults(defineProps<{
   currentForm: SelfAssessmentDetail;
@@ -41,29 +32,6 @@ const props = withDefaults(defineProps<{
 
 const blockRef = ref<InstanceType<typeof EvaluationFormBlock> | null>(null);
 
-const checkItemMap = computed(() => {
-  const m = new Map<number, CheckItemInfo>();
-  function walk(nodes: CheckItemInfo[]) {
-    for (const n of nodes) {
-      m.set(n.id, n);
-      if (n.children?.length)
-        walk(n.children);
-    }
-  }
-  walk(props.checkItemList);
-  return m;
-});
-
-const totalPoints = computed(() => {
-  return props.currentFormCheckItems
-    .filter((item) => {
-      const checkItem = checkItemMap.value.get(item.id);
-      return checkItem && !checkItem.isTitle;
-    })
-    .reduce((acc, item) => acc + (item.count * item.points), 0)
-    - (props.currentForm.deductPoints ?? 0);
-});
-
 defineExpose({
   validate: () => blockRef.value?.validate(),
 });