IotMainWorkOrder.vue 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  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="t('bomList.name')" 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="t('mainPlan.MaintenanceMethod')" prop="type">
  20. <el-select v-model="formData.outsourcingFlag" :placeholder="t('faultForm.choose')" clearable>
  21. <el-option
  22. v-for="dict in getIntDictOptions(DICT_TYPE.PMS_ORDER_PROCESS_MODE)"
  23. :key="dict.value"
  24. :label="dict.label"
  25. :value="dict.value"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="8">
  31. <el-form-item :label="t('mainPlan.MaintenanceCost')" prop="cost">
  32. <el-input
  33. v-model="formData.cost"
  34. placeholder="根据物料消耗自动生成"
  35. disabled
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item :label="t('fault.start')" prop="actualStartTime">
  41. <el-date-picker
  42. style="width: 150%"
  43. v-model="formData.actualStartTime"
  44. type="datetime"
  45. value-format="x"
  46. :placeholder="t('fault.start')"
  47. />
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="8">
  51. <el-form-item :label="t('fault.end')" prop="actualEndTime">
  52. <el-date-picker
  53. style="width: 150%"
  54. v-model="formData.actualEndTime"
  55. type="datetime"
  56. value-format="x"
  57. :placeholder="t('fault.end')"
  58. />
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8">
  62. <el-form-item :label="t('mainPlan.otherCost')" prop="otherCost">
  63. <el-input
  64. v-model="formData.otherCost"
  65. @input="handleInput(formData.otherCost, 'otherCost')"
  66. placeholder="其他费用"
  67. />
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8">
  71. <el-form-item :label="t('iotDevice.code')" prop="deviceCode">
  72. <el-input type="text" v-model="formData.deviceCode" disabled/>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="8">
  76. <el-form-item :label="t('iotDevice.name')" prop="deviceName">
  77. <el-input type="text" v-model="formData.deviceName" disabled/>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="8">
  81. <el-form-item :label="t('faultForm.remark')" prop="remark">
  82. <el-input v-model="formData.remark" type="textarea" :placeholder="t('faultForm.rHolder')" />
  83. </el-form-item>
  84. </el-col>
  85. </el-row>
  86. </div>
  87. </el-form>
  88. </ContentWrap>
  89. <ContentWrap>
  90. <!-- 列表 -->
  91. <ContentWrap>
  92. <el-table v-loading="loading" :data="paginatedList" :stripe="true"
  93. :show-overflow-tooltip="true" :header-cell-style="tableHeaderStyle" :span-method="handleSpanMethod">
  94. <!-- 序号列 -->
  95. <el-table-column
  96. type="index"
  97. :label="t('maintain.serial')"
  98. align="center"
  99. prop="serial"
  100. :width="columnWidths.serial"
  101. fixed="left"
  102. />
  103. <el-table-column :label="t('bomList.bomNode')" align="center" prop="bomNodeId" v-if="false"/>
  104. <el-table-column :label="t('iotDevice.code')" align="center" prop="deviceCode" :width="columnWidths.deviceCode" fixed="left" v-if="false">
  105. <template #default="{ row }">
  106. <div class="full-content-cell"> <!-- 自定义样式 -->
  107. {{ row.deviceCode }}
  108. </div>
  109. </template>
  110. </el-table-column>
  111. <el-table-column :label="t('iotDevice.name')" align="center" prop="deviceName" :width="columnWidths.deviceName" fixed="left" v-if="false">
  112. <template #default="{ row }">
  113. <div class="full-content-cell"> <!-- 自定义样式 -->
  114. {{ row.deviceName }}
  115. </div>
  116. </template>
  117. </el-table-column>
  118. <!-- 保养项组列 -->
  119. <el-table-column
  120. v-if="hasGroupInCurrentPage"
  121. :label="t('mainPlan.MaintItemsGroup')"
  122. align="center"
  123. prop="group"
  124. fixed="left"
  125. :width="columnWidths.group"
  126. :cell-class-name="groupCellClassName"
  127. >
  128. <template #default="{ row }">
  129. <div class="full-content-cell">
  130. {{ row.group }}
  131. </div>
  132. </template>
  133. </el-table-column>
  134. <el-table-column :label="t('mainPlan.MaintItems')" align="center" prop="name"
  135. :show-overflow-tooltip="false" :width="columnWidths.name" fixed="left">
  136. <template #default="{ row }">
  137. <div class="full-content-cell">
  138. <!-- 保养项 只显示'->'后的内容 -->
  139. {{ formatMaintItemName(row.name) }}
  140. </div>
  141. </template>
  142. </el-table-column>
  143. <el-table-column :label="t('main.mileage')" key="mileageRule" align="center"
  144. :width="columnWidths.mileageRule" v-if="false">
  145. <template #default="scope">
  146. <el-switch
  147. v-model="scope.row.mileageRule"
  148. :active-value="0"
  149. :inactive-value="1"
  150. :disabled="true"
  151. />
  152. </template>
  153. </el-table-column>
  154. <el-table-column :label="t('main.runTime')" key="runningTimeRule" align="center"
  155. :width="columnWidths.runningTimeRule" v-if="false">
  156. <template #default="scope">
  157. <el-switch
  158. v-model="scope.row.runningTimeRule"
  159. :active-value="0"
  160. :inactive-value="1"
  161. :disabled="true"
  162. />
  163. </template>
  164. </el-table-column>
  165. <el-table-column :label="t('main.date')" key="naturalDateRule" align="center"
  166. :width="columnWidths.naturalDateRule" v-if="false">
  167. <template #default="scope">
  168. <el-switch
  169. v-model="scope.row.naturalDateRule"
  170. :active-value="0"
  171. :inactive-value="1"
  172. :disabled="true"
  173. />
  174. </template>
  175. </el-table-column>
  176. <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" v-if="hasTimeRuleInCurrentPage"
  177. :formatter="erpPriceTableColumnFormatter" :width="columnWidths.totalRunTime">
  178. <template #default="{ row }">
  179. {{ row.totalRunTime ?? row.tempTotalRunTime }}
  180. </template>
  181. </el-table-column>
  182. <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" v-if="hasMileageRuleInCurrentPage"
  183. :formatter="erpPriceTableColumnFormatter" :width="columnWidths.totalMileage">
  184. <template #default="{ row }">
  185. {{ row.totalMileage ?? row.tempTotalMileage }}
  186. </template>
  187. </el-table-column>
  188. <el-table-column :label="t('mainPlan.lastMaintenanceDate')" prop="lastMaintenanceDate" :width="columnWidths.lastMaintenanceDate">
  189. <template #default="{ row }">
  190. <div class="full-content-cell">
  191. {{ row.lastMaintenanceDate }}
  192. </div>
  193. </template>
  194. </el-table-column>
  195. <!-- 保养里程 分组 -->
  196. <el-table-column v-if="hasMileageRuleInCurrentPage" label="保养里程" align="center">
  197. <el-table-column :label="t('mainPlan.lastMaintenanceMileage')" align="center" prop="lastRunningKilometers"
  198. :formatter="erpPriceTableColumnFormatter" :width="columnWidths.lastRunningKilometers">
  199. <template #default="{ row }">
  200. {{ row.lastRunningKilometers }}
  201. </template>
  202. </el-table-column>
  203. <el-table-column :label="t('mainPlan.nextMaintenanceKm')"
  204. align="center" prop="nextMaintenanceKm" :width="columnWidths.nextMaintenanceKm">
  205. <template #default="{ row }">
  206. {{ row.nextMaintenanceKm ?? '-' }}
  207. </template>
  208. </el-table-column>
  209. <el-table-column :label="t('mainPlan.remainKm')"
  210. align="center" prop="remainKm" :width="columnWidths.remainKm">
  211. <template #default="{ row }">
  212. {{ row.remainKm != null ? row.remainKm.toFixed(2) : '-' }}
  213. </template>
  214. </el-table-column>
  215. </el-table-column>
  216. <!-- 保养时长 分组 -->
  217. <el-table-column v-if="hasTimeRuleInCurrentPage" label="保养时长" align="center">
  218. <el-table-column :label="t('mainPlan.lastMaintenanceOperationTime')" align="center" prop="lastRunningTime"
  219. :formatter="erpPriceTableColumnFormatter" :width="columnWidths.lastRunningTime">
  220. <template #default="{ row }">
  221. {{ row.lastRunningTime }}
  222. </template>
  223. </el-table-column>
  224. <el-table-column :label="t('mainPlan.nextMaintenanceH')"
  225. align="center" prop="nextMaintenanceH" :width="columnWidths.nextMaintenanceH">
  226. <template #default="{ row }">
  227. {{ row.nextMaintenanceH ?? '-' }}
  228. </template>
  229. </el-table-column>
  230. <el-table-column :label="t('mainPlan.remainH')"
  231. align="center" prop="remainH" :width="columnWidths.remainH">
  232. <template #default="{ row }">
  233. {{ row.remainH != null ? row.remainH.toFixed(2) : '-' }}
  234. </template>
  235. </el-table-column>
  236. <el-table-column
  237. v-if="shouldShowRunningTimeColumn"
  238. :label="t('mainPlan.RunTimeCycle')"
  239. align="center"
  240. prop="nextRunningTime"
  241. :width="columnWidths.nextRunningTime"
  242. >
  243. <template #default="scope">
  244. <el-input-number
  245. v-if="scope.row.runningTimeRule === 0"
  246. v-model="scope.row.nextRunningTime"
  247. :precision="1"
  248. :min="1"
  249. :controls="false"
  250. style="width: 100%"
  251. @change="validateRunningTime(scope.row)"
  252. />
  253. <span v-else>-</span>
  254. <!-- 错误提示 -->
  255. <div v-if="scope.row.timeError" class="error-text">
  256. {{ scope.row.timeError }}
  257. </div>
  258. </template>
  259. </el-table-column>
  260. </el-table-column>
  261. <!-- 保养日期 分组 -->
  262. <el-table-column v-if="hasDateRuleInCurrentPage" label="保养日期" align="center">
  263. <el-table-column :label="t('mainPlan.lastMaintenanceNaturalDate')" align="center" prop="tempLastNaturalDate"
  264. :formatter="erpPriceTableColumnFormatter" :width="columnWidths.tempLastNaturalDate">
  265. <template #default="{ row }">
  266. {{ row.tempLastNaturalDate }}
  267. </template>
  268. </el-table-column>
  269. <el-table-column :label="t('mainPlan.nextMaintDate')"
  270. align="center" prop="nextMaintenanceDate" :width="columnWidths.nextMaintenanceDate">
  271. <template #default="{ row }">
  272. {{ row.nextMaintenanceDate ?? '-' }}
  273. </template>
  274. </el-table-column>
  275. <el-table-column :label="t('mainPlan.remainDay')"
  276. align="center" prop="remainDay" :width="columnWidths.remainDay">
  277. <template #default="{ row }">
  278. {{ row.remainDay ?? '-' }}
  279. </template>
  280. </el-table-column>
  281. </el-table-column>
  282. <el-table-column :label="t('common.status')" align="center" width="100">
  283. <template #default="scope">
  284. {{ getStatusText(scope.row) }}
  285. </template>
  286. </el-table-column>
  287. <el-table-column :label="t('iotMaintain.numberOfMaterials')" align="center" width="90">
  288. <template #default="scope">
  289. {{ getMaterialCount(scope.row.bomNodeId) }}
  290. </template>
  291. </el-table-column>
  292. <el-table-column :label="t('iotMaintain.operation')" align="center" prop="operation" :width="columnWidths.operation" fixed="right">
  293. <template #default="scope">
  294. <div class="horizontal-actions">
  295. <!-- 查看当前保养项已经绑定的物料列表 -->
  296. <el-tooltip
  297. v-if="scope.row.deviceBomMaterials && scope.row.deviceBomMaterials.length > 0"
  298. effect="dark"
  299. :content="t('mainPlan.deviceBomMaterials')"
  300. placement="top"
  301. :show-after="300"
  302. >
  303. <el-button
  304. type="primary"
  305. link
  306. :icon="View"
  307. @click="handleDropdownCommand({ action: 'deviceBomMaterials', row: scope.row })"
  308. class="action-button"
  309. />
  310. </el-tooltip>
  311. <!-- 延迟保养按钮 -->
  312. <el-tooltip
  313. v-if="scope.row.status === 0"
  314. effect="dark"
  315. :content="t('stock.DelayMaintenance')"
  316. placement="top"
  317. :show-after="300"
  318. >
  319. <el-button
  320. type="primary"
  321. link
  322. :icon="Clock"
  323. @click="handleDropdownCommand({ action: 'delay', row: scope.row })"
  324. class="action-button"
  325. />
  326. </el-tooltip>
  327. <!-- 选择物料按钮 -->
  328. <el-tooltip
  329. v-if="scope.row.status === 0"
  330. effect="dark"
  331. :content="t('stock.selectMaterial')"
  332. placement="top"
  333. :show-after="300"
  334. >
  335. <el-button
  336. type="primary"
  337. link
  338. :icon="Box"
  339. @click="handleDropdownCommand({ action: 'material', row: scope.row })"
  340. class="action-button"
  341. />
  342. </el-tooltip>
  343. <!-- 物料详情按钮 -->
  344. <el-tooltip
  345. effect="dark"
  346. :content="t('bomList.materialDetail')"
  347. placement="top"
  348. :show-after="300"
  349. >
  350. <el-button
  351. type="primary"
  352. link
  353. :icon="Document"
  354. @click="handleDropdownCommand({ action: 'detail', row: scope.row })"
  355. class="action-button"
  356. />
  357. </el-tooltip>
  358. </div>
  359. </template>
  360. </el-table-column>
  361. </el-table>
  362. <div style="margin-top: 20px; display: flex; justify-content: flex-end;">
  363. <el-pagination
  364. v-model:current-page="currentPage"
  365. v-model:page-size="pageSize"
  366. :page-sizes="[10]"
  367. :background="true"
  368. layout="total, sizes, prev, pager, next, jumper"
  369. :total="list.length"
  370. @current-change="handleCurrentChange"
  371. @size-change="handleSizeChange"
  372. />
  373. </div>
  374. </ContentWrap>
  375. <!-- 选择的物料列表 -->
  376. <ContentWrap>
  377. <el-table v-loading="false" :data="materialList" :stripe="true" :show-overflow-tooltip="true" v-if="false">
  378. <el-table-column :label="t('bomList.bomNode')" align="center" prop="bomNodeId" />
  379. <el-table-column label="工厂id" align="center" prop="factoryId" v-if="false"/>
  380. <el-table-column label="工厂名称" align="center" prop="factory" v-if="false"/>
  381. <el-table-column label="成本中心id" align="center" prop="costCenterId" v-if="false"/>
  382. <el-table-column label="成本中心名称" align="center" prop="costCenter" v-if="false"/>
  383. <el-table-column label="库存地点id" align="center" prop="storageLocationId" v-if="false"/>
  384. <el-table-column label="库存地点名称" align="center" prop="projectDepartment" v-if="false"/>
  385. <el-table-column label="物料编码" align="center" prop="materialCode" />
  386. <el-table-column label="物料名称" align="center" prop="materialName" />
  387. <el-table-column label="单位" align="center" prop="unit" />
  388. <el-table-column label="单价(CNY/元)" align="center" prop="unitPrice" :formatter="erpPriceTableColumnFormatter"/>
  389. <el-table-column label="消耗数量" align="center" prop="quantity" />
  390. <el-table-column label="总库存数量" align="center" prop="totalInventoryQuantity" />
  391. </el-table>
  392. </ContentWrap>
  393. </ContentWrap>
  394. <ContentWrap>
  395. <el-form>
  396. <el-form-item style="float: right">
  397. <el-button @click="submitForm" type="primary" :disabled="formLoading">{{t('common.save')}}</el-button>
  398. <el-button @click="close">{{t('common.cancel')}}</el-button>
  399. </el-form-item>
  400. </el-form>
  401. </ContentWrap>
  402. <!-- 新增配置对话框 -->
  403. <el-dialog
  404. v-model="configDialog.visible"
  405. :title="`设备 ${configDialog.current?.deviceCode+'-'+configDialog.current?.name} 保养配置`"
  406. width="600px"
  407. >
  408. <!-- 使用header插槽自定义标题 -->
  409. <template #header>
  410. <span>设备 <strong>{{ configDialog.current?.deviceCode }}-{{ configDialog.current?.name }}</strong> 保养项配置</span>
  411. </template>
  412. <el-form :model="configDialog.form" label-width="200px" :rules="configFormRules" ref="configFormRef">
  413. <div class="form-group">
  414. <div class="group-title">{{ t('mainPlan.basicMaintenanceRecords') }}</div>
  415. <!-- 里程配置 -->
  416. <el-form-item
  417. v-if="configDialog.current?.mileageRule === 0"
  418. :label="t('mainPlan.lastMaintenanceMileage')"
  419. prop="lastRunningKilometers"
  420. >
  421. <el-input-number
  422. v-model="configDialog.form.lastRunningKilometers"
  423. :precision="2"
  424. :min="0"
  425. controls-position="right"
  426. :controls="false"
  427. style="width: 60%"
  428. :disabled="true"
  429. />
  430. </el-form-item>
  431. <!-- 推迟公里数 -->
  432. <el-form-item
  433. v-if="configDialog.current?.mileageRule === 0"
  434. :label="t('mainPlan.DelayKil')"
  435. prop="delayKilometers"
  436. >
  437. <el-input-number
  438. v-model="configDialog.form.delayKilometers"
  439. :precision="2"
  440. :min="0"
  441. controls-position="right"
  442. :controls="false"
  443. style="width: 60%"
  444. />
  445. </el-form-item>
  446. <!-- 运行时间配置 -->
  447. <el-form-item
  448. v-if="configDialog.current?.runningTimeRule === 0"
  449. :label="t('mainPlan.lastMaintenanceOperationTime')"
  450. prop="lastRunningTime"
  451. >
  452. <el-input-number
  453. v-model="configDialog.form.lastRunningTime"
  454. :precision="1"
  455. :min="0"
  456. controls-position="right"
  457. :controls="false"
  458. style="width: 60%"
  459. :disabled="true"
  460. />
  461. </el-form-item>
  462. <!-- 推迟时长 -->
  463. <el-form-item
  464. v-if="configDialog.current?.runningTimeRule === 0"
  465. :label="t('mainPlan.DelayDuration')"
  466. prop="delayDuration"
  467. >
  468. <el-input-number
  469. v-model="configDialog.form.delayDuration"
  470. :precision="2"
  471. :min="0"
  472. controls-position="right"
  473. :controls="false"
  474. style="width: 60%"
  475. />
  476. </el-form-item>
  477. <!-- 自然日期配置 -->
  478. <el-form-item
  479. v-if="configDialog.current?.naturalDateRule === 0"
  480. :label="t('mainPlan.lastMaintenanceNaturalDate')"
  481. prop="lastNaturalDate"
  482. >
  483. <el-date-picker
  484. v-model="configDialog.form.lastNaturalDate"
  485. type="date"
  486. placeholder="选择日期"
  487. format="YYYY-MM-DD"
  488. value-format="YYYY-MM-DD"
  489. style="width: 60%"
  490. :disabled="true"
  491. />
  492. </el-form-item>
  493. <!-- 推迟自然日期 -->
  494. <el-form-item
  495. v-if="configDialog.current?.naturalDateRule === 0"
  496. :label="t('mainPlan.DelayDate')"
  497. prop="delayNaturalDate"
  498. >
  499. <el-input-number
  500. v-model="configDialog.form.delayNaturalDate"
  501. :precision="2"
  502. :min="0"
  503. controls-position="right"
  504. :controls="false"
  505. style="width: 60%"
  506. />
  507. </el-form-item>
  508. <el-form-item
  509. :label="t('stock.DelayReason')"
  510. prop="delayReason"
  511. v-if="configDialog.current?.mileageRule === 0 ||
  512. configDialog.current?.runningTimeRule === 0 ||
  513. configDialog.current?.naturalDateRule === 0"
  514. >
  515. <el-input
  516. v-model="configDialog.form.delayReason"
  517. type="textarea"
  518. :rows="2"
  519. :placeholder="t('stock.DelayReason')"
  520. style="width: 60%"
  521. />
  522. </el-form-item>
  523. </div>
  524. <div class="form-group" v-if="configDialog.current?.mileageRule === 0">
  525. <div class="group-title">{{ t('mainPlan.operatingMileageRuleConfiguration') }}</div>
  526. <!-- 保养规则周期值 + 提前量 -->
  527. <el-form-item
  528. v-if="configDialog.current?.mileageRule === 0"
  529. :label="t('mainPlan.operatingMileageCycle')"
  530. prop="nextRunningKilometers"
  531. >
  532. <el-input-number
  533. v-model="configDialog.form.nextRunningKilometers"
  534. :precision="2"
  535. :min="0"
  536. controls-position="right"
  537. :controls="false"
  538. style="width: 60%"
  539. :disabled="true"
  540. />
  541. </el-form-item>
  542. <el-form-item
  543. v-if="configDialog.current?.mileageRule === 0"
  544. :label="t('mainPlan.OperatingMileageCycle_lead')"
  545. prop="kiloCycleLead"
  546. >
  547. <el-input-number
  548. v-model="configDialog.form.kiloCycleLead"
  549. :precision="2"
  550. :min="0"
  551. controls-position="right"
  552. :controls="false"
  553. style="width: 60%"
  554. :disabled="true"
  555. />
  556. </el-form-item>
  557. </div>
  558. <div class="form-group" v-if="configDialog.current?.runningTimeRule === 0">
  559. <div class="group-title">{{ t('mainPlan.RunTimeRuleConfiguration') }}</div>
  560. <el-form-item
  561. v-if="configDialog.current?.runningTimeRule === 0"
  562. :label="t('mainPlan.RunTimeCycle')"
  563. prop="nextRunningTime"
  564. >
  565. <el-input-number
  566. v-model="configDialog.form.nextRunningTime"
  567. :precision="1"
  568. :min="0"
  569. controls-position="right"
  570. :controls="false"
  571. style="width: 60%"
  572. :disabled="true"
  573. />
  574. </el-form-item>
  575. <el-form-item
  576. v-if="configDialog.current?.runningTimeRule === 0"
  577. :label="t('mainPlan.RunTimeCycle_Lead')"
  578. prop="timePeriodLead"
  579. >
  580. <el-input-number
  581. v-model="configDialog.form.timePeriodLead"
  582. :precision="1"
  583. :min="0"
  584. controls-position="right"
  585. :controls="false"
  586. style="width: 60%"
  587. :disabled="true"
  588. />
  589. </el-form-item>
  590. </div>
  591. <div class="form-group" v-if="configDialog.current?.naturalDateRule === 0">
  592. <div class="group-title">{{ t('mainPlan.NaturalDayRuleConfig') }}</div>
  593. <el-form-item
  594. v-if="configDialog.current?.naturalDateRule === 0"
  595. :label="t('mainPlan.NaturalDailyCycle') "
  596. prop="nextNaturalDate"
  597. >
  598. <el-input-number
  599. v-model="configDialog.form.nextNaturalDate"
  600. :min="0"
  601. controls-position="right"
  602. :controls="false"
  603. style="width: 60%"
  604. :disabled="true"
  605. />
  606. </el-form-item>
  607. <el-form-item
  608. v-if="configDialog.current?.naturalDateRule === 0"
  609. :label="t('mainPlan.NaturalDailyCycle_Lead') "
  610. prop="naturalDatePeriodLead"
  611. >
  612. <el-input-number
  613. v-model="configDialog.form.naturalDatePeriodLead"
  614. :min="0"
  615. controls-position="right"
  616. :controls="false"
  617. style="width: 60%"
  618. :disabled="true"
  619. />
  620. </el-form-item>
  621. </div>
  622. </el-form>
  623. <template #footer>
  624. <el-button @click="configDialog.visible = false">{{ t('common.cancel')}}</el-button>
  625. <el-button type="primary" @click="saveConfig">{{ t('common.ok')}}</el-button>
  626. </template>
  627. </el-dialog>
  628. <!-- 表单弹窗:添加/修改 -->
  629. <WorkOrderMaterial ref="materialFormRef" @choose="selectChoose" />
  630. <!-- 设备BOM节点绑定的物料列表 -->
  631. <DeviceBomMaterials ref="deviceBomMaterialsRef" />
  632. <!-- 抽屉组件 展示已经选择的物料 并编辑物料消耗 -->
  633. <MaterialListDrawer
  634. :model-value="drawerVisible"
  635. @update:model-value="val => drawerVisible = val"
  636. :node-id="currentBomNodeId"
  637. :materials="materialList.filter(item => item.bomNodeId === currentBomNodeId)"
  638. @delete="handleDeleteMaterial"
  639. :hide-extra-columns="hideExtraColumnsInDrawer"
  640. />
  641. </template>
  642. <script setup lang="ts">
  643. import * as UserApi from '@/api/system/user'
  644. import { useUserStore } from '@/store/modules/user'
  645. import { ref } from 'vue'
  646. import { useRouter } from 'vue-router'
  647. import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
  648. import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
  649. import { IotMainWorkOrderBomMaterialApi, IotMainWorkOrderBomMaterialVO } from '@/api/pms/iotmainworkorderbommaterial'
  650. import { IotMainWorkOrderApi, IotMainWorkOrderVO } from '@/api/pms/iotmainworkorder'
  651. import { useTagsViewStore } from '@/store/modules/tagsView'
  652. import * as DeptApi from "@/api/system/dept";
  653. import {erpPriceTableColumnFormatter} from "@/utils";
  654. import dayjs from 'dayjs'
  655. import MaterialListDrawer from "@/views/pms/iotmainworkorder/SelectedMaterialDrawer.vue";
  656. import WorkOrderMaterial from "@/views/pms/iotmainworkorder/WorkOrderMaterial.vue";
  657. import DeviceBomMaterials from "@/views/pms/iotmainworkorder/DeviceBomMaterials.vue";
  658. import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
  659. // 引入图标
  660. import { View, Clock, Box, Document } from '@element-plus/icons-vue';
  661. /** 保养计划 表单 */
  662. defineOptions({ name: 'IotMainWorkOrderBom' })
  663. const { t } = useI18n() // 国际化
  664. const message = useMessage() // 消息弹窗
  665. const { delView } = useTagsViewStore() // 视图操作
  666. const { currentRoute, push } = useRouter()
  667. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  668. const dept = ref() // 当前登录人所属部门对象
  669. const configFormRef = ref() // 配置弹出框对象
  670. const bomNodeId = ref() // 最新的bomNodeId
  671. const dialogTitle = ref('') // 弹窗的标题
  672. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  673. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  674. const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
  675. const drawerVisible = ref<boolean>(false)
  676. const currentBomNodeId = ref() // 当前选中的bom节点
  677. const showDrawer = ref()
  678. const list = ref<IotMainWorkOrderBomVO[]>([]) // 保养工单bom关联列表的数据
  679. const materialList = ref<IotMainWorkOrderBomMaterialVO[]>([]) // 保养工单bom关联物料列表
  680. const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
  681. const { params, name } = useRoute() // 查询参数
  682. const id = params.id
  683. // 控制抽屉额外列的显示
  684. const hideExtraColumnsInDrawer = ref(false)
  685. // 分页相关变量
  686. const currentPage = ref(1)
  687. const pageSize = ref(10)
  688. const tableRef = ref();
  689. // 新增响应式变量
  690. const maintItemsWidth = ref('auto')
  691. const lastNaturalDateWatchers = ref(new Map())
  692. const columnWidths = ref<Record<string, string>>({});
  693. // 计算当前页是否有分组数据
  694. const hasGroupInCurrentPage = computed(() => {
  695. return paginatedList.value.some(item => item.group && item.group !== '');
  696. });
  697. // 分组合并计算逻辑
  698. const groupSpans = ref<Record<string, { span: number, index: number }>>({})
  699. const formData = ref({
  700. id: undefined,
  701. deptId: undefined,
  702. name: '',
  703. orderNumber: undefined,
  704. responsiblePerson: undefined,
  705. actualStartTime: undefined,
  706. actualEndTime: undefined,
  707. cost: undefined,
  708. otherCost: undefined,
  709. outsourcingFlag: 0,
  710. remark: undefined,
  711. status: undefined,
  712. devicePersons: '',
  713. deviceCode: '',
  714. deviceName: ''
  715. })
  716. const formRules = reactive({
  717. name: [{ required: true, message: '工单名称不能为空', trigger: 'blur' }],
  718. actualStartTime: [{
  719. required: true,
  720. message: t('fault.start') + '不能为空',
  721. trigger: 'change'
  722. }, {
  723. validator: (rule, value, callback) => {
  724. const now = dayjs();
  725. const start = value ? dayjs(Number(value)) : null;
  726. // 验证开始时间 <= 当前日期
  727. if (start && start.isAfter(now)) {
  728. callback(new Error(t('fault.start') + '不能超过当前日期'));
  729. return;
  730. }
  731. const end = formData.value.actualEndTime
  732. ? dayjs(Number(formData.value.actualEndTime))
  733. : null;
  734. // 只有当结束时间有效时,才比较开始和结束时间
  735. if (end && end.isValid() && !end.isAfter(now)) {
  736. if (start && start.isAfter(end)) {
  737. callback(new Error(t('fault.start') + '不能超过' + t('fault.end')));
  738. return;
  739. }
  740. }
  741. // 触发结束时间的重新校验
  742. if (formRef.value) {
  743. formRef.value.validateField('actualEndTime', () => {});
  744. }
  745. callback();
  746. },
  747. trigger: 'change'
  748. }],
  749. actualEndTime: [{
  750. required: true,
  751. message: t('fault.end') + '不能为空',
  752. trigger: 'change'
  753. }, {
  754. validator: (rule, value, callback) => {
  755. const now = dayjs();
  756. const end = value ? dayjs(Number(value)) : null;
  757. // 验证结束时间 <= 当前日期
  758. if (end && end.isAfter(now)) {
  759. callback(new Error(t('fault.end') + '不能超过当前日期'));
  760. return;
  761. }
  762. const start = formData.value.actualStartTime
  763. ? dayjs(Number(formData.value.actualStartTime))
  764. : null;
  765. // 验证结束时间 >= 开始时间(仅当开始时间存在时)
  766. if (start && end && end.isBefore(start)) {
  767. callback(new Error(t('fault.end') + '必须大于等于' + t('fault.start')));
  768. return;
  769. }
  770. callback();
  771. },
  772. trigger: 'change'
  773. }]
  774. })
  775. const formRef = ref() // 表单 Ref
  776. interface MaterialFormExpose {
  777. open: (deptId: number, bomNodeId: number, row: any, type: string) => void
  778. }
  779. const materialFormRef = ref<MaterialFormExpose>();
  780. const deviceBomMaterialsRef = ref<MaterialFormExpose>();
  781. // 新增配置相关状态
  782. const configDialog = reactive({
  783. visible: false,
  784. current: null as IotMaintenanceBomVO | null,
  785. form: {
  786. lastRunningKilometers: 0,
  787. delayKilometers: 0,
  788. lastRunningTime: 0,
  789. delayDuration: 0,
  790. lastNaturalDate: '',
  791. delayNaturalDate: 0,
  792. // 保养规则 周期
  793. nextRunningKilometers: 0,
  794. nextRunningTime: 0,
  795. nextNaturalDate: 0,
  796. // 提前量
  797. kiloCycleLead: 0,
  798. timePeriodLead: 0,
  799. naturalDatePeriodLead: 0,
  800. // 推迟原因
  801. delayReason: ''
  802. }
  803. })
  804. // 打开配置对话框
  805. const openConfigDialog = (row: IotMainWorkOrderBomVO) => {
  806. configDialog.current = row
  807. // 处理日期初始化(核心修改)
  808. let initialDate = ''
  809. if (row.lastNaturalDate) {
  810. // 如果已有值:时间戳 -> 日期字符串
  811. initialDate = dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
  812. } else {
  813. // 如果无值:设置默认值避免1970问题
  814. initialDate = ''
  815. }
  816. configDialog.form = {
  817. lastRunningKilometers: row.lastRunningKilometers || 0,
  818. delayKilometers: row.delayKilometers || 0,
  819. lastRunningTime: row.lastRunningTime || 0,
  820. delayDuration: row.delayDuration || 0,
  821. lastNaturalDate: initialDate,
  822. delayNaturalDate: row.delayNaturalDate || 0,
  823. // 保养规则 周期值
  824. nextRunningKilometers: row.nextRunningKilometers || 0,
  825. nextRunningTime: row.nextRunningTime || 0,
  826. nextNaturalDate: row.nextNaturalDate || 0,
  827. // 提前量
  828. kiloCycleLead: row.kiloCycleLead || 0,
  829. timePeriodLead: row.timePeriodLead || 0,
  830. naturalDatePeriodLead: row.naturalDatePeriodLead || 0,
  831. // 推迟原因
  832. delayReason: row.delayReason || ''
  833. }
  834. configDialog.visible = true
  835. }
  836. // 格式化 保养项名称 方法 只显示 -> 后面的内容
  837. const formatMaintItemName = (name: string) => {
  838. if (!name) return '';
  839. // 包含'->'时只取后半部分
  840. if (name.includes('->')) {
  841. return name.split('->').pop()?.trim() || name;
  842. }
  843. // 不含'->'时显示完整内容
  844. return name;
  845. };
  846. // 行合并方法 (优化后符合图片效果)
  847. const handleSpanMethod = ({ row, column, rowIndex, columnIndex }) => {
  848. // 只处理保养项组列
  849. if (column.property === 'group' && row.group) {
  850. const groupKey = `${currentPage.value}-${row.group}`;
  851. const spanInfo = groupSpans.value[groupKey];
  852. if (spanInfo && rowIndex === spanInfo.index) {
  853. return {
  854. rowspan: spanInfo.span,
  855. colspan: 1
  856. };
  857. } else {
  858. return {
  859. rowspan: 0,
  860. colspan: 0
  861. };
  862. }
  863. }
  864. // 其他列不合并
  865. return {
  866. rowspan: 1,
  867. colspan: 1
  868. };
  869. };
  870. // 计算分组合并信息 (优化后符合图片效果)
  871. const calculateGroupSpans = () => {
  872. // 重置分组信息
  873. groupSpans.value = {};
  874. const pageKey = currentPage.value;
  875. let currentGroup = '';
  876. let groupStartIndex = 0;
  877. let groupCount = 0;
  878. // 先清除所有行的分组标记
  879. paginatedList.value.forEach(item => {
  880. delete item.isGroupFirstRow;
  881. });
  882. paginatedList.value.forEach((item, index) => {
  883. // 获取当前行的分组(从name中提取)
  884. const group = item.name && item.name.includes('->')
  885. ? item.name.split('->')[0].trim()
  886. : '';
  887. // 如果分组变化
  888. if (group !== currentGroup) {
  889. // 保存上一个分组的信息
  890. if (currentGroup && groupCount > 0) {
  891. const groupKey = `${pageKey}-${currentGroup}`;
  892. groupSpans.value[groupKey] = {
  893. span: groupCount,
  894. index: groupStartIndex
  895. };
  896. // 标记上一个分组的起始行(添加这行)
  897. paginatedList.value[groupStartIndex].isGroupFirstRow = true;
  898. }
  899. // 开始新分组
  900. currentGroup = group;
  901. groupStartIndex = index;
  902. groupCount = 1;
  903. } else {
  904. // 相同分组,计数增加
  905. groupCount++;
  906. }
  907. });
  908. // 保存最后一个分组的信息
  909. if (currentGroup && groupCount > 0) {
  910. const groupKey = `${pageKey}-${currentGroup}`;
  911. groupSpans.value[groupKey] = {
  912. span: groupCount,
  913. index: groupStartIndex
  914. };
  915. // 标记最后一个分组的起始行(添加这行)
  916. paginatedList.value[groupStartIndex].isGroupFirstRow = true;
  917. }
  918. };
  919. // 运行时间周期 单行校验方法
  920. const validateRunningTime = (row: IotMainWorkOrderBomVO) => {
  921. if (row.runningTimeRule === 0 && (!row.nextRunningTime || row.nextRunningTime <= 0)) {
  922. row.timeError = t('mainPlan.runningTimeCycleError');
  923. return false;
  924. }
  925. row.timeError = '';
  926. return true;
  927. };
  928. // 计算属性:获取当前页的数据
  929. const paginatedList = computed(() => {
  930. const start = (currentPage.value - 1) * pageSize.value
  931. const end = start + pageSize.value
  932. return list.value.slice(start, end)
  933. })
  934. // 页码改变处理
  935. const handleCurrentChange = (newPage: number) => {
  936. currentPage.value = newPage
  937. }
  938. // 每页条数改变处理(保持10条)
  939. const handleSizeChange = (newSize: number) => {
  940. pageSize.value = newSize
  941. currentPage.value = 1 // 重置到第一页
  942. }
  943. // 运行时间周期 全局校验方法(在submitForm中调用)
  944. const validateAllRunningTimes = (): boolean => {
  945. let isValid = true;
  946. list.value.forEach(row => {
  947. if (row.runningTimeRule === 0 && (!row.nextRunningTime || row.nextRunningTime <= 0)) {
  948. isValid = false;
  949. // 高亮标记错误行
  950. row.timeError = t('mainPlan.runningTimeCycleError');
  951. message.error(`${t('mainPlan.runningTimeCycleError')}: ${row.deviceCode}-${row.name}`);
  952. }
  953. });
  954. return isValid;
  955. };
  956. const openMaterialForm = (row: any) => {
  957. bomNodeId.value = row.bomNodeId;
  958. console.log('这是一个对象:', row.bomNodeId)
  959. const type = 'maintenance'
  960. materialFormRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
  961. }
  962. // 查看当前保养项已经绑定的物料列表
  963. const openDeviceBomMaterials = (row: any) => {
  964. bomNodeId.value = row.bomNodeId;
  965. const type = 'maintenance'
  966. deviceBomMaterialsRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
  967. }
  968. const selectChoose = (selectedMaterial) => {
  969. selectedMaterial.bomNodeId = bomNodeId.value
  970. // 关联 bomNodeId
  971. const processedMaterials = selectedMaterial.map(material => ({
  972. ...material,
  973. bomNodeId: bomNodeId.value // 统一关联当前行的 bomNodeId
  974. }));
  975. // 避免重复添加
  976. processedMaterials.forEach(newMaterial => {
  977. // 检查是否已存在相同 工厂+成本中心+库存地点+bomNodeId + materialCode 的条目
  978. const isExist = materialList.value.some(item =>
  979. item.bomNodeId === bomNodeId.value &&
  980. item.materialCode === newMaterial.materialCode &&
  981. item.factoryId === newMaterial.factoryId &&
  982. item.costCenterId === newMaterial.costCenterId &&
  983. item.storageLocationId === newMaterial.storageLocationId
  984. );
  985. if (!isExist) {
  986. materialList.value.push(newMaterial);
  987. }
  988. });
  989. }
  990. // 计算属性:判断是否需要显示运行时间周期列
  991. const shouldShowRunningTimeColumn = computed(() => {
  992. return list.value.some(item => item.runningTimeRule === 0);
  993. });
  994. /** 查看已经选择的物料 并编辑 */
  995. const handleView = (row: IotMainWorkOrderBomVO) => {
  996. currentBomNodeId.value = row.bomNodeId
  997. drawerVisible.value = true
  998. // 根据状态值设置是否隐藏额外列
  999. hideExtraColumnsInDrawer.value = row.status === 1
  1000. console.log('当前bom节点:', currentBomNodeId.value)
  1001. }
  1002. // 计算保养金额
  1003. const calculateTotalCost = () => {
  1004. // 物料总金额 = ∑(单价 * 消耗数量)
  1005. const materialTotal = materialList.value.reduce((sum, item) => {
  1006. const price = Number(item.unitPrice) || 0
  1007. const quantity = Number(item.quantity) || 0
  1008. return sum + (price * quantity)
  1009. }, 0)
  1010. // 保养 = 物料总金额
  1011. formData.value.cost = (materialTotal).toFixed(2)
  1012. }
  1013. // 监听物料列表变化
  1014. watch(
  1015. () => materialList.value,
  1016. () => {
  1017. calculateTotalCost()
  1018. },
  1019. { deep: true }
  1020. )
  1021. const handleInput = (value, obj) => {
  1022. // 1. 过滤非法字符(只允许数字和小数点)
  1023. let filtered = value.replace(/[^\d.]/g, '')
  1024. // 2. 处理多个小数点的情况
  1025. filtered = filtered.replace(/\.{2,}/g, '.')
  1026. // 3. 限制小数点后最多两位
  1027. let decimalParts = filtered.split('.')
  1028. if (decimalParts.length > 1) {
  1029. decimalParts = decimalParts.slice(0, 2)
  1030. filtered = decimalParts.join('.')
  1031. }
  1032. // 4. 处理以小数点开头的情况(自动补0)
  1033. if (filtered.startsWith('.')) {
  1034. filtered = '0' + filtered
  1035. }
  1036. // 5. 更新绑定值(同时处理连续输入多个0的情况)
  1037. formData.value[obj] = filtered.replace(/^0+(?=\d)/, '')
  1038. }
  1039. // 保存配置
  1040. const saveConfig = () => {
  1041. (configFormRef.value as any).validate((valid: boolean) => {
  1042. if (!valid) return
  1043. if (!configDialog.current) return
  1044. // 动态校验逻辑
  1045. const requiredFields = []
  1046. if (configDialog.current.mileageRule === 0) {
  1047. requiredFields.push('nextRunningKilometers', 'kiloCycleLead')
  1048. }
  1049. if (configDialog.current.runningTimeRule === 0) {
  1050. requiredFields.push('nextRunningTime', 'timePeriodLead')
  1051. }
  1052. if (configDialog.current.naturalDateRule === 0) {
  1053. requiredFields.push('nextNaturalDate', 'naturalDatePeriodLead')
  1054. }
  1055. const missingFields = requiredFields.filter(field =>
  1056. !configDialog.form[field as keyof typeof configDialog.form]
  1057. )
  1058. if (missingFields.length > 0) {
  1059. message.error('请填写所有必填项')
  1060. return
  1061. }
  1062. // 强制校验逻辑
  1063. if (configDialog.current.naturalDateRule === 0) {
  1064. if (!configDialog.form.lastNaturalDate) {
  1065. message.error('必须选择自然日期')
  1066. return
  1067. }
  1068. // 验证日期有效性
  1069. const dateValue = dayjs(configDialog.form.lastNaturalDate)
  1070. if (!dateValue.isValid()) {
  1071. message.error('日期格式不正确')
  1072. return
  1073. }
  1074. }
  1075. // 转换逻辑(关键修改)
  1076. const finalDate = configDialog.form.lastNaturalDate
  1077. ? dayjs(configDialog.form.lastNaturalDate).valueOf()
  1078. : null // 改为null而不是0
  1079. // 更新当前行的数据
  1080. Object.assign(configDialog.current, {
  1081. ...configDialog.form,
  1082. lastNaturalDate: finalDate
  1083. })
  1084. configDialog.visible = false
  1085. })
  1086. }
  1087. const queryParams = reactive({
  1088. workOrderId: id
  1089. })
  1090. // 获取指定bomNodeId的物料数量
  1091. const getMaterialCount = (bomNodeId: number) => {
  1092. console.log('当前BOM节点:' + bomNodeId)
  1093. return materialList.value.filter(item => item.bomNodeId === bomNodeId).length
  1094. }
  1095. const handleDeleteMaterial = (material) => {
  1096. // 根据唯一标识查找要删除的物料索引
  1097. const index = materialList.value.findIndex(item =>
  1098. item.bomNodeId === material.bomNodeId &&
  1099. item.factoryId === material.factoryId &&
  1100. item.costCenterId === material.costCenterId &&
  1101. item.storageLocationId === material.storageLocationId &&
  1102. item.materialCode === material.materialCode
  1103. );
  1104. if (index !== -1) {
  1105. materialList.value.splice(index, 1);
  1106. message.success('物料删除成功');
  1107. }
  1108. };
  1109. const close = () => {
  1110. delView(unref(currentRoute))
  1111. push({ name: 'IotMainWorkOrder', params:{}})
  1112. }
  1113. // 分组单元格类名方法
  1114. const groupCellClassName = ({ row, column }) => {
  1115. if (column.property === 'group' && row.isGroupFirstRow) {
  1116. return 'group-first-row';
  1117. }
  1118. return '';
  1119. };
  1120. /** 提交表单 */
  1121. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  1122. const submitForm = async () => {
  1123. // 校验表单
  1124. await formRef.value.validate()
  1125. // 运行时间周期全局校验
  1126. if (!validateAllRunningTimes()) {
  1127. return; // 校验失败则终止提交
  1128. }
  1129. // 校验表格数据
  1130. const isValid = validateTableData()
  1131. if (!isValid) return
  1132. // 提交请求
  1133. formLoading.value = true
  1134. try {
  1135. const convertedList = list.value.map(item => ({
  1136. ...item,
  1137. lastNaturalDate: typeof item.lastNaturalDate === 'number'
  1138. ? item.lastNaturalDate
  1139. : (item.lastNaturalDate ? dayjs(item.lastNaturalDate).valueOf() : null)
  1140. }));
  1141. const data = {
  1142. mainWorkOrder: formData.value,
  1143. mainWorkOrderBom: convertedList,
  1144. mainWorkOrderMaterials: materialList.value
  1145. }
  1146. await IotMainWorkOrderApi.fillWorkOrder(data)
  1147. message.success(t('common.createSuccess'))
  1148. close()
  1149. // 发送操作成功的事件
  1150. emit('success')
  1151. } finally {
  1152. formLoading.value = false
  1153. }
  1154. }
  1155. const validateDelayReason = (rule: any, value: any, callback: any) => {
  1156. const form = configDialog.form
  1157. const hasDelay =
  1158. (form.delayKilometers > 0) ||
  1159. (form.delayDuration > 0) ||
  1160. (form.delayNaturalDate > 0)
  1161. if (hasDelay && (!value || value.trim() === '')) {
  1162. callback(new Error('请填写推迟原因'))
  1163. } else {
  1164. callback()
  1165. }
  1166. }
  1167. // 新增表单校验规则
  1168. const configFormRules = reactive({
  1169. nextRunningKilometers: [{
  1170. required: true,
  1171. message: '里程周期必须填写',
  1172. trigger: 'blur'
  1173. }],
  1174. kiloCycleLead: [{
  1175. required: true,
  1176. message: '提前量必须填写',
  1177. trigger: 'blur'
  1178. }],
  1179. nextRunningTime: [{
  1180. required: true,
  1181. message: '时间周期必须填写',
  1182. trigger: 'blur'
  1183. }],
  1184. timePeriodLead: [{
  1185. required: true,
  1186. message: '提前量必须填写',
  1187. trigger: 'blur'
  1188. }],
  1189. nextNaturalDate: [{
  1190. required: true,
  1191. message: '自然日周期必须填写',
  1192. trigger: 'blur'
  1193. }],
  1194. naturalDatePeriodLead: [{
  1195. required: true,
  1196. message: '提前量必须填写',
  1197. trigger: 'blur'
  1198. }],
  1199. // 新增推迟原因验证规则
  1200. delayReason: [
  1201. { validator: validateDelayReason, trigger: ['blur', 'change'] }
  1202. ]
  1203. })
  1204. // 计算文本宽度的辅助函数
  1205. const getTextWidth = (text: string, fontSize = 14): number => {
  1206. if (!text) return 0;
  1207. const span = document.createElement('span')
  1208. span.style.visibility = 'hidden'
  1209. span.style.position = 'absolute'
  1210. span.style.whiteSpace = 'nowrap'
  1211. span.style.fontSize = `${fontSize}px` // 与表格实际字体一致
  1212. span.style.fontFamily = 'inherit'
  1213. span.style.fontWeight = 'normal';
  1214. span.innerText = text
  1215. document.body.appendChild(span)
  1216. const width = span.offsetWidth
  1217. document.body.removeChild(span)
  1218. return width
  1219. }
  1220. // 计算列宽的主函数
  1221. const calculateMaintItemsWidth = () => {
  1222. if (list.value.length === 0) {
  1223. maintItemsWidth.value = 'auto'
  1224. return
  1225. }
  1226. // 1. 计算表头文本宽度
  1227. const headerText = t('mainPlan.MaintItems')
  1228. const headerWidth = getTextWidth(headerText)
  1229. // 2. 计算内容最大宽度
  1230. let contentMaxWidth = 0
  1231. list.value.forEach(item => {
  1232. if (item.name) {
  1233. const width = getTextWidth(item.name.toString())
  1234. if (width > contentMaxWidth) {
  1235. contentMaxWidth = width
  1236. }
  1237. }
  1238. })
  1239. // 3. 取最大值 + 内边距(20px)
  1240. const maxWidth = Math.max(headerWidth, contentMaxWidth) + 20
  1241. maintItemsWidth.value = `${maxWidth}px`
  1242. }
  1243. // 计算下次保养公里数(通用函数)
  1244. const calculateNextMaintenanceKm = (row: IotMaintenanceBomVO) => {
  1245. // 验证条件:规则开启 + 两个值都存在且 > 0
  1246. const isValid = row.mileageRule === 0 &&
  1247. row.lastRunningKilometers > 0 &&
  1248. row.nextRunningKilometers > 0;
  1249. return isValid
  1250. ? (row.lastRunningKilometers + row.nextRunningKilometers)
  1251. : null; // 不满足条件返回null
  1252. };
  1253. // 计算剩余保养公里数(通用函数)
  1254. const calculateRemainKm = (row: IotMaintenanceBomVO) => {
  1255. // 确定使用的里程值(优先totalMileage)
  1256. const mileageValue = row.totalMileage ?? row.tempTotalMileage;
  1257. // 验证条件:规则开启 + 3个值都存在且 > 0
  1258. const isValid = row.mileageRule === 0 &&
  1259. row.lastRunningKilometers > 0 &&
  1260. mileageValue > 0 &&
  1261. row.nextRunningKilometers > 0;
  1262. if (!isValid) return 0;
  1263. const result = row.nextRunningKilometers - (mileageValue - row.lastRunningKilometers);
  1264. return parseFloat(result.toFixed(2));
  1265. };
  1266. // 计算下次保养运行时长(通用函数)
  1267. const calculateNextMaintenanceH = (row: IotMaintenanceBomVO) => {
  1268. // 验证条件:规则开启 + 两个值都存在且 > 0
  1269. const isValid = row.runningTimeRule === 0 &&
  1270. row.lastRunningTime > 0 &&
  1271. row.nextRunningTime > 0;
  1272. return isValid
  1273. ? (row.lastRunningTime + row.nextRunningTime)
  1274. : null; // 不满足条件返回null
  1275. };
  1276. // 计算剩余运行时间(通用函数)
  1277. const calculateRemainH = (row: IotMaintenanceBomVO) => {
  1278. // 确定使用的 运行时长 值(优先 totalRunTime)
  1279. const runTimeValue = row.totalRunTime ?? row.tempTotalRunTime;
  1280. // 验证条件:规则开启 + 3个值都存在且 > 0
  1281. const isValid = row.runningTimeRule === 0 &&
  1282. row.lastRunningTime > 0 &&
  1283. runTimeValue > 0 &&
  1284. row.nextRunningTime > 0;
  1285. if (!isValid) return 0;
  1286. const result = row.nextRunningTime - (runTimeValue - row.lastRunningTime);
  1287. return parseFloat(result.toFixed(2));
  1288. };
  1289. // 计算下次保养日期(通用函数)
  1290. const calculateNextMaintenanceDate = (row: IotMaintenanceBomVO) => {
  1291. // 验证条件:规则开启 + 两个值都存在且 > 0
  1292. const isValid = row.naturalDateRule === 0 &&
  1293. row.lastNaturalDate &&
  1294. row.nextNaturalDate;
  1295. return isValid
  1296. ? dayjs(row.lastNaturalDate).add(row.nextNaturalDate, 'day').format('YYYY-MM-DD')
  1297. : null; // 不满足条件返回null
  1298. };
  1299. // 计算 自然日期保养 剩余天数(通用函数)
  1300. const calculateRemainDay = (row: IotMaintenanceBomVO) => {
  1301. // 验证条件:规则开启 + 两个值都存在且有效
  1302. const isValid = row.naturalDateRule === 0 &&
  1303. row.lastNaturalDate !== null &&
  1304. row.nextNaturalDate !== null &&
  1305. row.nextNaturalDate > 0;
  1306. if (!isValid) {
  1307. return '-';
  1308. }
  1309. try {
  1310. // 上次保养日期:将时间戳转换为 Day.js 对象
  1311. const lastNaturalDate = dayjs(row.lastNaturalDate);
  1312. // 计算下次保养日期
  1313. const nextMaintenanceDate = lastNaturalDate.add(row.nextNaturalDate, 'day');
  1314. // 计算剩余天数(当前日期到下次保养日期的天数差)
  1315. return nextMaintenanceDate.diff(dayjs(), 'day');
  1316. } catch (error) {
  1317. console.error('计算保养剩余天数错误:', error);
  1318. return null;
  1319. }
  1320. };
  1321. const getStatusText = (row: any) => {
  1322. // 状态为1直接返回"完成"
  1323. if (row.status === 1) return t('mainPlan.completed');
  1324. // 状态为0时判断延迟字段
  1325. const delayDuration = Number(row.delayDuration) || 0;
  1326. const delayKilometers = Number(row.delayKilometers) || 0;
  1327. const delayNaturalDate = Number(row.delayNaturalDate) || 0;
  1328. // 任意延迟字段大于0 -> 延时
  1329. if (delayDuration > 0 || delayKilometers > 0 || delayNaturalDate > 0) {
  1330. return t('mainPlan.delayed');
  1331. }
  1332. // 否则显示保养中
  1333. return t('mainPlan.maintaining');
  1334. };
  1335. // 计算属性 - 检查当前页是否有开启的里程规则
  1336. const hasMileageRuleInCurrentPage = computed(() => {
  1337. return paginatedList.value.some(row => row.mileageRule === 0);
  1338. });
  1339. // 计算属性 - 检查当前页是否有开启的 运行时间 规则
  1340. const hasTimeRuleInCurrentPage = computed(() => {
  1341. return paginatedList.value.some(row => row.runningTimeRule === 0);
  1342. });
  1343. // 计算属性 - 检查当前页是否有开启的 自然日期 规则
  1344. const hasDateRuleInCurrentPage = computed(() => {
  1345. return paginatedList.value.some(row => row.naturalDateRule === 0);
  1346. });
  1347. // 统一计算所有列宽
  1348. const calculateAllColumnsWidth = () => {
  1349. const MIN_WIDTH = 70; // 最小列宽
  1350. const PADDING = 10; // 列内边距
  1351. const FIXED_COLUMN_PADDING = 10; // 固定列额外内边距
  1352. const GROUP_COLUMN_EXTRA = 10; // 分组列额外宽度
  1353. // 需要自适应的列配置
  1354. const autoColumns = [
  1355. { prop: 'serial', label: t('iotDevice.serial') },
  1356. // { prop: 'deviceCode', label: t('iotMaintain.deviceCode') },
  1357. // { prop: 'deviceName', label: t('iotMaintain.deviceName') },
  1358. { prop: 'group', label: t('mainPlan.MaintItemsGroup') },
  1359. {
  1360. prop: 'totalRunTime',
  1361. label: t('operationFillForm.sumTime'),
  1362. getValue: (row) => row.totalRunTime ?? row.tempTotalRunTime
  1363. },
  1364. {
  1365. prop: 'totalMileage',
  1366. label: t('operationFillForm.sumKil'),
  1367. getValue: (row) => row.totalMileage ?? row.tempTotalMileage
  1368. },
  1369. { prop: 'name', label: t('bomList.bomNode') },
  1370. { prop: 'lastMaintenanceDate', label: t('mainPlan.lastMaintenanceDate') },
  1371. { prop: 'mileageRule', label: t('main.mileage') },
  1372. { prop: 'runningTimeRule', label: t('main.runTime') },
  1373. { prop: 'naturalDateRule', label: t('main.date') },
  1374. { prop: 'lastRunningKilometers', label: t('mainPlan.lastMaintenanceMileage') },
  1375. { prop: 'nextMaintenanceKm', label: t('mainPlan.nextMaintenanceKm') },
  1376. { prop: 'remainKm', label: t('mainPlan.remainKm') },
  1377. { prop: 'lastRunningTime', label: t('mainPlan.lastMaintenanceOperationTime') },
  1378. { prop: 'nextMaintenanceH', label: t('mainPlan.nextMaintenanceH') },
  1379. { prop: 'remainH', label: t('mainPlan.remainH') },
  1380. { prop: 'nextRunningTime', label: t('mainPlan.RunTimeCycle') },
  1381. { prop: 'tempLastNaturalDate', label: t('mainPlan.lastMaintenanceNaturalDate') },
  1382. { prop: 'nextMaintenanceDate', label: t('mainPlan.nextMaintDate') },
  1383. { prop: 'remainDay', label: t('mainPlan.remainDay') },
  1384. { prop: 'operation', label: t('operationFill.operation') }
  1385. ];
  1386. const newWidths: Record<string, number> = {};
  1387. autoColumns.forEach(col => {
  1388. const headerText = col.label;
  1389. // 计算表头宽度
  1390. const headerWidth = getTextWidth(headerText) * 1.2;
  1391. // 计算内容最大宽度
  1392. let contentMaxWidth = 0;
  1393. if (col.prop === 'operation') {
  1394. // 操作列固定宽度(根据按钮数量)
  1395. contentMaxWidth = 120;
  1396. } else if (['mileageRule', 'runningTimeRule', 'naturalDateRule'].includes(col.prop)) {
  1397. // 开关列固定宽度
  1398. contentMaxWidth = 80;
  1399. } else {
  1400. list.value.forEach(row => {
  1401. const text = col.getValue ? String(col.getValue(row)) : String(row[col.prop] || '');
  1402. const textWidth = getTextWidth(text);
  1403. if (textWidth > contentMaxWidth) contentMaxWidth = textWidth;
  1404. });
  1405. }
  1406. // 取最大值并添加内边距
  1407. let finalWidth = Math.max(headerWidth, contentMaxWidth, MIN_WIDTH) + PADDING;
  1408. // 为分组列增加额外宽度
  1409. if ([
  1410. 'group',
  1411. 'lastRunningKilometers',
  1412. 'nextMaintenanceKm',
  1413. 'remainKm',
  1414. 'lastRunningTime',
  1415. 'nextMaintenanceH',
  1416. 'remainH',
  1417. 'tempLastNaturalDate',
  1418. 'nextMaintenanceDate',
  1419. 'remainDay'
  1420. ].includes(col.prop)) {
  1421. finalWidth += GROUP_COLUMN_EXTRA;
  1422. }
  1423. newWidths[col.prop] = finalWidth;
  1424. });
  1425. // 固定列特殊处理 - 增加额外空间
  1426. ['serial', 'name'].forEach(prop => {
  1427. if (newWidths[prop]) {
  1428. newWidths[prop] += FIXED_COLUMN_PADDING;
  1429. }
  1430. });
  1431. // 转换为CSS宽度值
  1432. Object.keys(newWidths).forEach(prop => {
  1433. columnWidths.value[prop] = `${newWidths[prop]}px`;
  1434. });
  1435. };
  1436. // 为每一行建立lastNaturalDate到tempLastNaturalDate的同步
  1437. const setupNaturalDateSync = (row: IotMaintenanceBomVO) => {
  1438. // 如果该行已有watcher则跳过
  1439. if (lastNaturalDateWatchers.value.has(row.id)) return
  1440. // 为该行创建单独的watcher
  1441. const unwatch = watch(
  1442. () => row.lastNaturalDate,
  1443. (newVal) => {
  1444. // 转换日期格式 (时间戳 -> YYYY-MM-DD)
  1445. row.tempLastNaturalDate = newVal
  1446. ? dayjs(newVal).format('YYYY-MM-DD')
  1447. : null;
  1448. },
  1449. { immediate: true, deep: true }
  1450. )
  1451. // 保存watcher用于后续清理
  1452. lastNaturalDateWatchers.value.set(row.id, unwatch)
  1453. }
  1454. const tableHeaderStyle = ({ row, rowIndex }) => {
  1455. return {
  1456. border: '1px solid #333',
  1457. backgroundColor: rowIndex === 0 ? '#f0f9eb' : '#f5f7fa' // 分组行特殊背景
  1458. }
  1459. }
  1460. // 监听分页数据和规则变化 - 重新布局表格
  1461. watch([paginatedList, hasMileageRuleInCurrentPage, hasTimeRuleInCurrentPage, hasDateRuleInCurrentPage], () => {
  1462. nextTick(() => {
  1463. tableRef.value?.doLayout();
  1464. calculateAllColumnsWidth(); // 重新计算列宽
  1465. });
  1466. });
  1467. // 监听分页变化时重新计算分组信息
  1468. watch([paginatedList, currentPage], () => {
  1469. calculateGroupSpans();
  1470. calculateAllColumnsWidth();
  1471. tableRef.value?.doLayout(); // 确保表格重新布局
  1472. });
  1473. // 下拉菜单命令处理
  1474. const handleDropdownCommand = (command: { action: string; row: IotMainWorkOrderBomVO }) => {
  1475. switch (command.action) {
  1476. case 'delay':
  1477. openConfigDialog(command.row);
  1478. break;
  1479. case 'material':
  1480. openMaterialForm(command.row);
  1481. break;
  1482. case 'deviceBomMaterials':
  1483. openDeviceBomMaterials(command.row);
  1484. break;
  1485. case 'detail':
  1486. handleView(command.row);
  1487. break;
  1488. }
  1489. };
  1490. /** 校验表格数据 */
  1491. const validateTableData = (): boolean => {
  1492. let isValid = true;
  1493. const errorMessages: string[] = []; // 通用错误集合
  1494. const materialRequiredErrors: string[] = []; // 物料缺失专用错误集合
  1495. // 1. 基础校验:工单明细是否存在
  1496. if (list.value.length === 0) {
  1497. message.error('工单明细不存在');
  1498. return false;
  1499. }
  1500. // 2. 校验设备状态
  1501. list.value.forEach((row, index) => {
  1502. const rowNumber = index + 1;
  1503. if (row.deviceCode === null || row.deviceName === null) {
  1504. errorMessages.push(`第${rowNumber}行设备状态错误`);
  1505. isValid = false;
  1506. }
  1507. });
  1508. // 3. 校验物料必填(仅在非委外模式下)
  1509. if (formData.value.outsourcingFlag !== 1) {
  1510. list.value.forEach((row, index) => {
  1511. const rowNumber = index + 1;
  1512. const deviceIdentifier = `${row.deviceCode}-${row.name}`;
  1513. // 检查是否设置了推迟保养
  1514. const hasDelay =
  1515. (row.delayKilometers || 0) > 0 ||
  1516. (row.delayNaturalDate || 0) > 0 ||
  1517. (row.delayDuration || 0) > 0;
  1518. // 未设置推迟保养且未选择物料
  1519. if (!hasDelay && getMaterialCount(row.bomNodeId) === 0) {
  1520. materialRequiredErrors.push(`第${rowNumber}行【${deviceIdentifier}】未添加物料`);
  1521. isValid = false;
  1522. }
  1523. });
  1524. }
  1525. // 4. 智能错误提示
  1526. if (!isValid) {
  1527. // 构建错误消息HTML
  1528. let errorHtml = '';
  1529. // 添加通用错误
  1530. if (errorMessages.length > 0) {
  1531. errorHtml += errorMessages.join('<br>');
  1532. }
  1533. // 添加物料错误(带智能截断)
  1534. if (materialRequiredErrors.length > 0) {
  1535. if (errorHtml) errorHtml += '<br>'; // 添加换行分隔
  1536. if (materialRequiredErrors.length > 3) {
  1537. errorHtml += materialRequiredErrors.slice(0, 3).join('<br>');
  1538. errorHtml += `<br>...等共 ${materialRequiredErrors.length} 个保养项未添加物料`;
  1539. } else {
  1540. errorHtml += materialRequiredErrors.join('<br>');
  1541. }
  1542. }
  1543. // 添加标题
  1544. const title = "<span style='font-weight:bold;color:#f56c6c'></span>";
  1545. errorHtml = title + errorHtml;
  1546. // 显示带格式的错误消息
  1547. message.error({
  1548. message: errorHtml,
  1549. dangerouslyUseHTMLString: true,
  1550. duration: 8000 // 延长显示时间
  1551. });
  1552. }
  1553. return isValid;
  1554. };
  1555. /** 重置表单 */
  1556. const resetForm = () => {
  1557. formData.value = {
  1558. id: undefined,
  1559. deviceId: undefined,
  1560. status: undefined,
  1561. description: undefined,
  1562. pic: undefined,
  1563. remark: undefined,
  1564. deviceName: undefined,
  1565. processInstanceId: undefined,
  1566. auditStatus: undefined,
  1567. deptId: undefined
  1568. }
  1569. formRef.value?.resetFields()
  1570. }
  1571. // 防抖函数实现
  1572. function debounce(func: Function, wait: number) {
  1573. let timeout: ReturnType<typeof setTimeout> | null
  1574. return function executedFunction(...args: any[]) {
  1575. const later = () => {
  1576. clearTimeout(timeout!)
  1577. func(...args)
  1578. }
  1579. clearTimeout(timeout!)
  1580. timeout = setTimeout(later, wait)
  1581. }
  1582. }
  1583. // 响应窗口大小变化
  1584. const handleResize = debounce(calculateMaintItemsWidth, 300)
  1585. onMounted(async () => {
  1586. materialList.value = []
  1587. const deptId = useUserStore().getUser.deptId
  1588. // 查询当前登录人所属部门名称
  1589. dept.value = await DeptApi.getDept(deptId)
  1590. deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
  1591. formData.value.deptId = deptId
  1592. try{
  1593. formType.value = 'update'
  1594. // 查询保养工单 主表数据
  1595. const workOrder = await IotMainWorkOrderApi.getIotMainWorkOrder(id);
  1596. formData.value = workOrder
  1597. // 查询保养工单 明细数据
  1598. const data = await IotMainWorkOrderBomApi.getWorkOrderBOMs(queryParams);
  1599. list.value = []
  1600. if (Array.isArray(data)) {
  1601. list.value = data.map(item => {
  1602. // 提取分组名称
  1603. const group = item.name && item.name.includes('->')
  1604. ? item.name.split('->')[0].trim()
  1605. : '';
  1606. if (item.mileageRule === 0) {
  1607. item.nextMaintenanceKm = calculateNextMaintenanceKm(item);
  1608. item.remainKm = calculateRemainKm(item);
  1609. }
  1610. if (item.runningTimeRule === 0) {
  1611. item.nextMaintenanceH = calculateNextMaintenanceH(item);
  1612. item.remainH = calculateRemainH(item);
  1613. }
  1614. if (item.naturalDateRule === 0) {
  1615. item.nextMaintenanceDate = calculateNextMaintenanceDate(item);
  1616. item.remainDay = calculateRemainDay(item);
  1617. }
  1618. setupNaturalDateSync(item);
  1619. return {
  1620. ...item,
  1621. group,
  1622. lastNaturalDate: item.lastNaturalDate,
  1623. lastMaintenanceDate: item.lastMaintenanceDate
  1624. ? dayjs(item.lastMaintenanceDate).format("YYYY-MM-DD") // 时间戳 → 日期字符串
  1625. : null // 处理空值
  1626. }
  1627. })
  1628. // 设备信息提取逻辑
  1629. if (list.value.length > 0) {
  1630. // 从第一个保养项提取设备信息(所有保养项共享相同设备)
  1631. formData.value.deviceCode = list.value[0].deviceCode;
  1632. formData.value.deviceName = list.value[0].deviceName;
  1633. }
  1634. }
  1635. // 查询当前保养工单已经关联的所有物料
  1636. const materials = await IotMainWorkOrderBomMaterialApi.getWorkOrderBomMaterials(queryParams);
  1637. materialList.value = []
  1638. if (Array.isArray(materials)) {
  1639. materialList.value = materials
  1640. .map(item => ({
  1641. ...item,
  1642. }))
  1643. }
  1644. } catch (error) {
  1645. console.error('数据加载失败:', error)
  1646. message.error('数据加载失败,请重试')
  1647. }
  1648. nextTick(() => {
  1649. calculateAllColumnsWidth()
  1650. window.addEventListener('resize', calculateAllColumnsWidth);
  1651. })
  1652. // 初始化 保养项 分组信息
  1653. calculateGroupSpans();
  1654. })
  1655. onUnmounted(async () => {
  1656. window.removeEventListener('resize', calculateAllColumnsWidth);
  1657. })
  1658. </script>
  1659. <style scoped>
  1660. .base-expandable-content {
  1661. overflow: hidden; /* 隐藏溢出的内容 */
  1662. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  1663. }
  1664. :deep(.el-input-number .el-input__inner) {
  1665. text-align: left !important;
  1666. padding-left: 10px; /* 保持左侧间距 */
  1667. }
  1668. /* 分组容器样式 */
  1669. .form-group {
  1670. position: relative;
  1671. border: 1px solid #dcdfe6;
  1672. border-radius: 4px;
  1673. padding: 20px 15px 10px;
  1674. margin-bottom: 18px;
  1675. transition: border-color 0.2s;
  1676. }
  1677. /* 分组标题样式 */
  1678. .group-title {
  1679. position: absolute;
  1680. top: -10px;
  1681. left: 20px;
  1682. background: white;
  1683. padding: 0 8px;
  1684. color: #606266;
  1685. font-size: 12px;
  1686. font-weight: 500;
  1687. }
  1688. .error-text {
  1689. color: #f56c6c;
  1690. font-size: 12px;
  1691. margin-top: 5px;
  1692. }
  1693. :deep(.el-table__body) {
  1694. .el-table__cell {
  1695. .cell {
  1696. word-break: break-word;
  1697. max-width: 600px; /* 最大宽度限制 */
  1698. }
  1699. }
  1700. }
  1701. .full-content-cell {
  1702. white-space: nowrap; /* 禁止换行 */
  1703. overflow: visible; /* 允许内容溢出单元格 */
  1704. }
  1705. /* 分组表头样式 */
  1706. :deep(.el-table__header) {
  1707. border: 1px solid #dcdfe6 !important;
  1708. }
  1709. :deep(.el-table__header th) {
  1710. border-right: 1px solid #dcdfe6 !important;
  1711. border-bottom: 1px solid #dcdfe6 !important;
  1712. }
  1713. :deep(.el-table__header .is-group th) {
  1714. background-color: #f5f7fa !important;
  1715. border-bottom: 1px solid #dcdfe6 !important;
  1716. font-weight: 600;
  1717. position: relative;
  1718. }
  1719. :deep(.el-table__header .is-group th::after) {
  1720. display: none !important;
  1721. }
  1722. /* 分组标题下的子表头单元格 */
  1723. :deep(.el-table__header .el-table__cell:not(.is-group)) {
  1724. border-top: 1px solid #dcdfe6 !important; /* 添加顶部边框连接分组标题 */
  1725. }
  1726. /* 分组行样式 - 符合图片效果 */
  1727. :deep(.el-table .group-row) {
  1728. background-color: #f8f8f9; /* 轻微的背景色区分 */
  1729. }
  1730. /* 分组单元格样式 */
  1731. :deep(.el-table .group-cell) {
  1732. font-weight: 600; /* 加粗字体 */
  1733. vertical-align: middle; /* 垂直居中 */
  1734. }
  1735. /* 分组第一行单元格样式 - 添加底部边框 */
  1736. :deep(.el-table .group-first-row) {
  1737. position: relative;
  1738. }
  1739. /* 使用伪元素创建更明显的底部边框 */
  1740. :deep(.el-table .group-first-row::after) {
  1741. content: '';
  1742. position: absolute;
  1743. left: 0;
  1744. right: 0;
  1745. bottom: 0;
  1746. height: 2px;
  1747. background-color: #606266; /* 深灰色边框 */
  1748. z-index: 1;
  1749. }
  1750. /* 调整分组行的高度,使边框更明显 */
  1751. :deep(.el-table .el-table__row.group-first-row) {
  1752. border-bottom: none; /* 移除默认边框 */
  1753. }
  1754. </style>