|
|
@@ -175,7 +175,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
|
|
|
+import {
|
|
|
+ ref,
|
|
|
+ reactive,
|
|
|
+ getCurrentInstance,
|
|
|
+ watch,
|
|
|
+ onMounted,
|
|
|
+ nextTick,
|
|
|
+} from "vue";
|
|
|
import { onReady, onLoad } from "@dcloudio/uni-app";
|
|
|
import dayjs from "dayjs";
|
|
|
import {
|
|
|
@@ -193,6 +200,12 @@ 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();
|
|
|
|
|
|
@@ -238,6 +251,18 @@ 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绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
|
|
|
@@ -254,32 +279,50 @@ watch(
|
|
|
{ deep: true }
|
|
|
);
|
|
|
|
|
|
-// 处理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("箱式变电站", "当日用电量"); // 计算当日用电量总和
|
|
|
+// 更新生产日报显示
|
|
|
+// 更新生产日报显示 - 更准确的方法
|
|
|
+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;
|
|
|
}
|
|
|
+
|
|
|
+ // 更新生产日报中的累计字段
|
|
|
+ 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) {
|
|
|
@@ -293,43 +336,26 @@ function debounce(func, delay) {
|
|
|
//防抖
|
|
|
const debouncedCalculateTotalRunTime = debounce(calculateTotalRunTime, 100);
|
|
|
|
|
|
+// 修改 handleRealTimeUpdate 方法
|
|
|
const handleRealTimeUpdate = (nosum, deviceItem) => {
|
|
|
console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
|
|
|
|
|
|
- // 当日运转时间累加
|
|
|
- if (
|
|
|
- deviceItem.deviceName.includes("增压机") &&
|
|
|
- nosum.name === "当日运转时间H"
|
|
|
- ) {
|
|
|
- debouncedCalculateTotalRunTime("增压机", "当日运转时间H", "当日运转时间H");
|
|
|
- }
|
|
|
-
|
|
|
- // 当日注气量累加
|
|
|
- if (
|
|
|
- deviceItem.deviceName.includes("提纯撬") &&
|
|
|
- nosum.name === "当日注气量-方"
|
|
|
- ) {
|
|
|
- debouncedCalculateTotalRunTime("提纯撬", "当日注气量-方", "当日注气量-方");
|
|
|
- }
|
|
|
+ // 检查是否需要累加到生产日报
|
|
|
+ if (fillingDataStore.isAccumulatedField(deviceItem.deviceName, nosum.name)) {
|
|
|
+ console.log(`需要累加的字段: ${deviceItem.deviceName} - ${nosum.name}`);
|
|
|
|
|
|
- // 当日注水量累加
|
|
|
- if (
|
|
|
- deviceItem.deviceName.includes("注水泵") &&
|
|
|
- nosum.name === "当日注水量-方"
|
|
|
- ) {
|
|
|
- debouncedCalculateTotalRunTime("注水泵", "当日注水量-方", "当日注水量-方");
|
|
|
- }
|
|
|
-
|
|
|
- // 当日用电量累加
|
|
|
- if (
|
|
|
- deviceItem.deviceName.includes("箱式变电站") &&
|
|
|
- nosum.name === "当日用电量kWh"
|
|
|
- ) {
|
|
|
- debouncedCalculateTotalRunTime(
|
|
|
- "箱式变电站",
|
|
|
- "当日用电量kWh",
|
|
|
- "当日用电量kWh"
|
|
|
+ // 更新到 store
|
|
|
+ fillingDataStore.updateFillingItem(
|
|
|
+ deviceItem.deviceId,
|
|
|
+ deviceItem.deviceName,
|
|
|
+ nosum.name,
|
|
|
+ nosum.fillContent
|
|
|
);
|
|
|
+
|
|
|
+ // 立即更新生产日报显示
|
|
|
+ nextTick(() => {
|
|
|
+ updateProductionReportDisplay();
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -396,7 +422,6 @@ const queryList = (pageNo, pageSize) => {
|
|
|
pageNo,
|
|
|
pageSize,
|
|
|
orderId: params.value.orderId,
|
|
|
- // deviceCategoryId: 1,
|
|
|
})
|
|
|
.then(async (res) => {
|
|
|
console.log("🚀 ~ res:", res);
|
|
|
@@ -404,7 +429,7 @@ const queryList = (pageNo, pageSize) => {
|
|
|
const resList = [].concat(data.list);
|
|
|
// 列表总数
|
|
|
totalNum.value = data.total;
|
|
|
- // 遍历列表,处理attrsDetail
|
|
|
+
|
|
|
resList.map(async (item) => {
|
|
|
const attrParams = {
|
|
|
deviceCode: item.deviceCode,
|
|
|
@@ -416,12 +441,8 @@ 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")
|
|
|
@@ -429,17 +450,12 @@ 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
|
|
|
|
|
|
+ resAttrs.map((rtem) => {
|
|
|
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") {
|
|
|
@@ -448,24 +464,19 @@ const queryList = (pageNo, pageSize) => {
|
|
|
}
|
|
|
// 将sumItem的id赋值给modelId
|
|
|
sumItem.modelId = sumItem.id;
|
|
|
-
|
|
|
sumItem.pointName = sumItem.name;
|
|
|
// 合并attrParams到sumItem中
|
|
|
- sumItem = Object.assign(sumItem, attrParams);
|
|
|
+ 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") {
|
|
|
@@ -476,10 +487,10 @@ const queryList = (pageNo, pageSize) => {
|
|
|
// 将nonSumItem的id赋值给modelId
|
|
|
nonSumItem.modelId = nonSumItem.id;
|
|
|
// 合并attrParams到nonSumItem中
|
|
|
- nonSumItem = Object.assign(nonSumItem, attrParams);
|
|
|
+ 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)
|
|
|
@@ -494,7 +505,6 @@ const queryList = (pageNo, pageSize) => {
|
|
|
|
|
|
// 确保 fillContent 的类型与 enumList 中的 value 类型匹配
|
|
|
if (nonSumItem.name === "非生产原因") {
|
|
|
- // 如果是"非生产原因",将 fillContent 转换为数字类型以匹配 getIntDictOptions
|
|
|
if (
|
|
|
nonSumItem.fillContent !== null &&
|
|
|
nonSumItem.fillContent !== ""
|
|
|
@@ -502,32 +512,64 @@ const queryList = (pageNo, pageSize) => {
|
|
|
nonSumItem.fillContent = parseInt(nonSumItem.fillContent);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- console.log("🚀 ~ nonSumItem.enumList:", nonSumItem.enumList);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- item.sumList = rtem.sumList;
|
|
|
|
|
|
+ item.sumList = rtem.sumList;
|
|
|
item.nonSumList = rtem.nonSumList;
|
|
|
});
|
|
|
- console.log("resAttrs-modelId", resAttrs);
|
|
|
}
|
|
|
+
|
|
|
+ // 将设备数据存储到 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,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return item;
|
|
|
});
|
|
|
|
|
|
- console.log("resList--", resList);
|
|
|
- // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
|
|
|
+ // 重新计算所有累计值并更新生产日报显示
|
|
|
+ const calculatedTotals = fillingDataStore.calculateTotals();
|
|
|
+ console.log("计算后的累计值:", calculatedTotals);
|
|
|
+
|
|
|
+ // 立即更新生产日报显示
|
|
|
+ nextTick(() => {
|
|
|
+ updateProductionReportDisplay();
|
|
|
+ });
|
|
|
|
|
|
+ console.log("resList--", resList);
|
|
|
paging.value.completeByNoMore(
|
|
|
resList,
|
|
|
pageNo * pageSize >= totalNum.value
|
|
|
);
|
|
|
})
|
|
|
.catch((res) => {
|
|
|
- // 如果请求失败写paging.value.complete(false);
|
|
|
- // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
|
|
|
- // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
|
|
|
paging.value.complete(false);
|
|
|
});
|
|
|
};
|
|
|
@@ -575,6 +617,12 @@ 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) {
|