Bladeren bron

运行记录阈值

yanghao 2 dagen geleden
bovenliggende
commit
d4bacf3c2a
2 gewijzigde bestanden met toevoegingen van 116 en 1 verwijderingen
  1. 9 0
      api/recordFilling.js
  2. 107 1
      pages/recordFilling/detail.vue

+ 9 - 0
api/recordFilling.js

@@ -97,4 +97,13 @@ export function recordFillingDetailInsertDataList(data) {
 		method: 'POST',
 		data: data
 	})
+}
+
+
+// 获取部门名称
+export function getDeptName(deptId) {
+	return request({
+		url: `/rq/report/dept/${deptId}`,
+		method: 'GET'
+	});
 }

+ 107 - 1
pages/recordFilling/detail.vue

@@ -175,6 +175,7 @@
 </template>
 
 <script setup>
+import { getDeptId } from "@/utils/auth.js";
 import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
 import { onReady, onLoad } from "@dcloudio/uni-app";
 import dayjs from "dayjs";
@@ -186,6 +187,7 @@ import {
   recordFillingUpOperationOrder,
   recordFillingDetailGetPageAndAttrs,
   recordFillingDetailInsertDataList,
+  getDeptName,
 } from "@/api/recordFilling";
 import { getUserId, reloginByUserId } from "@/utils/auth.js";
 import { useDataDictStore } from "@/store/modules/dataDict";
@@ -200,6 +202,7 @@ const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
 const isFromMsg = ref(false);
 const params = ref({});
 const isView = ref(false); // 是否编辑 -- view == 1为编辑状态
+let deptName = ref("");
 
 // 累加状态对象,用于在生产日报加载前存储累加值
 const accumulatedValues = reactive({
@@ -210,7 +213,9 @@ const accumulatedValues = reactive({
 });
 
 onMounted(() => {
-  console.log("onMounted");
+  getDeptName(getDeptId()).then((res) => {
+    deptName.value = res.data;
+  });
 });
 
 onReady(() => {
@@ -631,6 +636,42 @@ const queryList = (pageNo, pageSize) => {
     });
 };
 
+/**
+ * 检查累计公里数和运转时长限制(仅针对deptName为'rd'的公司)
+ * @param item 需要检查的填报项
+ * @param totalValue 累计值
+ * @param maxIncrement 最大增量
+ * @param itemName 项目名称
+ */
+const rdThresholdExceededItems = ref([]);
+
+const checkRdThreshold = (item, totalValue, maxIncrement, itemName) => {
+  if (deptName.value !== "rd") {
+    return true; // 不是rd公司,跳过检查
+  }
+
+  if (!item.fillContent) {
+    return true; // 没有填写内容,跳过检查
+  }
+
+  const fillValue = parseFloat(item.fillContent);
+  const maxValue = totalValue + maxIncrement;
+
+  if (fillValue > maxValue) {
+    // 收集超限信息
+    rdThresholdExceededItems.value.push({
+      deviceCode: item.deviceCode,
+      // deviceName: item.deviceName,
+      itemName: itemName,
+      maxValue: maxValue,
+      currentValue: fillValue,
+    });
+    return false;
+  }
+
+  return true;
+};
+
 // 判断是否小于阈值 (<0)
 const checkLessThreshold = (item) => {
   if (item.fillContent < 0) {
@@ -674,6 +715,8 @@ const toFixed = (num) => {
 };
 
 const onSubmit = async () => {
+  // 清空之前的超限记录
+  rdThresholdExceededItems.value = [];
   // console.log("onSubmit", dataList.value);
   // 校验是否所有待填写项都已加载
   if (dataList.value.length < totalNum) {
@@ -738,7 +781,32 @@ const onSubmit = async () => {
             nonSumItem.fillContent = Math.floor(num);
           }
         }
+
+        //  **********************
+        // 新增:针对rd公司的特殊阈值检查
+        // 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
+        if (nonSumItem.name.includes("累计公里数填报")) {
+          const correspondingSumItem = item.sumList.find((sumItem) =>
+            sumItem.name.includes("累计公里数")
+          );
+          if (correspondingSumItem) {
+            const totalKm = parseFloat(correspondingSumItem.totalRunTime) || 0;
+            checkRdThreshold(nonSumItem, totalKm, 3000, nonSumItem.name);
+          }
+        }
+        // 检查包含"累计运转时长填报"的字段不能超过对应"累计运转时长"字段 + 100
+        else if (nonSumItem.name.includes("累计运转时长填报")) {
+          const correspondingSumItem = item.sumList.find((sumItem) =>
+            sumItem.name.includes("累计运转时长")
+          );
+          if (correspondingSumItem) {
+            const totalRunTime =
+              parseFloat(correspondingSumItem.totalRunTime) || 0;
+            checkRdThreshold(nonSumItem, totalRunTime, 100, nonSumItem.name);
+          }
+        }
       }
+
       // 如果threshold > 0,则判断fillContent是否大于threshold
       if (nonSumItem.threshold > 0) {
         if (nonSumItem.fillContent > nonSumItem.threshold) {
@@ -762,6 +830,43 @@ const onSubmit = async () => {
       }
     }
   }
+
+  // 检查是否有超限的项目,如果有则统一显示
+  if (rdThresholdExceededItems.value.length > 0) {
+    const exceededInfo = rdThresholdExceededItems.value
+      .map(
+        (item, index) =>
+          `${index + 1}. ${item.deviceCode} ${item.itemName}不能超过${
+            item.maxValue
+          },当前值为${item.currentValue}`
+      )
+      .join("\n");
+
+    uni.showModal({
+      title: "阈值超限提示",
+      content: `以下项目超过阈值限制:\n${exceededInfo}\n\n是否继续保存?`,
+      showCancel: true,
+      cancelText: "取消",
+      confirmText: "继续",
+      success: (res) => {
+        if (res.confirm) {
+          // 用户选择继续,执行保存操作
+          submitData();
+        } else if (res.cancel) {
+          // 用户选择取消,不执行保存
+          return;
+        }
+      },
+    });
+    return;
+  }
+
+  // 如果没有超限项目,直接执行保存
+  submitData();
+};
+
+// 将原来的保存逻辑提取到单独函数中
+const submitData = async () => {
   // 定义新的dataList副本 用于提交数据,避免修改原数据
   const subDataList = JSON.parse(JSON.stringify(dataList.value));
 
@@ -776,6 +881,7 @@ const onSubmit = async () => {
       }
     }
   }
+
   console.log("处理提交用的副本数据:subDataList", subDataList);
   // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
   const submitList = subDataList.map((item) => ({