Procházet zdrojové kódy

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

快乐的梦鱼 před 1 měsícem
rodič
revize
a32abf0474

+ 4 - 1
src/api/collect/AssessmentContent.ts

@@ -396,7 +396,10 @@ export class SelfAssessmentDetail extends DataModel<SelfAssessmentDetail> {
       },
       checkItems: {
         customToClientFn: (value) => {
-          return transformArrayDataModel(SelfAssessmentCheckItemAnswer, transformSomeToArray(value), 'data');
+          const arr = transformSomeToArray(value);
+          for (const item of arr) 
+            item.id = item.item_id;
+          return transformArrayDataModel(SelfAssessmentCheckItemAnswer, arr, 'data');
         },
         customToServerFn: (value) => {
           return (value as SelfAssessmentCheckItemAnswer[])

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

@@ -113,6 +113,11 @@
       </div>
     </div>
     <a-divider />
+    <a-row justify="space-between" align="bottom" class="mb-2">
+      <a-typography-title :level="4" class="mb-0">自评总分</a-typography-title>
+      <span class="total-points">{{ totalPoints }} 分</span>
+    </a-row>
+    <a-divider />
     <DynamicForm
       ref="tailFormRef"
       :model="currentForm"
@@ -332,6 +337,39 @@ const tailFormOptionsComputed = computed<IDynamicFormOptions>(() => ({
   },
 }));
 
+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.parent = n;
+        m.set(child.id, child);
+      }
+    }
+  }
+  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.isTitle || !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;
+});
+
 function getCheckModeText(checkMode: number) {
   switch (checkMode) {
     case 1:

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

@@ -7,11 +7,6 @@
       :current-form-check-items="currentFormCheckItems"
       :readonly="readonly"
     />
-    <a-divider />
-    <a-row justify="space-between" align="bottom" class="mb-2">
-      <a-typography-title :level="4" class="mb-0">自评总分</a-typography-title>
-      <span class="total-points">{{ totalPoints }} 分</span>
-    </a-row>
   </div>
 </template>
 
@@ -31,29 +26,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(),
 });