| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995 |
- <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
- v-if="deptName === 'ry'"
- class="item-content flex-row align-center">
- <view class="item-title full-cell flex-row align-center">
- <span class="item-title-width">井号:</span>
- <uni-data-select
- :localdata="taskOptions"
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :clear="false"
- :disabled="!isView"
- :placeholder="$t('operation.PleaseSelect')"
- v-model="taskId"></uni-data-select>
- </view>
- </view>
- <view v-else class="item-content flex-row align-center">
- <view class="item-title full-cell flex-row align-center">
- <span class="item-title-width">井号:</span>
- <span>{{ params.wellName || "" }}</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.filter(
- (nosum) =>
- !keys.includes(nosum.description) &&
- (deptName === 'ry'
- ? nosum.description !== 'productionStatus'
- : true)
- )">
- <!-- 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>
- <!-- {{ nosum.name }} {{ nosum.description }} -->
- <uni-forms
- v-if="item.deviceName === '生产日报'"
- ref="formRef"
- labelWidth="auto"
- validateTrigger="submit"
- err-show-type="toast"
- :model="{ nonSumList: item.nonSumList, reportDetails }">
- <template
- v-for="(nosum, nosumIndex) in item.nonSumList"
- :key="nosumIndex">
- <uni-forms-item
- v-if="keys.includes(nosum.description)"
- :label="nosum.name"
- :rules="rules[nosum.description]?.(index)"
- :name="['nonSumList', nosumIndex, 'fillContent']">
- <uni-easyinput
- v-if="nosum.description !== 'otherNptReason'"
- type="number"
- :placeholder="$t('operation.PleaseFillIn')"
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :inputBorder="false"
- :clearable="false"
- :disabled="!isView"
- v-model.number="nosum.fillContent"
- @input="(val) => onInputChange(val, nosum)" />
- <uni-easyinput
- v-else
- type="textarea"
- autoHeight
- :placeholder="$t('operation.PleaseFillIn')"
- style="text-align: right"
- :styles="{ disableColor: '#fff' }"
- :inputBorder="false"
- :clearable="false"
- :disabled="!isView"
- v-model="nosum.fillContent"
- :maxlength="1000" />
- </uni-forms-item>
- </template>
- <template v-if="deptName === 'ry'">
- <uv-divider text="生产动态" textPosition="left"> </uv-divider>
- <uni-forms-item v-if="isView">
- <button
- type="primary"
- size="mini"
- class="detail-btn"
- @click="addProductionStatusRow()">
- 添加一行
- </button>
- </uni-forms-item>
- <template v-for="(detail, index) in reportDetails" :key="index">
- <uv-divider v-if="index !== 0" class="divider"></uv-divider>
- <uni-forms-item
- label="日期"
- required
- :name="['reportDetails', index, 'reportDate']"
- :rules="[{ required: true, errorMessage: '请选择日期' }]">
- <uni-datetime-picker
- class="datetime-picker"
- type="date"
- returnType="timestamp"
- v-model="detail.reportDate"
- :border="false"
- :disabled="!isView"
- @change="inputCurrentDepth(item.nonSumList)" />
- </uni-forms-item>
- <uni-forms-item :label="`${$t('ruiDu.timeNode')}:`" required>
- <view
- @click="
- !isView
- ? undefined
- : handleClickTimeRangeItem(index, item.nonSumList)
- ">
- <view
- class="time-range-item"
- v-if="detail.startTime && detail.endTime">
- {{ detail.startTime }} 至 {{ detail.endTime }}
- </view>
- <view class="time-range-item" v-else> 请选择 </view>
- </view>
- </uni-forms-item>
- <uni-forms-item label="时长(H)">
- <span>{{ detail.duration }}</span>
- </uni-forms-item>
- <uni-forms-item
- label="工况"
- required
- :name="['reportDetails', index, 'currentOperation']"
- :rules="[{ required: true, errorMessage: '请输入工况' }]">
- <uni-easyinput
- type="textarea"
- autoHeight
- v-bind="defaultProps"
- v-model="detail.currentOperation"
- :disabled="!isView"
- :maxlength="2000" />
- </uni-forms-item>
- <uni-forms-item
- label="结束井深(m)"
- required
- v-if="showDepth(item.nonSumList)"
- :name="['reportDetails', index, 'currentDepth']"
- :rules="[{ required: true, errorMessage: '请输入结束深度' }]">
- <uni-easyinput
- type="number"
- v-bind="defaultProps"
- :disabled="!isView"
- v-model.number="detail.currentDepth"
- @input="(val) => inputCurrentDepth(item.nonSumList)" />
- </uni-forms-item>
- <uni-forms-item
- label="详情"
- required
- :name="['reportDetails', index, 'constructionDetail']"
- :rules="[{ required: true, errorMessage: '请输入详情' }]">
- <uni-easyinput
- type="textarea"
- autoHeight
- :disabled="!isView"
- v-bind="defaultProps"
- v-model="detail.constructionDetail"
- :maxlength="2000" />
- </uni-forms-item>
- <uni-forms-item v-if="isView" label="操作">
- <button
- type="warn"
- size="mini"
- class="detail-btn"
- @click="removeReportDetailRow(index)">
- 删除
- </button>
- </uni-forms-item>
- </template>
- </template>
- </uni-forms>
- </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>
- <tpf-time-range
- ref="reportDetailsTimeRangeRef"
- :startTime="startTime"
- :startDefaultTime="startDefaultTime"
- :endTime="endTime"
- :endDefaultTime="endDefaultTime"
- @timeRange="reportDetailsTimeRange"></tpf-time-range>
- </template>
- <script setup>
- import { ref, reactive, getCurrentInstance, watch, computed } from "vue";
- import { onReady, onLoad } from "@dcloudio/uni-app";
- import dayjs from "dayjs";
- import {
- getRecordFillingDetail,
- recordFillingUpOperationOrder,
- recordFillingDetailGetPageAndAttrs,
- recordFillingDetailInsertDataList,
- getDeptName,
- reportDetailsGet,
- } from "@/api/recordFilling";
- import { reloginByUserId } from "@/utils/auth.js";
- import { useDataDictStore } from "@/store/modules/dataDict";
- import { useDebounceFn } from "@/utils/useDebounceFn.js";
- import tpfTimeRange from "@/components/tpf-time-range/tpf-time-range.vue";
- // 引用全局变量$t
- const { appContext } = getCurrentInstance();
- const t = appContext.config.globalProperties.$t;
- // 获取字典项
- const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
- const defaultProps = computed(() => ({
- inputBorder: false,
- clearable: false,
- placeholder: "请输入",
- style: {
- "text-align": "right",
- },
- styles: {
- disableColor: "#fff",
- },
- }));
- const reportDetailsTimeRangeRef = ref(null);
- const startTime = ref("00:00");
- const startDefaultTime = ref("08:00");
- const endTime = ref("24:00");
- const endDefaultTime = ref("08:00");
- const reportDetailIndex = ref(0);
- const aaaList = ref();
- const handleClickTimeRangeItem = (index, list) => {
- reportDetailIndex.value = index;
- aaaList.value = list;
- reportDetailsTimeRangeRef.value.open();
- };
- const calculateDuration = (row) => {
- if (!row.startTime || !row.endTime) {
- row.duration = 0;
- return;
- }
- const todayStr = dayjs().format("YYYY-MM-DD");
- const start = dayjs(`${todayStr} ${row.startTime}`);
- const end = dayjs(`${todayStr} ${row.endTime}`);
- let diffMinutes = end.diff(start, "minute");
- if (diffMinutes < 0) {
- diffMinutes += 1440;
- }
- row.duration = Number((diffMinutes / 60).toFixed(2));
- };
- const reportDetailsTimeRange = (data) => {
- reportDetails.value[reportDetailIndex.value].startTime = data[0];
- reportDetails.value[reportDetailIndex.value].endTime = data[1];
- calculateDuration(reportDetails.value[reportDetailIndex.value]);
- inputCurrentDepth(aaaList.value ?? []);
- };
- const reportDetails = ref([]);
- const addProductionStatusRow = () => {
- if (!reportDetails.value) {
- reportDetails.value = [];
- }
- reportDetails.value.push({
- reportDate: params.createTime
- ? dayjs(params.createTime).valueOf()
- : dayjs().valueOf(),
- startTime: "08:00",
- endTime: "08:00",
- duration: 0,
- currentDepth: 0,
- currentOperation: "",
- constructionDetail: "",
- });
- };
- const removeReportDetailRow = (index) => {
- if (index === 0) {
- uni.showToast({ title: "至少填写一条生产动态", icon: "none" });
- return;
- }
- reportDetails.value.splice(index, 1);
- };
- const taskId = ref(undefined);
- const taskOptions = ref([]);
- const inputCurrentDepth = useDebounceFn(function inputCurrentDepth(list) {
- const details = reportDetails.value;
- if (Array.isArray(details) && details.length > 0) {
- const latestDetail = details.reduce((prev, current) => {
- const currentFullTime = dayjs(current.reportDate)
- .hour(parseInt(current.endTime.split(":")[0]))
- .minute(parseInt(current.endTime.split(":")[1]))
- .valueOf();
- const prevFullTime = dayjs(prev.reportDate)
- .hour(parseInt(prev.endTime.split(":")[0]))
- .minute(parseInt(prev.endTime.split(":")[1]))
- .valueOf();
- return currentFullTime >= prevFullTime ? current : prev;
- });
- const currentDepth = list.find(
- (item) => item?.description === "currentDepth"
- );
- if (currentDepth) currentDepth.fillContent = latestDetail.currentDepth;
- }
- }, 300);
- const showDepth = computed(() => (list) => {
- return list.some((item) => item.description === "currentDepth");
- });
- const NON_KEYS = [
- "repairTime",
- "selfStopTime",
- "accidentTime",
- "complexityTime",
- "rectificationTime",
- "waitingStopTime",
- "partyaDesign",
- "partyaPrepare",
- "partyaResource",
- "relocationTime",
- "winterBreakTime",
- "otherNptTime",
- ];
- const keys = [
- "repairTime",
- "selfStopTime",
- "accidentTime",
- "complexityTime",
- "rectificationTime",
- "waitingStopTime",
- "partyaDesign",
- "partyaPrepare",
- "partyaResource",
- "relocationTime",
- "winterBreakTime",
- "otherNptTime",
- "drillingWorkingTime",
- "otherProductionTime",
- "ratedProductionTime",
- "productionTime",
- "dailyInjectGasTime",
- "otherNptReason",
- ];
- const sumNonProdTimes = (index) => {
- let sum = 0;
- const { nonSumList } = dataList.value[index];
- NON_KEYS.forEach((field) => {
- sum += Number(
- (nonSumList || []).find((item) => item.description === field)
- ?.fillContent || 0
- );
- });
- return sum;
- };
- const handleInputRaw = (val, item) => {
- let num = Number(val);
- if (val === "" || isNaN(num) || num < 0) {
- num = 0;
- } else if (num > 24) {
- num = 24;
- }
- item.fillContent = num;
- };
- const onInputChange = debounce(handleInputRaw, 500);
- // 校验函数:总时间必须为 24
- const ryValidateTotalTime = (index) => (rule, value, data, callback) => {
- const { nonSumList } = dataList.value[index];
- const drillingTime = Number(
- (nonSumList || []).find(
- (item) => item.description === "drillingWorkingTime"
- )?.fillContent || 0
- );
- const otherTime = Number(
- (nonSumList || []).find(
- (item) => item.description === "otherProductionTime"
- )?.fillContent || 0
- );
- const nonProdSum = sumNonProdTimes(index);
- let total = 0;
- let msg = "";
- total = parseFloat((drillingTime + otherTime + nonProdSum).toFixed(2));
- msg = `进尺(${drillingTime})+其他(${otherTime})+非生产(${nonProdSum})=${total}H,必须为24H`;
- if (Math.abs(total - 24) > 0.01) {
- callback(msg);
- }
- return true;
- };
- const rhValidateTotalTime = (index) => (rule, value, data, callback) => {
- const { nonSumList } = dataList.value[index];
- const gasTime = Number(
- (nonSumList || []).find((item) => item.description === "dailyInjectGasTime")
- ?.fillContent || 0
- );
- const nonProdSum = sumNonProdTimes(index);
- let total = 0;
- let msg = "";
- total = parseFloat((gasTime + nonProdSum).toFixed(2));
- msg = `运转(${gasTime})+非生产(${nonProdSum})=${total}H,必须为24H`;
- console.log("total :>> ", total);
- if (Math.abs(total - 24) > 0.01) {
- callback(msg);
- }
- return true;
- };
- const rules = reactive({
- drillingWorkingTime: (index) => [
- { required: true, errorMessage: "请输入进尺工作时间" },
- { validateFunction: ryValidateTotalTime(index) },
- ],
- dailyInjectGasTime: (index) => [
- { required: true, errorMessage: "请输入当日运转时间" },
- { validateFunction: rhValidateTotalTime(index) },
- ],
- });
- // -------------------------------------
- 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 daily = detail ?? {
- wellNamePair: {},
- };
- taskOptions.value = Object.keys(daily.wellNamePair ?? {}).map((key) => ({
- text: daily.wellNamePair[key],
- value: Number(key),
- }));
- taskId.value = taskOptions.value[0]?.value || undefined;
- 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) {
- if (timer) 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);
- }
- const formatT = (arr) =>
- `${arr[0].toString().padStart(2, "0")}:${arr[1].toString().padStart(2, "0")}`;
- // @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;
- const timeKeys = keys.filter((k) => k !== "otherNptReason");
- item.nonSumList = rtem.nonSumList
- .sort((a, b) => a.modelId - b.modelId)
- .map((item) => {
- if (timeKeys.includes(item.description)) {
- item.fillContent = Number(item.fillContent || 0);
- }
- return item;
- });
- });
- 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();
- reportDetailsGet(params.value.orderId).then((res) => {
- reportDetails.value = (res.data ?? []).map((item) => ({
- reportDate: item.reportDate ?? dayjs(params.createTime).valueOf(),
- startTime: formatT(item.startTime),
- endTime: formatT(item.endTime),
- duration: item.duration,
- currentDepth: item.currentDepth,
- currentOperation: item.currentOperation,
- constructionDetail: item.constructionDetail,
- }));
- console.log("🚀 ~ reportDetails.value:", reportDetails.value);
- if (!reportDetails.value.length) {
- addProductionStatusRow();
- }
- });
- }
- })
- .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 formRef = ref(null);
- const onSubmit = async () => {
- try {
- if (formRef.value) {
- for (const item of formRef.value) {
- await item.validate();
- }
- }
- } catch (error) {
- return;
- }
- // 清空之前的超限记录
- 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 otherNptTime = nonSumList.find((i) => i.name === "其他非生产时间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为非必填,否则为必填
- if (
- nonSumItem.description === "dailyGasInjection" &&
- deptName.value === "rh"
- ) {
- if (runtimeItem.fillContent > 0 && nonSumItem.fillContent > 0) {
- } else {
- uni.showToast({
- title: "当日运转时间大于0,注气量也需要大于0",
- icon: "none",
- });
- return;
- }
- }
- if (
- nonSumItem.name === "其他非生产时间原因" &&
- !nonSumItem.fillContent &&
- otherNptTime.fillContent > 0
- ) {
- uni.showToast({
- title: "其他非生产时间大于 0 时,必须填写其他非生产时间原因",
- icon: "none",
- });
- return;
- }
- const isExemptField =
- isRuntime24 &&
- (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
- if (
- (!item.isReport || item.isReport != 1) &&
- !isExemptField &&
- (nonSumItem.fillContent == null || nonSumItem.fillContent === "") &&
- nonSumItem.name !== "其他非生产时间原因"
- ) {
- 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 reqData = {
- createReqVO: submitList,
- reportDetails: reportDetails.value.map((item) => ({
- ...item,
- taskId: taskId.value,
- })),
- };
- const res = await recordFillingDetailInsertDataList(reqData);
- 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;
- }
- .uni-forms {
- .uni-forms-item {
- display: flex;
- align-items: center;
- flex: 1;
- margin-bottom: 0px;
- border-bottom: 1px dashed #cacccf;
- }
- :deep(.uni-forms-item__content) {
- text-align: right;
- .readOnly {
- padding-right: 10px;
- }
- }
- :deep(.uni-forms-item__label) {
- height: 44px;
- font-weight: 500;
- font-size: 14px;
- color: #333333 !important;
- width: max-content !important;
- }
- :deep(.uni-easyinput__content-input) {
- padding: 0 !important;
- }
- }
- :deep(.uni-easyinput__content-textarea) {
- margin: 0 !important;
- }
- .divider {
- margin: 0;
- transform: translateY(-2px);
- :deep(.uv-line) {
- border-width: 2px !important;
- border-color: rgb(41, 121, 255) !important;
- }
- }
- :deep(.datetime-picker) {
- .uniui-calendar {
- &::before {
- display: none;
- }
- }
- .uni-date-editor--x__disabled {
- opacity: 1 !important;
- }
- .uni-date__x-input {
- color: #333 !important;
- }
- }
- </style>
|