detail.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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"
  169. v-if="isView"
  170. >
  171. {{ $t("operation.save") }}
  172. </button>
  173. </template>
  174. </z-paging>
  175. </template>
  176. <script setup>
  177. import { getDeptId } from "@/utils/auth.js";
  178. import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
  179. import { onReady, onLoad } from "@dcloudio/uni-app";
  180. import dayjs from "dayjs";
  181. import {
  182. getRecordFillingDetailGetPage,
  183. getRecordFillingDetailGetAttrs,
  184. recordFillingDetailInsertLog,
  185. getRecordFillingDetail,
  186. recordFillingUpOperationOrder,
  187. recordFillingDetailGetPageAndAttrs,
  188. recordFillingDetailInsertDataList,
  189. getDeptName,
  190. } from "@/api/recordFilling";
  191. import { getUserId, reloginByUserId } from "@/utils/auth.js";
  192. import { useDataDictStore } from "@/store/modules/dataDict";
  193. // 引用全局变量$t
  194. const { appContext } = getCurrentInstance();
  195. const t = appContext.config.globalProperties.$t;
  196. // 获取字典项
  197. const { getStrDictOptions, getIntDictOptions } = useDataDictStore();
  198. // -------------------------------------
  199. const isFromMsg = ref(false);
  200. const params = ref({});
  201. const isView = ref(false); // 是否编辑 -- view == 1为编辑状态
  202. let deptName = ref("");
  203. // 累加状态对象,用于在生产日报加载前存储累加值
  204. const accumulatedValues = reactive({
  205. "当日注水量-方": 0,
  206. 当日用电量kWh: 0,
  207. 当日运转时间H: 0,
  208. "当日注气量-方": 0,
  209. });
  210. onMounted(() => {
  211. getDeptName(getDeptId()).then((res) => {
  212. deptName.value = res.data;
  213. });
  214. });
  215. onReady(() => {
  216. console.log("onReady");
  217. });
  218. onLoad(async (option) => {
  219. console.log("onLoad", option);
  220. await reloginByUserId(option.reloginUserId);
  221. isFromMsg.value = !!option.reloginUserId;
  222. // 初始化params
  223. params.value = JSON.parse(option.param);
  224. // 处理createTime
  225. params.value.createTime = params.value.createTime
  226. ? dayjs(Number.parseInt(params.value.createTime)).format("YYYY-MM-DD")
  227. : "";
  228. // 请求工单详情
  229. if (params.value?.orderId) {
  230. const detail = (await getRecordFillingDetail(params.value.orderId)).data;
  231. console.log("🚀getRecordFillingDetail ~ detail:", detail);
  232. params.value = {
  233. ...params.value,
  234. ...detail,
  235. // 处理createTime
  236. createTime: detail.createTime
  237. ? dayjs(Number.parseInt(detail.createTime)).format("YYYY-MM-DD")
  238. : "",
  239. orderId: detail.id,
  240. };
  241. }
  242. console.log("🚀 ~ params.value:", params.value);
  243. // 处理是否可编辑 {0: '待填写', 1: '已完成', 2: '填写中', 3: '忽略'}
  244. isView.value = params.value?.orderStatus % 2 == 0;
  245. console.log("🚀 ~ isView.value:", isView.value);
  246. });
  247. const paging = ref(null);
  248. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  249. const dataList = ref([]);
  250. // 列表总数
  251. const totalNum = ref(0);
  252. // 监听dataList变化,初始化时计算一次总和
  253. watch(
  254. dataList,
  255. (newVal) => {
  256. // calculateTotalRunTime();
  257. },
  258. { deep: true }
  259. );
  260. // 处理fillContent变化的方法
  261. const handleFillContentChange = (nosum, deviceItem) => {
  262. console.log("🚀 ~ nosum, deviceItem:", nosum, deviceItem);
  263. // 处理增压机
  264. if (
  265. deviceItem.deviceName.includes("增压机") &&
  266. nosum.name === "当日运转时间"
  267. ) {
  268. calculateTotalRunTime("增压机", "当日运转时间"); // 计算当日运转时间总和
  269. }
  270. // 处理提纯撬
  271. if (deviceItem.deviceName.includes("提纯撬") && nosum.name === "当日注气量") {
  272. calculateTotalRunTime("提纯撬", "当日注气量"); // 计算当日注气量总和
  273. }
  274. // 处理注水泵
  275. if (deviceItem.deviceName.includes("注水泵") && nosum.name === "当日注水量") {
  276. calculateTotalRunTime("注水泵", "当日注水量"); // 计算当日注水量总和
  277. }
  278. // 处理箱式变电站
  279. if (
  280. deviceItem.deviceName.includes("箱式变电站") &&
  281. nosum.name === "当日用电量"
  282. ) {
  283. calculateTotalRunTime("箱式变电站", "当日用电量"); // 计算当日用电量总和
  284. }
  285. };
  286. // 防抖函数
  287. function debounce(func, delay) {
  288. let timer;
  289. return function (...args) {
  290. clearTimeout(timer);
  291. timer = setTimeout(() => func.apply(this, args), delay);
  292. };
  293. }
  294. //防抖
  295. const debouncedCalculateTotalRunTime = debounce(calculateTotalRunTime, 100);
  296. const debouncedApplyAccumulatedToReport = debounce(
  297. applyAccumulatedToReport,
  298. 100
  299. );
  300. /**
  301. * 更新累加值
  302. * @param fieldName 字段名
  303. * @param deviceType 设备类型
  304. */
  305. const updateAccumulatedValue = (fieldName, deviceType) => {
  306. let total = 0;
  307. dataList.value.forEach((item) => {
  308. if (item.deviceName.includes(deviceType) && item.nonSumList) {
  309. item.nonSumList.forEach((nonSum) => {
  310. if (
  311. nonSum.type === "double" &&
  312. nonSum.name === fieldName &&
  313. nonSum.fillContent !== null &&
  314. nonSum.fillContent !== ""
  315. ) {
  316. const value = parseFloat(nonSum.fillContent) || 0;
  317. total += value;
  318. }
  319. });
  320. }
  321. });
  322. accumulatedValues[fieldName] = total;
  323. };
  324. /**
  325. * 重新计算所有累加值
  326. */
  327. const recalculateAllAccumulatedValues = () => {
  328. const fields = [
  329. { field: "当日运转时间H", device: "增压机" },
  330. { field: "当日注气量-方", device: "提纯撬" },
  331. { field: "当日注水量-方", device: "注水泵" },
  332. { field: "当日用电量kWh", device: "箱式变电站" },
  333. ];
  334. fields.forEach(({ field, device }) => {
  335. updateAccumulatedValue(field, device);
  336. });
  337. };
  338. /**
  339. * 将累加值应用到生产日报
  340. */
  341. function applyAccumulatedToReport() {
  342. // 先重新计算所有累加值
  343. recalculateAllAccumulatedValues();
  344. const reportItem = dataList.value.find(
  345. (item) => item.deviceName === "生产日报"
  346. );
  347. if (!reportItem) {
  348. console.warn("⚠️ 未找到生产日报,累加值已存储,等待加载");
  349. return;
  350. }
  351. Object.keys(accumulatedValues).forEach((fieldName) => {
  352. const targetItem = reportItem.nonSumList.find(
  353. (item) => item.name === fieldName
  354. );
  355. if (targetItem) {
  356. console.log(
  357. `📊 应用累加值 (${fieldName}):`,
  358. accumulatedValues[fieldName]
  359. );
  360. targetItem.fillContent = toFixed(accumulatedValues[fieldName]);
  361. }
  362. });
  363. }
  364. const handleRealTimeUpdate = (nosum, deviceItem) => {
  365. console.log("🚀 实时更新 ~ nosum, deviceItem:", nosum, deviceItem);
  366. let fieldName = "";
  367. let deviceType = "";
  368. // 当日运转时间累加
  369. if (
  370. deviceItem.deviceName.includes("增压机") &&
  371. nosum.name === "当日运转时间H"
  372. ) {
  373. fieldName = "当日运转时间H";
  374. deviceType = "增压机";
  375. }
  376. // 当日注气量累加
  377. if (
  378. deviceItem.deviceName.includes("提纯撬") &&
  379. nosum.name === "当日注气量-方"
  380. ) {
  381. fieldName = "当日注气量-方";
  382. deviceType = "提纯撬";
  383. }
  384. // 当日注水量累加
  385. if (
  386. deviceItem.deviceName.includes("注水泵") &&
  387. nosum.name === "当日注水量-方"
  388. ) {
  389. fieldName = "当日注水量-方";
  390. deviceType = "注水泵";
  391. }
  392. // 当日用电量累加
  393. if (
  394. deviceItem.deviceName.includes("箱式变电站") &&
  395. nosum.name === "当日用电量kWh"
  396. ) {
  397. fieldName = "当日用电量kWh";
  398. deviceType = "箱式变电站";
  399. }
  400. if (fieldName) {
  401. // 更新累加值
  402. updateAccumulatedValue(fieldName, deviceType);
  403. // 应用到生产日报(如果已加载)
  404. debouncedApplyAccumulatedToReport();
  405. }
  406. };
  407. /**
  408. * 计算所有deviceName中包含deviceNameToMatch的对象中对应的reportName的fillContent总和并更新到reportName的fillContent中
  409. * @param deviceNameToMatch {string} 设备名称包含的字符串
  410. * @param reportName {string} 填写项名称
  411. */
  412. function calculateTotalRunTime(
  413. deviceNameToMatch,
  414. sourceFieldName,
  415. targetFieldName
  416. ) {
  417. const reportItem = dataList.value.find(
  418. (item) => item.deviceName === "生产日报"
  419. );
  420. if (!reportItem) {
  421. console.warn("⚠️ 未找到生产日报");
  422. return;
  423. }
  424. const targetItem = reportItem.nonSumList.find(
  425. (item) => item.name === targetFieldName
  426. );
  427. if (!targetItem) {
  428. console.warn(`⚠️ 未找到目标字段:${targetFieldName}`);
  429. return;
  430. }
  431. let total = 0;
  432. dataList.value.forEach((item) => {
  433. if (item.deviceName.includes(deviceNameToMatch) && item.nonSumList) {
  434. item.nonSumList.forEach((nonSum) => {
  435. if (
  436. nonSum.type === "double" &&
  437. nonSum.name === sourceFieldName &&
  438. nonSum.fillContent !== null &&
  439. nonSum.fillContent !== ""
  440. ) {
  441. const value = parseFloat(nonSum.fillContent) || 0;
  442. total += value;
  443. }
  444. });
  445. }
  446. });
  447. console.log(`📊 累计值 (${sourceFieldName} -> ${targetFieldName}):`, total);
  448. targetItem.fillContent = toFixed(total);
  449. }
  450. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  451. const queryList = (pageNo, pageSize) => {
  452. const userId = uni.getStorageSync("userId");
  453. if (!userId) {
  454. paging.value.complete([]);
  455. return;
  456. }
  457. // 请求填报设备及属性
  458. recordFillingDetailGetPageAndAttrs({
  459. pageNo,
  460. pageSize,
  461. orderId: params.value.orderId,
  462. // deviceCategoryId: 1,
  463. })
  464. .then(async (res) => {
  465. console.log("🚀 ~ res:", res);
  466. const { data } = res;
  467. const resList = [].concat(data.list);
  468. // 列表总数
  469. totalNum.value = data.total;
  470. // 遍历列表,处理attrsDetail
  471. resList.map(async (item) => {
  472. const attrParams = {
  473. deviceCode: item.deviceCode,
  474. deviceName: item.deviceName,
  475. deptId: item.deptId,
  476. createTime: params.value.createTime,
  477. deviceCategoryId: item.deviceCategoryId,
  478. deviceId: item.deviceId,
  479. userId: params.value.userId,
  480. orderId: params.value.orderId,
  481. };
  482. // console.log(
  483. // "getRecordFillingDetailGetAttrs- attrParams",
  484. // attrParams
  485. // );
  486. const resAttrs = item?.attrsDetail;
  487. // console.log("resAttrs", resAttrs);
  488. if (resAttrs) {
  489. attrParams.createTime = attrParams.createTime
  490. ? dayjs(attrParams.createTime).format("YYYY-MM-DD")
  491. : "";
  492. attrParams.id = attrParams.orderId;
  493. delete attrParams.orderId;
  494. delete attrParams.deviceName;
  495. resAttrs.map((rtem) => {
  496. // 将rtem中sumList和nonSumList两个数组中的
  497. // fillContent字段判断是否为null, 如果为null,则赋值为0 不为null则保留两位小数
  498. // 将attrParams合并到两个数组的每个对象中
  499. // 然后将sumList和nonSumList分别赋值给item的sumList和nonSumList
  500. if (rtem.sumList) {
  501. rtem.sumList.map((sumItem) => {
  502. if (sumItem.fillContent == null || sumItem.fillContent == "") {
  503. // console.log("🚀 ~ rtem.sumList.map ~ sumItem:", sumItem);
  504. // sumItem.fillContent = 0;
  505. } else {
  506. // 如果是double类型,保留两位小数
  507. if (sumItem.type == "double") {
  508. sumItem.fillContent = toFixed(sumItem.fillContent);
  509. }
  510. }
  511. // 将sumItem的id赋值给modelId
  512. sumItem.modelId = sumItem.id;
  513. sumItem.pointName = sumItem.name;
  514. // 合并attrParams到sumItem中
  515. sumItem = Object.assign(sumItem, attrParams);
  516. });
  517. }
  518. if (rtem.nonSumList) {
  519. //
  520. rtem.nonSumList.map((nonSumItem) => {
  521. if (
  522. nonSumItem.fillContent == null ||
  523. nonSumItem.fillContent == ""
  524. ) {
  525. // console.log(
  526. // "🚀 ~ rtem.nonSumList.map ~ nonSumItem:",
  527. // nonSumItem
  528. // );
  529. // nonSumItem.fillContent = 0;
  530. } else {
  531. // 如果是double类型,保留两位小数
  532. if (nonSumItem.type == "double") {
  533. nonSumItem.fillContent = toFixed(nonSumItem.fillContent);
  534. }
  535. }
  536. nonSumItem.pointName = nonSumItem.name;
  537. // 将nonSumItem的id赋值给modelId
  538. nonSumItem.modelId = nonSumItem.id;
  539. // 合并attrParams到nonSumItem中
  540. nonSumItem = Object.assign(nonSumItem, attrParams);
  541. // 如果是enum类型,且description不为null,则根据description获取对应字典项数组,赋值给enumList
  542. if (nonSumItem.type == "enum" && nonSumItem.description) {
  543. console.log("🚀 ~ onSumItem.description:");
  544. const dictOptions =
  545. nonSumItem.name === "非生产原因"
  546. ? getIntDictOptions(nonSumItem.description)
  547. : getStrDictOptions(nonSumItem.description);
  548. nonSumItem.enumList = dictOptions.map((dict) => {
  549. return {
  550. ...dict,
  551. text: dict.label,
  552. };
  553. });
  554. // 确保 fillContent 的类型与 enumList 中的 value 类型匹配
  555. if (nonSumItem.name === "非生产原因") {
  556. // 如果是"非生产原因",将 fillContent 转换为数字类型以匹配 getIntDictOptions
  557. if (
  558. nonSumItem.fillContent !== null &&
  559. nonSumItem.fillContent !== ""
  560. ) {
  561. nonSumItem.fillContent = parseInt(nonSumItem.fillContent);
  562. }
  563. }
  564. console.log("🚀 ~ nonSumItem.enumList:", nonSumItem.enumList);
  565. }
  566. });
  567. }
  568. item.sumList = rtem.sumList;
  569. item.nonSumList = rtem.nonSumList;
  570. });
  571. console.log("resAttrs-modelId", resAttrs);
  572. }
  573. return item;
  574. });
  575. console.log("resList--", resList);
  576. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  577. paging.value.completeByNoMore(
  578. resList,
  579. pageNo * pageSize >= totalNum.value
  580. );
  581. // 如果加载的数据中包含生产日报,应用累加值
  582. const hasReport = resList.some((item) => item.deviceName === "生产日报");
  583. if (hasReport) {
  584. applyAccumulatedToReport();
  585. }
  586. })
  587. .catch((res) => {
  588. // 如果请求失败写paging.value.complete(false);
  589. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  590. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  591. paging.value.complete(false);
  592. });
  593. };
  594. /**
  595. * 检查累计公里数和运转时长限制(仅针对deptName为'rd'的公司)
  596. * @param item 需要检查的填报项
  597. * @param totalValue 累计值
  598. * @param maxIncrement 最大增量
  599. * @param itemName 项目名称
  600. */
  601. const rdThresholdExceededItems = ref([]);
  602. const checkRdThreshold = (item, totalValue, maxIncrement, itemName) => {
  603. if (deptName.value !== "rd") {
  604. return true; // 不是rd公司,跳过检查
  605. }
  606. if (!item.fillContent) {
  607. return true; // 没有填写内容,跳过检查
  608. }
  609. const fillValue = parseFloat(item.fillContent);
  610. const maxValue = totalValue + maxIncrement;
  611. if (fillValue > maxValue) {
  612. // 收集超限信息
  613. rdThresholdExceededItems.value.push({
  614. deviceCode: item.deviceCode,
  615. // deviceName: item.deviceName,
  616. itemName: itemName,
  617. maxValue: maxValue,
  618. currentValue: fillValue,
  619. });
  620. return false;
  621. }
  622. return true;
  623. };
  624. // 判断是否小于阈值 (<0)
  625. const checkLessThreshold = (item) => {
  626. if (item.fillContent < 0) {
  627. uni.showToast({
  628. title:
  629. item.name +
  630. t("operationRecordFilling.fillContentCannotLessThanThreshold") +
  631. "0",
  632. icon: "none",
  633. });
  634. item.fillContent = ""; // 清空输入
  635. return false; // 返回false表示校验失败
  636. }
  637. };
  638. // 判断是否大于阈值
  639. const checkThreshold = (item) => {
  640. checkLessThreshold(item);
  641. // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
  642. if (item.fillContent > item.threshold) {
  643. uni.showToast({
  644. title:
  645. item.name +
  646. t("operationRecordFilling.fillContentCannotGreaterThanThreshold") +
  647. item.threshold,
  648. icon: "none",
  649. });
  650. item.fillContent = ""; // 清空输入
  651. return false; // 返回false表示校验失败
  652. }
  653. };
  654. // 保留两位小数
  655. const toFixed = (num) => {
  656. if (num) {
  657. num = Number(num);
  658. num = num.toFixed(2);
  659. } else {
  660. num = 0.0;
  661. }
  662. return num;
  663. };
  664. const onSubmit = async () => {
  665. // 清空之前的超限记录
  666. rdThresholdExceededItems.value = [];
  667. // console.log("onSubmit", dataList.value);
  668. // 校验是否所有待填写项都已加载
  669. if (dataList.value.length < totalNum) {
  670. uni.showToast({
  671. title: t("operationRecordFilling.PleaseLoadAllItems"),
  672. icon: "none",
  673. });
  674. return; // 校验失败直接返回
  675. }
  676. // 1. 校验所有必填项
  677. // 遍历dataList.value中nonSumList每个item(非生产日报 isReport!=1)的fillContent字段,
  678. // 如果为null或者为空,则提示用户填写,
  679. // 如果threshold > 0,则判断fillContent是否大于threshold,如果大于则提示用户填写小于等于threshold的值
  680. // 如果所有项全部填写,则调用填写记录接口
  681. for (const item of dataList.value) {
  682. const nonSumList = Array.isArray(item.nonSumList) ? item.nonSumList : [];
  683. // 查找当日运转时间H项目
  684. const runtimeItem = nonSumList.find((i) => i.name === "当日运转时间H");
  685. const isRuntime24 =
  686. runtimeItem &&
  687. (runtimeItem.fillContent == 24 || runtimeItem.fillContent == "24");
  688. for (const nonSumItem of nonSumList) {
  689. // 增加判断条件:如果当日运转时间H等于24,则非生产原因和非生产时间H为非必填,否则为必填
  690. const isExemptField =
  691. isRuntime24 &&
  692. (nonSumItem.name === "非生产原因" || nonSumItem.name === "非生产时间H");
  693. if (
  694. (!item.isReport || item.isReport != 1) &&
  695. !isExemptField &&
  696. (nonSumItem.fillContent == null || nonSumItem.fillContent === "")
  697. ) {
  698. uni.showToast({
  699. title:
  700. t("operation.PleaseFillIn") +
  701. item.deviceCode +
  702. "(" +
  703. item.deviceName +
  704. ")" +
  705. t("operation.allItem"),
  706. icon: "none",
  707. });
  708. return; // 校验失败直接返回
  709. }
  710. if (nonSumItem.fillContent != "" && nonSumItem.fillContent != null) {
  711. console.log("🚀 ~ nonSumItem:", nonSumItem);
  712. console.log("🚀 ~ nonSumItem.fillContent:", nonSumItem.fillContent);
  713. // 先将值转换为字符串进行操作
  714. const fillContentStr = String(nonSumItem.fillContent);
  715. // 将字符串转换为数字
  716. const num = Number(fillContentStr);
  717. // 检查转换后的数字是否有效
  718. if (!isNaN(num)) {
  719. // 检查是否包含小数(使用字符串检查)
  720. if (fillContentStr.includes(".")) {
  721. // 保留两位小数(假设toFixed是你定义的保留两位小数的函数)
  722. nonSumItem.fillContent = toFixed(num);
  723. } else {
  724. // 转换为整数
  725. nonSumItem.fillContent = Math.floor(num);
  726. }
  727. }
  728. // **********************
  729. // 新增:针对rd公司的特殊阈值检查
  730. // 检查包含"累计公里数填报"的字段不能超过对应"累计公里数"字段 + 3000
  731. if (nonSumItem.name.includes("累计公里数填报")) {
  732. const correspondingSumItem = item.sumList.find((sumItem) =>
  733. sumItem.name.includes("累计公里数")
  734. );
  735. if (correspondingSumItem) {
  736. const totalKm = parseFloat(correspondingSumItem.totalRunTime) || 0;
  737. checkRdThreshold(nonSumItem, totalKm, 3000, nonSumItem.name);
  738. }
  739. }
  740. // 检查包含"累计运转时长填报"的字段不能超过对应"累计运转时长"字段 + 100
  741. else if (nonSumItem.name.includes("累计运转时长填报")) {
  742. const correspondingSumItem = item.sumList.find((sumItem) =>
  743. sumItem.name.includes("累计运转时长")
  744. );
  745. if (correspondingSumItem) {
  746. const totalRunTime =
  747. parseFloat(correspondingSumItem.totalRunTime) || 0;
  748. checkRdThreshold(nonSumItem, totalRunTime, 100, nonSumItem.name);
  749. }
  750. }
  751. }
  752. // 如果threshold > 0,则判断fillContent是否大于threshold
  753. if (nonSumItem.threshold > 0) {
  754. if (nonSumItem.fillContent > nonSumItem.threshold) {
  755. uni.showToast({
  756. title:
  757. item.deviceCode +
  758. "(" +
  759. item.deviceName +
  760. ")" +
  761. nonSumItem.name +
  762. t(
  763. "operationRecordFilling.fillContentCannotGreaterThanThreshold"
  764. ) +
  765. nonSumItem.threshold,
  766. icon: "none",
  767. duration: 3000,
  768. });
  769. nonSumItem.fillContent = ""; // 清空输入
  770. return; // 校验失败直接返回
  771. }
  772. }
  773. }
  774. }
  775. // 检查是否有超限的项目,如果有则统一显示
  776. if (rdThresholdExceededItems.value.length > 0) {
  777. const exceededInfo = rdThresholdExceededItems.value
  778. .map(
  779. (item, index) =>
  780. `${index + 1}. ${item.deviceCode} ${item.itemName}不能超过${
  781. item.maxValue
  782. },当前值为${item.currentValue}`
  783. )
  784. .join("\n");
  785. uni.showModal({
  786. title: "阈值超限提示",
  787. content: `以下项目超过阈值限制:\n${exceededInfo}\n\n是否继续保存?`,
  788. showCancel: true,
  789. cancelText: "取消",
  790. confirmText: "继续",
  791. success: (res) => {
  792. if (res.confirm) {
  793. // 用户选择继续,执行保存操作
  794. submitData();
  795. } else if (res.cancel) {
  796. // 用户选择取消,不执行保存
  797. return;
  798. }
  799. },
  800. });
  801. return;
  802. }
  803. // 如果没有超限项目,直接执行保存
  804. submitData();
  805. };
  806. // 将原来的保存逻辑提取到单独函数中
  807. const submitData = async () => {
  808. // 定义新的dataList副本 用于提交数据,避免修改原数据
  809. const subDataList = JSON.parse(JSON.stringify(dataList.value));
  810. // 3. 处理副本:删除 enumList(仅修改副本,不影响原数据)
  811. for (const item of subDataList) {
  812. // 先判断 item.nonSumList 存在,避免空指针
  813. if (item.nonSumList && item.nonSumList.length) {
  814. for (const nonSumItem of item.nonSumList) {
  815. if (nonSumItem.enumList) {
  816. delete nonSumItem.enumList;
  817. }
  818. }
  819. }
  820. }
  821. console.log("处理提交用的副本数据:subDataList", subDataList);
  822. // 2. 处理提交数据:将nonSumList和sumList合并为新数组并赋值给deviceInfoList对象,将所有的deviceInfoList合并为submitList
  823. const submitList = subDataList.map((item) => ({
  824. deviceInfoList: [].concat(item.sumList).concat(item.nonSumList),
  825. }));
  826. console.log("提交用的数据:submitList", submitList);
  827. // 3. 提交所有填写记录
  828. await recordFillingDetailInsertDataList(submitList)
  829. .then(async (res) => {
  830. console.log("🚀 ~ 提交工单填报内容结果 ~ res:", res);
  831. if (res?.code === 0) {
  832. // 3. 调用更新工单状态接口
  833. const upRes = await recordFillingUpOperationOrder({
  834. id: params.value.orderId,
  835. });
  836. console.log("🚀 ~ upRes:", upRes);
  837. if (upRes?.code === 0) {
  838. console.log("工单状态更新成功");
  839. uni.showToast({
  840. title: t("operation.success"),
  841. duration: 1500,
  842. icon: "none",
  843. });
  844. setTimeout(() => {
  845. uni.navigateBack();
  846. }, 1500);
  847. } else {
  848. console.error("工单状态更新失败", upRes);
  849. uni.showToast({
  850. title: t("operation.fail"),
  851. icon: "none",
  852. });
  853. }
  854. } else {
  855. uni.showToast({
  856. title: t("operation.fail"),
  857. icon: "none",
  858. });
  859. }
  860. })
  861. .catch((error) => {
  862. console.error("保存失败", error);
  863. uni.showToast({
  864. title: t("operation.fail"),
  865. icon: "error",
  866. });
  867. });
  868. };
  869. </script>
  870. <style lang="scss" scoped>
  871. .page {
  872. padding: 0;
  873. box-sizing: border-box;
  874. }
  875. .top {
  876. padding: 10px;
  877. }
  878. .list {
  879. // margin-top: calc(10px);
  880. padding: 10px;
  881. // height: calc(100%);
  882. }
  883. .item {
  884. width: 100%;
  885. // height: 204px;
  886. background: #ffffff;
  887. border-radius: 6px;
  888. margin-bottom: 10px;
  889. box-sizing: border-box;
  890. padding: 20px 15px;
  891. }
  892. .item-module {
  893. width: 100%;
  894. height: 16px;
  895. position: relative;
  896. font-weight: 600;
  897. font-size: 14px;
  898. color: #333333;
  899. margin-bottom: 10px;
  900. .module-border {
  901. position: absolute;
  902. left: -15px;
  903. width: 0px;
  904. height: 12px;
  905. border: 1px solid #004098;
  906. }
  907. }
  908. .item-content {
  909. position: relative;
  910. width: 100%;
  911. // height: calc(38px);
  912. box-sizing: border-box;
  913. font-weight: 500;
  914. font-size: 14px;
  915. color: #333333;
  916. line-height: 20px;
  917. border-bottom: 1px dashed #cacccf;
  918. &:last-child {
  919. border-bottom: none;
  920. }
  921. &.bold {
  922. font-weight: 600;
  923. // :deep(.uni-easyinput__content-input){
  924. // padding-right: 0 !important;
  925. // }
  926. }
  927. &.bottom-bold {
  928. border-bottom: 1px dashed #cacccf;
  929. }
  930. }
  931. .item-title {
  932. position: relative;
  933. min-height: 38px;
  934. width: 55%;
  935. &.total {
  936. :deep(.is-disabled) {
  937. color: #333333 !important;
  938. }
  939. }
  940. &.full-cell {
  941. width: 100%;
  942. min-width: max-content;
  943. }
  944. }
  945. .item-value {
  946. width: 45%;
  947. position: relative;
  948. &.textarea {
  949. width: 65%;
  950. }
  951. }
  952. .word-break-all {
  953. min-width: unset;
  954. }
  955. :deep(.uni-select) {
  956. border: none;
  957. text-align: right;
  958. padding-right: 0;
  959. .uniui-bottom:before {
  960. content: "\e6b5" !important;
  961. font-size: 16px !important;
  962. }
  963. }
  964. :deep(.uni-select__input-text) {
  965. text-align: right;
  966. .align-left {
  967. text-align: right;
  968. }
  969. }
  970. :deep(.uni-select--disabled) {
  971. color: #d5d5d5 !important;
  972. background-color: transparent;
  973. .uni-select__input-text {
  974. color: #d5d5d5 !important;
  975. }
  976. }
  977. :deep(.uni-select__selector) {
  978. text-align: left;
  979. }
  980. :deep(.uni-select__selector-item) {
  981. border-bottom: 1px dashed #cacccf;
  982. text-align: left;
  983. }
  984. :deep(.uni-easyinput__content-textarea) {
  985. min-height: inherit;
  986. margin: 10px;
  987. }
  988. </style>