|
|
@@ -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,9 +202,20 @@ const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
|
|
|
const isFromMsg = ref(false);
|
|
|
const params = ref({});
|
|
|
const isView = ref(false); // 是否编辑 -- view == 1为编辑状态
|
|
|
+let deptName = ref("");
|
|
|
+
|
|
|
+// 累加状态对象,用于在生产日报加载前存储累加值
|
|
|
+const accumulatedValues = reactive({
|
|
|
+ "当日注水量-方": 0,
|
|
|
+ 当日用电量kWh: 0,
|
|
|
+ 当日运转时间H: 0,
|
|
|
+ "当日注气量-方": 0,
|
|
|
+});
|
|
|
|
|
|
onMounted(() => {
|
|
|
- console.log("onMounted");
|
|
|
+ getDeptName(getDeptId()).then((res) => {
|
|
|
+ deptName.value = res.data;
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
onReady(() => {
|
|
|
@@ -292,16 +305,95 @@ function debounce(func, delay) {
|
|
|
|
|
|
//防抖
|
|
|
const debouncedCalculateTotalRunTime = debounce(calculateTotalRunTime, 100);
|
|
|
+const debouncedApplyAccumulatedToReport = debounce(
|
|
|
+ applyAccumulatedToReport,
|
|
|
+ 100
|
|
|
+);
|
|
|
+
|
|
|
+/**
|
|
|
+ * 更新累加值
|
|
|
+ * @param fieldName 字段名
|
|
|
+ * @param deviceType 设备类型
|
|
|
+ */
|
|
|
+const updateAccumulatedValue = (fieldName, deviceType) => {
|
|
|
+ let total = 0;
|
|
|
+ dataList.value.forEach((item) => {
|
|
|
+ if (item.deviceName.includes(deviceType) && item.nonSumList) {
|
|
|
+ item.nonSumList.forEach((nonSum) => {
|
|
|
+ if (
|
|
|
+ nonSum.type === "double" &&
|
|
|
+ nonSum.name === fieldName &&
|
|
|
+ nonSum.fillContent !== null &&
|
|
|
+ nonSum.fillContent !== ""
|
|
|
+ ) {
|
|
|
+ const value = parseFloat(nonSum.fillContent) || 0;
|
|
|
+ total += value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ accumulatedValues[fieldName] = total;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重新计算所有累加值
|
|
|
+ */
|
|
|
+const recalculateAllAccumulatedValues = () => {
|
|
|
+ const fields = [
|
|
|
+ { field: "当日运转时间H", device: "增压机" },
|
|
|
+ { field: "当日注气量-方", device: "提纯撬" },
|
|
|
+ { field: "当日注水量-方", device: "注水泵" },
|
|
|
+ { field: "当日用电量kWh", device: "箱式变电站" },
|
|
|
+ ];
|
|
|
+
|
|
|
+ fields.forEach(({ field, device }) => {
|
|
|
+ updateAccumulatedValue(field, device);
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 将累加值应用到生产日报
|
|
|
+ */
|
|
|
+function applyAccumulatedToReport() {
|
|
|
+ // 先重新计算所有累加值
|
|
|
+ recalculateAllAccumulatedValues();
|
|
|
+
|
|
|
+ const reportItem = dataList.value.find(
|
|
|
+ (item) => item.deviceName === "生产日报"
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!reportItem) {
|
|
|
+ console.warn("⚠️ 未找到生产日报,累加值已存储,等待加载");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.keys(accumulatedValues).forEach((fieldName) => {
|
|
|
+ const targetItem = reportItem.nonSumList.find(
|
|
|
+ (item) => item.name === fieldName
|
|
|
+ );
|
|
|
+ if (targetItem) {
|
|
|
+ console.log(
|
|
|
+ `📊 应用累加值 (${fieldName}):`,
|
|
|
+ accumulatedValues[fieldName]
|
|
|
+ );
|
|
|
+ targetItem.fillContent = toFixed(accumulatedValues[fieldName]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
|
|
|
|
|
|
+ let fieldName = "";
|
|
|
+ let deviceType = "";
|
|
|
+
|
|
|
// 当日运转时间累加
|
|
|
if (
|
|
|
deviceItem.deviceName.includes("增压机") &&
|
|
|
nosum.name === "当日运转时间H"
|
|
|
) {
|
|
|
- debouncedCalculateTotalRunTime("增压机", "当日运转时间H", "当日运转时间H");
|
|
|
+ fieldName = "当日运转时间H";
|
|
|
+ deviceType = "增压机";
|
|
|
}
|
|
|
|
|
|
// 当日注气量累加
|
|
|
@@ -309,7 +401,8 @@ const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
deviceItem.deviceName.includes("提纯撬") &&
|
|
|
nosum.name === "当日注气量-方"
|
|
|
) {
|
|
|
- debouncedCalculateTotalRunTime("提纯撬", "当日注气量-方", "当日注气量-方");
|
|
|
+ fieldName = "当日注气量-方";
|
|
|
+ deviceType = "提纯撬";
|
|
|
}
|
|
|
|
|
|
// 当日注水量累加
|
|
|
@@ -317,7 +410,8 @@ const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
deviceItem.deviceName.includes("注水泵") &&
|
|
|
nosum.name === "当日注水量-方"
|
|
|
) {
|
|
|
- debouncedCalculateTotalRunTime("注水泵", "当日注水量-方", "当日注水量-方");
|
|
|
+ fieldName = "当日注水量-方";
|
|
|
+ deviceType = "注水泵";
|
|
|
}
|
|
|
|
|
|
// 当日用电量累加
|
|
|
@@ -325,11 +419,15 @@ const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
deviceItem.deviceName.includes("箱式变电站") &&
|
|
|
nosum.name === "当日用电量kWh"
|
|
|
) {
|
|
|
- debouncedCalculateTotalRunTime(
|
|
|
- "箱式变电站",
|
|
|
- "当日用电量kWh",
|
|
|
- "当日用电量kWh"
|
|
|
- );
|
|
|
+ fieldName = "当日用电量kWh";
|
|
|
+ deviceType = "箱式变电站";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldName) {
|
|
|
+ // 更新累加值
|
|
|
+ updateAccumulatedValue(fieldName, deviceType);
|
|
|
+ // 应用到生产日报(如果已加载)
|
|
|
+ debouncedApplyAccumulatedToReport();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -523,6 +621,12 @@ const queryList = (pageNo, pageSize) => {
|
|
|
resList,
|
|
|
pageNo * pageSize >= totalNum.value
|
|
|
);
|
|
|
+
|
|
|
+ // 如果加载的数据中包含生产日报,应用累加值
|
|
|
+ const hasReport = resList.some((item) => item.deviceName === "生产日报");
|
|
|
+ if (hasReport) {
|
|
|
+ applyAccumulatedToReport();
|
|
|
+ }
|
|
|
})
|
|
|
.catch((res) => {
|
|
|
// 如果请求失败写paging.value.complete(false);
|
|
|
@@ -532,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) {
|
|
|
@@ -575,6 +715,8 @@ const toFixed = (num) => {
|
|
|
};
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
+ // 清空之前的超限记录
|
|
|
+ rdThresholdExceededItems.value = [];
|
|
|
// console.log("onSubmit", dataList.value);
|
|
|
// 校验是否所有待填写项都已加载
|
|
|
if (dataList.value.length < totalNum) {
|
|
|
@@ -639,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) {
|
|
|
@@ -663,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));
|
|
|
|
|
|
@@ -677,6 +881,7 @@ const onSubmit = async () => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
console.log("处理提交用的副本数据:subDataList", subDataList);
|
|
|
// 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
|
|
|
const submitList = subDataList.map((item) => ({
|