IotMainWorkOrder.vue 62 KB

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