| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450 |
- <template>
- <z-paging
- class="page"
- ref="paging"
- v-model="dataList"
- :loading-more-enabled="true"
- @query="queryList"
- >
- <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
- <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
- <template #top>
- <!-- 工单基础信息 -->
- <view class="item top">
- <view class="item-content flex-row align-center">
- <view class="item-title full-cell flex-row align-center">
- <span class="item-title-width"
- >{{ $t("operationRecordFilling.workOrderName") }}:</span
- >
- <span>{{ params.orderName }}</span>
- </view>
- </view>
- <view class="item-content flex-row align-center">
- <view class="item-title full-cell flex-row align-center">
- <span class="item-title-width"
- >{{ $t("operationRecordFilling.responsiblePerson") }}:</span
- >
- <span>{{ params.userName }}</span>
- </view>
- </view>
- <view class="item-content flex-row align-center">
- <view class="item-title full-cell flex-row align-center">
- <span class="item-title-width"
- >{{ $t("operation.createTime") }}:</span
- >
- <span>{{ params.createTime }}</span>
- </view>
- </view>
- </view>
- </template>
- <!-- 填报列表 -->
- <view class="list">
- <view class="item" v-for="(item, index) in dataList" :key="index">
- <view class="item-module flex-row align-center justify-between">
- <view class="module-name">
- {{ item.deviceCode }}({{ item.deviceName }})
- </view>
- <view class="module-border"> </view>
- </view>
- <view class="item-content flex-row align-center justify-between bold">
- <view class="item-title flex-row align-center">
- <span>{{ $t("operationRecordFilling.belongToTeam") }}:</span>
- <span>{{ item.orgName }}</span>
- </view>
- </view>
- <view
- class="item-content flex-row align-center justify-between bold"
- v-for="sum in item.sumList"
- >
- <view class="item-title flex-row align-center word-break-all">
- <span>{{ sum.name }}:</span>
- </view>
- <view class="item-value flex-row align-center justify-end total">
- <uni-easyinput
- style="text-align: right"
- :inputBorder="false"
- :clearable="true"
- :styles="{ disableColor: '#fff' }"
- :value="`${sum.totalRunTime} ${
- sum.modelAttr ? (sum.modelAttr.includes('Time') ? 'h' : '') : ''
- }`"
- :disabled="true"
- ></uni-easyinput>
- </view>
- </view>
- <view
- class="item-content flex-col align-center justify-between"
- :class="{ 'bottom-bold': item.nonSumList.length > 0 }"
- v-for="nosum in item.nonSumList"
- >
- <!-- isCollection为1,提示:以下数值取自PLC,如有不符请修改 -->
- <uni-notice-bar
- :text="$t('operationRecordFilling.plcNotice')"
- v-if="nosum.isCollection == 1"
- />
- <view class="flex-row align-center justify-between item-content">
- <view class="item-title flex-row align-center">
- <span>{{ nosum.name }}:</span>
- </view>
- <!-- 判断填写项的属性 -->
- <!-- type为double时,输入框为数字类型 -->
- <view
- class="item-value flex-row align-center justify-end"
- v-if="nosum.type == 'double'"
- >
- <uni-easyinput
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :inputBorder="false"
- :clearable="true"
- :placeholder="$t('operation.PleaseFillIn')"
- :disabled="!isView"
- v-model="nosum.fillContent"
- :type="'digit'"
- @blur="
- nosum.threshold > 0
- ? checkThreshold(nosum)
- : checkLessThreshold(nosum)
- "
- @input="handleRealTimeUpdate(nosum, item)"
- ></uni-easyinput>
- </view>
- <!-- type为textarea时,输入框为文本类型 -->
- <view
- class="item-value flex-row align-center justify-end"
- v-else-if="nosum.type == 'textarea'"
- >
- <uni-easyinput
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :inputBorder="false"
- :clearable="true"
- :placeholder="$t('operation.PleaseFillIn')"
- :disabled="!isView"
- v-model="nosum.fillContent"
- :type="'textarea'"
- :autoHeight="true"
- :maxlength="-1"
- ></uni-easyinput>
- </view>
- <!-- type为enum时,使用下拉菜单 -->
- <view
- class="item-value select flex-row align-center justify-end"
- v-else-if="nosum.type == 'enum' && nosum.description !== null"
- >
- <uni-data-select
- :localdata="nosum.enumList"
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :clear="false"
- :disabled="!isView"
- :placeholder="$t('operation.PleaseSelect')"
- v-model="nosum.fillContent"
- ></uni-data-select>
- </view>
- <!-- 其他类型时,输入框为文本类型 -->
- <view class="item-value flex-row align-center justify-end" v-else>
- <uni-easyinput
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :inputBorder="false"
- :clearable="true"
- :placeholder="$t('operation.PleaseFillIn')"
- :disabled="!isView"
- v-model="nosum.fillContent"
- :type="'text'"
- ></uni-easyinput>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 如果需要使用页脚,请使用slot="bottom"slot节点不支持通过v-if或v-show动态显示/隐藏,若需要动态控制,可将v-if添加在其子节点上 -->
- <template #bottom>
- <button
- style="border-radius: 0"
- type="primary"
- @click="onSubmit()"
- :disabled="dataList.length < totalNum || isSubmitting"
- v-if="isView"
- >
- {{ isSubmitting ? "提交中" : $t("operation.save") }}
- </button>
- </template>
- </z-paging>
- </template>
- <script setup>
- import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
- import { onReady, onLoad } from "@dcloudio/uni-app";
- import dayjs from "dayjs";
- import {
- getRecordFillingDetailGetPage,
- getRecordFillingDetailGetAttrs,
- recordFillingDetailInsertLog,
- getRecordFillingDetail,
- recordFillingUpOperationOrder,
- recordFillingDetailGetPageAndAttrs,
- recordFillingDetailInsertDataList,
- getDeptName,
- } from "@/api/recordFilling";
- import { getUserId, reloginByUserId } from "@/utils/auth.js";
- import { useDataDictStore } from "@/store/modules/dataDict";
- // 引用全局变量$t
- const { appContext } = getCurrentInstance();
- const t = appContext.config.globalProperties.$t;
- // 获取字典项
- 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,
- });
- onReady(() => {
- console.log("onReady");
- });
- onLoad(async (option) => {
- console.log("onLoad", option);
- await reloginByUserId(option.reloginUserId);
- isFromMsg.value = !!option.reloginUserId;
- // 初始化params
- params.value = JSON.parse(option.param);
- // 处理createTime
- params.value.createTime = params.value.createTime
- ? dayjs(Number.parseInt(params.value.createTime)).format("YYYY-MM-DD")
- : "";
- // 请求工单详情
- if (params.value?.orderId) {
- const detail = (await getRecordFillingDetail(params.value.orderId)).data;
- 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,
- // 处理createTime
- createTime: detail.createTime
- ? dayjs(Number.parseInt(detail.createTime)).format("YYYY-MM-DD")
- : "",
- orderId: detail.id,
- };
- }
- console.log("🚀 ~ params.value:", params.value);
- // 处理是否可编辑 {0: '待填写', 1: '已完成', 2: '填写中', 3: '忽略'}
- isView.value = params.value?.orderStatus % 2 == 0;
- console.log("🚀 ~ isView.value:", isView.value);
- });
- const paging = ref(null);
- // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
- const dataList = ref([]);
- // 列表总数
- const totalNum = ref(0);
- // 监听dataList变化,初始化时计算一次总和
- watch(
- dataList,
- (newVal) => {
- // calculateTotalRunTime();
- },
- { 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("箱式变电站", "当日用电量"); // 计算当日用电量总和
- }
- };
- // 防抖函数
- function debounce(func, delay) {
- let timer;
- return function (...args) {
- clearTimeout(timer);
- timer = setTimeout(() => func.apply(this, args), 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"
- ) {
- fieldName = "当日运转时间H";
- deviceType = "增压机";
- }
- // 当日注气量累加
- 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();
- }
- };
- /**
- * 计算所有deviceName中包含deviceNameToMatch的对象中对应的reportName的fillContent总和并更新到reportName的fillContent中
- * @param deviceNameToMatch {string} 设备名称包含的字符串
- * @param reportName {string} 填写项名称
- */
- function calculateTotalRunTime(
- deviceNameToMatch,
- sourceFieldName,
- targetFieldName
- ) {
- const reportItem = dataList.value.find(
- (item) => item.deviceName === "生产日报"
- );
- if (!reportItem) {
- console.warn("⚠️ 未找到生产日报");
- return;
- }
- const targetItem = reportItem.nonSumList.find(
- (item) => item.name === targetFieldName
- );
- if (!targetItem) {
- console.warn(`⚠️ 未找到目标字段:${targetFieldName}`);
- return;
- }
- let total = 0;
- dataList.value.forEach((item) => {
- if (item.deviceName.includes(deviceNameToMatch) && item.nonSumList) {
- item.nonSumList.forEach((nonSum) => {
- if (
- nonSum.type === "double" &&
- nonSum.name === sourceFieldName &&
- nonSum.fillContent !== null &&
- nonSum.fillContent !== ""
- ) {
- const value = parseFloat(nonSum.fillContent) || 0;
- total += value;
- }
- });
- }
- });
- console.log(`📊 累计值 (${sourceFieldName} -> ${targetFieldName}):`, total);
- targetItem.fillContent = toFixed(total);
- }
- // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
- const queryList = (pageNo, pageSize) => {
- const userId = uni.getStorageSync("userId");
- if (!userId) {
- paging.value.complete([]);
- return;
- }
- // 请求填报设备及属性
- recordFillingDetailGetPageAndAttrs({
- pageNo,
- pageSize,
- orderId: params.value.orderId,
- // deviceCategoryId: 1,
- })
- .then(async (res) => {
- console.log("🚀 ~ res:", res);
- const { data } = res;
- const resList = [].concat(data.list);
- // 列表总数
- totalNum.value = data.total;
- // 遍历列表,处理attrsDetail
- resList.map(async (item) => {
- const attrParams = {
- deviceCode: item.deviceCode,
- deviceName: item.deviceName,
- deptId: item.deptId,
- createTime: params.value.createTime,
- deviceCategoryId: item.deviceCategoryId,
- deviceId: item.deviceId,
- 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")
- : "";
- 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") {
- sumItem.fillContent = toFixed(sumItem.fillContent);
- }
- }
- // 将sumItem的id赋值给modelId
- sumItem.modelId = sumItem.id;
- sumItem.pointName = sumItem.name;
- // 合并attrParams到sumItem中
- 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") {
- nonSumItem.fillContent = toFixed(nonSumItem.fillContent);
- }
- }
- nonSumItem.pointName = nonSumItem.name;
- // 将nonSumItem的id赋值给modelId
- nonSumItem.modelId = nonSumItem.id;
- // 合并attrParams到nonSumItem中
- 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)
- : getStrDictOptions(nonSumItem.description);
- nonSumItem.enumList = dictOptions.map((dict) => {
- return {
- ...dict,
- text: dict.label,
- };
- });
- // 确保 fillContent 的类型与 enumList 中的 value 类型匹配
- if (nonSumItem.name === "非生产原因") {
- // 如果是"非生产原因",将 fillContent 转换为数字类型以匹配 getIntDictOptions
- if (
- nonSumItem.fillContent !== null &&
- nonSumItem.fillContent !== ""
- ) {
- nonSumItem.fillContent = parseInt(nonSumItem.fillContent);
- }
- }
- console.log("🚀 ~ nonSumItem.enumList:", nonSumItem.enumList);
- }
- });
- }
- item.sumList = rtem.sumList;
- item.nonSumList = rtem.nonSumList;
- });
- console.log("resAttrs-modelId", resAttrs);
- }
- return item;
- });
- 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);
- });
- };
- /**
- * 检查累计公里数和运转时长限制(仅针对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) {
- uni.showToast({
- title:
- item.name +
- t("operationRecordFilling.fillContentCannotLessThanThreshold") +
- "0",
- icon: "none",
- });
- item.fillContent = ""; // 清空输入
- return false; // 返回false表示校验失败
- }
- };
- // 判断是否大于阈值
- const checkThreshold = (item) => {
- checkLessThreshold(item);
- // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
- if (item.fillContent > item.threshold) {
- uni.showToast({
- title:
- item.name +
- t("operationRecordFilling.fillContentCannotGreaterThanThreshold") +
- item.threshold,
- icon: "none",
- });
- item.fillContent = ""; // 清空输入
- return false; // 返回false表示校验失败
- }
- };
- // 保留两位小数
- const toFixed = (num) => {
- if (num) {
- num = Number(num);
- num = num.toFixed(2);
- } else {
- num = 0.0;
- }
- 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 = [];
- // 校验是否所有待填写项都已加载
- 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; // 校验失败直接返回,不设置按钮禁用
- }
- }
- }
- }
- // 检查是否有超限的项目,如果有则统一显示
- // 需要在基础校验通过后,执行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("累计公里数填报")) {
- 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);
- }
- }
- }
- }
- }
- // 检查是否有超限的项目,如果有则统一显示
- 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 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);
- }
- }
- }
- }
- }
- // 执行实际的数据提交
- 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;
- }
- }
- }
- }
- 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.success"),
- duration: 1500,
- icon: "none",
- });
- // 成功后延迟跳转,不启用按钮
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- // 注意:这里不设置 isSubmitting.value = false,因为成功后会跳转页面
- return; // 成功完成,直接返回
- } else {
- console.error("工单状态更新失败", upRes);
- throw new Error("工单状态更新失败"); // 抛出错误,让 catch 处理
- }
- } 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>
- .page {
- padding: 0;
- box-sizing: border-box;
- }
- .top {
- padding: 10px;
- }
- .list {
- // margin-top: calc(10px);
- padding: 10px;
- // height: calc(100%);
- }
- .item {
- width: 100%;
- // height: 204px;
- background: #ffffff;
- border-radius: 6px;
- margin-bottom: 10px;
- box-sizing: border-box;
- padding: 20px 15px;
- }
- .item-module {
- width: 100%;
- height: 16px;
- position: relative;
- font-weight: 600;
- font-size: 14px;
- color: #333333;
- margin-bottom: 10px;
- .module-border {
- position: absolute;
- left: -15px;
- width: 0px;
- height: 12px;
- border: 1px solid #004098;
- }
- }
- .item-content {
- position: relative;
- width: 100%;
- // height: calc(38px);
- box-sizing: border-box;
- font-weight: 500;
- font-size: 14px;
- color: #333333;
- line-height: 20px;
- border-bottom: 1px dashed #cacccf;
- &:last-child {
- border-bottom: none;
- }
- &.bold {
- font-weight: 600;
- // :deep(.uni-easyinput__content-input){
- // padding-right: 0 !important;
- // }
- }
- &.bottom-bold {
- border-bottom: 1px dashed #cacccf;
- }
- }
- .item-title {
- position: relative;
- min-height: 38px;
- width: 55%;
- &.total {
- :deep(.is-disabled) {
- color: #333333 !important;
- }
- }
- &.full-cell {
- width: 100%;
- min-width: max-content;
- }
- }
- .item-value {
- width: 45%;
- position: relative;
- &.textarea {
- width: 65%;
- }
- }
- .word-break-all {
- min-width: unset;
- }
- :deep(.uni-select) {
- border: none;
- text-align: right;
- padding-right: 0;
- .uniui-bottom:before {
- content: "\e6b5" !important;
- font-size: 16px !important;
- }
- }
- :deep(.uni-select__input-text) {
- text-align: right;
- .align-left {
- text-align: right;
- }
- }
- :deep(.uni-select--disabled) {
- color: #d5d5d5 !important;
- background-color: transparent;
- .uni-select__input-text {
- color: #d5d5d5 !important;
- }
- }
- :deep(.uni-select__selector) {
- text-align: left;
- }
- :deep(.uni-select__selector-item) {
- border-bottom: 1px dashed #cacccf;
- text-align: left;
- }
- :deep(.uni-easyinput__content-textarea) {
- min-height: inherit;
- margin: 10px;
- }
- </style>
|