|
|
@@ -175,14 +175,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import {
|
|
|
- ref,
|
|
|
- reactive,
|
|
|
- getCurrentInstance,
|
|
|
- watch,
|
|
|
- onMounted,
|
|
|
- nextTick,
|
|
|
-} from "vue";
|
|
|
+import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
|
|
|
import { onReady, onLoad } from "@dcloudio/uni-app";
|
|
|
import dayjs from "dayjs";
|
|
|
import {
|
|
|
@@ -200,12 +193,6 @@ import { useDataDictStore } from "@/store/modules/dataDict";
|
|
|
const { appContext } = getCurrentInstance();
|
|
|
const t = appContext.config.globalProperties.$t;
|
|
|
|
|
|
-// 导入 store
|
|
|
-import { useFillingDataStore } from "@/store/modules/fillingData";
|
|
|
-
|
|
|
-// 获取 store 实例
|
|
|
-const fillingDataStore = useFillingDataStore();
|
|
|
-
|
|
|
// 获取字典项
|
|
|
const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
|
|
|
|
|
|
@@ -214,6 +201,14 @@ const isFromMsg = ref(false);
|
|
|
const params = ref({});
|
|
|
const isView = ref(false); // 是否编辑 -- view == 1为编辑状态
|
|
|
|
|
|
+// 累加状态对象,用于在生产日报加载前存储累加值
|
|
|
+const accumulatedValues = reactive({
|
|
|
+ "当日注水量-方": 0,
|
|
|
+ 当日用电量kWh: 0,
|
|
|
+ 当日运转时间H: 0,
|
|
|
+ "当日注气量-方": 0,
|
|
|
+});
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
console.log("onMounted");
|
|
|
});
|
|
|
@@ -251,18 +246,6 @@ onLoad(async (option) => {
|
|
|
// 处理是否可编辑 {0: '待填写', 1: '已完成', 2: '填写中', 3: '忽略'}
|
|
|
isView.value = params.value?.orderStatus % 2 == 0;
|
|
|
console.log("🚀 ~ isView.value:", isView.value);
|
|
|
-
|
|
|
- // 清理旧的 store 数据
|
|
|
- if (params.value.orderId) {
|
|
|
- fillingDataStore.clearData(params.value.orderId);
|
|
|
- }
|
|
|
-
|
|
|
- // 页面加载完成后,延迟一点时间确保数据加载完成后再更新生产日报
|
|
|
- setTimeout(() => {
|
|
|
- nextTick(() => {
|
|
|
- updateProductionReportDisplay();
|
|
|
- });
|
|
|
- }, 500);
|
|
|
});
|
|
|
const paging = ref(null);
|
|
|
// v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
|
|
|
@@ -279,50 +262,32 @@ watch(
|
|
|
{ deep: true }
|
|
|
);
|
|
|
|
|
|
-// 更新生产日报显示
|
|
|
-// 更新生产日报显示 - 更准确的方法
|
|
|
-const updateProductionReportDisplay = () => {
|
|
|
- // 获取最新的累计值
|
|
|
- const latestTotals = fillingDataStore.getAllTotals();
|
|
|
- console.log("更新生产日报显示,最新的累计值:", latestTotals);
|
|
|
-
|
|
|
- // 在当前页面数据中查找生产日报
|
|
|
- const reportItem = dataList.value.find(
|
|
|
- (item) => item.deviceName === "生产日报"
|
|
|
- );
|
|
|
-
|
|
|
- if (!reportItem || !reportItem.nonSumList) {
|
|
|
- console.warn("⚠️ 当前页面未找到生产日报或其 nonSumList");
|
|
|
- return;
|
|
|
+// 处理fillContent变化的方法
|
|
|
+const handleFillContentChange = (nosum, deviceItem) => {
|
|
|
+ console.log("🚀 ~ nosum, deviceItem:", nosum, deviceItem);
|
|
|
+ // 处理增压机
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("增压机") &&
|
|
|
+ nosum.name === "当日运转时间"
|
|
|
+ ) {
|
|
|
+ calculateTotalRunTime("增压机", "当日运转时间"); // 计算当日运转时间总和
|
|
|
+ }
|
|
|
+ // 处理提纯撬
|
|
|
+ if (deviceItem.deviceName.includes("提纯撬") && nosum.name === "当日注气量") {
|
|
|
+ calculateTotalRunTime("提纯撬", "当日注气量"); // 计算当日注气量总和
|
|
|
+ }
|
|
|
+ // 处理注水泵
|
|
|
+ if (deviceItem.deviceName.includes("注水泵") && nosum.name === "当日注水量") {
|
|
|
+ calculateTotalRunTime("注水泵", "当日注水量"); // 计算当日注水量总和
|
|
|
+ }
|
|
|
+ // 处理箱式变电站
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("箱式变电站") &&
|
|
|
+ nosum.name === "当日用电量"
|
|
|
+ ) {
|
|
|
+ calculateTotalRunTime("箱式变电站", "当日用电量"); // 计算当日用电量总和
|
|
|
}
|
|
|
-
|
|
|
- // 更新生产日报中的累计字段
|
|
|
- reportItem.nonSumList.forEach((item) => {
|
|
|
- // 根据字段名称匹配对应的累计值
|
|
|
- if (latestTotals.hasOwnProperty(item.name)) {
|
|
|
- const newValue = toFixed(latestTotals[item.name]);
|
|
|
- console.log(`更新生产日报字段 ${item.name}: ${newValue}`);
|
|
|
-
|
|
|
- // 只有当值真正变化时才更新,避免不必要的响应式更新
|
|
|
- if (item.fillContent !== newValue) {
|
|
|
- item.fillContent = newValue;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
};
|
|
|
-// 监听 store 中的 totals 变化并更新生产日报
|
|
|
-// 监听 store 中的 totals 变化并更新生产日报显示
|
|
|
-watch(
|
|
|
- () => fillingDataStore.totals,
|
|
|
- (newTotals) => {
|
|
|
- console.log("Store totals 更新:", newTotals);
|
|
|
- // 使用 nextTick 确保 DOM 更新后再更新显示
|
|
|
- nextTick(() => {
|
|
|
- updateProductionReportDisplay();
|
|
|
- });
|
|
|
- },
|
|
|
- { deep: true, immediate: true }
|
|
|
-);
|
|
|
|
|
|
// 防抖函数
|
|
|
function debounce(func, delay) {
|
|
|
@@ -335,27 +300,129 @@ 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]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
-// 修改 handleRealTimeUpdate 方法
|
|
|
const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
|
|
|
|
|
|
- // 检查是否需要累加到生产日报
|
|
|
- if (fillingDataStore.isAccumulatedField(deviceItem.deviceName, nosum.name)) {
|
|
|
- console.log(`需要累加的字段: ${deviceItem.deviceName} - ${nosum.name}`);
|
|
|
+ let fieldName = "";
|
|
|
+ let deviceType = "";
|
|
|
|
|
|
- // 更新到 store
|
|
|
- fillingDataStore.updateFillingItem(
|
|
|
- deviceItem.deviceId,
|
|
|
- deviceItem.deviceName,
|
|
|
- nosum.name,
|
|
|
- nosum.fillContent
|
|
|
- );
|
|
|
+ // 当日运转时间累加
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("增压机") &&
|
|
|
+ nosum.name === "当日运转时间H"
|
|
|
+ ) {
|
|
|
+ fieldName = "当日运转时间H";
|
|
|
+ deviceType = "增压机";
|
|
|
+ }
|
|
|
|
|
|
- // 立即更新生产日报显示
|
|
|
- nextTick(() => {
|
|
|
- updateProductionReportDisplay();
|
|
|
- });
|
|
|
+ // 当日注气量累加
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("提纯撬") &&
|
|
|
+ nosum.name === "当日注气量-方"
|
|
|
+ ) {
|
|
|
+ fieldName = "当日注气量-方";
|
|
|
+ deviceType = "提纯撬";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当日注水量累加
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("注水泵") &&
|
|
|
+ nosum.name === "当日注水量-方"
|
|
|
+ ) {
|
|
|
+ fieldName = "当日注水量-方";
|
|
|
+ deviceType = "注水泵";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当日用电量累加
|
|
|
+ if (
|
|
|
+ deviceItem.deviceName.includes("箱式变电站") &&
|
|
|
+ nosum.name === "当日用电量kWh"
|
|
|
+ ) {
|
|
|
+ fieldName = "当日用电量kWh";
|
|
|
+ deviceType = "箱式变电站";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldName) {
|
|
|
+ // 更新累加值
|
|
|
+ updateAccumulatedValue(fieldName, deviceType);
|
|
|
+ // 应用到生产日报(如果已加载)
|
|
|
+ debouncedApplyAccumulatedToReport();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -422,6 +489,7 @@ const queryList = (pageNo, pageSize) => {
|
|
|
pageNo,
|
|
|
pageSize,
|
|
|
orderId: params.value.orderId,
|
|
|
+ // deviceCategoryId: 1,
|
|
|
})
|
|
|
.then(async (res) => {
|
|
|
console.log("🚀 ~ res:", res);
|
|
|
@@ -429,7 +497,7 @@ const queryList = (pageNo, pageSize) => {
|
|
|
const resList = [].concat(data.list);
|
|
|
// 列表总数
|
|
|
totalNum.value = data.total;
|
|
|
-
|
|
|
+ // 遍历列表,处理attrsDetail
|
|
|
resList.map(async (item) => {
|
|
|
const attrParams = {
|
|
|
deviceCode: item.deviceCode,
|
|
|
@@ -441,8 +509,12 @@ const queryList = (pageNo, pageSize) => {
|
|
|
userId: params.value.userId,
|
|
|
orderId: params.value.orderId,
|
|
|
};
|
|
|
-
|
|
|
+ // console.log(
|
|
|
+ // "getRecordFillingDetailGetAttrs- attrParams",
|
|
|
+ // attrParams
|
|
|
+ // );
|
|
|
const resAttrs = item?.attrsDetail;
|
|
|
+ // console.log("resAttrs", resAttrs);
|
|
|
if (resAttrs) {
|
|
|
attrParams.createTime = attrParams.createTime
|
|
|
? dayjs(attrParams.createTime).format("YYYY-MM-DD")
|
|
|
@@ -450,12 +522,17 @@ const queryList = (pageNo, pageSize) => {
|
|
|
attrParams.id = attrParams.orderId;
|
|
|
delete attrParams.orderId;
|
|
|
delete attrParams.deviceName;
|
|
|
-
|
|
|
resAttrs.map((rtem) => {
|
|
|
+ // 将rtem中sumList和nonSumList两个数组中的
|
|
|
+ // fillContent字段判断是否为null, 如果为null,则赋值为0 不为null则保留两位小数
|
|
|
+ // 将attrParams合并到两个数组的每个对象中
|
|
|
+ // 然后将sumList和nonSumList分别赋值给item的sumList和nonSumList
|
|
|
+
|
|
|
if (rtem.sumList) {
|
|
|
rtem.sumList.map((sumItem) => {
|
|
|
if (sumItem.fillContent == null || sumItem.fillContent == "") {
|
|
|
- // 保留原逻辑
|
|
|
+ // console.log("🚀 ~ rtem.sumList.map ~ sumItem:", sumItem);
|
|
|
+ // sumItem.fillContent = 0;
|
|
|
} else {
|
|
|
// 如果是double类型,保留两位小数
|
|
|
if (sumItem.type == "double") {
|
|
|
@@ -464,19 +541,24 @@ const queryList = (pageNo, pageSize) => {
|
|
|
}
|
|
|
// 将sumItem的id赋值给modelId
|
|
|
sumItem.modelId = sumItem.id;
|
|
|
+
|
|
|
sumItem.pointName = sumItem.name;
|
|
|
// 合并attrParams到sumItem中
|
|
|
- Object.assign(sumItem, attrParams);
|
|
|
+ sumItem = Object.assign(sumItem, attrParams);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
if (rtem.nonSumList) {
|
|
|
+ //
|
|
|
rtem.nonSumList.map((nonSumItem) => {
|
|
|
if (
|
|
|
nonSumItem.fillContent == null ||
|
|
|
nonSumItem.fillContent == ""
|
|
|
) {
|
|
|
- // 保留原逻辑
|
|
|
+ // console.log(
|
|
|
+ // "🚀 ~ rtem.nonSumList.map ~ nonSumItem:",
|
|
|
+ // nonSumItem
|
|
|
+ // );
|
|
|
+ // nonSumItem.fillContent = 0;
|
|
|
} else {
|
|
|
// 如果是double类型,保留两位小数
|
|
|
if (nonSumItem.type == "double") {
|
|
|
@@ -487,10 +569,10 @@ const queryList = (pageNo, pageSize) => {
|
|
|
// 将nonSumItem的id赋值给modelId
|
|
|
nonSumItem.modelId = nonSumItem.id;
|
|
|
// 合并attrParams到nonSumItem中
|
|
|
- Object.assign(nonSumItem, attrParams);
|
|
|
-
|
|
|
+ nonSumItem = Object.assign(nonSumItem, attrParams);
|
|
|
// 如果是enum类型,且description不为null,则根据description获取对应字典项数组,赋值给enumList
|
|
|
if (nonSumItem.type == "enum" && nonSumItem.description) {
|
|
|
+ console.log("🚀 ~ onSumItem.description:");
|
|
|
const dictOptions =
|
|
|
nonSumItem.name === "非生产原因"
|
|
|
? getIntDictOptions(nonSumItem.description)
|
|
|
@@ -505,6 +587,7 @@ const queryList = (pageNo, pageSize) => {
|
|
|
|
|
|
// 确保 fillContent 的类型与 enumList 中的 value 类型匹配
|
|
|
if (nonSumItem.name === "非生产原因") {
|
|
|
+ // 如果是"非生产原因",将 fillContent 转换为数字类型以匹配 getIntDictOptions
|
|
|
if (
|
|
|
nonSumItem.fillContent !== null &&
|
|
|
nonSumItem.fillContent !== ""
|
|
|
@@ -512,64 +595,38 @@ const queryList = (pageNo, pageSize) => {
|
|
|
nonSumItem.fillContent = parseInt(nonSumItem.fillContent);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ console.log("🚀 ~ nonSumItem.enumList:", nonSumItem.enumList);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
item.sumList = rtem.sumList;
|
|
|
- item.nonSumList = rtem.nonSumList;
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- // 将设备数据存储到 store(只存储需要累加的字段)
|
|
|
- if (item.deviceName !== "生产日报") {
|
|
|
- const storeData = {
|
|
|
- deviceId: item.deviceId,
|
|
|
- deviceName: item.deviceName,
|
|
|
- deviceCode: item.deviceCode,
|
|
|
- nonSumList: [],
|
|
|
- };
|
|
|
-
|
|
|
- // 处理 nonSumList
|
|
|
- if (item.nonSumList && Array.isArray(item.nonSumList)) {
|
|
|
- storeData.nonSumList = item.nonSumList.filter((nosum) =>
|
|
|
- fillingDataStore.isAccumulatedField(item.deviceName, nosum.name)
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- // 如果有需要累加的字段,才存储到 store
|
|
|
- if (storeData.nonSumList.length > 0) {
|
|
|
- fillingDataStore.updateDeviceFilling(item.deviceId, storeData);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 如果是生产日报,也存储到 store 并使用 store 中的累计值更新
|
|
|
- const updatedReportData =
|
|
|
- fillingDataStore.updateProductionReportFields(item);
|
|
|
- fillingDataStore.updateDeviceFilling(item.deviceId, {
|
|
|
- ...updatedReportData,
|
|
|
- isProductionReport: true,
|
|
|
+ item.nonSumList = rtem.nonSumList;
|
|
|
});
|
|
|
+ console.log("resAttrs-modelId", resAttrs);
|
|
|
}
|
|
|
-
|
|
|
return item;
|
|
|
});
|
|
|
|
|
|
- // 重新计算所有累计值并更新生产日报显示
|
|
|
- const calculatedTotals = fillingDataStore.calculateTotals();
|
|
|
- console.log("计算后的累计值:", calculatedTotals);
|
|
|
-
|
|
|
- // 立即更新生产日报显示
|
|
|
- nextTick(() => {
|
|
|
- updateProductionReportDisplay();
|
|
|
- });
|
|
|
-
|
|
|
console.log("resList--", resList);
|
|
|
+ // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
|
|
|
+
|
|
|
paging.value.completeByNoMore(
|
|
|
resList,
|
|
|
pageNo * pageSize >= totalNum.value
|
|
|
);
|
|
|
+
|
|
|
+ // 如果加载的数据中包含生产日报,应用累加值
|
|
|
+ const hasReport = resList.some((item) => item.deviceName === "生产日报");
|
|
|
+ if (hasReport) {
|
|
|
+ applyAccumulatedToReport();
|
|
|
+ }
|
|
|
})
|
|
|
.catch((res) => {
|
|
|
+ // 如果请求失败写paging.value.complete(false);
|
|
|
+ // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
|
|
|
+ // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
|
|
|
paging.value.complete(false);
|
|
|
});
|
|
|
};
|
|
|
@@ -617,12 +674,6 @@ const toFixed = (num) => {
|
|
|
};
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
- // 确保 store 中的累计值是最新的
|
|
|
- const latestTotals = fillingDataStore.calculateTotals();
|
|
|
- console.log("重新计算后的 totals:", latestTotals);
|
|
|
-
|
|
|
- // 更新生产日报的数据
|
|
|
- updateProductionReportDisplay();
|
|
|
// console.log("onSubmit", dataList.value);
|
|
|
// 校验是否所有待填写项都已加载
|
|
|
if (dataList.value.length < totalNum) {
|