|
|
@@ -165,17 +165,16 @@
|
|
|
style="border-radius: 0"
|
|
|
type="primary"
|
|
|
@click="onSubmit()"
|
|
|
- :disabled="dataList.length < totalNum"
|
|
|
+ :disabled="dataList.length < totalNum || isSubmitting"
|
|
|
v-if="isView"
|
|
|
>
|
|
|
- {{ $t("operation.save") }}
|
|
|
+ {{ isSubmitting ? "提交中" : $t("operation.save") }}
|
|
|
</button>
|
|
|
</template>
|
|
|
</z-paging>
|
|
|
</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";
|
|
|
@@ -212,12 +211,6 @@ const accumulatedValues = reactive({
|
|
|
"当日注气量-方": 0,
|
|
|
});
|
|
|
|
|
|
-onMounted(() => {
|
|
|
- getDeptName(getDeptId()).then((res) => {
|
|
|
- deptName.value = res.data;
|
|
|
- });
|
|
|
-});
|
|
|
-
|
|
|
onReady(() => {
|
|
|
console.log("onReady");
|
|
|
});
|
|
|
@@ -235,7 +228,13 @@ onLoad(async (option) => {
|
|
|
// 请求工单详情
|
|
|
if (params.value?.orderId) {
|
|
|
const detail = (await getRecordFillingDetail(params.value.orderId)).data;
|
|
|
- console.log("🚀getRecordFillingDetail ~ detail:", detail);
|
|
|
+
|
|
|
+ const data = await getDeptName(detail.deptId);
|
|
|
+ console.log("data>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", data);
|
|
|
+ deptName.value = data.data;
|
|
|
+
|
|
|
+ console.log("deptName.value>>>>>>>>>>>>>>>>>>>", deptName.value);
|
|
|
+
|
|
|
params.value = {
|
|
|
...params.value,
|
|
|
...detail,
|
|
|
@@ -714,24 +713,274 @@ const toFixed = (num) => {
|
|
|
return num;
|
|
|
};
|
|
|
|
|
|
+const isSubmitting = ref(false); // 添加提交状态
|
|
|
+// const onSubmit = async () => {
|
|
|
+// // 清空之前的超限记录
|
|
|
+// rdThresholdExceededItems.value = [];
|
|
|
+// // console.log("onSubmit", dataList.value);
|
|
|
+// // 校验是否所有待填写项都已加载
|
|
|
+// if (dataList.value.length < totalNum) {
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operationRecordFilling.PleaseLoadAllItems"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// return; // 校验失败直接返回
|
|
|
+// }
|
|
|
+// // 1. 校验所有必填项
|
|
|
+// // 遍历dataList.value中nonSumList每个item(非生产日报 isReport!=1)的fillContent字段,
|
|
|
+// // 如果为null或者为空,则提示用户填写,
|
|
|
+// // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
|
|
|
+// // 如果所有项全部填写,则调用填写记录接口
|
|
|
+
|
|
|
+// for (const item of dataList.value) {
|
|
|
+// const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
|
|
|
+
|
|
|
+// // 查找当日运转时间H项目
|
|
|
+// const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
|
|
|
+// const isRuntime24 =
|
|
|
+// runtimeItem &&
|
|
|
+// (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
|
|
|
+// for (const nonSumItem of nonSumList) {
|
|
|
+// // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
|
|
|
+// const isExemptField =
|
|
|
+// isRuntime24 &&
|
|
|
+// (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
|
|
|
+// if (
|
|
|
+// (!item.isReport || item.isReport != 1) &&
|
|
|
+// !isExemptField &&
|
|
|
+// (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
|
|
|
+// ) {
|
|
|
+// uni.showToast({
|
|
|
+// title:
|
|
|
+// t("operation.PleaseFillIn") +
|
|
|
+// item.deviceCode +
|
|
|
+// "(" +
|
|
|
+// item.deviceName +
|
|
|
+// ")" +
|
|
|
+// t("operation.allItem"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// return; // 校验失败直接返回
|
|
|
+// }
|
|
|
+// if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
|
|
|
+// console.log("🚀 ~ nonSumItem:", nonSumItem);
|
|
|
+// console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
|
|
|
+// // 先将值转换为字符串进行操作
|
|
|
+// const fillContentStr = String(nonSumItem.fillContent);
|
|
|
+// // 将字符串转换为数字
|
|
|
+// const num = Number(fillContentStr);
|
|
|
+
|
|
|
+// // 检查转换后的数字是否有效
|
|
|
+// if (!isNaN(num)) {
|
|
|
+// // 检查是否包含小数(使用字符串检查)
|
|
|
+// if (fillContentStr.includes(".")) {
|
|
|
+// // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
|
|
|
+// nonSumItem.fillContent = toFixed(num);
|
|
|
+// } else {
|
|
|
+// // 转换为整数
|
|
|
+// 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) {
|
|
|
+// uni.showToast({
|
|
|
+// title:
|
|
|
+// item.deviceCode +
|
|
|
+// "(" +
|
|
|
+// item.deviceName +
|
|
|
+// ")" +
|
|
|
+// nonSumItem.name +
|
|
|
+// t(
|
|
|
+// "operationRecordFilling.fillContentCannotGreaterThanThreshold"
|
|
|
+// ) +
|
|
|
+// nonSumItem.threshold,
|
|
|
+// icon: "none",
|
|
|
+// duration: 3000,
|
|
|
+// });
|
|
|
+// nonSumItem.fillContent = ""; // 清空输入
|
|
|
+// return; // 校验失败直接返回
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// // 检查是否有超限的项目,如果有则统一显示
|
|
|
+// 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();
|
|
|
+// };
|
|
|
+
|
|
|
+// 修改 onSubmit 方法
|
|
|
+
|
|
|
+// const onSubmit = async () => {
|
|
|
+// // 校验是否所有待填写项都已加载
|
|
|
+// if (dataList.value.length < totalNum) {
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operationRecordFilling.PleaseLoadAllItems"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// return; // 校验失败直接返回,不设置按钮禁用
|
|
|
+// }
|
|
|
+
|
|
|
+// // 1. 校验所有必填项 - 在这里进行所有基础校验
|
|
|
+// for (const item of dataList.value) {
|
|
|
+// const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
|
|
|
+
|
|
|
+// // 查找当日运转时间H项目
|
|
|
+// const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
|
|
|
+// const isRuntime24 =
|
|
|
+// runtimeItem &&
|
|
|
+// (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
|
|
|
+// for (const nonSumItem of nonSumList) {
|
|
|
+// // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
|
|
|
+// const isExemptField =
|
|
|
+// isRuntime24 &&
|
|
|
+// (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
|
|
|
+// if (
|
|
|
+// (!item.isReport || item.isReport != 1) &&
|
|
|
+// !isExemptField &&
|
|
|
+// (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
|
|
|
+// ) {
|
|
|
+// uni.showToast({
|
|
|
+// title:
|
|
|
+// t("operation.PleaseFillIn") +
|
|
|
+// item.deviceCode +
|
|
|
+// "(" +
|
|
|
+// item.deviceName +
|
|
|
+// ")" +
|
|
|
+// t("operation.allItem"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// return; // 校验失败直接返回,不设置按钮禁用
|
|
|
+// }
|
|
|
+
|
|
|
+// // 如果threshold > 0,则判断fillContent是否大于threshold
|
|
|
+// if (nonSumItem.threshold > 0) {
|
|
|
+// if (nonSumItem.fillContent > nonSumItem.threshold) {
|
|
|
+// uni.showToast({
|
|
|
+// title:
|
|
|
+// item.deviceCode +
|
|
|
+// "(" +
|
|
|
+// item.deviceName +
|
|
|
+// ")" +
|
|
|
+// nonSumItem.name +
|
|
|
+// t(
|
|
|
+// "operationRecordFilling.fillContentCannotGreaterThanThreshold"
|
|
|
+// ) +
|
|
|
+// nonSumItem.threshold,
|
|
|
+// icon: "none",
|
|
|
+// duration: 3000,
|
|
|
+// });
|
|
|
+// nonSumItem.fillContent = ""; // 清空输入
|
|
|
+// return; // 校验失败直接返回,不设置按钮禁用
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// // 检查是否有超限的项目,如果有则统一显示
|
|
|
+// 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) {
|
|
|
+// // 用户选择继续,执行保存操作,此时才设置按钮禁用
|
|
|
+// submitDataWithDisable();
|
|
|
+// } else if (res.cancel) {
|
|
|
+// // 用户选择取消,不执行保存
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// },
|
|
|
+// });
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+// // 所有基础校验通过后,才设置提交状态并执行提交
|
|
|
+// submitDataWithDisable();
|
|
|
+// };
|
|
|
+
|
|
|
const onSubmit = async () => {
|
|
|
// 清空之前的超限记录
|
|
|
rdThresholdExceededItems.value = [];
|
|
|
- // console.log("onSubmit", dataList.value);
|
|
|
+
|
|
|
// 校验是否所有待填写项都已加载
|
|
|
if (dataList.value.length < totalNum) {
|
|
|
uni.showToast({
|
|
|
title: t("operationRecordFilling.PleaseLoadAllItems"),
|
|
|
icon: "none",
|
|
|
});
|
|
|
- return; // 校验失败直接返回
|
|
|
+ return; // 校验失败直接返回,不设置按钮禁用
|
|
|
}
|
|
|
- // 1. 校验所有必填项
|
|
|
- // 遍历dataList.value中nonSumList每个item(非生产日报 isReport!=1)的fillContent字段,
|
|
|
- // 如果为null或者为空,则提示用户填写,
|
|
|
- // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
|
|
|
- // 如果所有项全部填写,则调用填写记录接口
|
|
|
|
|
|
+ // 1. 校验所有必填项 - 在这里进行所有基础校验
|
|
|
for (const item of dataList.value) {
|
|
|
const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
|
|
|
|
|
|
@@ -760,29 +1009,42 @@ const onSubmit = async () => {
|
|
|
t("operation.allItem"),
|
|
|
icon: "none",
|
|
|
});
|
|
|
- return; // 校验失败直接返回
|
|
|
+ return; // 校验失败直接返回,不设置按钮禁用
|
|
|
}
|
|
|
- if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
|
|
|
- console.log("🚀 ~ nonSumItem:", nonSumItem);
|
|
|
- console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
|
|
|
- // 先将值转换为字符串进行操作
|
|
|
- const fillContentStr = String(nonSumItem.fillContent);
|
|
|
- // 将字符串转换为数字
|
|
|
- const num = Number(fillContentStr);
|
|
|
-
|
|
|
- // 检查转换后的数字是否有效
|
|
|
- if (!isNaN(num)) {
|
|
|
- // 检查是否包含小数(使用字符串检查)
|
|
|
- if (fillContentStr.includes(".")) {
|
|
|
- // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
|
|
|
- nonSumItem.fillContent = toFixed(num);
|
|
|
- } else {
|
|
|
- // 转换为整数
|
|
|
- nonSumItem.fillContent = Math.floor(num);
|
|
|
- }
|
|
|
+
|
|
|
+ // 如果threshold > 0,则判断fillContent是否大于threshold
|
|
|
+ if (nonSumItem.threshold > 0) {
|
|
|
+ if (nonSumItem.fillContent > nonSumItem.threshold) {
|
|
|
+ uni.showToast({
|
|
|
+ title:
|
|
|
+ item.deviceCode +
|
|
|
+ "(" +
|
|
|
+ item.deviceName +
|
|
|
+ ")" +
|
|
|
+ nonSumItem.name +
|
|
|
+ t(
|
|
|
+ "operationRecordFilling.fillContentCannotGreaterThanThreshold"
|
|
|
+ ) +
|
|
|
+ nonSumItem.threshold,
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000,
|
|
|
+ });
|
|
|
+ nonSumItem.fillContent = ""; // 清空输入
|
|
|
+ return; // 校验失败直接返回,不设置按钮禁用
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // **********************
|
|
|
+ // 检查是否有超限的项目,如果有则统一显示
|
|
|
+ // 需要在基础校验通过后,执行rd特殊阈值检查
|
|
|
+ // 重新检查rd特殊阈值
|
|
|
+ for (const item of dataList.value) {
|
|
|
+ const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
|
|
|
+
|
|
|
+ for (const nonSumItem of nonSumList) {
|
|
|
+ if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
|
|
|
+ // **********************
|
|
|
// 新增:针对rd公司的特殊阈值检查
|
|
|
// 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
|
|
|
if (nonSumItem.name.includes("累计公里数填报")) {
|
|
|
@@ -806,28 +1068,6 @@ const onSubmit = async () => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 如果threshold > 0,则判断fillContent是否大于threshold
|
|
|
- if (nonSumItem.threshold > 0) {
|
|
|
- if (nonSumItem.fillContent > nonSumItem.threshold) {
|
|
|
- uni.showToast({
|
|
|
- title:
|
|
|
- item.deviceCode +
|
|
|
- "(" +
|
|
|
- item.deviceName +
|
|
|
- ")" +
|
|
|
- nonSumItem.name +
|
|
|
- t(
|
|
|
- "operationRecordFilling.fillContentCannotGreaterThanThreshold"
|
|
|
- ) +
|
|
|
- nonSumItem.threshold,
|
|
|
- icon: "none",
|
|
|
- duration: 3000,
|
|
|
- });
|
|
|
- nonSumItem.fillContent = ""; // 清空输入
|
|
|
- return; // 校验失败直接返回
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -850,8 +1090,8 @@ const onSubmit = async () => {
|
|
|
confirmText: "继续",
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- // 用户选择继续,执行保存操作
|
|
|
- submitData();
|
|
|
+ // 用户选择继续,执行保存操作,此时才设置按钮禁用
|
|
|
+ submitDataWithDisable();
|
|
|
} else if (res.cancel) {
|
|
|
// 用户选择取消,不执行保存
|
|
|
return;
|
|
|
@@ -861,76 +1101,221 @@ const onSubmit = async () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 如果没有超限项目,直接执行保存
|
|
|
- submitData();
|
|
|
+ // 所有基础校验通过后,才设置提交状态并执行提交
|
|
|
+ submitDataWithDisable();
|
|
|
};
|
|
|
|
|
|
-// 将原来的保存逻辑提取到单独函数中
|
|
|
-const submitData = async () => {
|
|
|
- // 定义新的dataList副本 用于提交数据,避免修改原数据
|
|
|
- const subDataList = JSON.parse(JSON.stringify(dataList.value));
|
|
|
-
|
|
|
- // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
|
|
|
- for (const item of subDataList) {
|
|
|
- // 先判断 item.nonSumList 存在,避免空指针
|
|
|
- if (item.nonSumList && item.nonSumList.length) {
|
|
|
- for (const nonSumItem of item.nonSumList) {
|
|
|
- if (nonSumItem.enumList) {
|
|
|
- delete nonSumItem.enumList;
|
|
|
+// 新增一个带禁用状态的提交方法
|
|
|
+const submitDataWithDisable = async () => {
|
|
|
+ // 如果正在提交,直接返回
|
|
|
+ if (isSubmitting.value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置提交状态为 true,禁用按钮
|
|
|
+ isSubmitting.value = true;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 处理数据内容的校验和格式化
|
|
|
+ for (const item of dataList.value) {
|
|
|
+ const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
|
|
|
+
|
|
|
+ for (const nonSumItem of nonSumList) {
|
|
|
+ if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
|
|
|
+ console.log("🚀 ~ nonSumItem:", nonSumItem);
|
|
|
+ console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
|
|
|
+ // 先将值转换为字符串进行操作
|
|
|
+ const fillContentStr = String(nonSumItem.fillContent);
|
|
|
+ // 将字符串转换为数字
|
|
|
+ const num = Number(fillContentStr);
|
|
|
+
|
|
|
+ // 检查转换后的数字是否有效
|
|
|
+ if (!isNaN(num)) {
|
|
|
+ // 检查是否包含小数(使用字符串检查)
|
|
|
+ if (fillContentStr.includes(".")) {
|
|
|
+ // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
|
|
|
+ nonSumItem.fillContent = toFixed(num);
|
|
|
+ } else {
|
|
|
+ // 转换为整数
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- console.log("处理提交用的副本数据:subDataList", subDataList);
|
|
|
- // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
|
|
|
- const submitList = subDataList.map((item) => ({
|
|
|
- deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
|
|
|
- }));
|
|
|
- console.log("提交用的数据:submitList", submitList);
|
|
|
- // 3. 提交所有填写记录
|
|
|
-
|
|
|
- await recordFillingDetailInsertDataList(submitList)
|
|
|
- .then(async (res) => {
|
|
|
- console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
|
|
|
- if (res?.code === 0) {
|
|
|
- // 3. 调用更新工单状态接口
|
|
|
- const upRes = await recordFillingUpOperationOrder({
|
|
|
- id: params.value.orderId,
|
|
|
- });
|
|
|
- console.log("🚀 ~ upRes:", upRes);
|
|
|
- if (upRes?.code === 0) {
|
|
|
- console.log("工单状态更新成功");
|
|
|
- uni.showToast({
|
|
|
- title: t("operation.success"),
|
|
|
- duration: 1500,
|
|
|
- icon: "none",
|
|
|
- });
|
|
|
- setTimeout(() => {
|
|
|
- uni.navigateBack();
|
|
|
- }, 1500);
|
|
|
- } else {
|
|
|
- console.error("工单状态更新失败", upRes);
|
|
|
- uni.showToast({
|
|
|
- title: t("operation.fail"),
|
|
|
- icon: "none",
|
|
|
- });
|
|
|
+ // 执行实际的数据提交
|
|
|
+ await submitData();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存失败", error);
|
|
|
+ // 启用按钮
|
|
|
+ isSubmitting.value = false;
|
|
|
+ uni.showToast({
|
|
|
+ title: t("operation.fail"),
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|
|
|
+// 修改 submitData 方法,使其返回 Promise
|
|
|
+const submitData = async () => {
|
|
|
+ try {
|
|
|
+ // 定义新的dataList副本 用于提交数据,避免修改原数据
|
|
|
+ const subDataList = JSON.parse(JSON.stringify(dataList.value));
|
|
|
+
|
|
|
+ // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
|
|
|
+ for (const item of subDataList) {
|
|
|
+ // 先判断 item.nonSumList 存在,避免空指针
|
|
|
+ if (item.nonSumList && item.nonSumList.length) {
|
|
|
+ for (const nonSumItem of item.nonSumList) {
|
|
|
+ if (nonSumItem.enumList) {
|
|
|
+ delete nonSumItem.enumList;
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log("处理提交用的副本数据:subDataList", subDataList);
|
|
|
+ // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
|
|
|
+ const submitList = subDataList.map((item) => ({
|
|
|
+ deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
|
|
|
+ }));
|
|
|
+ console.log("提交用的数据:submitList", submitList);
|
|
|
+ // 3. 提交所有填写记录
|
|
|
+
|
|
|
+ const res = await recordFillingDetailInsertDataList(submitList);
|
|
|
+ console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
|
|
|
+
|
|
|
+ if (res?.code === 0) {
|
|
|
+ // 3. 调用更新工单状态接口
|
|
|
+ const upRes = await recordFillingUpOperationOrder({
|
|
|
+ id: params.value.orderId,
|
|
|
+ });
|
|
|
+ console.log("🚀 ~ upRes:", upRes);
|
|
|
+ if (upRes?.code === 0) {
|
|
|
+ console.log("工单状态更新成功");
|
|
|
uni.showToast({
|
|
|
- title: t("operation.fail"),
|
|
|
+ title: t("operation.success"),
|
|
|
+ duration: 1500,
|
|
|
icon: "none",
|
|
|
});
|
|
|
+
|
|
|
+ // 成功后延迟跳转,不启用按钮
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.navigateBack();
|
|
|
+ }, 1500);
|
|
|
+
|
|
|
+ // 注意:这里不设置 isSubmitting.value = false,因为成功后会跳转页面
|
|
|
+ return; // 成功完成,直接返回
|
|
|
+ } else {
|
|
|
+ console.error("工单状态更新失败", upRes);
|
|
|
+ throw new Error("工单状态更新失败"); // 抛出错误,让 catch 处理
|
|
|
}
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.error("保存失败", error);
|
|
|
- uni.showToast({
|
|
|
- title: t("operation.fail"),
|
|
|
- icon: "error",
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ throw new Error("提交失败"); // 抛出错误,让 catch 处理
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存失败", error);
|
|
|
+ // 启用按钮,让用户可以重试
|
|
|
+ isSubmitting.value = false;
|
|
|
+ uni.showToast({
|
|
|
+ title: t("operation.fail"),
|
|
|
+ icon: "none",
|
|
|
});
|
|
|
+ throw error; // 重新抛出错误
|
|
|
+ }
|
|
|
};
|
|
|
+
|
|
|
+// 将原来的保存逻辑提取到单独函数中
|
|
|
+// const submitData = async () => {
|
|
|
+// // 定义新的dataList副本 用于提交数据,避免修改原数据
|
|
|
+// const subDataList = JSON.parse(JSON.stringify(dataList.value));
|
|
|
+
|
|
|
+// // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
|
|
|
+// for (const item of subDataList) {
|
|
|
+// // 先判断 item.nonSumList 存在,避免空指针
|
|
|
+// if (item.nonSumList && item.nonSumList.length) {
|
|
|
+// for (const nonSumItem of item.nonSumList) {
|
|
|
+// if (nonSumItem.enumList) {
|
|
|
+// delete nonSumItem.enumList;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// console.log("处理提交用的副本数据:subDataList", subDataList);
|
|
|
+// // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
|
|
|
+// const submitList = subDataList.map((item) => ({
|
|
|
+// deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
|
|
|
+// }));
|
|
|
+// console.log("提交用的数据:submitList", submitList);
|
|
|
+// // 3. 提交所有填写记录
|
|
|
+
|
|
|
+// await recordFillingDetailInsertDataList(submitList)
|
|
|
+// .then(async (res) => {
|
|
|
+// console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
|
|
|
+// if (res?.code === 0) {
|
|
|
+// // 3. 调用更新工单状态接口
|
|
|
+// const upRes = await recordFillingUpOperationOrder({
|
|
|
+// id: params.value.orderId,
|
|
|
+// });
|
|
|
+// console.log("🚀 ~ upRes:", upRes);
|
|
|
+// if (upRes?.code === 0) {
|
|
|
+// console.log("工单状态更新成功");
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operation.success"),
|
|
|
+// duration: 1500,
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// setTimeout(() => {
|
|
|
+// uni.navigateBack();
|
|
|
+// }, 1500);
|
|
|
+// } else {
|
|
|
+// console.error("工单状态更新失败", upRes);
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operation.fail"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operation.fail"),
|
|
|
+// icon: "none",
|
|
|
+// });
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .catch((error) => {
|
|
|
+// console.error("保存失败", error);
|
|
|
+// uni.showToast({
|
|
|
+// title: t("operation.fail"),
|
|
|
+// icon: "error",
|
|
|
+// });
|
|
|
+// });
|
|
|
+// };
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|