IotMaintain.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  3. <ContentWrap>
  4. <el-form
  5. ref="formRef"
  6. :model="formData"
  7. :rules="formRules"
  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="t('iotMaintain.device')" prop="deviceName">
  15. <el-select
  16. :disabled="formType === 'update'"
  17. v-model="formData.deviceName"
  18. clearable
  19. @clear="deviceClear"
  20. :placeholder="t('iotMaintain.deviceHolder')"
  21. @click="formType === 'update' ? undefined : openForm()"
  22. />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="8">
  26. <el-form-item :label="t('iotMaintain.repairType')" prop="type">
  27. <el-select v-model="formData.type" :placeholder="t('iotMaintain.repairTypeHolder')" clearable>
  28. <el-option
  29. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_MAIN_TYPE)"
  30. :key="dict.value"
  31. :label="dict.label"
  32. :value="dict.value"
  33. />
  34. </el-select>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8">
  38. <el-form-item :label="t('iotMaintain.shutDown')" prop="ifStop">
  39. <el-select v-model="formData.ifStop" :placeholder="t('iotMaintain.shutDownHolder')" clearable>
  40. <el-option
  41. v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  42. :key="dict.value"
  43. :label="dict.label"
  44. :value="dict.value"
  45. />
  46. </el-select>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="8">
  50. <el-form-item
  51. :label="t('iotMaintain.startTime')"
  52. prop="maintainStartTime"
  53. :rules="formData.type === 'in' ? startRule : []"
  54. >
  55. <el-date-picker
  56. style="width: 150%"
  57. v-model="formData.maintainStartTime"
  58. type="datetime"
  59. value-format="x"
  60. :placeholder="t('iotMaintain.startTimeHolder')"
  61. />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="8">
  65. <el-form-item
  66. :label="t('iotMaintain.endTime')"
  67. prop="maintainEndTime"
  68. :rules="formData.type === 'in' ? endRule : []"
  69. >
  70. <el-date-picker
  71. @change="endTimeBlur"
  72. style="width: 150%"
  73. v-model="formData.maintainEndTime"
  74. type="datetime"
  75. value-format="x"
  76. :placeholder="t('iotMaintain.endTimeHolder')"
  77. />
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="8">
  81. <el-form-item :label="t('iotMaintain.failureTime')" prop="failureTime" :rules="formData.type==='out'?failureTimeRule:[]" >
  82. <el-date-picker
  83. @change="failureTimeBlur"
  84. :disabled="formData.maintainType==='故障上报'"
  85. style="width: 150%"
  86. v-model="formData.failureTime"
  87. type="datetime"
  88. value-format="x"
  89. :placeholder="t('iotMaintain.failureTimeHolder')"
  90. />
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="8">
  94. <el-form-item :label="t('iotMaintain.failureImpact')" prop="failureInfluence">
  95. <el-input v-model="formData.failureInfluence" :placeholder="t('iotMaintain.failureImpactHolder')" />
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="8">
  99. <el-form-item :label="t('iotMaintain.faultySystem')" prop="failureSystem">
  100. <el-input v-model="formData.failureSystem" :placeholder="t('iotMaintain.faultySystemHolder')" />
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="8">
  104. <el-form-item :label="t('iotMaintain.picture')" prop="pic">
  105. <UploadImg v-model="formData.pic" height="55px" />
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="8" v-if="formData.type === 'out'&&formData.maintainPerson===userId">
  109. <el-form-item label="供应商" prop="supplier" :rules="supplierRules">
  110. <el-select
  111. v-model="formData.supplier"
  112. placeholder="请输入供应商"
  113. :model-value="supplierLabel"
  114. @click="openCustomer('supplier')"
  115. />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="8" >
  119. <el-form-item :label="t('iotMaintain.repairCosts')" prop="maintainFee">
  120. <el-input-number
  121. :disabled="formData.type==='in'"
  122. v-model="formData.maintainFee"
  123. :min="0"
  124. :precision="2"
  125. :step="0.1"
  126. style="width: 100%"
  127. />
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="8" v-if="formData.type === 'out'&&formData.maintainPerson===userId">
  131. <el-form-item label="委外相关附件" prop="outFile">
  132. <UploadFile v-model="formData.outFile" class="min-w-80px" multiple :limit="2" />
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="16">
  136. <el-form-item :label="t('iotMaintain.faultDescription')" prop="description">
  137. <el-input type="textarea" v-model="formData.description"/>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="12">
  141. <el-form-item :label="t('iotMaintain.repairDescription')" :rules="formData.type === 'in' ? descriptionRule : []" prop="maintainDescription">
  142. <el-input type="textarea" v-model="formData.maintainDescription" />
  143. </el-form-item>
  144. </el-col>
  145. <el-col :span="12">
  146. <el-form-item :label="t('iotMaintain.solution')" prop="solution">
  147. <el-input type="textarea" v-model="formData.solution" />
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="24">
  151. <el-form-item :label="t('iotMaintain.remark')" prop="remark">
  152. <el-input v-model="formData.remark" type="textarea" :placeholder="t('iotMaintain.remarkHolder')" />
  153. </el-form-item>
  154. </el-col>
  155. </el-row>
  156. </div>
  157. </el-form>
  158. </ContentWrap>
  159. <ContentWrap>
  160. <ContentWrap>
  161. <!-- 搜索工作栏 -->
  162. <el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
  163. <el-form-item>
  164. <!-- <el-button @click="openMaterialForm" type="primary"-->
  165. <!-- ><Icon icon="ep:plus" class="mr-5px" /> 选择物料</el-button>-->
  166. <el-button @click="openMaintainForm" type="primary"
  167. ><Icon icon="ep:plus" class="mr-5px" />
  168. {{ t('iotMaintain.selectMaintenanceItem') }}</el-button
  169. >
  170. <el-button @click="openMaintainItem" type="warning"
  171. ><Icon icon="ep:plus" class="mr-5px" />
  172. {{ t('iotMaintain.addMaintenanceItems') }}</el-button
  173. >
  174. <!-- <el-button @click="handleViewNew" type="warning"-->
  175. <!-- ><Icon icon="ep:plus" class="mr-5px" /> 新增物料</el-button>-->
  176. </el-form-item>
  177. </el-form>
  178. </ContentWrap>
  179. <!-- 列表 -->
  180. <ContentWrap>
  181. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  182. <el-table-column :label="t('iotMaintain.deviceCode')" align="center" prop="deviceCode" />
  183. <el-table-column :label="t('iotMaintain.deviceName')" align="center" prop="deviceName" />
  184. <el-table-column :label="t('iotMaintain.repairItems')" align="center" prop="name" />
  185. <el-table-column :label="t('iotMaintain.numberOfMaterials')" align="center" prop="materialCount" >
  186. <template #default="scope">
  187. <el-tag v-if="scope.row.materialCount" type="danger"> {{scope.row.materialCount}}</el-tag>
  188. </template>
  189. </el-table-column>
  190. <el-table-column :label="t('iotMaintain.operation')" align="center" min-width="120px">
  191. <template #default="scope">
  192. <div style="display: flex; justify-content: center; align-items: center; width: 100%">
  193. <div>
  194. <el-button
  195. style="vertical-align: middle"
  196. link
  197. type="danger"
  198. @click="handleDelete(scope.row.bomNodeId)"
  199. >
  200. <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
  201. {{ t('iotMaintain.remove') }}
  202. </el-button>
  203. </div>
  204. <div style="margin-left: 12px">
  205. <el-button link type="primary" @click="openMaterialForm(scope.row)">
  206. {{ t('iotMaintain.selectMaterials') }}
  207. </el-button>
  208. </div>
  209. <div style="margin-left: 12px">
  210. <el-button link type="primary" @click="handleViewNew(scope.row.bomNodeId)">
  211. {{ t('iotMaintain.viewMaterials') }}
  212. </el-button>
  213. </div>
  214. </div>
  215. </template>
  216. </el-table-column>
  217. </el-table>
  218. </ContentWrap>
  219. <!-- 表单弹窗:添加/修改 -->
  220. <WorkOrderMaterial ref="materialFormRef" @choose="selectChoose" />
  221. <ChooseMaintain ref="maintainFormRef" @choose="maintainChoose" />
  222. </ContentWrap>
  223. <ContentWrap>
  224. <el-form>
  225. <el-form-item style="float: right">
  226. <el-button @click="submitForm" type="primary" :disabled="formLoading">{{ t('iotMaintain.save') }}</el-button>
  227. <el-button @click="close">{{ t('iotMaintain.cancel') }}</el-button>
  228. </el-form-item>
  229. </el-form>
  230. </ContentWrap>
  231. <DeviceList ref="deviceFormRef" @choose="deviceChoose" />
  232. <CustomerList ref="customerFormRef" @choose="customerChoose" />
  233. <MaterialListDrawer
  234. :model-value="drawerVisible"
  235. @update:model-value="(val) => (drawerVisible = val)"
  236. :node-id="currentBomNodeId"
  237. :materials="materialList.filter((item) => item.bomNodeId === currentBomNodeId)"
  238. @delete = "materialDelete"
  239. />
  240. <Dialog :title="t('iotMaintain.repairItems')" v-model="addItemVisible" style="min-height: 300px">
  241. <el-form
  242. ref="addFormRef"
  243. :model="addFormData"
  244. :rules="addFormRules"
  245. label-position="right"
  246. label-width="68px"
  247. >
  248. <el-form-item :label="t('iotMaintain.BOMNodeID')" v-if="false" prop="deviceCode">
  249. <el-input v-model="addFormData.bomNodeId" disabled />
  250. </el-form-item>
  251. <el-form-item :label="t('iotMaintain.deviceCode')" prop="deviceCode">
  252. <el-input v-model="addFormData.deviceCode" disabled />
  253. </el-form-item>
  254. <el-form-item :label="t('iotMaintain.deviceName')" prop="deviceName">
  255. <el-input v-model="addFormData.deviceName" disabled />
  256. </el-form-item>
  257. <el-form-item :label="t('iotMaintain.repairItems')" prop="name">
  258. <el-input v-model="addFormData.name" :placeholder="t('iotMaintain.repairItemsHolder')" />
  259. </el-form-item>
  260. </el-form>
  261. <el-form>
  262. <el-form-item style="float: right">
  263. <el-button @click="handleConfirm" type="primary">{{ t('iotMaintain.ok') }}</el-button>
  264. <el-button @click="closeDialog">{{ t('iotMaintain.cancel') }}</el-button>
  265. </el-form-item>
  266. </el-form>
  267. </Dialog>
  268. </ContentWrap>
  269. </template>
  270. <script setup lang="ts">
  271. import { IotMaintainApi } from '@/api/pms/maintain'
  272. import { DICT_TYPE, getBoolDictOptions, getStrDictOptions } from '@/utils/dict'
  273. import DeviceList from '@/views/pms/failure/DeviceList.vue'
  274. import * as UserApi from '@/api/system/user'
  275. import { ref } from 'vue'
  276. import { IotMaintainMaterialVO } from '@/api/pms/maintain/material'
  277. import { useTagsViewStore } from '@/store/modules/tagsView'
  278. import CustomerList from '@/views/pms/device/CustomerList.vue'
  279. import WorkOrderMaterial from '@/views/pms/iotmainworkorder/WorkOrderMaterial.vue'
  280. import { IotMainWorkOrderBomMaterialVO } from '@/api/pms/iotmainworkorderbommaterial'
  281. import MaterialListDrawer from '@/views/pms/iotmainworkorder/SelectedMaterialDrawer.vue'
  282. import ChooseMaintain from '@/views/pms/maintain/material/ChooseMaintain.vue'
  283. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  284. import dayjs from 'dayjs'
  285. /** 维修工单 表单 */
  286. defineOptions({ name: 'MaintainAdd' })
  287. const addItemVisible = ref(false) // 弹窗的是否展示
  288. const { t } = useI18n() // 国际化
  289. const message = useMessage() // 消息弹窗
  290. const { delView } = useTagsViewStore() // 视图操作
  291. const { currentRoute, push } = useRouter()
  292. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  293. const dialogTitle = ref('') // 弹窗的标题
  294. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  295. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  296. const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
  297. const drawerVisible = ref<boolean>(false)
  298. const showDrawer = ref()
  299. const list = ref<IotMaintainMaterialVO[]>([]) // 列表的数据
  300. const { params, name } = useRoute() // 查询参数
  301. const id = params.id
  302. const supplierLabel = ref('') // 表单的类型:create - 新增;update - 修改
  303. const totalFee = ref(0)
  304. const { wsCache } = useCache()
  305. const addFormData = ref({
  306. name: '',
  307. deviceName: '',
  308. deviceCode: '',
  309. bomNodeId: '',
  310. })
  311. const formData = ref({
  312. id: undefined,
  313. failureCode: undefined,
  314. failureName: undefined,
  315. deviceId: undefined,
  316. status: undefined,
  317. type: undefined,
  318. ifStop: undefined,
  319. failureTime: undefined,
  320. failureInfluence: undefined,
  321. failureSystem: undefined,
  322. description: undefined,
  323. pic: undefined,
  324. solution: undefined,
  325. maintainStartTime: undefined,
  326. maintainEndTime: undefined,
  327. remark: undefined,
  328. deviceName: undefined,
  329. deviceCode: undefined,
  330. processInstanceId: undefined,
  331. auditStatus: undefined,
  332. deptId: undefined,
  333. maintainPerson: undefined,
  334. maintainDescription: undefined,
  335. supplier: undefined,
  336. maintainFee: undefined,
  337. outFile: undefined,
  338. maintainType: undefined,
  339. })
  340. const failureTimeRule = [{ required: true, message: '故障时间不能为空', trigger: 'blur' }]
  341. const startRule = [{ required: true, message: '维修开始时间不能为空', trigger: 'blur' }]
  342. const descriptionRule = [{required: true, message:'维修描述不能为空', trigger: 'blur' }]
  343. const endRule = [{ required: true, message: '维修结束时间不能为空', trigger: 'blur' }]
  344. const formRules = reactive({
  345. deviceName: [{ required: true, message: '设备不能为空', trigger: 'blur' }],
  346. failureCode: [{ required: true, message: '故障编码不能为空', trigger: 'blur' }],
  347. type: [{ required: true, message: '维修类型不能为空', trigger: 'blur' }],
  348. ifStop: [{ required: true, message: '是否停机不能为空', trigger: 'blur' }],
  349. failureName: [{ required: true, message: '故障名称不能为空', trigger: 'blur' }],
  350. // failureTime: [{ required: true, message: '故障时间不能为空', trigger: 'blur' }],
  351. // maintainStartTime: [{ required: true, message: '维修开始时间不能为空', trigger: 'blur' }],
  352. // maintainEndTime: [{ required: true, message: '维修结束时间不能为空', trigger: 'blur' }],
  353. // maintainDescription: [{ required: true, message: '维修描述不能为空', trigger: 'blur' }],
  354. // maintainPerson: [{ required: true, message: '维修负责人不能为空', trigger: 'blur' }],
  355. deviceId: [{ required: true, message: '设备id不能为空', trigger: 'blur' }]
  356. // status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
  357. })
  358. const addFormRules = reactive({
  359. name: [{ required: true, message: '维修项不能为空', trigger: 'blur' }]
  360. })
  361. const handleConfirm = () => {
  362. addFormData.value.bomNodeId = Math.floor(100000 + Math.random() * 900000)
  363. const index = list.value.findIndex((item) => item.name === addFormData.value.name)
  364. if (index !== -1) {
  365. message.warning("维修项重复")
  366. return
  367. }
  368. list.value.push(addFormData.value)
  369. addItemVisible.value = false
  370. }
  371. const customerChoose = (row) => {
  372. formData.value.supplier = row.id
  373. supplierLabel.value = row.name
  374. }
  375. const customerFormRef = ref()
  376. const openCustomer = (type) => {
  377. customerFormRef.value.open(type)
  378. }
  379. const formRef = ref() // 表单 Ref
  380. const addFormRef = ref()
  381. const deviceChoose = (row) => {
  382. formData.value.deviceId = row.id
  383. formData.value.deviceName = row.deviceName
  384. formData.value.deviceCode = row.deviceCode
  385. formData.value.deptId = row.deptId
  386. // deviceLabel.value = row.deviceName
  387. list.value = []
  388. }
  389. const deviceClear = () => {
  390. formData.value.deviceId = undefined
  391. formData.value.deviceName = undefined
  392. formData.value.deviceCode = undefined
  393. formData.value.deptId = undefined
  394. list.value = []
  395. }
  396. const deviceFormRef = ref()
  397. const openForm = () => {
  398. deviceFormRef.value.open()
  399. }
  400. const materialFormRef = ref()
  401. const currentBomNodeId = ref() // 当前选中的bom节点
  402. const openMaterialForm = (row: any) => {
  403. bomNodeId.value = row.bomNodeId
  404. console.log('设备id:', formData.value.deviceId)
  405. row.deviceId = formData.value.deviceId
  406. const type = 'repair'
  407. materialFormRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
  408. }
  409. const maintainFormRef = ref()
  410. const openMaintainForm = (type: string, id?: number) => {
  411. if (!formData.value.deviceId) {
  412. message.error(t('iotMaintain.deviceHolder'))
  413. return
  414. }
  415. maintainFormRef.value.open(type, formData.value.deviceId)
  416. }
  417. const openMaintainItem = () => {
  418. if (!formData.value.deviceId) {
  419. message.error(t('iotMaintain.deviceHolder'))
  420. return
  421. }
  422. addItemVisible.value = true
  423. addFormData.value.deviceName = formData.value.deviceName
  424. addFormData.value.deviceCode = formData.value.deviceCode
  425. addFormData.value.name = ''
  426. }
  427. const endTimeBlur = () => {
  428. if (formData.value.maintainEndTime <= formData.value.maintainStartTime) {
  429. message.error('维修结束时间不得早于开始时间')
  430. formData.value.maintainEndTime = undefined
  431. }
  432. const now = dayjs();
  433. const target = dayjs(formData.value.maintainEndTime);
  434. if (target.isAfter(now)) {
  435. message.error('维修结束时间不得晚于当前时间')
  436. formData.value.maintainEndTime = undefined
  437. }
  438. }
  439. const failureTimeBlur = () => {
  440. if (formData.value.maintainStartTime < formData.value.failureTime) {
  441. message.error('维修开始时间不得早于故障时间')
  442. formData.value.maintainStartTime = undefined
  443. }
  444. if (formData.value.maintainEndTime < formData.value.failureTime) {
  445. message.error('维修结束时间不得早于故障时间')
  446. formData.value.maintainEndTime = undefined
  447. }
  448. }
  449. const close = () => {
  450. delView(unref(currentRoute))
  451. push({ name: 'IotMaintain', params: {} })
  452. }
  453. const closeDialog = () => {
  454. addItemVisible.value = false
  455. }
  456. const handleViewNew = (nodeId) => {
  457. currentBomNodeId.value = nodeId
  458. drawerVisible.value = true
  459. console.log('当前bom节点:', currentBomNodeId.value)
  460. }
  461. const materialDelete = (row) =>{
  462. totalFee.value = 0
  463. const index = materialList.value.findIndex((item) => item.bomNodeId === bomNodeId.value&&item.materialCode===row.materialCode)
  464. if (index>-1) {
  465. materialList.value.splice(index,1)
  466. }
  467. list.value.forEach((item)=>{
  468. if (item.bomNodeId === row.bomNodeId){
  469. item.materials = materialList.value.filter((item)=>item.bomNodeId===row.bomNodeId)
  470. item.materialCount = item.materials.length;
  471. }
  472. })
  473. materialList.value.forEach((it) => {
  474. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  475. })
  476. formData.value.maintainFee = totalFee.value
  477. }
  478. const materialList = ref<IotMainWorkOrderBomMaterialVO[]>([]) // 保养工单bom关联物料列表
  479. const bomNodeId = ref() // 最新的bomNodeId
  480. const selectChoose = (selectedMaterial) => {
  481. selectedMaterial.bomNodeId = bomNodeId.value
  482. // 关联 bomNodeId
  483. const processedMaterials = selectedMaterial.map((material) => ({
  484. ...material,
  485. bomNodeId: bomNodeId.value // 统一关联当前行的 bomNodeId
  486. }))
  487. // 避免重复添加
  488. processedMaterials.forEach((newMaterial) => {
  489. // 检查是否已存在相同 bomNodeId + materialCode 的条目
  490. const isExist = materialList.value.some(
  491. (item) => item.bomNodeId === bomNodeId.value && item.materialCode === newMaterial.materialCode
  492. )
  493. if (!isExist) {
  494. materialList.value.push(newMaterial)
  495. }
  496. })
  497. totalFee.value = 0;
  498. list.value.forEach((item) => {
  499. if (item.bomNodeId === bomNodeId.value) {
  500. item.materials = materialList.value.filter((item) => item.bomNodeId === bomNodeId.value)
  501. if (item.materials) {
  502. item.materialCount = item.materials.length;
  503. }
  504. }
  505. })
  506. materialList.value.forEach((it) => {
  507. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  508. })
  509. formData.value.maintainFee = totalFee.value
  510. console.log('选择完成的数据:', JSON.stringify(selectedMaterial))
  511. console.log('添加到本地列表的数据:', materialList.value)
  512. }
  513. const maintainChoose = (formData) => {
  514. formData.forEach((item) => {
  515. const index = list.value.findIndex((li) => item.name === li.name)
  516. if (index==-1){
  517. list.value.push(item)
  518. }
  519. })
  520. }
  521. const removeOnesFromKeys = (obj: Record<string, any>) => {
  522. return Object.keys(obj).reduce(
  523. (acc, key) => {
  524. const newKey = key.replace(/1/g, '') // 替换所有 1
  525. acc[newKey] = obj[key]
  526. return acc
  527. },
  528. {} as Record<string, any>
  529. )
  530. }
  531. /** 提交表单 */
  532. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  533. const submitForm = async () => {
  534. // 校验表单
  535. await formRef.value.validate()
  536. // 提交请求
  537. formLoading.value = true
  538. try {
  539. if (formData.value.type==='in') {
  540. formData.value.status = 'finished'
  541. } else {
  542. formData.value.status = 'tx'
  543. }
  544. // let files: any[]
  545. // files = formData.value.outFile
  546. // if (files) {
  547. // formData.value.outFile = files
  548. // .map((element) => {
  549. // return element.path
  550. // })
  551. // .join(',')
  552. // }
  553. const data = {
  554. maintain: formData.value,
  555. maintainMaterials: list.value
  556. }
  557. if (formType.value === 'create') {
  558. await IotMaintainApi.createIotMaintain(data)
  559. message.success(t('common.createSuccess'))
  560. close()
  561. } else {
  562. await IotMaintainApi.updateIotMaintain(data)
  563. message.success(t('common.updateSuccess'))
  564. close()
  565. }
  566. // 发送操作成功的事件
  567. emit('success')
  568. } finally {
  569. formLoading.value = false
  570. }
  571. }
  572. /** 重置表单 */
  573. const resetForm = () => {
  574. formData.value = {
  575. id: undefined,
  576. failureCode: undefined,
  577. failureName: undefined,
  578. deviceId: undefined,
  579. status: undefined,
  580. ifStop: undefined,
  581. failureTime: undefined,
  582. failureInfluence: undefined,
  583. failureSystem: undefined,
  584. description: undefined,
  585. pic: undefined,
  586. solution: undefined,
  587. maintainStartTime: undefined,
  588. maintainEndTime: undefined,
  589. remark: undefined,
  590. deviceName: undefined,
  591. processInstanceId: undefined,
  592. auditStatus: undefined,
  593. deptId: undefined
  594. }
  595. formRef.value?.resetFields()
  596. }
  597. const userId = ref('')
  598. onMounted(async () => {
  599. const userInfo = wsCache.get(CACHE_KEY.USER)
  600. userId.value = userInfo.user.id;
  601. if (id) {
  602. formType.value = 'update'
  603. const iotMaintain = await IotMaintainApi.getIotMaintain(id)
  604. deviceLabel.value = iotMaintain.deviceName
  605. formData.value = iotMaintain
  606. formData.value.status = undefined
  607. } else {
  608. formData.value.type = 'in'
  609. formType.value = 'create'
  610. }
  611. })
  612. const handleDelete = async (id: number) => {
  613. try {
  614. const index = list.value.findIndex((item) => item.bomNodeId === id)
  615. if (index !== -1) {
  616. // 通过 splice 删除元素
  617. list.value.splice(index, 1)
  618. totalFee.value = 0
  619. list.value.forEach(item => {
  620. item.materials.forEach((it) => {
  621. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  622. })
  623. })
  624. formData.value.maintainFee = totalFee.value
  625. }
  626. } catch {}
  627. }
  628. </script>
  629. <style scoped>
  630. .base-expandable-content {
  631. overflow: hidden; /* 隐藏溢出的内容 */
  632. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  633. }
  634. </style>