detail.vue 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. <template>
  2. <z-paging
  3. class="page"
  4. ref="paging"
  5. v-model="dataList"
  6. :loading-more-enabled="true"
  7. @query="queryList"
  8. >
  9. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  10. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  11. <template #top>
  12. <!-- 工单基础信息 -->
  13. <view class="item top">
  14. <view class="item-content flex-row align-center">
  15. <view class="item-title full-cell flex-row align-center">
  16. <span class="item-title-width"
  17. >{{ $t("operationRecordFilling.workOrderName") }}:</span
  18. >
  19. <span>{{ params.orderName }}</span>
  20. </view>
  21. </view>
  22. <view class="item-content flex-row align-center">
  23. <view class="item-title full-cell flex-row align-center">
  24. <span class="item-title-width"
  25. >{{ $t("operationRecordFilling.responsiblePerson") }}:</span
  26. >
  27. <span>{{ params.userName }}</span>
  28. </view>
  29. </view>
  30. <view class="item-content flex-row align-center">
  31. <view class="item-title full-cell flex-row align-center">
  32. <span class="item-title-width"
  33. >{{ $t("operation.createTime") }}:</span
  34. >
  35. <span>{{ params.createTime }}</span>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <!-- 填报列表 -->
  41. <view class="list">
  42. <view class="item" v-for="(item, index) in dataList" :key="index">
  43. <view class="item-module flex-row align-center justify-between">
  44. <view class="module-name">
  45. {{ item.deviceCode }}({{ item.deviceName }})
  46. </view>
  47. <view class="module-border"> </view>
  48. </view>
  49. <view class="item-content flex-row align-center justify-between bold">
  50. <view class="item-title flex-row align-center">
  51. <span>{{ $t("operationRecordFilling.belongToTeam") }}:</span>
  52. <span>{{ item.orgName }}</span>
  53. </view>
  54. </view>
  55. <view
  56. class="item-content flex-row align-center justify-between bold"
  57. v-for="sum in item.sumList"
  58. >
  59. <view class="item-title flex-row align-center word-break-all">
  60. <span>{{ sum.name }}:</span>
  61. </view>
  62. <view class="item-value flex-row align-center justify-end total">
  63. <uni-easyinput
  64. style="text-align: right"
  65. :inputBorder="false"
  66. :clearable="true"
  67. :styles="{ disableColor: '#fff' }"
  68. :value="`${sum.totalRunTime} ${
  69. sum.modelAttr ? (sum.modelAttr.includes('Time') ? 'h' : '') : ''
  70. }`"
  71. :disabled="true"
  72. ></uni-easyinput>
  73. </view>
  74. </view>
  75. <view
  76. class="item-content flex-col align-center justify-between"
  77. :class="{ 'bottom-bold': item.nonSumList.length > 0 }"
  78. v-for="nosum in item.nonSumList"
  79. >
  80. <!-- isCollection为1,提示:以下数值取自PLC,如有不符请修改 -->
  81. <uni-notice-bar
  82. :text="$t('operationRecordFilling.plcNotice')"
  83. v-if="nosum.isCollection == 1"
  84. />
  85. <view class="flex-row align-center justify-between item-content">
  86. <view class="item-title flex-row align-center">
  87. <span>{{ nosum.name }}:</span>
  88. </view>
  89. <!-- 判断填写项的属性 -->
  90. <!-- type为double时,输入框为数字类型 -->
  91. <view
  92. class="item-value flex-row align-center justify-end"
  93. v-if="nosum.type == 'double'"
  94. >
  95. <uni-easyinput
  96. style="text-align: right"
  97. :styles="{ disableColor: '#fff' }"
  98. :inputBorder="false"
  99. :clearable="true"
  100. :placeholder="$t('operation.PleaseFillIn')"
  101. :disabled="!isView"
  102. v-model="nosum.fillContent"
  103. :type="'digit'"
  104. @blur="
  105. nosum.threshold > 0
  106. ? checkThreshold(nosum)
  107. : checkLessThreshold(nosum)
  108. "
  109. @input="handleRealTimeUpdate(nosum, item)"
  110. ></uni-easyinput>
  111. </view>
  112. <!-- type为textarea时,输入框为文本类型 -->
  113. <view
  114. class="item-value flex-row align-center justify-end"
  115. v-else-if="nosum.type == 'textarea'"
  116. >
  117. <uni-easyinput
  118. style="text-align: right"
  119. :styles="{ disableColor: '#fff' }"
  120. :inputBorder="false"
  121. :clearable="true"
  122. :placeholder="$t('operation.PleaseFillIn')"
  123. :disabled="!isView"
  124. v-model="nosum.fillContent"
  125. :type="'textarea'"
  126. :autoHeight="true"
  127. :maxlength="-1"
  128. ></uni-easyinput>
  129. </view>
  130. <!-- type为enum时,使用下拉菜单 -->
  131. <view
  132. class="item-value select flex-row align-center justify-end"
  133. v-else-if="nosum.type == 'enum' && nosum.description !== null"
  134. >
  135. <uni-data-select
  136. :localdata="nosum.enumList"
  137. style="text-align: right"
  138. :styles="{ disableColor: '#fff' }"
  139. :clear="false"
  140. :disabled="!isView"
  141. :placeholder="$t('operation.PleaseSelect')"
  142. v-model="nosum.fillContent"
  143. ></uni-data-select>
  144. </view>
  145. <!-- 其他类型时,输入框为文本类型 -->
  146. <view class="item-value flex-row align-center justify-end" v-else>
  147. <uni-easyinput
  148. style="text-align: right"
  149. :styles="{ disableColor: '#fff' }"
  150. :inputBorder="false"
  151. :clearable="true"
  152. :placeholder="$t('operation.PleaseFillIn')"
  153. :disabled="!isView"
  154. v-model="nosum.fillContent"
  155. :type="'text'"
  156. ></uni-easyinput>
  157. </view>
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. <!-- 如果需要使用页脚,请使用slot="bottom"slot节点不支持通过v-if或v-show动态显示/隐藏,若需要动态控制,可将v-if添加在其子节点上 -->
  163. <template #bottom>
  164. <button
  165. style="border-radius: 0"
  166. type="primary"
  167. @click="onSubmit()"
  168. :disabled="dataList.length < totalNum || isSubmitting"
  169. v-if="isView"
  170. >
  171. {{ isSubmitting ? "提交中" : $t("operation.save") }}
  172. </button>
  173. </template>
  174. </z-paging>
  175. </template>
  176. <script setup>
  177. import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
  178. import { onReady, onLoad } from "@dcloudio/uni-app";
  179. import dayjs from "dayjs";
  180. import {
  181. getRecordFillingDetailGetPage,
  182. getRecordFillingDetailGetAttrs,
  183. recordFillingDetailInsertLog,
  184. getRecordFillingDetail,
  185. recordFillingUpOperationOrder,
  186. recordFillingDetailGetPageAndAttrs,
  187. recordFillingDetailInsertDataList,
  188. getDeptName,
  189. } from "@/api/recordFilling";
  190. import { getUserId, reloginByUserId } from "@/utils/auth.js";
  191. import { useDataDictStore } from "@/store/modules/dataDict";
  192. // 引用全局变量$t
  193. const { appContext } = getCurrentInstance();
  194. const t = appContext.config.globalProperties.$t;
  195. // 获取字典项
  196. const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
  197. // -------------------------------------
  198. const isFromMsg = ref(false);
  199. const params = ref({});
  200. const isView = ref(false); // 是否编辑 -- view == 1为编辑状态
  201. let deptName = ref("");
  202. // 累加状态对象,用于在生产日报加载前存储累加值
  203. const accumulatedValues = reactive({
  204. "当日注水量-方": 0,
  205. 当日用电量kWh: 0,
  206. 当日运转时间H: 0,
  207. "当日注气量-方": 0,
  208. });
  209. onReady(() => {
  210. console.log("onReady");
  211. });
  212. onLoad(async (option) => {
  213. console.log("onLoad", option);
  214. await reloginByUserId(option.reloginUserId);
  215. isFromMsg.value = !!option.reloginUserId;
  216. // 初始化params
  217. params.value = JSON.parse(option.param);
  218. // 处理createTime
  219. params.value.createTime = params.value.createTime
  220. ? dayjs(Number.parseInt(params.value.createTime)).format("YYYY-MM-DD")
  221. : "";
  222. // 请求工单详情
  223. if (params.value?.orderId) {
  224. const detail = (await getRecordFillingDetail(params.value.orderId)).data;
  225. const data = await getDeptName(detail.deptId);
  226. console.log("data>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", data);
  227. deptName.value = data.data;
  228. console.log("deptName.value>>>>>>>>>>>>>>>>>>>", deptName.value);
  229. params.value = {
  230. ...params.value,
  231. ...detail,
  232. // 处理createTime
  233. createTime: detail.createTime
  234. ? dayjs(Number.parseInt(detail.createTime)).format("YYYY-MM-DD")
  235. : "",
  236. orderId: detail.id,
  237. };
  238. }
  239. console.log("🚀 ~ params.value:", params.value);
  240. // 处理是否可编辑 {0: '待填写', 1: '已完成', 2: '填写中', 3: '忽略'}
  241. isView.value = params.value?.orderStatus % 2 == 0;
  242. console.log("🚀 ~ isView.value:", isView.value);
  243. });
  244. const paging = ref(null);
  245. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  246. const dataList = ref([]);
  247. // 列表总数
  248. const totalNum = ref(0);
  249. // 监听dataList变化,初始化时计算一次总和
  250. watch(
  251. dataList,
  252. (newVal) => {
  253. // calculateTotalRunTime();
  254. },
  255. { deep: true }
  256. );
  257. // 处理fillContent变化的方法
  258. const handleFillContentChange = (nosum, deviceItem) => {
  259. console.log("🚀 ~ nosum, deviceItem:", nosum, deviceItem);
  260. // 处理增压机
  261. if (
  262. deviceItem.deviceName.includes("增压机") &&
  263. nosum.name === "当日运转时间"
  264. ) {
  265. calculateTotalRunTime("增压机", "当日运转时间"); // 计算当日运转时间总和
  266. }
  267. // 处理提纯撬
  268. if (deviceItem.deviceName.includes("提纯撬") && nosum.name === "当日注气量") {
  269. calculateTotalRunTime("提纯撬", "当日注气量"); // 计算当日注气量总和
  270. }
  271. // 处理注水泵
  272. if (deviceItem.deviceName.includes("注水泵") && nosum.name === "当日注水量") {
  273. calculateTotalRunTime("注水泵", "当日注水量"); // 计算当日注水量总和
  274. }
  275. // 处理箱式变电站
  276. if (
  277. deviceItem.deviceName.includes("箱式变电站") &&
  278. nosum.name === "当日用电量"
  279. ) {
  280. calculateTotalRunTime("箱式变电站", "当日用电量"); // 计算当日用电量总和
  281. }
  282. };
  283. // 防抖函数
  284. function debounce(func, delay) {
  285. let timer;
  286. return function (...args) {
  287. clearTimeout(timer);
  288. timer = setTimeout(() => func.apply(this, args), delay);
  289. };
  290. }
  291. //防抖
  292. const debouncedCalculateTotalRunTime = debounce(calculateTotalRunTime, 100);
  293. const debouncedApplyAccumulatedToReport = debounce(
  294. applyAccumulatedToReport,
  295. 100
  296. );
  297. /**
  298. * 更新累加值
  299. * @param fieldName 字段名
  300. * @param deviceType 设备类型
  301. */
  302. const updateAccumulatedValue = (fieldName, deviceType) => {
  303. let total = 0;
  304. dataList.value.forEach((item) => {
  305. if (item.deviceName.includes(deviceType) && item.nonSumList) {
  306. item.nonSumList.forEach((nonSum) => {
  307. if (
  308. nonSum.type === "double" &&
  309. nonSum.name === fieldName &&
  310. nonSum.fillContent !== null &&
  311. nonSum.fillContent !== ""
  312. ) {
  313. const value = parseFloat(nonSum.fillContent) || 0;
  314. total += value;
  315. }
  316. });
  317. }
  318. });
  319. accumulatedValues[fieldName] = total;
  320. };
  321. /**
  322. * 重新计算所有累加值
  323. */
  324. const recalculateAllAccumulatedValues = () => {
  325. const fields = [
  326. { field: "当日运转时间H", device: "增压机" },
  327. { field: "当日注气量-方", device: "提纯撬" },
  328. { field: "当日注水量-方", device: "注水泵" },
  329. { field: "当日用电量kWh", device: "箱式变电站" },
  330. ];
  331. fields.forEach(({ field, device }) => {
  332. updateAccumulatedValue(field, device);
  333. });
  334. };
  335. /**
  336. * 将累加值应用到生产日报
  337. */
  338. function applyAccumulatedToReport() {
  339. // 先重新计算所有累加值
  340. recalculateAllAccumulatedValues();
  341. const reportItem = dataList.value.find(
  342. (item) => item.deviceName === "生产日报"
  343. );
  344. if (!reportItem) {
  345. console.warn("⚠️ 未找到生产日报,累加值已存储,等待加载");
  346. return;
  347. }
  348. Object.keys(accumulatedValues).forEach((fieldName) => {
  349. const targetItem = reportItem.nonSumList.find(
  350. (item) => item.name === fieldName
  351. );
  352. if (targetItem) {
  353. console.log(
  354. `📊 应用累加值 (${fieldName}):`,
  355. accumulatedValues[fieldName]
  356. );
  357. targetItem.fillContent = toFixed(accumulatedValues[fieldName]);
  358. }
  359. });
  360. }
  361. const handleRealTimeUpdate = (nosum, deviceItem) => {
  362. console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
  363. let fieldName = "";
  364. let deviceType = "";
  365. // 当日运转时间累加
  366. if (
  367. deviceItem.deviceName.includes("增压机") &&
  368. nosum.name === "当日运转时间H"
  369. ) {
  370. fieldName = "当日运转时间H";
  371. deviceType = "增压机";
  372. }
  373. // 当日注气量累加
  374. if (
  375. deviceItem.deviceName.includes("提纯撬") &&
  376. nosum.name === "当日注气量-方"
  377. ) {
  378. fieldName = "当日注气量-方";
  379. deviceType = "提纯撬";
  380. }
  381. // 当日注水量累加
  382. if (
  383. deviceItem.deviceName.includes("注水泵") &&
  384. nosum.name === "当日注水量-方"
  385. ) {
  386. fieldName = "当日注水量-方";
  387. deviceType = "注水泵";
  388. }
  389. // 当日用电量累加
  390. if (
  391. deviceItem.deviceName.includes("箱式变电站") &&
  392. nosum.name === "当日用电量kWh"
  393. ) {
  394. fieldName = "当日用电量kWh";
  395. deviceType = "箱式变电站";
  396. }
  397. if (fieldName) {
  398. // 更新累加值
  399. updateAccumulatedValue(fieldName, deviceType);
  400. // 应用到生产日报(如果已加载)
  401. debouncedApplyAccumulatedToReport();
  402. }
  403. };
  404. /**
  405. * 计算所有deviceName中包含deviceNameToMatch的对象中对应的reportName的fillContent总和并更新到reportName的fillContent中
  406. * @param deviceNameToMatch {string} 设备名称包含的字符串
  407. * @param reportName {string} 填写项名称
  408. */
  409. function calculateTotalRunTime(
  410. deviceNameToMatch,
  411. sourceFieldName,
  412. targetFieldName
  413. ) {
  414. const reportItem = dataList.value.find(
  415. (item) => item.deviceName === "生产日报"
  416. );
  417. if (!reportItem) {
  418. console.warn("⚠️ 未找到生产日报");
  419. return;
  420. }
  421. const targetItem = reportItem.nonSumList.find(
  422. (item) => item.name === targetFieldName
  423. );
  424. if (!targetItem) {
  425. console.warn(`⚠️ 未找到目标字段:${targetFieldName}`);
  426. return;
  427. }
  428. let total = 0;
  429. dataList.value.forEach((item) => {
  430. if (item.deviceName.includes(deviceNameToMatch) && item.nonSumList) {
  431. item.nonSumList.forEach((nonSum) => {
  432. if (
  433. nonSum.type === "double" &&
  434. nonSum.name === sourceFieldName &&
  435. nonSum.fillContent !== null &&
  436. nonSum.fillContent !== ""
  437. ) {
  438. const value = parseFloat(nonSum.fillContent) || 0;
  439. total += value;
  440. }
  441. });
  442. }
  443. });
  444. console.log(`📊 累计值 (${sourceFieldName} -> ${targetFieldName}):`, total);
  445. targetItem.fillContent = toFixed(total);
  446. }
  447. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  448. const queryList = (pageNo, pageSize) => {
  449. const userId = uni.getStorageSync("userId");
  450. if (!userId) {
  451. paging.value.complete([]);
  452. return;
  453. }
  454. // 请求填报设备及属性
  455. recordFillingDetailGetPageAndAttrs({
  456. pageNo,
  457. pageSize,
  458. orderId: params.value.orderId,
  459. // deviceCategoryId: 1,
  460. })
  461. .then(async (res) => {
  462. console.log("🚀 ~ res:", res);
  463. const { data } = res;
  464. const resList = [].concat(data.list);
  465. // 列表总数
  466. totalNum.value = data.total;
  467. // 遍历列表,处理attrsDetail
  468. resList.map(async (item) => {
  469. const attrParams = {
  470. deviceCode: item.deviceCode,
  471. deviceName: item.deviceName,
  472. deptId: item.deptId,
  473. createTime: params.value.createTime,
  474. deviceCategoryId: item.deviceCategoryId,
  475. deviceId: item.deviceId,
  476. userId: params.value.userId,
  477. orderId: params.value.orderId,
  478. };
  479. // console.log(
  480. // "getRecordFillingDetailGetAttrs- attrParams",
  481. // attrParams
  482. // );
  483. const resAttrs = item?.attrsDetail;
  484. // console.log("resAttrs", resAttrs);
  485. if (resAttrs) {
  486. attrParams.createTime = attrParams.createTime
  487. ? dayjs(attrParams.createTime).format("YYYY-MM-DD")
  488. : "";
  489. attrParams.id = attrParams.orderId;
  490. delete attrParams.orderId;
  491. delete attrParams.deviceName;
  492. resAttrs.map((rtem) => {
  493. // 将rtem中sumList和nonSumList两个数组中的
  494. // fillContent字段判断是否为null, 如果为null,则赋值为0 不为null则保留两位小数
  495. // 将attrParams合并到两个数组的每个对象中
  496. // 然后将sumList和nonSumList分别赋值给item的sumList和nonSumList
  497. if (rtem.sumList) {
  498. rtem.sumList.map((sumItem) => {
  499. if (sumItem.fillContent == null || sumItem.fillContent == "") {
  500. // console.log("🚀 ~ rtem.sumList.map ~ sumItem:", sumItem);
  501. // sumItem.fillContent = 0;
  502. } else {
  503. // 如果是double类型,保留两位小数
  504. if (sumItem.type == "double") {
  505. sumItem.fillContent = toFixed(sumItem.fillContent);
  506. }
  507. }
  508. // 将sumItem的id赋值给modelId
  509. sumItem.modelId = sumItem.id;
  510. sumItem.pointName = sumItem.name;
  511. // 合并attrParams到sumItem中
  512. sumItem = Object.assign(sumItem, attrParams);
  513. });
  514. }
  515. if (rtem.nonSumList) {
  516. //
  517. rtem.nonSumList.map((nonSumItem) => {
  518. if (
  519. nonSumItem.fillContent == null ||
  520. nonSumItem.fillContent == ""
  521. ) {
  522. // console.log(
  523. // "🚀 ~ rtem.nonSumList.map ~ nonSumItem:",
  524. // nonSumItem
  525. // );
  526. // nonSumItem.fillContent = 0;
  527. } else {
  528. // 如果是double类型,保留两位小数
  529. if (nonSumItem.type == "double") {
  530. nonSumItem.fillContent = toFixed(nonSumItem.fillContent);
  531. }
  532. }
  533. nonSumItem.pointName = nonSumItem.name;
  534. // 将nonSumItem的id赋值给modelId
  535. nonSumItem.modelId = nonSumItem.id;
  536. // 合并attrParams到nonSumItem中
  537. nonSumItem = Object.assign(nonSumItem, attrParams);
  538. // 如果是enum类型,且description不为null,则根据description获取对应字典项数组,赋值给enumList
  539. if (nonSumItem.type == "enum" && nonSumItem.description) {
  540. console.log("🚀 ~ onSumItem.description:");
  541. const dictOptions =
  542. nonSumItem.name === "非生产原因"
  543. ? getIntDictOptions(nonSumItem.description)
  544. : getStrDictOptions(nonSumItem.description);
  545. nonSumItem.enumList = dictOptions.map((dict) => {
  546. return {
  547. ...dict,
  548. text: dict.label,
  549. };
  550. });
  551. // 确保 fillContent 的类型与 enumList 中的 value 类型匹配
  552. if (nonSumItem.name === "非生产原因") {
  553. // 如果是"非生产原因",将 fillContent 转换为数字类型以匹配 getIntDictOptions
  554. if (
  555. nonSumItem.fillContent !== null &&
  556. nonSumItem.fillContent !== ""
  557. ) {
  558. nonSumItem.fillContent = parseInt(nonSumItem.fillContent);
  559. }
  560. }
  561. console.log("🚀 ~ nonSumItem.enumList:", nonSumItem.enumList);
  562. }
  563. });
  564. }
  565. item.sumList = rtem.sumList;
  566. item.nonSumList = rtem.nonSumList;
  567. });
  568. console.log("resAttrs-modelId", resAttrs);
  569. }
  570. return item;
  571. });
  572. console.log("resList--", resList);
  573. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  574. paging.value.completeByNoMore(
  575. resList,
  576. pageNo * pageSize >= totalNum.value
  577. );
  578. // 如果加载的数据中包含生产日报,应用累加值
  579. const hasReport = resList.some((item) => item.deviceName === "生产日报");
  580. if (hasReport) {
  581. applyAccumulatedToReport();
  582. }
  583. })
  584. .catch((res) => {
  585. // 如果请求失败写paging.value.complete(false);
  586. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  587. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  588. paging.value.complete(false);
  589. });
  590. };
  591. /**
  592. * 检查累计公里数和运转时长限制(仅针对deptName为'rd'的公司)
  593. * @param item 需要检查的填报项
  594. * @param totalValue 累计值
  595. * @param maxIncrement 最大增量
  596. * @param itemName 项目名称
  597. */
  598. const rdThresholdExceededItems = ref([]);
  599. const checkRdThreshold = (item, totalValue, maxIncrement, itemName) => {
  600. if (deptName.value !== "rd") {
  601. return true; // 不是rd公司,跳过检查
  602. }
  603. if (!item.fillContent) {
  604. return true; // 没有填写内容,跳过检查
  605. }
  606. const fillValue = parseFloat(item.fillContent);
  607. const maxValue = totalValue + maxIncrement;
  608. if (fillValue > maxValue) {
  609. // 收集超限信息
  610. rdThresholdExceededItems.value.push({
  611. deviceCode: item.deviceCode,
  612. // deviceName: item.deviceName,
  613. itemName: itemName,
  614. maxValue: maxValue,
  615. currentValue: fillValue,
  616. });
  617. return false;
  618. }
  619. return true;
  620. };
  621. // 判断是否小于阈值 (<0)
  622. const checkLessThreshold = (item) => {
  623. if (item.fillContent < 0) {
  624. uni.showToast({
  625. title:
  626. item.name +
  627. t("operationRecordFilling.fillContentCannotLessThanThreshold") +
  628. "0",
  629. icon: "none",
  630. });
  631. item.fillContent = ""; // 清空输入
  632. return false; // 返回false表示校验失败
  633. }
  634. };
  635. // 判断是否大于阈值
  636. const checkThreshold = (item) => {
  637. checkLessThreshold(item);
  638. // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
  639. if (item.fillContent > item.threshold) {
  640. uni.showToast({
  641. title:
  642. item.name +
  643. t("operationRecordFilling.fillContentCannotGreaterThanThreshold") +
  644. item.threshold,
  645. icon: "none",
  646. });
  647. item.fillContent = ""; // 清空输入
  648. return false; // 返回false表示校验失败
  649. }
  650. };
  651. // 保留两位小数
  652. const toFixed = (num) => {
  653. if (num) {
  654. num = Number(num);
  655. num = num.toFixed(2);
  656. } else {
  657. num = 0.0;
  658. }
  659. return num;
  660. };
  661. const isSubmitting = ref(false); // 添加提交状态
  662. // const onSubmit = async () => {
  663. // // 清空之前的超限记录
  664. // rdThresholdExceededItems.value = [];
  665. // // console.log("onSubmit", dataList.value);
  666. // // 校验是否所有待填写项都已加载
  667. // if (dataList.value.length < totalNum) {
  668. // uni.showToast({
  669. // title: t("operationRecordFilling.PleaseLoadAllItems"),
  670. // icon: "none",
  671. // });
  672. // return; // 校验失败直接返回
  673. // }
  674. // // 1. 校验所有必填项
  675. // // 遍历dataList.value中nonSumList每个item(非生产日报 isReport!=1)的fillContent字段,
  676. // // 如果为null或者为空,则提示用户填写,
  677. // // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
  678. // // 如果所有项全部填写,则调用填写记录接口
  679. // for (const item of dataList.value) {
  680. // const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  681. // // 查找当日运转时间H项目
  682. // const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
  683. // const isRuntime24 =
  684. // runtimeItem &&
  685. // (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
  686. // for (const nonSumItem of nonSumList) {
  687. // // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
  688. // const isExemptField =
  689. // isRuntime24 &&
  690. // (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
  691. // if (
  692. // (!item.isReport || item.isReport != 1) &&
  693. // !isExemptField &&
  694. // (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
  695. // ) {
  696. // uni.showToast({
  697. // title:
  698. // t("operation.PleaseFillIn") +
  699. // item.deviceCode +
  700. // "(" +
  701. // item.deviceName +
  702. // ")" +
  703. // t("operation.allItem"),
  704. // icon: "none",
  705. // });
  706. // return; // 校验失败直接返回
  707. // }
  708. // if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
  709. // console.log("🚀 ~ nonSumItem:", nonSumItem);
  710. // console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
  711. // // 先将值转换为字符串进行操作
  712. // const fillContentStr = String(nonSumItem.fillContent);
  713. // // 将字符串转换为数字
  714. // const num = Number(fillContentStr);
  715. // // 检查转换后的数字是否有效
  716. // if (!isNaN(num)) {
  717. // // 检查是否包含小数(使用字符串检查)
  718. // if (fillContentStr.includes(".")) {
  719. // // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
  720. // nonSumItem.fillContent = toFixed(num);
  721. // } else {
  722. // // 转换为整数
  723. // nonSumItem.fillContent = Math.floor(num);
  724. // }
  725. // }
  726. // // **********************
  727. // // 新增:针对rd公司的特殊阈值检查
  728. // // 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
  729. // if (nonSumItem.name.includes("累计公里数填报")) {
  730. // const correspondingSumItem = item.sumList.find((sumItem) =>
  731. // sumItem.name.includes("累计公里数")
  732. // );
  733. // if (correspondingSumItem) {
  734. // const totalKm = parseFloat(correspondingSumItem.totalRunTime) || 0;
  735. // checkRdThreshold(nonSumItem, totalKm, 3000, nonSumItem.name);
  736. // }
  737. // }
  738. // // 检查包含"累计运转时长填报"的字段不能超过对应"累计运转时长"字段 + 100
  739. // else if (nonSumItem.name.includes("累计运转时长填报")) {
  740. // const correspondingSumItem = item.sumList.find((sumItem) =>
  741. // sumItem.name.includes("累计运转时长")
  742. // );
  743. // if (correspondingSumItem) {
  744. // const totalRunTime =
  745. // parseFloat(correspondingSumItem.totalRunTime) || 0;
  746. // checkRdThreshold(nonSumItem, totalRunTime, 100, nonSumItem.name);
  747. // }
  748. // }
  749. // }
  750. // // 如果threshold > 0,则判断fillContent是否大于threshold
  751. // if (nonSumItem.threshold > 0) {
  752. // if (nonSumItem.fillContent > nonSumItem.threshold) {
  753. // uni.showToast({
  754. // title:
  755. // item.deviceCode +
  756. // "(" +
  757. // item.deviceName +
  758. // ")" +
  759. // nonSumItem.name +
  760. // t(
  761. // "operationRecordFilling.fillContentCannotGreaterThanThreshold"
  762. // ) +
  763. // nonSumItem.threshold,
  764. // icon: "none",
  765. // duration: 3000,
  766. // });
  767. // nonSumItem.fillContent = ""; // 清空输入
  768. // return; // 校验失败直接返回
  769. // }
  770. // }
  771. // }
  772. // }
  773. // // 检查是否有超限的项目,如果有则统一显示
  774. // if (rdThresholdExceededItems.value.length > 0) {
  775. // const exceededInfo = rdThresholdExceededItems.value
  776. // .map(
  777. // (item, index) =>
  778. // `${index + 1}. ${item.deviceCode} ${item.itemName}不能超过${
  779. // item.maxValue
  780. // },当前值为${item.currentValue}`
  781. // )
  782. // .join("\n");
  783. // uni.showModal({
  784. // title: "阈值超限提示",
  785. // content: `以下项目超过阈值限制:\n${exceededInfo}\n\n是否继续保存?`,
  786. // showCancel: true,
  787. // cancelText: "取消",
  788. // confirmText: "继续",
  789. // success: (res) => {
  790. // if (res.confirm) {
  791. // // 用户选择继续,执行保存操作
  792. // submitData();
  793. // } else if (res.cancel) {
  794. // // 用户选择取消,不执行保存
  795. // return;
  796. // }
  797. // },
  798. // });
  799. // return;
  800. // }
  801. // // 如果没有超限项目,直接执行保存
  802. // submitData();
  803. // };
  804. // 修改 onSubmit 方法
  805. // const onSubmit = async () => {
  806. // // 校验是否所有待填写项都已加载
  807. // if (dataList.value.length < totalNum) {
  808. // uni.showToast({
  809. // title: t("operationRecordFilling.PleaseLoadAllItems"),
  810. // icon: "none",
  811. // });
  812. // return; // 校验失败直接返回,不设置按钮禁用
  813. // }
  814. // // 1. 校验所有必填项 - 在这里进行所有基础校验
  815. // for (const item of dataList.value) {
  816. // const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  817. // // 查找当日运转时间H项目
  818. // const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
  819. // const isRuntime24 =
  820. // runtimeItem &&
  821. // (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
  822. // for (const nonSumItem of nonSumList) {
  823. // // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
  824. // const isExemptField =
  825. // isRuntime24 &&
  826. // (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
  827. // if (
  828. // (!item.isReport || item.isReport != 1) &&
  829. // !isExemptField &&
  830. // (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
  831. // ) {
  832. // uni.showToast({
  833. // title:
  834. // t("operation.PleaseFillIn") +
  835. // item.deviceCode +
  836. // "(" +
  837. // item.deviceName +
  838. // ")" +
  839. // t("operation.allItem"),
  840. // icon: "none",
  841. // });
  842. // return; // 校验失败直接返回,不设置按钮禁用
  843. // }
  844. // // 如果threshold > 0,则判断fillContent是否大于threshold
  845. // if (nonSumItem.threshold > 0) {
  846. // if (nonSumItem.fillContent > nonSumItem.threshold) {
  847. // uni.showToast({
  848. // title:
  849. // item.deviceCode +
  850. // "(" +
  851. // item.deviceName +
  852. // ")" +
  853. // nonSumItem.name +
  854. // t(
  855. // "operationRecordFilling.fillContentCannotGreaterThanThreshold"
  856. // ) +
  857. // nonSumItem.threshold,
  858. // icon: "none",
  859. // duration: 3000,
  860. // });
  861. // nonSumItem.fillContent = ""; // 清空输入
  862. // return; // 校验失败直接返回,不设置按钮禁用
  863. // }
  864. // }
  865. // }
  866. // }
  867. // // 检查是否有超限的项目,如果有则统一显示
  868. // if (rdThresholdExceededItems.value.length > 0) {
  869. // const exceededInfo = rdThresholdExceededItems.value
  870. // .map(
  871. // (item, index) =>
  872. // `${index + 1}. ${item.deviceCode} ${item.itemName}不能超过${
  873. // item.maxValue
  874. // },当前值为${item.currentValue}`
  875. // )
  876. // .join("\n");
  877. // uni.showModal({
  878. // title: "阈值超限提示",
  879. // content: `以下项目超过阈值限制:\n${exceededInfo}\n\n是否继续保存?`,
  880. // showCancel: true,
  881. // cancelText: "取消",
  882. // confirmText: "继续",
  883. // success: (res) => {
  884. // if (res.confirm) {
  885. // // 用户选择继续,执行保存操作,此时才设置按钮禁用
  886. // submitDataWithDisable();
  887. // } else if (res.cancel) {
  888. // // 用户选择取消,不执行保存
  889. // return;
  890. // }
  891. // },
  892. // });
  893. // return;
  894. // }
  895. // // 所有基础校验通过后,才设置提交状态并执行提交
  896. // submitDataWithDisable();
  897. // };
  898. const onSubmit = async () => {
  899. // 清空之前的超限记录
  900. rdThresholdExceededItems.value = [];
  901. // 校验是否所有待填写项都已加载
  902. if (dataList.value.length < totalNum) {
  903. uni.showToast({
  904. title: t("operationRecordFilling.PleaseLoadAllItems"),
  905. icon: "none",
  906. });
  907. return; // 校验失败直接返回,不设置按钮禁用
  908. }
  909. // 1. 校验所有必填项 - 在这里进行所有基础校验
  910. for (const item of dataList.value) {
  911. const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  912. // 查找当日运转时间H项目
  913. const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
  914. const isRuntime24 =
  915. runtimeItem &&
  916. (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
  917. for (const nonSumItem of nonSumList) {
  918. // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
  919. const isExemptField =
  920. isRuntime24 &&
  921. (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
  922. if (
  923. (!item.isReport || item.isReport != 1) &&
  924. !isExemptField &&
  925. (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
  926. ) {
  927. uni.showToast({
  928. title:
  929. t("operation.PleaseFillIn") +
  930. item.deviceCode +
  931. "(" +
  932. item.deviceName +
  933. ")" +
  934. t("operation.allItem"),
  935. icon: "none",
  936. });
  937. return; // 校验失败直接返回,不设置按钮禁用
  938. }
  939. // 如果threshold > 0,则判断fillContent是否大于threshold
  940. if (nonSumItem.threshold > 0) {
  941. if (nonSumItem.fillContent > nonSumItem.threshold) {
  942. uni.showToast({
  943. title:
  944. item.deviceCode +
  945. "(" +
  946. item.deviceName +
  947. ")" +
  948. nonSumItem.name +
  949. t(
  950. "operationRecordFilling.fillContentCannotGreaterThanThreshold"
  951. ) +
  952. nonSumItem.threshold,
  953. icon: "none",
  954. duration: 3000,
  955. });
  956. nonSumItem.fillContent = ""; // 清空输入
  957. return; // 校验失败直接返回,不设置按钮禁用
  958. }
  959. }
  960. }
  961. }
  962. // 检查是否有超限的项目,如果有则统一显示
  963. // 需要在基础校验通过后,执行rd特殊阈值检查
  964. // 重新检查rd特殊阈值
  965. for (const item of dataList.value) {
  966. const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  967. for (const nonSumItem of nonSumList) {
  968. if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
  969. // **********************
  970. // 新增:针对rd公司的特殊阈值检查
  971. // 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
  972. if (nonSumItem.name.includes("累计公里数填报")) {
  973. const correspondingSumItem = item.sumList.find((sumItem) =>
  974. sumItem.name.includes("累计公里数")
  975. );
  976. if (correspondingSumItem) {
  977. const totalKm = parseFloat(correspondingSumItem.totalRunTime) || 0;
  978. checkRdThreshold(nonSumItem, totalKm, 3000, nonSumItem.name);
  979. }
  980. }
  981. // 检查包含"累计运转时长填报"的字段不能超过对应"累计运转时长"字段 + 100
  982. else if (nonSumItem.name.includes("累计运转时长填报")) {
  983. const correspondingSumItem = item.sumList.find((sumItem) =>
  984. sumItem.name.includes("累计运转时长")
  985. );
  986. if (correspondingSumItem) {
  987. const totalRunTime =
  988. parseFloat(correspondingSumItem.totalRunTime) || 0;
  989. checkRdThreshold(nonSumItem, totalRunTime, 100, nonSumItem.name);
  990. }
  991. }
  992. }
  993. }
  994. }
  995. // 检查是否有超限的项目,如果有则统一显示
  996. if (rdThresholdExceededItems.value.length > 0) {
  997. const exceededInfo = rdThresholdExceededItems.value
  998. .map(
  999. (item, index) =>
  1000. `${index + 1}. ${item.deviceCode} ${item.itemName}不能超过${
  1001. item.maxValue
  1002. },当前值为${item.currentValue}`
  1003. )
  1004. .join("\n");
  1005. uni.showModal({
  1006. title: "阈值超限提示",
  1007. content: `以下项目超过阈值限制:\n${exceededInfo}\n\n是否继续保存?`,
  1008. showCancel: true,
  1009. cancelText: "取消",
  1010. confirmText: "继续",
  1011. success: (res) => {
  1012. if (res.confirm) {
  1013. // 用户选择继续,执行保存操作,此时才设置按钮禁用
  1014. submitDataWithDisable();
  1015. } else if (res.cancel) {
  1016. // 用户选择取消,不执行保存
  1017. return;
  1018. }
  1019. },
  1020. });
  1021. return;
  1022. }
  1023. // 所有基础校验通过后,才设置提交状态并执行提交
  1024. submitDataWithDisable();
  1025. };
  1026. // 新增一个带禁用状态的提交方法
  1027. const submitDataWithDisable = async () => {
  1028. // 如果正在提交,直接返回
  1029. if (isSubmitting.value) {
  1030. return;
  1031. }
  1032. // 设置提交状态为 true,禁用按钮
  1033. isSubmitting.value = true;
  1034. try {
  1035. // 处理数据内容的校验和格式化
  1036. for (const item of dataList.value) {
  1037. const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  1038. for (const nonSumItem of nonSumList) {
  1039. if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
  1040. console.log("🚀 ~ nonSumItem:", nonSumItem);
  1041. console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
  1042. // 先将值转换为字符串进行操作
  1043. const fillContentStr = String(nonSumItem.fillContent);
  1044. // 将字符串转换为数字
  1045. const num = Number(fillContentStr);
  1046. // 检查转换后的数字是否有效
  1047. if (!isNaN(num)) {
  1048. // 检查是否包含小数(使用字符串检查)
  1049. if (fillContentStr.includes(".")) {
  1050. // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
  1051. nonSumItem.fillContent = toFixed(num);
  1052. } else {
  1053. // 转换为整数
  1054. nonSumItem.fillContent = Math.floor(num);
  1055. }
  1056. }
  1057. // **********************
  1058. // 新增:针对rd公司的特殊阈值检查
  1059. // 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
  1060. if (nonSumItem.name.includes("累计公里数填报")) {
  1061. const correspondingSumItem = item.sumList.find((sumItem) =>
  1062. sumItem.name.includes("累计公里数")
  1063. );
  1064. if (correspondingSumItem) {
  1065. const totalKm =
  1066. parseFloat(correspondingSumItem.totalRunTime) || 0;
  1067. checkRdThreshold(nonSumItem, totalKm, 3000, nonSumItem.name);
  1068. }
  1069. }
  1070. // 检查包含"累计运转时长填报"的字段不能超过对应"累计运转时长"字段 + 100
  1071. else if (nonSumItem.name.includes("累计运转时长填报")) {
  1072. const correspondingSumItem = item.sumList.find((sumItem) =>
  1073. sumItem.name.includes("累计运转时长")
  1074. );
  1075. if (correspondingSumItem) {
  1076. const totalRunTime =
  1077. parseFloat(correspondingSumItem.totalRunTime) || 0;
  1078. checkRdThreshold(nonSumItem, totalRunTime, 100, nonSumItem.name);
  1079. }
  1080. }
  1081. }
  1082. }
  1083. }
  1084. // 执行实际的数据提交
  1085. await submitData();
  1086. } catch (error) {
  1087. console.error("保存失败", error);
  1088. // 启用按钮
  1089. isSubmitting.value = false;
  1090. uni.showToast({
  1091. title: t("operation.fail"),
  1092. icon: "none",
  1093. });
  1094. }
  1095. };
  1096. // 修改 submitData 方法,使其返回 Promise
  1097. const submitData = async () => {
  1098. try {
  1099. // 定义新的dataList副本 用于提交数据,避免修改原数据
  1100. const subDataList = JSON.parse(JSON.stringify(dataList.value));
  1101. // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
  1102. for (const item of subDataList) {
  1103. // 先判断 item.nonSumList 存在,避免空指针
  1104. if (item.nonSumList && item.nonSumList.length) {
  1105. for (const nonSumItem of item.nonSumList) {
  1106. if (nonSumItem.enumList) {
  1107. delete nonSumItem.enumList;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. console.log("处理提交用的副本数据:subDataList", subDataList);
  1113. // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
  1114. const submitList = subDataList.map((item) => ({
  1115. deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
  1116. }));
  1117. console.log("提交用的数据:submitList", submitList);
  1118. // 3. 提交所有填写记录
  1119. const res = await recordFillingDetailInsertDataList(submitList);
  1120. console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
  1121. if (res?.code === 0) {
  1122. // 3. 调用更新工单状态接口
  1123. const upRes = await recordFillingUpOperationOrder({
  1124. id: params.value.orderId,
  1125. });
  1126. console.log("🚀 ~ upRes:", upRes);
  1127. if (upRes?.code === 0) {
  1128. console.log("工单状态更新成功");
  1129. uni.showToast({
  1130. title: t("operation.success"),
  1131. duration: 1500,
  1132. icon: "none",
  1133. });
  1134. // 成功后延迟跳转,不启用按钮
  1135. setTimeout(() => {
  1136. uni.navigateBack();
  1137. }, 1500);
  1138. // 注意:这里不设置 isSubmitting.value = false,因为成功后会跳转页面
  1139. return; // 成功完成,直接返回
  1140. } else {
  1141. console.error("工单状态更新失败", upRes);
  1142. throw new Error("工单状态更新失败"); // 抛出错误,让 catch 处理
  1143. }
  1144. } else {
  1145. throw new Error("提交失败"); // 抛出错误,让 catch 处理
  1146. }
  1147. } catch (error) {
  1148. console.error("保存失败", error);
  1149. // 启用按钮,让用户可以重试
  1150. isSubmitting.value = false;
  1151. uni.showToast({
  1152. title: t("operation.fail"),
  1153. icon: "none",
  1154. });
  1155. throw error; // 重新抛出错误
  1156. }
  1157. };
  1158. // 将原来的保存逻辑提取到单独函数中
  1159. // const submitData = async () => {
  1160. // // 定义新的dataList副本 用于提交数据,避免修改原数据
  1161. // const subDataList = JSON.parse(JSON.stringify(dataList.value));
  1162. // // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
  1163. // for (const item of subDataList) {
  1164. // // 先判断 item.nonSumList 存在,避免空指针
  1165. // if (item.nonSumList && item.nonSumList.length) {
  1166. // for (const nonSumItem of item.nonSumList) {
  1167. // if (nonSumItem.enumList) {
  1168. // delete nonSumItem.enumList;
  1169. // }
  1170. // }
  1171. // }
  1172. // }
  1173. // console.log("处理提交用的副本数据:subDataList", subDataList);
  1174. // // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
  1175. // const submitList = subDataList.map((item) => ({
  1176. // deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
  1177. // }));
  1178. // console.log("提交用的数据:submitList", submitList);
  1179. // // 3. 提交所有填写记录
  1180. // await recordFillingDetailInsertDataList(submitList)
  1181. // .then(async (res) => {
  1182. // console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
  1183. // if (res?.code === 0) {
  1184. // // 3. 调用更新工单状态接口
  1185. // const upRes = await recordFillingUpOperationOrder({
  1186. // id: params.value.orderId,
  1187. // });
  1188. // console.log("🚀 ~ upRes:", upRes);
  1189. // if (upRes?.code === 0) {
  1190. // console.log("工单状态更新成功");
  1191. // uni.showToast({
  1192. // title: t("operation.success"),
  1193. // duration: 1500,
  1194. // icon: "none",
  1195. // });
  1196. // setTimeout(() => {
  1197. // uni.navigateBack();
  1198. // }, 1500);
  1199. // } else {
  1200. // console.error("工单状态更新失败", upRes);
  1201. // uni.showToast({
  1202. // title: t("operation.fail"),
  1203. // icon: "none",
  1204. // });
  1205. // }
  1206. // } else {
  1207. // uni.showToast({
  1208. // title: t("operation.fail"),
  1209. // icon: "none",
  1210. // });
  1211. // }
  1212. // })
  1213. // .catch((error) => {
  1214. // console.error("保存失败", error);
  1215. // uni.showToast({
  1216. // title: t("operation.fail"),
  1217. // icon: "error",
  1218. // });
  1219. // });
  1220. // };
  1221. </script>
  1222. <style lang="scss" scoped>
  1223. .page {
  1224. padding: 0;
  1225. box-sizing: border-box;
  1226. }
  1227. .top {
  1228. padding: 10px;
  1229. }
  1230. .list {
  1231. // margin-top: calc(10px);
  1232. padding: 10px;
  1233. // height: calc(100%);
  1234. }
  1235. .item {
  1236. width: 100%;
  1237. // height: 204px;
  1238. background: #ffffff;
  1239. border-radius: 6px;
  1240. margin-bottom: 10px;
  1241. box-sizing: border-box;
  1242. padding: 20px 15px;
  1243. }
  1244. .item-module {
  1245. width: 100%;
  1246. height: 16px;
  1247. position: relative;
  1248. font-weight: 600;
  1249. font-size: 14px;
  1250. color: #333333;
  1251. margin-bottom: 10px;
  1252. .module-border {
  1253. position: absolute;
  1254. left: -15px;
  1255. width: 0px;
  1256. height: 12px;
  1257. border: 1px solid #004098;
  1258. }
  1259. }
  1260. .item-content {
  1261. position: relative;
  1262. width: 100%;
  1263. // height: calc(38px);
  1264. box-sizing: border-box;
  1265. font-weight: 500;
  1266. font-size: 14px;
  1267. color: #333333;
  1268. line-height: 20px;
  1269. border-bottom: 1px dashed #cacccf;
  1270. &:last-child {
  1271. border-bottom: none;
  1272. }
  1273. &.bold {
  1274. font-weight: 600;
  1275. // :deep(.uni-easyinput__content-input){
  1276. // padding-right: 0 !important;
  1277. // }
  1278. }
  1279. &.bottom-bold {
  1280. border-bottom: 1px dashed #cacccf;
  1281. }
  1282. }
  1283. .item-title {
  1284. position: relative;
  1285. min-height: 38px;
  1286. width: 55%;
  1287. &.total {
  1288. :deep(.is-disabled) {
  1289. color: #333333 !important;
  1290. }
  1291. }
  1292. &.full-cell {
  1293. width: 100%;
  1294. min-width: max-content;
  1295. }
  1296. }
  1297. .item-value {
  1298. width: 45%;
  1299. position: relative;
  1300. &.textarea {
  1301. width: 65%;
  1302. }
  1303. }
  1304. .word-break-all {
  1305. min-width: unset;
  1306. }
  1307. :deep(.uni-select) {
  1308. border: none;
  1309. text-align: right;
  1310. padding-right: 0;
  1311. .uniui-bottom:before {
  1312. content: "\e6b5" !important;
  1313. font-size: 16px !important;
  1314. }
  1315. }
  1316. :deep(.uni-select__input-text) {
  1317. text-align: right;
  1318. .align-left {
  1319. text-align: right;
  1320. }
  1321. }
  1322. :deep(.uni-select--disabled) {
  1323. color: #d5d5d5 !important;
  1324. background-color: transparent;
  1325. .uni-select__input-text {
  1326. color: #d5d5d5 !important;
  1327. }
  1328. }
  1329. :deep(.uni-select__selector) {
  1330. text-align: left;
  1331. }
  1332. :deep(.uni-select__selector-item) {
  1333. border-bottom: 1px dashed #cacccf;
  1334. text-align: left;
  1335. }
  1336. :deep(.uni-easyinput__content-textarea) {
  1337. min-height: inherit;
  1338. margin: 10px;
  1339. }
  1340. </style>