IotMaintainAddEdit.vue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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 @change="typeChange">
  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="pics">
  105. <UploadImgs v-model="formData.pics" height="55px" />
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="8" v-if="formData.type === 'out'">
  109. <el-form-item :label="t('iotMaintain.applyPerson')" prop="applyPersonId" :rules="formData.type==='out'?classifyRules:[]">
  110. <el-select v-model="formData.applyPersonId" :placeholder="t('iotMaintain.applyPersonHolder')" clearable filterable>
  111. <el-option
  112. v-for="person in applyPeoPle"
  113. :key="person.oaId"
  114. :label="person.lastname"
  115. :value="person.oaId"
  116. />
  117. </el-select>
  118. </el-form-item>
  119. </el-col>
  120. <el-col :span="8" v-if="formData.type === 'out'">
  121. <el-form-item :label="t('iotMaintain.maintainClassify')" prop="maintainClassify" :rules="formData.type==='out'?classifyRules:[]">
  122. <el-select v-model="formData.maintainClassify" :placeholder="t('iotMaintain.maintainClassifyHolder')" clearable>
  123. <el-option
  124. v-for="dict in getStrDictOptions(DICT_TYPE.PMS_MAIN_CLASSIFY)"
  125. :key="dict.value"
  126. :label="dict.label"
  127. :value="dict.value"
  128. />
  129. </el-select>
  130. </el-form-item>
  131. </el-col>
  132. <el-col :span="8" v-if="formData.type === 'out'">
  133. <el-form-item :label="t('iotMaintain.kmHour')" prop="kmHour">
  134. <el-input v-model="formData.kmHour" :placeholder="t('iotMaintain.kmHourHolder')" />
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="8" v-if="formData.type === 'out'">
  138. <el-form-item :label="t('deviceForm.model')" prop="model" :rules="formData.type==='out'?modelRules:[]">
  139. <el-input v-model="formData.model" :placeholder="t('deviceForm.modelHolder')" />
  140. </el-form-item>
  141. </el-col>
  142. <el-col :span="8" v-if="formData.type === 'out'">
  143. <el-form-item :label="t('deviceForm.enable')" prop="enableDate" :rules="formData.type==='out'?modelRules:[]">
  144. <el-date-picker
  145. style="width: 150%"
  146. v-model="formData.enableDate"
  147. type="date"
  148. value-format="YYYY-MM-DD"
  149. :placeholder="t('deviceForm.enableHolder')"
  150. />
  151. </el-form-item>
  152. </el-col>
  153. <el-col :span="8" v-if="formData.type === 'out'">
  154. <div style="display: flex;flex-direction: row">
  155. <el-form-item :label="t('iotMaintain.supplier')" prop="supplier" style="width: 86%" :rules="formData.type==='out'?supplierRules:[]">
  156. <el-input
  157. clearable
  158. v-model="formData.supplier"
  159. :placeholder="t('iotMaintain.suppHolder')"
  160. />
  161. </el-form-item>
  162. <el-button type="info" @click="openCustomer('supplier')">请选择</el-button>
  163. </div>
  164. </el-col>
  165. <el-col :span="8" >
  166. <el-form-item :label="t('iotMaintain.repairCosts')" prop="maintainFee" :rules="formData.type==='out'?feeRules:[]">
  167. <el-input-number
  168. v-model="formData.maintainFee"
  169. :min="0"
  170. :precision="2"
  171. :step="0.1"
  172. style="width: 100%"
  173. />
  174. </el-form-item>
  175. </el-col>
  176. <el-col :span="8" v-if="formData.type === 'out'">
  177. <el-form-item :label="t('iotMaintain.projectManager')" prop="projectManager" :rules="formData.type==='out'?projectRules:[]">
  178. <el-select v-model="formData.projectManager" :placeholder="t('iotMaintain.projectManagerHolder')" clearable filterable>
  179. <el-option
  180. v-for="person in projectManager"
  181. :key="person.oaId"
  182. :label="person.lastname"
  183. :value="person.oaId"
  184. />
  185. </el-select>
  186. </el-form-item>
  187. </el-col>
  188. <el-col :span="8" v-if="formData.type === 'out'">
  189. <el-form-item :label="t('iotMaintain.address')" prop="address">
  190. <el-input v-model="formData.address"/>
  191. </el-form-item>
  192. </el-col>
  193. <el-col :span="8" v-if="formData.type === 'out'">
  194. <el-form-item :label="t('iotMaintain.attachment')" prop="outFiles">
  195. <UploadFile v-model="formData.outFiles" :is-show-tip="false" class="min-w-80px" multiple :limit="9" />
  196. </el-form-item>
  197. </el-col>
  198. <el-col :span="16" v-if="formData.type === 'out'" >
  199. <el-form-item :label="t('iotMaintain.maintainItem')" prop="maintainItem" :rules="formData.type==='out'?itemRules:[]">
  200. <el-input type="textarea" v-model="formData.maintainItem"/>
  201. </el-form-item>
  202. </el-col>
  203. <el-col :span="16">
  204. <el-form-item :label="t('iotMaintain.faultDescription')" prop="description">
  205. <el-input type="textarea" v-model="formData.description"/>
  206. </el-form-item>
  207. </el-col>
  208. <el-col :span="12">
  209. <el-form-item :label="t('iotMaintain.repairDescription')" prop="maintainDescription">
  210. <el-input type="textarea" v-model="formData.maintainDescription" />
  211. </el-form-item>
  212. </el-col>
  213. <el-col :span="12">
  214. <el-form-item :label="t('iotMaintain.solution')" prop="solution">
  215. <el-input type="textarea" v-model="formData.solution" />
  216. </el-form-item>
  217. </el-col>
  218. <el-col :span="24">
  219. <el-form-item :label="t('iotMaintain.remark')" prop="remark">
  220. <el-input v-model="formData.remark" type="textarea" :placeholder="t('iotMaintain.remarkHolder')" />
  221. </el-form-item>
  222. </el-col>
  223. </el-row>
  224. </div>
  225. </el-form>
  226. </ContentWrap>
  227. <DeviceList ref="deviceFormRef" @choose="deviceChoose" />
  228. <CustomerList ref="customerFormRef" @choose="customerChoose" />
  229. <MaterialListDrawer
  230. :model-value="drawerVisible"
  231. @update:model-value="(val) => (drawerVisible = val)"
  232. :node-id="currentBomNodeId"
  233. :materials="materialList.filter((item) => item.bomNodeId === currentBomNodeId)"
  234. @delete = "materialDelete"
  235. />
  236. <Dialog :title="t('iotMaintain.repairItems')" v-model="addItemVisible" style="min-height: 300px">
  237. <el-form
  238. ref="addFormRef"
  239. :model="addFormData"
  240. :rules="addFormRules"
  241. label-position="right"
  242. label-width="68px"
  243. >
  244. <el-form-item :label="t('iotMaintain.BOMNodeID')" v-if="false" prop="deviceCode">
  245. <el-input v-model="addFormData.bomNodeId" disabled />
  246. </el-form-item>
  247. <el-form-item :label="t('iotMaintain.deviceCode')" prop="deviceCode">
  248. <el-input v-model="addFormData.deviceCode" disabled />
  249. </el-form-item>
  250. <el-form-item :label="t('iotMaintain.deviceName')" prop="deviceName">
  251. <el-input v-model="addFormData.deviceName" disabled />
  252. </el-form-item>
  253. <el-form-item :label="t('iotMaintain.repairItems')" prop="name">
  254. <el-input v-model="addFormData.name" :placeholder="t('iotMaintain.repairItemsHolder')" />
  255. </el-form-item>
  256. </el-form>
  257. <el-form>
  258. <el-form-item style="float: right">
  259. <el-button @click="handleConfirm" type="primary">{{ t('iotMaintain.ok') }}</el-button>
  260. <el-button @click="closeDialog">{{ t('iotMaintain.cancel') }}</el-button>
  261. </el-form-item>
  262. </el-form>
  263. </Dialog>
  264. </ContentWrap>
  265. <ContentWrap v-loading="formLoading">
  266. <ContentWrap>
  267. <!-- 搜索工作栏 -->
  268. <el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
  269. <el-form-item>
  270. <!-- <el-button @click="openMaterialForm" type="primary"-->
  271. <!-- ><Icon icon="ep:plus" class="mr-5px" /> 选择物料</el-button>-->
  272. <el-button @click="openMaintainForm" type="primary"
  273. ><Icon icon="ep:select" class="mr-5px" />
  274. {{ t('iotMaintain.selectMaintenanceItem') }}</el-button
  275. >
  276. <el-button @click="openMaintainItem" type="primary"
  277. ><Icon icon="ep:plus" class="mr-5px" />
  278. {{ t('iotMaintain.addMaintenanceItems') }}</el-button
  279. >
  280. <!-- <el-button @click="handleViewNew" type="warning"-->
  281. <!-- ><Icon icon="ep:plus" class="mr-5px" /> 新增物料</el-button>-->
  282. </el-form-item>
  283. </el-form>
  284. </ContentWrap>
  285. <!-- 列表 -->
  286. <ContentWrap>
  287. <el-table v-loading="loading" :data="list" class="abc" @row-click="handleRowClick"
  288. :row-class-name="tableRowClassName">
  289. <el-table-column :label="t('iotMaintain.deviceCode')" align="center" prop="deviceCode" />
  290. <el-table-column :label="t('iotMaintain.deviceName')" align="center" prop="deviceName" />
  291. <el-table-column :label="t('iotMaintain.repairItems')" align="center" prop="name" />
  292. <el-table-column :label="t('iotMaintain.numberOfMaterials')" align="center" prop="materialCount" >
  293. <template #default="scope">
  294. <el-tag v-if="scope.row.materialCount" type="danger"> {{scope.row.materialCount}}</el-tag>
  295. </template>
  296. </el-table-column>
  297. <el-table-column :label="t('iotMaintain.ifNeed')" align="center" prop="ifNeed">
  298. <template #default="scope">
  299. <el-switch
  300. v-model="scope.row.ifNeed"
  301. @change="handleIfNeedChange(scope.row)"
  302. />
  303. </template>
  304. </el-table-column>
  305. <el-table-column :label="t('iotMaintain.operation')" align="center" min-width="120px">
  306. <template #default="scope">
  307. <div style="display: flex; justify-content: center; align-items: center; width: 100%">
  308. <div>
  309. <el-button
  310. style="vertical-align: middle"
  311. link
  312. type="danger"
  313. @click="handleDelete(scope.row.bomNodeId)"
  314. >
  315. <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
  316. {{ t('iotMaintain.remove') }}
  317. </el-button>
  318. </div>
  319. </div>
  320. </template>
  321. </el-table-column>
  322. </el-table>
  323. </ContentWrap>
  324. <!-- 表单弹窗:添加/修改 -->
  325. <WorkOrderMaterial ref="materialFormRef" @choose="selectChoose" />
  326. <ChooseMaintain ref="maintainFormRef" @choose="maintainChoose" />
  327. </ContentWrap>
  328. <ContentWrap v-loading="formLoading" v-if="materialIfShow">
  329. <ContentWrap>
  330. <!-- 搜索工作栏 -->
  331. <el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
  332. <el-form-item>
  333. <el-button type="primary" @click="openMaterialForm()">
  334. <Icon icon="ep:select" class="mr-5px" />
  335. {{ t('iotMaintain.selectMaterials') }}
  336. </el-button>
  337. <el-button type="primary" @click="addMaterial">
  338. <Icon icon="ep:plus" class="mr-5px" />
  339. {{ t('iotMaintain.addMaterials') }}
  340. </el-button>
  341. <el-button type="primary" @click="showAllMaterial">
  342. <Icon icon="ep:star-filled" class="mr-5px" />
  343. {{ t('iotMaintain.showAllMaterials') }}
  344. </el-button>
  345. </el-form-item>
  346. </el-form>
  347. </ContentWrap>
  348. <ContentWrap>
  349. <el-table :data="filteredMaterials" style="width: 100%">
  350. <el-table-column prop="bomNodeId" :label="t('bomList.bomNode')" width="180" v-if="false"/>
  351. <el-table-column prop="factory" :label="t('workOrderMaterial.factory')" width="180" v-if="!hideExtraColumns" />
  352. <el-table-column prop="costCenter" :label="t('workOrderMaterial.costCenter')" width="180" v-if="!hideExtraColumns"/>
  353. <el-table-column prop="projectDepartment" :label="t('workOrderMaterial.storageLocation')" width="180" v-if="!hideExtraColumns" />
  354. <el-table-column prop="materialName" :label="t('workOrderMaterial.materialName')" width="180" >
  355. <template #default="scope">
  356. <el-input
  357. v-model="scope.row.materialName"
  358. size="small"
  359. v-if="scope.row.materialSource === '手动添加'"
  360. :placeholder="t('workOrderMaterial.nameHolder')"
  361. />
  362. <span v-else>{{ scope.row.materialName }}</span>
  363. </template>
  364. </el-table-column>
  365. <el-table-column prop="materialCode" :label="t('workOrderMaterial.materialCode')" width="180" >
  366. <template #default="scope">
  367. <el-input
  368. v-model="scope.row.materialCode"
  369. size="small"
  370. v-if="scope.row.materialSource === '手动添加'"
  371. :placeholder="t('workOrderMaterial.codeHolder')"
  372. />
  373. <span v-else>{{ scope.row.materialCode }}</span>
  374. </template>
  375. </el-table-column>
  376. <el-table-column prop="unit" :label="t('workOrderMaterial.unit')" width="180" >
  377. <template #default="scope">
  378. <el-input
  379. v-model="scope.row.unit"
  380. size="small"
  381. v-if="scope.row.materialSource === '手动添加'"
  382. :placeholder="t('workOrderMaterial.unitHolder')"
  383. />
  384. <span v-else>{{ scope.row.unit }}</span>
  385. </template>
  386. </el-table-column>
  387. <el-table-column prop="unitPrice" :label="t('workOrderMaterial.unitPrice')" width="180" >
  388. <template #default="scope">
  389. <el-input
  390. v-model="scope.row.unitPrice"
  391. size="small"
  392. v-if="scope.row.materialSource === '手动添加'"
  393. :placeholder="t('workOrderMaterial.unitPriceHolder')"
  394. />
  395. <span v-else>{{ scope.row.unitPrice }}</span>
  396. </template>
  397. </el-table-column>
  398. <el-table-column prop="quantity" :label="t('workOrderMaterial.ConsumptionQuantity')" width="180" >
  399. <template #default="scope">
  400. <el-input
  401. type="number"
  402. :controls="false"
  403. v-model="scope.row.quantity"
  404. @click.stop=""
  405. @blur="(event) => handleQuantityBlur(event, scope.row)"
  406. size="small"
  407. :placeholder="t('iotMaintain.quantityHolder')"
  408. />
  409. </template>
  410. </el-table-column>
  411. <el-table-column prop="materialSource" :label="t('bomList.type')" width="180" />
  412. <el-table-column :label="t('workplace.operation')" align="right" v-if="true">
  413. <template #default="scope">
  414. <el-button
  415. size="small"
  416. type="danger"
  417. @click="materialDelete(scope.row)"
  418. >{{ t('form.delete') }}</el-button>
  419. </template>
  420. </el-table-column>
  421. </el-table>
  422. </ContentWrap>
  423. <ContentWrap>
  424. <el-form>
  425. <el-form-item style="float: right">
  426. <el-button @click="submitForm" type="primary" :disabled="formLoading">{{ t('iotMaintain.save') }}</el-button>
  427. <el-button @click="close">{{ t('iotMaintain.cancel') }}</el-button>
  428. </el-form-item>
  429. </el-form>
  430. </ContentWrap>
  431. </ContentWrap>
  432. </template>
  433. <script setup lang="ts">
  434. import { IotMaintainApi } from '@/api/pms/maintain'
  435. import { DICT_TYPE, getBoolDictOptions, getStrDictOptions } from '@/utils/dict'
  436. import DeviceList from '@/views/pms/failure/DeviceList.vue'
  437. import * as UserApi from '@/api/system/user'
  438. import { ref } from 'vue'
  439. import { IotMaintainMaterialVO } from '@/api/pms/maintain/material'
  440. import { useTagsViewStore } from '@/store/modules/tagsView'
  441. import CustomerList from '@/views/pms/device/CustomerList.vue'
  442. import WorkOrderMaterial from '@/views/pms/iotmainworkorder/WorkOrderMaterial.vue'
  443. import { IotMainWorkOrderBomMaterialVO } from '@/api/pms/iotmainworkorderbommaterial'
  444. import MaterialListDrawer from '@/views/pms/iotmainworkorder/SelectedMaterialDrawer.vue'
  445. import ChooseMaintain from '@/views/pms/maintain/material/ChooseMaintain.vue'
  446. import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
  447. import dayjs from 'dayjs'
  448. import {checkPermi} from "@/utils/permission";
  449. /** 维修工单 表单 */
  450. defineOptions({ name: 'MaintainAdd' })
  451. const addItemVisible = ref(false) // 弹窗的是否展示
  452. const materialIfShow = ref(true)
  453. const { t } = useI18n() // 国际化
  454. const message = useMessage() // 消息弹窗
  455. const { delView } = useTagsViewStore() // 视图操作
  456. const { currentRoute, push } = useRouter()
  457. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  458. const dialogTitle = ref('') // 弹窗的标题
  459. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  460. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  461. const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
  462. const drawerVisible = ref<boolean>(false)
  463. const showDrawer = ref()
  464. const list = ref<IotMaintainMaterialVO[]>([]) // 列表的数据
  465. const { params, name } = useRoute() // 查询参数
  466. const id = params.id
  467. const supplierLabel = ref('') // 表单的类型:create - 新增;update - 修改
  468. const totalFee = ref(0)
  469. const applyPeoPle = ref([])
  470. const projectManager = ref([])
  471. const { wsCache } = useCache()
  472. const hideExtraColumns = ref(false)
  473. const filteredMaterials = ref([])
  474. const selectedRowId = ref<number | null>(null)
  475. const selectedRow = ref({})
  476. const loading = ref(false)
  477. const addFormData = ref({
  478. name: '',
  479. deviceName: '',
  480. deviceCode: '',
  481. bomNodeId: '',
  482. })
  483. const formData = ref({
  484. kmHour:undefined,
  485. maintainItem:undefined,
  486. enableDate: undefined,
  487. projectManager:undefined,
  488. applyPersonId:undefined,
  489. maintainClassify: undefined,
  490. address:undefined,
  491. model:undefined,
  492. id: undefined,
  493. failureCode: undefined,
  494. failureName: undefined,
  495. deviceId: undefined,
  496. status: undefined,
  497. type: undefined,
  498. ifStop: undefined,
  499. failureTime: undefined,
  500. failureInfluence: undefined,
  501. failureSystem: undefined,
  502. description: undefined,
  503. pic: undefined,
  504. pics: [],
  505. outFiles:[],
  506. solution: undefined,
  507. maintainStartTime: undefined,
  508. maintainEndTime: undefined,
  509. remark: undefined,
  510. deviceName: undefined,
  511. deviceCode: undefined,
  512. processInstanceId: undefined,
  513. auditStatus: undefined,
  514. deptId: undefined,
  515. maintainPerson: undefined,
  516. maintainDescription: undefined,
  517. supplier: undefined,
  518. maintainFee: undefined,
  519. outFile: undefined,
  520. maintainType: undefined,
  521. })
  522. const failureTimeRule = [{ required: true, message: '故障时间不能为空', trigger: 'blur' }]
  523. const supplierRules = [{ required: true, message: '供应商不能为空', trigger: 'blur' }]
  524. const projectRules = [{ required: true, message: '项目经理不能为空', trigger: 'blur' }]
  525. const itemRules = [{ required: true, message: '维修项目不能为空', trigger: 'blur' }]
  526. const classifyRules = [{ required: true, message: '维修类别不能为空', trigger: 'blur' }]
  527. const feeRules = [{ required: true, message: '维修费用不能为空', trigger: 'blur' }]
  528. const modelRules = [{ required: true, message: '规格型号不能为空', trigger: 'blur' }]
  529. const startRule = [{ required: true, message: '维修开始时间不能为空', trigger: 'blur' }]
  530. const descriptionRule = [{required: true, message:'维修描述不能为空', trigger: 'blur' }]
  531. const endRule = [{ required: true, message: '维修结束时间不能为空', trigger: 'blur' }]
  532. const formRules = reactive({
  533. deviceName: [{ required: true, message: '设备不能为空', trigger: 'blur' }],
  534. failureCode: [{ required: true, message: '故障编码不能为空', trigger: 'blur' }],
  535. type: [{ required: true, message: '维修类型不能为空', trigger: 'blur' }],
  536. ifStop: [{ required: true, message: '是否停机不能为空', trigger: 'blur' }],
  537. failureName: [{ required: true, message: '故障名称不能为空', trigger: 'blur' }],
  538. description: [{ required: true, message: '故障描述不能为空', trigger: 'blur' }],
  539. maintainDescription: [{ required: true, message: '维修描述不能为空', trigger: 'blur' }],
  540. // failureTime: [{ required: true, message: '故障时间不能为空', trigger: 'blur' }],
  541. // maintainStartTime: [{ required: true, message: '维修开始时间不能为空', trigger: 'blur' }],
  542. // maintainEndTime: [{ required: true, message: '维修结束时间不能为空', trigger: 'blur' }],
  543. // maintainDescription: [{ required: true, message: '维修描述不能为空', trigger: 'blur' }],
  544. // maintainPerson: [{ required: true, message: '维修负责人不能为空', trigger: 'blur' }],
  545. deviceId: [{ required: true, message: '设备id不能为空', trigger: 'blur' }]
  546. // status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
  547. })
  548. const handleIfNeedChange = (row) =>{
  549. if (row.ifNeed) {
  550. materialIfShow.value = true
  551. } else {
  552. materialIfShow.value = false
  553. //关闭的同时清除该维修项的物料
  554. materialList.value = materialList.value.filter(item => item.bomNodeId !== row.bomNodeId);
  555. const targetItem = list.value.find(item => item.bomNodeId === row.bomNodeId);
  556. if (targetItem) {
  557. targetItem.materialCount = 0;
  558. }
  559. }
  560. }
  561. const showAllMaterial = () =>{
  562. selectedRow.value = null;
  563. selectedRowId.value = null;
  564. filteredMaterials.value = materialList.value
  565. }
  566. const addMaterial = () =>{
  567. if (selectedRowId.value === null) {
  568. message.error('请点击选择维修项');
  569. return
  570. }
  571. const newId = Math.max(...filteredMaterials.value.map(item => item.id), 0) + 1;
  572. const newMaterial = {
  573. id: newId,
  574. factory: '',
  575. costCenter: null,
  576. projectDepartment: null,
  577. materialName: null,
  578. materialCode:null,
  579. bomNodeId: selectedRowId.value,
  580. unit: null,
  581. unitPrice: null,
  582. quantity: null,
  583. materialSource: '手动添加'
  584. }
  585. filteredMaterials.value.unshift(newMaterial);
  586. materialList.value.unshift(newMaterial);
  587. list.value.forEach((item)=>{
  588. if (item.bomNodeId === selectedRowId.value) {
  589. item.materials = materialList.value.filter((item)=>item.bomNodeId===selectedRowId.value)
  590. item.materialCount = item.materials.length;
  591. }
  592. })
  593. }
  594. const handleQuantityBlur = (event: Event, row: any) => {
  595. const inputValue = (event.target as HTMLInputElement).value;
  596. let num = parseFloat(inputValue);
  597. // 处理无效值
  598. if (isNaN(num)) {
  599. row.quantity = 0;
  600. return;
  601. }
  602. // 处理小于等于0的情况
  603. if (num <= 0) {
  604. row.quantity = 0;
  605. return;
  606. }
  607. totalFee.value = 0
  608. // 保留两位小数
  609. row.quantity = parseFloat(num.toFixed(4));
  610. materialList.value.forEach((it) => {
  611. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  612. })
  613. formData.value.maintainFee = totalFee.value
  614. };
  615. // 行点击事件处理函数
  616. const handleRowClick = (row: any) => {
  617. if (selectedRowId.value === row.bomNodeId) {
  618. selectedRowId.value = null
  619. selectedRow.value = null
  620. } else {
  621. // 否则选中当前行
  622. selectedRowId.value = row.bomNodeId
  623. selectedRow.value = row
  624. }
  625. // 保留原有的点击逻辑(如果有的话)
  626. console.log('点击了行:', selectedRowId.value)
  627. if (selectedRow.value === null) {
  628. filteredMaterials.value = materialList.value;
  629. } else {
  630. filteredMaterials.value = materialList.value.filter((item) => item.bomNodeId === row.bomNodeId)
  631. }
  632. if (row.ifNeed) {
  633. materialIfShow.value = true
  634. } else {
  635. materialIfShow.value = false
  636. }
  637. }
  638. // 行样式类名方法
  639. const tableRowClassName = ({ row }: { row: any }) => {
  640. // 如果是选中的行,返回自定义类名
  641. return row.bomNodeId === selectedRowId.value ? 'green-row' : ''
  642. }
  643. const addFormRules = reactive({
  644. name: [{ required: true, message: '维修项不能为空', trigger: 'blur' }]
  645. })
  646. const typeChange = async () =>{
  647. if (formData.value.type === 'out') {
  648. await IotMaintainApi.getApplyUsers("").then((res) => {
  649. applyPeoPle.value = res
  650. })
  651. await IotMaintainApi.getProjectUsers("").then((res) => {
  652. projectManager.value = res
  653. })
  654. }
  655. }
  656. const handleConfirm = () => {
  657. addFormData.value.bomNodeId = Math.floor(100000 + Math.random() * 900000)
  658. const index = list.value.findIndex((item) => item.name === addFormData.value.name)
  659. if (index !== -1) {
  660. message.warning("维修项重复")
  661. return
  662. }
  663. const addItem = {...addFormData.value}
  664. addItem.ifNeed = true
  665. list.value.push(addItem)
  666. addItemVisible.value = false
  667. }
  668. const customerChoose = (row) => {
  669. formData.value.supplier = row.name
  670. // supplierLabel.value = row.name
  671. }
  672. const customerFormRef = ref()
  673. const openCustomer = (type) => {
  674. customerFormRef.value.open(type)
  675. }
  676. const formRef = ref() // 表单 Ref
  677. const addFormRef = ref()
  678. const deviceChoose = (row) => {
  679. formData.value.model = row.model
  680. formData.value.enableDate = row.enableDate
  681. formData.value.deviceId = row.id
  682. formData.value.deviceName = row.deviceName
  683. formData.value.deviceCode = row.deviceCode
  684. formData.value.deptId = row.deptId
  685. // deviceLabel.value = row.deviceName
  686. list.value = []
  687. }
  688. const deviceClear = () => {
  689. formData.value.deviceId = undefined
  690. formData.value.deviceName = undefined
  691. formData.value.deviceCode = undefined
  692. formData.value.deptId = undefined
  693. list.value = []
  694. }
  695. const deviceFormRef = ref()
  696. const openForm = () => {
  697. deviceFormRef.value.open()
  698. }
  699. const materialFormRef = ref()
  700. const currentBomNodeId = ref() // 当前选中的bom节点
  701. const openMaterialForm = () => {
  702. if (selectedRowId.value === null) {
  703. message.error('请点击选择维修项');
  704. return
  705. }
  706. const row = selectedRow.value
  707. bomNodeId.value = row.bomNodeId
  708. console.log('设备id:', formData.value.deviceId)
  709. row.deviceId = formData.value.deviceId
  710. const type = 'repair'
  711. materialFormRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
  712. }
  713. const maintainFormRef = ref()
  714. const openMaintainForm = (type: string, id?: number) => {
  715. if (!formData.value.deviceId) {
  716. message.error(t('iotMaintain.deviceHolder'))
  717. return
  718. }
  719. maintainFormRef.value.open(type, formData.value.deviceId)
  720. }
  721. const openMaintainItem = () => {
  722. if (!formData.value.deviceId) {
  723. message.error(t('iotMaintain.deviceHolder'))
  724. return
  725. }
  726. addItemVisible.value = true
  727. addFormData.value.deviceName = formData.value.deviceName
  728. addFormData.value.deviceCode = formData.value.deviceCode
  729. addFormData.value.name = ''
  730. }
  731. const endTimeBlur = () => {
  732. if (formData.value.maintainEndTime <= formData.value.maintainStartTime) {
  733. message.error('维修结束时间不得早于开始时间')
  734. formData.value.maintainEndTime = undefined
  735. }
  736. const now = dayjs();
  737. const target = dayjs(formData.value.maintainEndTime);
  738. if (target.isAfter(now)) {
  739. message.error('维修结束时间不得晚于当前时间')
  740. formData.value.maintainEndTime = undefined
  741. }
  742. }
  743. const failureTimeBlur = () => {
  744. if (formData.value.maintainStartTime < formData.value.failureTime) {
  745. message.error('维修开始时间不得早于故障时间')
  746. formData.value.maintainStartTime = undefined
  747. }
  748. if (formData.value.maintainEndTime < formData.value.failureTime) {
  749. message.error('维修结束时间不得早于故障时间')
  750. formData.value.maintainEndTime = undefined
  751. }
  752. }
  753. const close = () => {
  754. delView(unref(currentRoute))
  755. push({ name: 'IotMaintain', params: {} })
  756. }
  757. const closeDialog = () => {
  758. addItemVisible.value = false
  759. }
  760. const handleViewNew = (nodeId) => {
  761. currentBomNodeId.value = nodeId
  762. drawerVisible.value = true
  763. console.log('当前bom节点:', currentBomNodeId.value)
  764. }
  765. const materialDelete = (row) =>{
  766. totalFee.value = 0
  767. const index = materialList.value.findIndex((item) => item.bomNodeId === selectedRowId.value&&item.materialCode===row.materialCode)
  768. const filterIndex = filteredMaterials.value.findIndex((item) => item.bomNodeId === selectedRowId.value&&item.materialCode===row.materialCode)
  769. if (index>-1) {
  770. materialList.value.splice(index,1)
  771. }
  772. if (filterIndex > -1) {
  773. filteredMaterials.value.splice(filterIndex, 1)
  774. }
  775. list.value.forEach((item)=>{
  776. if (item.bomNodeId === row.bomNodeId){
  777. item.materials = materialList.value.filter((item)=>item.bomNodeId===row.bomNodeId)
  778. item.materialCount = item.materials.length;
  779. }
  780. })
  781. materialList.value.forEach((it) => {
  782. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  783. })
  784. formData.value.maintainFee = totalFee.value
  785. }
  786. const materialList = ref<IotMainWorkOrderBomMaterialVO[]>([]) // 保养工单bom关联物料列表
  787. const bomNodeId = ref() // 最新的bomNodeId
  788. const selectChoose = (selectedMaterial) => {
  789. selectedMaterial.bomNodeId = bomNodeId.value
  790. // 关联 bomNodeId
  791. const processedMaterials = selectedMaterial.map((material) => ({
  792. ...material,
  793. bomNodeId: bomNodeId.value // 统一关联当前行的 bomNodeId
  794. }))
  795. // 避免重复添加
  796. processedMaterials.forEach((newMaterial) => {
  797. // 检查是否已存在相同 bomNodeId + materialCode 的条目
  798. const isExist = materialList.value.some(
  799. (item) => item.bomNodeId === bomNodeId.value && item.materialCode === newMaterial.materialCode
  800. )
  801. if (!isExist) {
  802. materialList.value.push(newMaterial)
  803. }
  804. })
  805. totalFee.value = 0;
  806. list.value.forEach((item) => {
  807. if (item.bomNodeId === bomNodeId.value) {
  808. item.materials = materialList.value.filter((item) => item.bomNodeId === bomNodeId.value)
  809. if (item.materials) {
  810. item.materialCount = item.materials.length;
  811. }
  812. }
  813. })
  814. materialList.value.forEach((it) => {
  815. totalFee.value = it.unitPrice * it.quantity + totalFee.value
  816. })
  817. formData.value.maintainFee = totalFee.value
  818. console.log('选择完成的数据:', JSON.stringify(selectedMaterial))
  819. console.log('添加到本地列表的数据:', materialList.value)
  820. filteredMaterials.value = materialList.value.filter((item) => item.bomNodeId === bomNodeId.value)
  821. }
  822. const maintainChoose = (formData) => {
  823. formData.forEach((item) => {
  824. const index = list.value.findIndex((li) => item.name === li.name)
  825. if (index==-1){
  826. item.ifNeed= true
  827. list.value.push(item)
  828. if (item.deviceBomMaterials) {
  829. item.materialCount = item.deviceBomMaterials.length
  830. item.materials = item.deviceBomMaterials;
  831. item.deviceBomMaterials.forEach((it) => {
  832. it.bomNodeId = item.bomNodeId
  833. it.materialCode = it.code;
  834. it.materialName = it.name
  835. materialList.value.push(it)
  836. })
  837. }
  838. }
  839. })
  840. if (selectedRow.value === null) {
  841. filteredMaterials.value = materialList.value
  842. }
  843. }
  844. const removeOnesFromKeys = (obj: Record<string, any>) => {
  845. return Object.keys(obj).reduce(
  846. (acc, key) => {
  847. const newKey = key.replace(/1/g, '') // 替换所有 1
  848. acc[newKey] = obj[key]
  849. return acc
  850. },
  851. {} as Record<string, any>
  852. )
  853. }
  854. /** 提交表单 */
  855. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  856. const submitForm = async () => {
  857. // 校验表单
  858. await formRef.value.validate()
  859. // 提交请求
  860. formLoading.value = true
  861. try {
  862. if (formData.value.type==='in') {
  863. formData.value.status = 'finished'
  864. } else {
  865. formData.value.status = 'tx'
  866. }
  867. // let files: any[]
  868. // files = formData.value.outFile
  869. // if (files) {
  870. // formData.value.outFile = files
  871. // .map((element) => {
  872. // return element.path
  873. // })
  874. // .join(',')
  875. // }
  876. const data = {
  877. maintain: formData.value,
  878. maintainMaterials: list.value
  879. }
  880. if (formType.value === 'create') {
  881. await IotMaintainApi.createIotMaintain(data)
  882. message.success(t('common.createSuccess'))
  883. close()
  884. } else {
  885. await IotMaintainApi.updateIotMaintain(data)
  886. message.success(t('common.updateSuccess'))
  887. close()
  888. }
  889. // 发送操作成功的事件
  890. emit('success')
  891. } finally {
  892. formLoading.value = false
  893. }
  894. }
  895. /** 重置表单 */
  896. const resetForm = () => {
  897. formData.value = {
  898. id: undefined,
  899. failureCode: undefined,
  900. failureName: undefined,
  901. deviceId: undefined,
  902. status: undefined,
  903. ifStop: undefined,
  904. failureTime: undefined,
  905. failureInfluence: undefined,
  906. failureSystem: undefined,
  907. description: undefined,
  908. pic: undefined,
  909. pics:[],
  910. solution: undefined,
  911. maintainStartTime: undefined,
  912. maintainEndTime: undefined,
  913. remark: undefined,
  914. deviceName: undefined,
  915. processInstanceId: undefined,
  916. auditStatus: undefined,
  917. deptId: undefined
  918. }
  919. formRef.value?.resetFields()
  920. }
  921. const userId = ref('')
  922. onMounted(async () => {
  923. const userInfo = wsCache.get(CACHE_KEY.USER)
  924. userId.value = userInfo.user.id;
  925. if (id) {
  926. formType.value = 'update'
  927. const iotMaintain = await IotMaintainApi.getIotMaintain(id)
  928. deviceLabel.value = iotMaintain.deviceName
  929. formData.value = iotMaintain
  930. formData.value.status = undefined
  931. if (formData.value.type === 'out') {
  932. await IotMaintainApi.getApplyUsers("").then((res) => {
  933. applyPeoPle.value = res
  934. })
  935. await IotMaintainApi.getProjectUsers("").then((res) => {
  936. projectManager.value = res
  937. })
  938. }
  939. } else {
  940. formData.value.type = 'in'
  941. formType.value = 'create'
  942. }
  943. })
  944. const handleDelete = async (id: number) => {
  945. try {
  946. const index = list.value.findIndex((item) => item.bomNodeId === id)
  947. if (index !== -1) {
  948. // 通过 splice 删除元素
  949. list.value.splice(index, 1)
  950. materialList.value = materialList.value.filter((item) => item.bomNodeId !== id)
  951. totalFee.value = 0
  952. // list.value.forEach(item => {
  953. // // item.materials = item.materials.filter(item => item.bomNodeId !== id);
  954. // item.materials.forEach((it) => {
  955. // totalFee.value = it.unitPrice * it.quantity + totalFee.value
  956. // })
  957. // })
  958. materialList.value.forEach((item) => {
  959. totalFee.value = item.unitPrice * item.quantity + totalFee.value
  960. })
  961. formData.value.maintainFee = totalFee.value
  962. }
  963. } catch {}
  964. }
  965. </script>
  966. <style scoped>
  967. .base-expandable-content {
  968. overflow: hidden; /* 隐藏溢出的内容 */
  969. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  970. }
  971. /* 添加绿色行的样式 */
  972. ::v-deep .abc .el-table__row.green-row {
  973. background-color: #7fc6f3; /* 浅绿色背景 */
  974. }
  975. ::v-deep .abc .el-table__row.green-row:hover > td {
  976. background-color: #7fc6f3 !important; /* 鼠标悬停时的绿色背景 */
  977. }
  978. ::v-deep .abc .el-table__row.green-row > td {
  979. background-color: #7fc6f3; /* 选中行的单元格背景 */
  980. }
  981. /* 可选:添加选中行的边框样式 */
  982. ::v-deep .abc .el-table__row.green-row {
  983. border-left: 3px solid #52c41a; /* 左侧绿色边框标识 */
  984. }
  985. </style>