IotMainWorkOrder.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <el-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. v-loading="formLoading"
  8. style="margin-right: 4em; margin-left: 0.5em; margin-top: 1em"
  9. label-width="130px"
  10. >
  11. <div class="base-expandable-content">
  12. <el-row>
  13. <el-col :span="8">
  14. <el-form-item label="工单名称" prop="name">
  15. <el-input type="text" v-model="formData.name" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="8">
  19. <el-form-item label="工单编号" prop="orderNumber">
  20. <el-input type="text" v-model="formData.orderNumber" disabled/>
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="8">
  24. <el-form-item label="责任人" prop="responsiblePerson">
  25. <el-select v-model="formData.responsiblePerson" filterable clearable style="width: 100%">
  26. <el-option
  27. v-for="item in deptUsers"
  28. :key="item.id"
  29. :label="item.nickname"
  30. :value="item.id"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="24">
  36. <el-form-item label="备注" prop="remark">
  37. <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" />
  38. </el-form-item>
  39. </el-col>
  40. </el-row>
  41. </div>
  42. </el-form>
  43. </ContentWrap>
  44. <ContentWrap>
  45. <ContentWrap>
  46. <!-- 搜索工作栏 -->
  47. <el-form
  48. class="-mb-15px"
  49. :model="queryParams"
  50. ref="queryFormRef"
  51. :inline="true"
  52. label-width="68px"
  53. >
  54. <!--
  55. <el-form-item>
  56. <el-button @click="openForm" type="warning">
  57. <Icon icon="ep:plus" class="mr-5px" /> 新增设备</el-button>
  58. </el-form-item>
  59. -->
  60. </el-form>
  61. </ContentWrap>
  62. <!-- 列表 -->
  63. <ContentWrap>
  64. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  65. <el-table-column label="设备编码" align="center" prop="deviceCode" />
  66. <el-table-column label="设备名称" align="center" prop="deviceName" />
  67. <el-table-column label="累计运行时间(H)" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter"/>
  68. <el-table-column label="累计运行公里数(KM)" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter"/>
  69. <el-table-column label="BOM节点" align="center" prop="name" />
  70. <el-table-column label="运行里程" key="mileageRule" width="80">
  71. <template #default="scope">
  72. <el-switch
  73. v-model="scope.row.mileageRule"
  74. :active-value="0"
  75. :inactive-value="1"
  76. />
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="运行时间" key="runningTimeRule" width="80">
  80. <template #default="scope">
  81. <el-switch
  82. v-model="scope.row.runningTimeRule"
  83. :active-value="0"
  84. :inactive-value="1"
  85. />
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="自然日期" key="naturalDateRule" width="80">
  89. <template #default="scope">
  90. <el-switch
  91. v-model="scope.row.naturalDateRule"
  92. :active-value="0"
  93. :inactive-value="1"
  94. />
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="操作" align="center" min-width="120px">
  98. <template #default="scope">
  99. <div style="display: flex; justify-content: center; align-items: center; width: 100%">
  100. <!-- 新增配置按钮 -->
  101. <div style="margin-left: 12px">
  102. <el-button
  103. link
  104. type="primary"
  105. @click="openConfigDialog(scope.row)"
  106. >
  107. 配置
  108. </el-button>
  109. </div>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </ContentWrap>
  115. </ContentWrap>
  116. <ContentWrap>
  117. <el-form>
  118. <el-form-item style="float: right">
  119. <el-button @click="submitForm" type="primary" :disabled="formLoading">保 存</el-button>
  120. <el-button @click="close">取 消</el-button>
  121. </el-form-item>
  122. </el-form>
  123. </ContentWrap>
  124. <!-- 新增配置对话框 -->
  125. <el-dialog
  126. v-model="configDialog.visible"
  127. :title="`设备 ${configDialog.current?.deviceCode+'-'+configDialog.current?.name} 保养配置`"
  128. width="600px"
  129. >
  130. <el-form :model="configDialog.form" label-width="200px" :rules="configFormRules" ref="configFormRef">
  131. <!-- 里程配置 -->
  132. <el-form-item
  133. v-if="configDialog.current?.mileageRule === 0"
  134. label="上次保养里程数(KM)"
  135. prop="lastRunningKilometers"
  136. >
  137. <el-input-number
  138. v-model="configDialog.form.lastRunningKilometers"
  139. :precision="2"
  140. :min="0"
  141. controls-position="right"
  142. />
  143. </el-form-item>
  144. <!-- 推迟公里数 -->
  145. <el-form-item
  146. v-if="configDialog.current?.mileageRule === 0"
  147. label="推迟公里数(KM)"
  148. prop="delayKilometers"
  149. >
  150. <el-input-number
  151. v-model="configDialog.form.delayKilometers"
  152. :precision="2"
  153. :min="0"
  154. controls-position="right"
  155. />
  156. </el-form-item>
  157. <!-- 运行时间配置 -->
  158. <el-form-item
  159. v-if="configDialog.current?.runningTimeRule === 0"
  160. label="上次保养运行时间(H)"
  161. prop="lastRunningTime"
  162. >
  163. <el-input-number
  164. v-model="configDialog.form.lastRunningTime"
  165. :precision="1"
  166. :min="0"
  167. controls-position="right"
  168. />
  169. </el-form-item>
  170. <!-- 推迟时长 -->
  171. <el-form-item
  172. v-if="configDialog.current?.runningTimeRule === 0"
  173. label="推迟时长(H)"
  174. prop="delayDuration"
  175. >
  176. <el-input-number
  177. v-model="configDialog.form.delayDuration"
  178. :precision="2"
  179. :min="0"
  180. controls-position="right"
  181. />
  182. </el-form-item>
  183. <!-- 自然日期配置 -->
  184. <el-form-item
  185. v-if="configDialog.current?.naturalDateRule === 0"
  186. label="上次保养自然日期(D)"
  187. prop="lastNaturalDate"
  188. >
  189. <el-date-picker
  190. v-model="configDialog.form.lastNaturalDate"
  191. type="date"
  192. placeholder="选择日期"
  193. format="YYYY-MM-DD"
  194. value-format="YYYY-MM-DD"
  195. />
  196. </el-form-item>
  197. <!-- 推迟自然日期 -->
  198. <el-form-item
  199. v-if="configDialog.current?.naturalDateRule === 0"
  200. label="推迟自然日期(D)"
  201. prop="delayNaturalDate"
  202. >
  203. <el-input-number
  204. v-model="configDialog.form.delayNaturalDate"
  205. :precision="2"
  206. :min="0"
  207. controls-position="right"
  208. />
  209. </el-form-item>
  210. <!-- 保养规则周期值 + 提前量 -->
  211. <el-form-item
  212. v-if="configDialog.current?.mileageRule === 0"
  213. label="运行里程周期(KM)"
  214. prop="nextRunningKilometers"
  215. >
  216. <el-input-number
  217. v-model="configDialog.form.nextRunningKilometers"
  218. :precision="2"
  219. :min="0"
  220. controls-position="right"
  221. />
  222. </el-form-item>
  223. <el-form-item
  224. v-if="configDialog.current?.mileageRule === 0"
  225. label="运行里程周期-提前量(KM)"
  226. prop="kiloCycleLead"
  227. >
  228. <el-input-number
  229. v-model="configDialog.form.kiloCycleLead"
  230. :precision="2"
  231. :min="0"
  232. controls-position="right"
  233. />
  234. </el-form-item>
  235. <el-form-item
  236. v-if="configDialog.current?.runningTimeRule === 0"
  237. label="运行时间周期(H)"
  238. prop="nextRunningTime"
  239. >
  240. <el-input-number
  241. v-model="configDialog.form.nextRunningTime"
  242. :precision="1"
  243. :min="0"
  244. controls-position="right"
  245. />
  246. </el-form-item>
  247. <el-form-item
  248. v-if="configDialog.current?.runningTimeRule === 0"
  249. label="运行时间周期-提前量(H)"
  250. prop="timePeriodLead"
  251. >
  252. <el-input-number
  253. v-model="configDialog.form.timePeriodLead"
  254. :precision="1"
  255. :min="0"
  256. controls-position="right"
  257. />
  258. </el-form-item>
  259. <el-form-item
  260. v-if="configDialog.current?.naturalDateRule === 0"
  261. label="自然日周期(D)"
  262. prop="nextNaturalDate"
  263. >
  264. <el-input-number
  265. v-model="configDialog.form.nextNaturalDate"
  266. :min="0"
  267. controls-position="right"
  268. />
  269. </el-form-item>
  270. <el-form-item
  271. v-if="configDialog.current?.naturalDateRule === 0"
  272. label="自然日周期-提前量(D)"
  273. prop="naturalDatePeriodLead"
  274. >
  275. <el-input-number
  276. v-model="configDialog.form.naturalDatePeriodLead"
  277. :min="0"
  278. controls-position="right"
  279. />
  280. </el-form-item>
  281. </el-form>
  282. <template #footer>
  283. <el-button @click="configDialog.visible = false">取消</el-button>
  284. <el-button type="primary" @click="saveConfig">保存</el-button>
  285. </template>
  286. </el-dialog>
  287. </template>
  288. <script setup lang="ts">
  289. import { IotMaintainApi, IotMaintainVO } from '@/api/pms/maintain'
  290. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  291. import * as UserApi from '@/api/system/user'
  292. import { useUserStore } from '@/store/modules/user'
  293. import { ref } from 'vue'
  294. import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
  295. import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
  296. import { IotMaintenancePlanApi, IotMaintenancePlanVO } from '@/api/pms/maintenance'
  297. import { IotMainWorkOrderApi, IotMainWorkOrderVO } from '@/api/pms/iotmainworkorder'
  298. import { useTagsViewStore } from '@/store/modules/tagsView'
  299. import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
  300. import MainPlanDeviceList from "@/views/pms/maintenance/MainPlanDeviceList.vue";
  301. import * as DeptApi from "@/api/system/dept";
  302. import {erpPriceTableColumnFormatter} from "@/utils";
  303. import dayjs from 'dayjs'
  304. /** 保养计划 表单 */
  305. defineOptions({ name: 'IotMainWorkOrderBom' })
  306. const { t } = useI18n() // 国际化
  307. const message = useMessage() // 消息弹窗
  308. const { delView } = useTagsViewStore() // 视图操作
  309. const { currentRoute, push } = useRouter()
  310. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  311. const dept = ref() // 当前登录人所属部门对象
  312. const configFormRef = ref() // 配置弹出框对象
  313. const dialogTitle = ref('') // 弹窗的标题
  314. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  315. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  316. const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
  317. // const list = ref<IotMaintenanceBomVO[]>([]) // 设备bom关联列表的数据
  318. const list = ref<IotMainWorkOrderBomVO[]>([]) // 保养工单bom关联列表的数据
  319. const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
  320. const { params, name } = useRoute() // 查询参数
  321. const id = params.id
  322. const formData = ref({
  323. id: undefined,
  324. deptId: undefined,
  325. name: '',
  326. orderNumber: undefined,
  327. responsiblePerson: undefined,
  328. remark: undefined,
  329. status: undefined,
  330. })
  331. const formRules = reactive({
  332. name: [{ required: true, message: '工单名称不能为空', trigger: 'blur' }],
  333. responsiblePerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
  334. })
  335. const formRef = ref() // 表单 Ref
  336. // 新增配置相关状态
  337. const configDialog = reactive({
  338. visible: false,
  339. current: null as IotMaintenanceBomVO | null,
  340. form: {
  341. lastRunningKilometers: 0,
  342. delayKilometers: 0,
  343. lastRunningTime: 0,
  344. delayDuration: 0,
  345. lastNaturalDate: '',
  346. delayNaturalDate: 0,
  347. // 保养规则 周期
  348. nextRunningKilometers: 0,
  349. nextRunningTime: 0,
  350. nextNaturalDate: 0,
  351. // 提前量
  352. kiloCycleLead: 0,
  353. timePeriodLead: 0,
  354. naturalDatePeriodLead: 0
  355. }
  356. })
  357. // 打开配置对话框
  358. const openConfigDialog = (row: IotMainWorkOrderBomVO) => {
  359. configDialog.current = row
  360. // 处理日期初始化(核心修改)
  361. let initialDate = ''
  362. if (row.lastNaturalDate) {
  363. // 如果已有值:时间戳 -> 日期字符串
  364. initialDate = dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
  365. } else {
  366. // 如果无值:设置默认值避免1970问题
  367. initialDate = ''
  368. }
  369. configDialog.form = {
  370. lastRunningKilometers: row.lastRunningKilometers || 0,
  371. delayKilometers: row.delayKilometers || 0,
  372. lastRunningTime: row.lastRunningTime || 0,
  373. delayDuration: row.delayDuration || 0,
  374. lastNaturalDate: initialDate,
  375. delayNaturalDate: row.delayNaturalDate || 0,
  376. // 保养规则 周期值
  377. nextRunningKilometers: row.nextRunningKilometers || 0,
  378. nextRunningTime: row.nextRunningTime || 0,
  379. nextNaturalDate: row.nextNaturalDate || 0,
  380. // 提前量
  381. kiloCycleLead: row.kiloCycleLead || 0,
  382. timePeriodLead: row.timePeriodLead || 0,
  383. naturalDatePeriodLead: row.naturalDatePeriodLead || 0
  384. }
  385. configDialog.visible = true
  386. }
  387. // 保存配置
  388. const saveConfig = () => {
  389. (configFormRef.value as any).validate((valid: boolean) => {
  390. if (!valid) return
  391. if (!configDialog.current) return
  392. // 动态校验逻辑
  393. const requiredFields = []
  394. if (configDialog.current.mileageRule === 0) {
  395. requiredFields.push('nextRunningKilometers', 'kiloCycleLead')
  396. }
  397. if (configDialog.current.runningTimeRule === 0) {
  398. requiredFields.push('nextRunningTime', 'timePeriodLead')
  399. }
  400. if (configDialog.current.naturalDateRule === 0) {
  401. requiredFields.push('nextNaturalDate', 'naturalDatePeriodLead')
  402. }
  403. const missingFields = requiredFields.filter(field =>
  404. !configDialog.form[field as keyof typeof configDialog.form]
  405. )
  406. if (missingFields.length > 0) {
  407. message.error('请填写所有必填项')
  408. return
  409. }
  410. // 强制校验逻辑
  411. if (configDialog.current.naturalDateRule === 0) {
  412. if (!configDialog.form.lastNaturalDate) {
  413. message.error('必须选择自然日期')
  414. return
  415. }
  416. // 验证日期有效性
  417. const dateValue = dayjs(configDialog.form.lastNaturalDate)
  418. if (!dateValue.isValid()) {
  419. message.error('日期格式不正确')
  420. return
  421. }
  422. }
  423. // 转换逻辑(关键修改)
  424. const finalDate = configDialog.form.lastNaturalDate
  425. ? dayjs(configDialog.form.lastNaturalDate).valueOf()
  426. : null // 改为null而不是0
  427. // 更新当前行的数据
  428. Object.assign(configDialog.current, {
  429. ...configDialog.form,
  430. lastNaturalDate: finalDate
  431. })
  432. configDialog.visible = false
  433. })
  434. }
  435. const queryParams = reactive({
  436. workOrderId: id
  437. })
  438. const close = () => {
  439. delView(unref(currentRoute))
  440. push({ name: 'IotMainWorkOrder', params:{}})
  441. }
  442. /** 提交表单 */
  443. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  444. const submitForm = async () => {
  445. // 校验表单
  446. await formRef.value.validate()
  447. // 校验表格数据
  448. const isValid = validateTableData()
  449. if (!isValid) return
  450. // 提交请求
  451. formLoading.value = true
  452. try {
  453. const data = {
  454. mainPlan: formData.value,
  455. mainPlanBom: list.value
  456. }
  457. if (formType.value === 'create') {
  458. await IotMaintenancePlanApi.createIotMaintenancePlan(data)
  459. message.success(t('common.createSuccess'))
  460. close()
  461. } else {
  462. await IotMaintainApi.updateIotMaintain(data)
  463. message.success(t('common.updateSuccess'))
  464. close()
  465. }
  466. // 发送操作成功的事件
  467. emit('success')
  468. } finally {
  469. formLoading.value = false
  470. }
  471. }
  472. // 新增表单校验规则
  473. const configFormRules = reactive({
  474. nextRunningKilometers: [{
  475. required: true,
  476. message: '里程周期必须填写',
  477. trigger: 'blur'
  478. }],
  479. kiloCycleLead: [{
  480. required: true,
  481. message: '提前量必须填写',
  482. trigger: 'blur'
  483. }],
  484. nextRunningTime: [{
  485. required: true,
  486. message: '时间周期必须填写',
  487. trigger: 'blur'
  488. }],
  489. timePeriodLead: [{
  490. required: true,
  491. message: '提前量必须填写',
  492. trigger: 'blur'
  493. }],
  494. nextNaturalDate: [{
  495. required: true,
  496. message: '自然日周期必须填写',
  497. trigger: 'blur'
  498. }],
  499. naturalDatePeriodLead: [{
  500. required: true,
  501. message: '提前量必须填写',
  502. trigger: 'blur'
  503. }]
  504. })
  505. /** 校验表格数据 */
  506. const validateTableData = (): boolean => {
  507. let isValid = true
  508. const errorMessages: string[] = []
  509. const noRulesErrorMessages: string[] = [] // 未设置任何保养项规则 的错误提示信息
  510. const noRules: string[] = [] // 行记录中设置了保养规则的记录数量
  511. const configErrors: string[] = [] // 保养规则配置弹出框
  512. let shouldBreak = false;
  513. if (list.value.length === 0) {
  514. errorMessages.push('请至少添加一条设备保养明细')
  515. isValid = false
  516. // 直接返回无需后续校验
  517. message.error('请至少添加一条设备保养明细')
  518. return isValid
  519. }
  520. list.value.forEach((row, index) => {
  521. if (shouldBreak) return;
  522. const rowNumber = index + 1 // 用户可见的行号从1开始
  523. const deviceIdentifier = `${row.deviceCode}-${row.name}` // 设备标识
  524. // 校验逻辑
  525. const checkConfig = (ruleName: string, ruleValue: number, configField: keyof typeof row) => {
  526. if (ruleValue === 0) { // 规则开启
  527. if (!row[configField] || row[configField] <= 0) {
  528. configErrors.push(`第 ${rowNumber} 行(${deviceIdentifier}):请点击【配置】维护${ruleName}上次保养值`)
  529. isValid = false
  530. }
  531. }
  532. }
  533. // 里程校验逻辑
  534. if (row.mileageRule === 0) { // 假设 0 表示开启状态
  535. if (!row.nextRunningKilometers || row.nextRunningKilometers <= 0) {
  536. errorMessages.push(`第 ${rowNumber} 行:开启里程规则必须填写有效的里程周期`)
  537. isValid = false
  538. }
  539. // 再校验配置值
  540. checkConfig('里程', row.mileageRule, 'lastRunningKilometers')
  541. } else {
  542. noRules.push(`第 ${rowNumber} 行:未设置里程规则`)
  543. }
  544. // 运行时间校验逻辑
  545. if (row.runningTimeRule === 0) {
  546. if (!row.nextRunningTime || row.nextRunningTime <= 0) {
  547. errorMessages.push(`第 ${rowNumber} 行:开启运行时间规则必须填写有效的时间周期`)
  548. isValid = false
  549. }
  550. checkConfig('运行时间', row.runningTimeRule, 'lastRunningTime')
  551. } else {
  552. noRules.push(`第 ${rowNumber} 行:未设置运行时间规则`)
  553. }
  554. // 自然日期校验逻辑
  555. if (row.naturalDateRule === 0) {
  556. if (!row.nextNaturalDate) {
  557. errorMessages.push(`第 ${rowNumber} 行:开启自然日期规则必须填写有效的自然日期周期`)
  558. isValid = false
  559. }
  560. checkConfig('自然日期', row.naturalDateRule, 'lastNaturalDate')
  561. } else {
  562. noRules.push(`第 ${rowNumber} 行:未设置自然日期规则`)
  563. }
  564. // 如果选中的一行记录未设置任何保养规则 提示 ‘保养项未设置任何保养规则’
  565. if (noRules.length === 3) {
  566. isValid = false
  567. shouldBreak = true; // 设置标志变量为true,退出循环
  568. noRulesErrorMessages.push('保养项至少设置1个保养规则')
  569. }
  570. noRules.length = 0;
  571. })
  572. if (errorMessages.length > 0) {
  573. message.error('设置保养规则后,请维护对应的周期值')
  574. } else if (noRulesErrorMessages.length > 0) {
  575. message.error(noRulesErrorMessages.pop())
  576. } else if (configErrors.length > 0) {
  577. message.error(configErrors.pop())
  578. }
  579. return isValid
  580. }
  581. /** 重置表单 */
  582. const resetForm = () => {
  583. formData.value = {
  584. id: undefined,
  585. deviceId: undefined,
  586. status: undefined,
  587. description: undefined,
  588. pic: undefined,
  589. remark: undefined,
  590. deviceName: undefined,
  591. processInstanceId: undefined,
  592. auditStatus: undefined,
  593. deptId: undefined
  594. }
  595. formRef.value?.resetFields()
  596. }
  597. onMounted(async () => {
  598. console.log('id-'+id)
  599. const deptId = useUserStore().getUser.deptId
  600. // 查询当前登录人所属部门名称
  601. dept.value = await DeptApi.getDept(deptId)
  602. // formData.value.name = dept.value.name + ' - 保养计划'
  603. deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
  604. formData.value.deptId = deptId
  605. // if (id){
  606. try{
  607. formType.value = 'update'
  608. // const iotMaintain = await IotMaintainApi.getIotMaintain(id);
  609. // deviceLabel.value = iotMaintain.deviceName
  610. // formData.value = iotMaintain
  611. // 查询保养工单 主表数据
  612. const workOrder = await IotMainWorkOrderApi.getIotMainWorkOrder(id);
  613. formData.value = workOrder
  614. // 查询保养工单 明细数据
  615. const data = await IotMainWorkOrderBomApi.getWorkOrderBOMs(queryParams);
  616. console.log('这是个数组:', data)
  617. list.value = []
  618. if (Array.isArray(data)) {
  619. list.value = data.map(item => ({
  620. ...item,
  621. // 这里可以添加必要的字段转换(如果有日期等需要格式化的字段)
  622. lastNaturalDate: item.lastNaturalDate ? dayjs(item.lastNaturalDate).format('YYYY-MM-DD') : null
  623. }))
  624. }
  625. } catch (error) {
  626. console.error('数据加载失败:', error)
  627. message.error('数据加载失败,请重试')
  628. }
  629. /* } else {
  630. formType.value = 'create';
  631. const { wsCache } = useCache()
  632. const userInfo = wsCache.get(CACHE_KEY.USER)
  633. formData.value.responsiblePerson = userInfo.user.id;
  634. } */
  635. })
  636. </script>
  637. <style scoped>
  638. .base-expandable-content {
  639. overflow: hidden; /* 隐藏溢出的内容 */
  640. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  641. }
  642. </style>