IotMaintenancePlan.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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="12">
  14. <el-form-item :label="t('main.planName')" prop="name">
  15. <el-input type="text" v-model="formData.name" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="12">
  19. <el-form-item :label="t('main.planCode')" prop="serialNumber">
  20. <el-input type="text" v-model="formData.serialNumber" disabled/>
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="24">
  24. <el-form-item :label="t('iotMaintain.remark')" prop="remark">
  25. <el-input v-model="formData.remark" type="textarea" :placeholder="t('iotMaintain.remarkHolder')" />
  26. </el-form-item>
  27. </el-col>
  28. </el-row>
  29. </div>
  30. </el-form>
  31. </ContentWrap>
  32. <ContentWrap>
  33. <ContentWrap>
  34. <!-- 搜索工作栏 -->
  35. <el-form
  36. class="-mb-15px"
  37. :model="queryParams"
  38. ref="queryFormRef"
  39. :inline="true"
  40. label-width="68px"
  41. >
  42. <el-form-item>
  43. <el-button @click="openForm" type="warning">
  44. <Icon icon="ep:plus" class="mr-5px" /> {{ t('operationFill.add') }}</el-button>
  45. </el-form-item>
  46. </el-form>
  47. </ContentWrap>
  48. <!-- 列表 -->
  49. <ContentWrap>
  50. <el-table v-loading="loading" :data="pagedList" :stripe="true" :show-overflow-tooltip="true" :cell-class-name="cellClassName">
  51. <!-- 添加序号列 -->
  52. <el-table-column
  53. type="index"
  54. :label="t('iotDevice.serial')"
  55. width="70"
  56. align="center"
  57. />
  58. <el-table-column label="设备id" align="center" prop="deviceId" v-if="false"/>
  59. <el-table-column :label="t('iotMaintain.deviceCode')" align="center" prop="deviceCode" />
  60. <el-table-column :label="t('iotMaintain.deviceName')" align="center" prop="deviceName" />
  61. <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter">
  62. <template #default="{ row }">
  63. {{ row.totalRunTime ?? row.tempTotalRunTime }}
  64. </template>
  65. </el-table-column>
  66. <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter">
  67. <template #default="{ row }">
  68. {{ row.totalMileage ?? row.tempTotalMileage }}
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="tempTotalRunTime" align="center" prop="tempTotalRunTime" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
  72. <el-table-column label="tempTotalMileage" align="center" prop="tempTotalMileage" :formatter="erpPriceTableColumnFormatter" v-if="false"/>
  73. <el-table-column :label="t('bomList.bomNode')" align="center" prop="name" />
  74. <el-table-column :label="t('main.mileage')" key="mileageRule" width="80">
  75. <template #default="scope">
  76. <el-switch
  77. v-model="scope.row.mileageRule"
  78. :active-value="0"
  79. :inactive-value="1"
  80. @change="handleRuleChange(scope.row, 'mileage')"
  81. />
  82. </template>
  83. </el-table-column>
  84. <el-table-column :label="t('main.runTime')" key="runningTimeRule" width="90">
  85. <template #default="scope">
  86. <el-switch
  87. v-model="scope.row.runningTimeRule"
  88. :active-value="0"
  89. :inactive-value="1"
  90. @change="handleRuleChange(scope.row, 'runningTime')"
  91. />
  92. </template>
  93. </el-table-column>
  94. <el-table-column :label="t('main.date')" key="naturalDateRule" width="80">
  95. <template #default="scope">
  96. <el-switch
  97. v-model="scope.row.naturalDateRule"
  98. :active-value="0"
  99. :inactive-value="1"
  100. />
  101. </template>
  102. </el-table-column>
  103. <el-table-column :label="t('operationFill.operation')" align="center" min-width="120px">
  104. <template #default="scope">
  105. <div style="display: flex; justify-content: center; align-items: center; width: 100%">
  106. <div>
  107. <Icon style="vertical-align: middle; color: #ea3434" icon="ep:zoom-out" />
  108. <el-button
  109. style="vertical-align: middle"
  110. link
  111. type="danger"
  112. @click="handleDelete(scope.row.deviceId+'-'+scope.row.bomNodeId)"
  113. >
  114. {{t('modelTemplate.delete')}}
  115. </el-button>
  116. </div>
  117. <!-- 新增配置按钮 -->
  118. <div style="margin-left: 12px">
  119. <el-button
  120. link
  121. type="primary"
  122. @click="openConfigDialog(scope.row)"
  123. >
  124. {{t('modelTemplate.update')}}
  125. </el-button>
  126. </div>
  127. </div>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <!-- 添加分页组件 -->
  132. <el-pagination
  133. :key="`pagination-${list.length}-${currentPage}`"
  134. style="margin-top: 20px; justify-content: flex-end"
  135. :total="list.length"
  136. v-model:current-page="currentPage"
  137. v-model:page-size="pageSize"
  138. :page-sizes="[10, 20, 50, 100]"
  139. layout="total, sizes, prev, pager, next, jumper"
  140. @current-change="handlePageChange"
  141. @size-change="handleSizeChange"
  142. />
  143. </ContentWrap>
  144. </ContentWrap>
  145. <ContentWrap>
  146. <el-form>
  147. <el-form-item style="float: right">
  148. <el-button @click="submitForm" type="primary" :disabled="formLoading">{{t('iotMaintain.save')}}</el-button>
  149. <el-button @click="close">{{t('iotMaintain.cancel')}}</el-button>
  150. </el-form-item>
  151. </el-form>
  152. </ContentWrap>
  153. <MainPlanDeviceList ref="deviceFormRef" @choose="deviceChoose" />
  154. <!-- 新增配置对话框 -->
  155. <el-dialog
  156. v-model="configDialog.visible"
  157. :title="`设备 ${configDialog.current?.deviceCode+'-'+configDialog.current?.name} 保养配置`"
  158. width="600px"
  159. :close-on-click-modal="false"
  160. >
  161. <!-- 使用header插槽自定义标题 -->
  162. <template #header>
  163. <span>设备 <strong>{{ configDialog.current?.deviceCode }}-{{ configDialog.current?.name }}</strong> 保养项配置</span>
  164. </template>
  165. <el-form :model="configDialog.form" label-width="200px" :rules="configFormRules" ref="configFormRef">
  166. <div class="form-group">
  167. <div class="group-title">{{ t('mainPlan.basicMaintenanceRecords') }}</div>
  168. <!-- 里程配置 -->
  169. <el-form-item
  170. v-if="configDialog.current?.mileageRule === 0"
  171. :label="t('mainPlan.lastMaintenanceMileage')"
  172. prop="lastRunningKilometers"
  173. >
  174. <el-input-number
  175. v-model="configDialog.form.lastRunningKilometers"
  176. :precision="2"
  177. :min="0"
  178. controls-position="right"
  179. :controls="false"
  180. style="width: 80%"
  181. />
  182. </el-form-item>
  183. <!-- 运行时间配置 -->
  184. <el-form-item
  185. v-if="configDialog.current?.runningTimeRule === 0"
  186. :label="t('mainPlan.lastMaintenanceOperationTime')"
  187. prop="lastRunningTime"
  188. >
  189. <el-input-number
  190. v-model="configDialog.form.lastRunningTime"
  191. :precision="1"
  192. :min="0"
  193. controls-position="right"
  194. :controls="false"
  195. style="width: 80%"
  196. />
  197. </el-form-item>
  198. <!-- 自然日期配置 -->
  199. <el-form-item
  200. v-if="configDialog.current?.naturalDateRule === 0"
  201. :label="t('mainPlan.lastMaintenanceNaturalDate')"
  202. prop="lastNaturalDate"
  203. >
  204. <el-date-picker
  205. v-model="configDialog.form.lastNaturalDate"
  206. type="date"
  207. placeholder="选择日期"
  208. format="YYYY-MM-DD"
  209. value-format="YYYY-MM-DD"
  210. style="width: 80%"
  211. />
  212. </el-form-item>
  213. </div>
  214. <div class="form-group" v-if="configDialog.current?.mileageRule === 0">
  215. <div class="group-title">{{ t('mainPlan.operatingMileageRuleConfiguration') }}</div>
  216. <!-- 保养规则周期值 + 提前量 -->
  217. <el-form-item
  218. v-if="configDialog.current?.mileageRule === 0"
  219. :label="t('mainPlan.operatingMileageCycle')"
  220. prop="nextRunningKilometers"
  221. >
  222. <el-input-number
  223. v-model="configDialog.form.nextRunningKilometers"
  224. :precision="2"
  225. :min="0"
  226. controls-position="right"
  227. :controls="false"
  228. style="width: 80%"
  229. />
  230. </el-form-item>
  231. <el-form-item
  232. v-if="configDialog.current?.mileageRule === 0"
  233. :label="t('mainPlan.OperatingMileageCycle_lead')"
  234. prop="kiloCycleLead"
  235. >
  236. <el-input-number
  237. v-model="configDialog.form.kiloCycleLead"
  238. :precision="2"
  239. :min="0"
  240. controls-position="right"
  241. :controls="false"
  242. style="width: 80%"
  243. />
  244. </el-form-item>
  245. </div>
  246. <div class="form-group" v-if="configDialog.current?.runningTimeRule === 0">
  247. <div class="group-title">{{ t('mainPlan.RunTimeRuleConfiguration') }}</div>
  248. <el-form-item
  249. v-if="configDialog.current?.runningTimeRule === 0"
  250. :label="t('mainPlan.RunTimeCycle')"
  251. prop="nextRunningTime"
  252. >
  253. <el-input-number
  254. v-model="configDialog.form.nextRunningTime"
  255. :precision="1"
  256. :min="0"
  257. controls-position="right"
  258. :controls="false"
  259. style="width: 80%"
  260. />
  261. </el-form-item>
  262. <el-form-item
  263. v-if="configDialog.current?.runningTimeRule === 0"
  264. :label="t('mainPlan.RunTimeCycle_Lead')"
  265. prop="timePeriodLead"
  266. >
  267. <el-input-number
  268. v-model="configDialog.form.timePeriodLead"
  269. :precision="1"
  270. :min="0"
  271. controls-position="right"
  272. :controls="false"
  273. style="width: 80%"
  274. />
  275. </el-form-item>
  276. </div>
  277. <div class="form-group" v-if="configDialog.current?.naturalDateRule === 0">
  278. <div class="group-title">{{ t('mainPlan.NaturalDayRuleConfig') }}</div>
  279. <el-form-item
  280. v-if="configDialog.current?.naturalDateRule === 0"
  281. :label="t('mainPlan.NaturalDailyCycle') "
  282. prop="nextNaturalDate"
  283. >
  284. <el-input-number
  285. v-model="configDialog.form.nextNaturalDate"
  286. :min="0"
  287. controls-position="right"
  288. :controls="false"
  289. style="width: 80%"
  290. />
  291. </el-form-item>
  292. <el-form-item
  293. v-if="configDialog.current?.naturalDateRule === 0"
  294. :label="t('mainPlan.NaturalDailyCycle_Lead') "
  295. prop="naturalDatePeriodLead"
  296. >
  297. <el-input-number
  298. v-model="configDialog.form.naturalDatePeriodLead"
  299. :min="0"
  300. controls-position="right"
  301. :controls="false"
  302. style="width: 80%"
  303. />
  304. </el-form-item>
  305. </div>
  306. <!-- 运行记录模板中 多个 累计运行时长 累计运行里程 属性匹配-->
  307. <div class="form-group"
  308. v-if="(configDialog.current?.runningTimeRule === 0 || configDialog.current?.mileageRule === 0)
  309. && (configDialog.current?.timeAccumulatedAttrs?.length || configDialog.current?.mileageAccumulatedAttrs?.length)
  310. && (configDialog.current.totalRunTime == null || isNaN(configDialog.current.totalRunTime))
  311. && (configDialog.current.totalMileage == null || isNaN(configDialog.current.totalMileage))" >
  312. <div class="group-title">{{ t('mainPlan.accumulatedParams') }}</div>
  313. <!-- 累计运行时长 -->
  314. <el-form-item
  315. v-if="configDialog.current?.runningTimeRule === 0
  316. && configDialog.current?.timeAccumulatedAttrs?.length
  317. && (configDialog.current.totalRunTime == null || isNaN(configDialog.current.totalRunTime))"
  318. :label="t('mainPlan.accumulatedRunTime')"
  319. prop="accumulatedTimeOption"
  320. :rules="[{
  321. required: configDialog.current?.runningTimeRule === 0 && configDialog.current?.timeAccumulatedAttrs?.length
  322. && (configDialog.current.totalRunTime == null || isNaN(configDialog.current.totalRunTime)),
  323. message: '请选择累计运行时长',
  324. trigger: 'change'
  325. }]"
  326. >
  327. <el-select
  328. v-model="configDialog.form.accumulatedTimeOption"
  329. placeholder="请选择累计运行时长"
  330. style="width: 80%"
  331. clearable
  332. @change="handleAccumulatedTimeChange"
  333. >
  334. <el-option
  335. v-for="(item, index) in configDialog.current.timeAccumulatedAttrs"
  336. :key="`time-${item.pointName}-${index}`"
  337. :label="item.pointName"
  338. :value="item.pointName"
  339. />
  340. </el-select>
  341. </el-form-item>
  342. <!-- 累计运行公里数 -->
  343. <el-form-item
  344. v-if="configDialog.current?.mileageRule === 0
  345. && configDialog.current?.mileageAccumulatedAttrs?.length
  346. && (configDialog.current.totalMileage == null || isNaN(configDialog.current.totalMileage))"
  347. :label="t('mainPlan.accumulatedMileage')"
  348. prop="accumulatedMileageOption"
  349. :rules="[{
  350. required: configDialog.current?.mileageRule === 0 && configDialog.current?.mileageAccumulatedAttrs?.length
  351. && (configDialog.current.totalMileage == null || isNaN(configDialog.current.totalMileage)),
  352. message: '请选择累计运行公里数',
  353. trigger: 'change'
  354. }]"
  355. >
  356. <el-select
  357. v-model="configDialog.form.accumulatedMileageOption"
  358. placeholder="请选择累计运行公里数"
  359. style="width: 80%"
  360. clearable
  361. @change="handleAccumulatedMileageChange"
  362. >
  363. <el-option
  364. v-for="(item, index) in configDialog.current.mileageAccumulatedAttrs"
  365. :key="`mileage-${item.pointName}-${index}`"
  366. :label="item.pointName"
  367. :value="item.pointName"
  368. />
  369. </el-select>
  370. </el-form-item>
  371. </div>
  372. </el-form>
  373. <template #footer>
  374. <el-button @click="configDialog.visible = false">{{ t('common.cancel') }}</el-button>
  375. <el-button type="primary" @click="saveConfig">{{ t('common.save') }}</el-button>
  376. </template>
  377. </el-dialog>
  378. </template>
  379. <script setup lang="ts">
  380. import { IotDeviceApi, IotDeviceVO } from '@/api/pms/device'
  381. import * as UserApi from '@/api/system/user'
  382. import { useUserStore } from '@/store/modules/user'
  383. import { ref, computed, nextTick } from 'vue'
  384. import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
  385. import { IotMaintenancePlanApi, IotMaintenancePlanVO } from '@/api/pms/maintenance'
  386. import { useTagsViewStore } from '@/store/modules/tagsView'
  387. import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
  388. import MainPlanDeviceList from "@/views/pms/maintenance/MainPlanDeviceList.vue";
  389. import * as DeptApi from "@/api/system/dept";
  390. import {erpPriceTableColumnFormatter} from "@/utils";
  391. import dayjs from 'dayjs'
  392. /** 保养计划 表单 */
  393. defineOptions({ name: 'IotAddMainPlan' })
  394. const { t } = useI18n() // 国际化
  395. const message = useMessage() // 消息弹窗
  396. const { delView } = useTagsViewStore() // 视图操作
  397. const { currentRoute, push } = useRouter()
  398. const deptUsers = ref<UserApi.UserVO[]>([]) // 用户列表
  399. const dept = ref() // 当前登录人所属部门对象
  400. const configFormRef = ref() // 配置弹出框对象
  401. const dialogTitle = ref('') // 弹窗的标题
  402. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  403. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  404. const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
  405. const list = ref<IotMaintenanceBomVO[]>([]) // 设备bom关联列表的数据
  406. const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
  407. // 分页相关变量
  408. const currentPage = ref(1)
  409. const pageSize = ref(10)
  410. // 计算分页后的数据
  411. const pagedList = computed(() => {
  412. const start = (currentPage.value - 1) * pageSize.value;
  413. const end = Math.min(start + pageSize.value, list.value.length);
  414. return list.value.slice(start, end);
  415. });
  416. // 处理页码变化
  417. const handlePageChange = (page: number) => {
  418. currentPage.value = page
  419. }
  420. // 处理每页数量变化
  421. const handleSizeChange = (size: number) => {
  422. pageSize.value = size
  423. // currentPage.value = 1 // 重置到第一页
  424. // 添加以下两行防止页码越界
  425. const maxPage = Math.ceil(list.value.length / size);
  426. if (currentPage.value > maxPage) currentPage.value = maxPage;
  427. }
  428. const { params, name } = useRoute() // 查询参数
  429. const id = params.id
  430. const formData = ref({
  431. id: undefined,
  432. deptId: undefined,
  433. name: '',
  434. serialNumber: undefined,
  435. responsiblePerson: undefined,
  436. remark: undefined,
  437. failureName: undefined,
  438. status: undefined,
  439. devicePersons: '',
  440. })
  441. const formRules = reactive({
  442. name: [{ required: true, message: '计划名称不能为空', trigger: 'blur' }],
  443. responsiblePerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
  444. })
  445. const formRef = ref() // 表单 Ref
  446. // 新增配置相关状态
  447. const configDialog = reactive({
  448. visible: false,
  449. current: null as IotMaintenanceBomVO | null,
  450. form: {
  451. lastRunningKilometers: 0,
  452. lastRunningTime: 0,
  453. lastNaturalDate: '',
  454. // 保养规则 周期
  455. nextRunningKilometers: 0,
  456. nextRunningTime: 0,
  457. nextNaturalDate: 0,
  458. // 提前量
  459. kiloCycleLead: 0,
  460. timePeriodLead: 0,
  461. naturalDatePeriodLead: 0,
  462. // 多个累计时长 累计里程 匹配
  463. accumulatedTimeOption: null, // 累计运行时长选项
  464. accumulatedMileageOption: null, // 累计运行公里数选项
  465. }
  466. })
  467. // 单元格类名回调方法
  468. const cellClassName = ({ row, column }) => {
  469. // 只对序号列进行处理
  470. if (column.type === 'index') {
  471. // 检查该行所有启用的规则是否都已配置完整
  472. if (checkRowFilled(row)) {
  473. return 'all-filled'; // 返回自定义类名
  474. }
  475. }
  476. return '';
  477. };
  478. // 检查行数据是否完整填写
  479. const checkRowFilled = (row: IotMaintenanceBomVO) => {
  480. // 检查是否启用了至少一个规则
  481. const hasRuleEnabled =
  482. row.mileageRule === 0 ||
  483. row.runningTimeRule === 0 ||
  484. row.naturalDateRule === 0;
  485. if (!hasRuleEnabled) {
  486. return false; // 没有任何规则启用,不显示背景色
  487. }
  488. // 检查里程规则
  489. const mileageFilled = row.mileageRule !== 0
  490. ? true // 规则未启用,视为已"填写"
  491. : (row.lastRunningKilometers > 0 &&
  492. row.nextRunningKilometers > 0 &&
  493. row.kiloCycleLead > 0 &&
  494. // 检查累计里程参数是否已选择(当条件满足时)
  495. (!(row.mileageAccumulatedAttrs?.length && (row.totalMileage==null || isNaN(row.totalMileage))) ||
  496. (row.mileageAccumulatedAttrs?.length && (row.totalMileage==null || isNaN(row.totalMileage)) && row.type)));
  497. // 检查运行时间规则
  498. const runningTimeFilled = row.runningTimeRule !== 0
  499. ? true
  500. : (row.lastRunningTime > 0 &&
  501. row.nextRunningTime > 0 &&
  502. row.timePeriodLead > 0 &&
  503. // 检查累计时间参数是否已选择(当条件满足时)
  504. (!(row.timeAccumulatedAttrs?.length && (row.totalRunTime==null || isNaN(row.totalRunTime))) ||
  505. (row.timeAccumulatedAttrs?.length && (row.totalRunTime==null || isNaN(row.totalRunTime)) && row.code)));
  506. // 检查自然日期规则
  507. const naturalDateFilled = row.naturalDateRule !== 0
  508. ? true
  509. : (row.lastNaturalDate &&
  510. row.nextNaturalDate > 0 &&
  511. row.naturalDatePeriodLead > 0);
  512. return mileageFilled && runningTimeFilled && naturalDateFilled;
  513. };
  514. // 打开配置对话框
  515. const openConfigDialog = (row: IotMaintenanceBomVO) => {
  516. // 新增规则校验:至少一个规则开启
  517. if (row.mileageRule !== 0 && row.runningTimeRule !== 0 && row.naturalDateRule !== 0) {
  518. message.error('请先设置保养规则')
  519. return
  520. }
  521. configDialog.current = row
  522. // 处理日期初始化(核心修改)
  523. let initialDate = ''
  524. if (row.lastNaturalDate) {
  525. // 如果已有值:时间戳 -> 日期字符串
  526. initialDate = dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
  527. } else {
  528. // 如果无值:设置默认值避免1970问题
  529. initialDate = ''
  530. }
  531. configDialog.form = {
  532. lastRunningKilometers: row.lastRunningKilometers || 0,
  533. lastRunningTime: row.lastRunningTime || 0,
  534. // 时间戳 -> Date对象(用于日期选择器)
  535. lastNaturalDate: row.lastNaturalDate
  536. ? dayjs(row.lastNaturalDate).format('YYYY-MM-DD')
  537. : null,
  538. // 保养规则 周期值
  539. nextRunningKilometers: row.nextRunningKilometers || 0,
  540. nextRunningTime: row.nextRunningTime || 0,
  541. nextNaturalDate: row.nextNaturalDate || 0,
  542. // 提前量
  543. kiloCycleLead: row.kiloCycleLead || 0,
  544. timePeriodLead: row.timePeriodLead || 0,
  545. naturalDatePeriodLead: row.naturalDatePeriodLead || 0,
  546. // 多个累计时长 累计里程 匹配
  547. accumulatedTimeOption: null, // 累计运行时长选项
  548. accumulatedMileageOption: null, // 累计运行公里数选项
  549. }
  550. // 初始化累计参数选择
  551. configDialog.form.accumulatedTimeOption = row.isRuntimeFromTemp
  552. ? row.code
  553. : null;
  554. configDialog.form.accumulatedMileageOption = row.isMileageFromTemp
  555. ? row.type
  556. : null;
  557. configDialog.visible = true
  558. }
  559. // 保存配置
  560. const saveConfig = () => {
  561. (configFormRef.value as any).validate((valid: boolean) => {
  562. if (!valid) return
  563. if (!configDialog.current) return
  564. // 累计运行时长配置 校验逻辑
  565. if (configDialog.current.runningTimeRule === 0 &&
  566. configDialog.current.timeAccumulatedAttrs?.length &&
  567. !configDialog.form.accumulatedTimeOption &&
  568. (configDialog.current.totalRunTime == null || isNaN(configDialog.current.totalRunTime)) ) {
  569. message.error('请选择累计运行时长');
  570. return;
  571. }
  572. // 累计运行公里数配置 校验逻辑
  573. if (configDialog.current.mileageRule === 0 &&
  574. configDialog.current.mileageAccumulatedAttrs?.length &&
  575. !configDialog.form.accumulatedMileageOption &&
  576. (configDialog.current.totalMileage == null || isNaN(configDialog.current.totalMileage)) ) {
  577. message.error('请选择累计运行公里数');
  578. return;
  579. }
  580. // 动态校验逻辑
  581. const requiredFields = []
  582. if (configDialog.current.mileageRule === 0) {
  583. requiredFields.push('nextRunningKilometers', 'kiloCycleLead')
  584. }
  585. if (configDialog.current.runningTimeRule === 0) {
  586. requiredFields.push('nextRunningTime', 'timePeriodLead')
  587. }
  588. if (configDialog.current.naturalDateRule === 0) {
  589. requiredFields.push('nextNaturalDate', 'naturalDatePeriodLead')
  590. }
  591. const missingFields = requiredFields.filter(field =>
  592. !configDialog.form[field as keyof typeof configDialog.form]
  593. )
  594. if (missingFields.length > 0) {
  595. message.error('请填写所有必填项')
  596. return
  597. }
  598. // 强制校验逻辑
  599. if (configDialog.current.naturalDateRule === 0) {
  600. if (!configDialog.form.lastNaturalDate) {
  601. message.error('必须选择自然日期')
  602. return
  603. }
  604. // 验证日期有效性
  605. const dateValue = dayjs(configDialog.form.lastNaturalDate)
  606. if (!dateValue.isValid()) {
  607. message.error('日期格式不正确')
  608. return
  609. }
  610. }
  611. // 转换逻辑(关键修改)
  612. const finalDate = configDialog.form.lastNaturalDate
  613. ? dayjs(configDialog.form.lastNaturalDate).valueOf()
  614. : null // 改为null而不是0
  615. const updateData = {
  616. ...configDialog.form,
  617. lastNaturalDate: finalDate,
  618. };
  619. // 处理累计运行时长
  620. // 当规则关闭时,无论是否有选择值,都清除相关数据
  621. if (configDialog.current.runningTimeRule !== 0) {
  622. configDialog.current.code = null;
  623. configDialog.current.totalRunTime = null;
  624. configDialog.form.accumulatedTimeOption = null; // 清除选择值
  625. } else if (configDialog.form.accumulatedTimeOption) {
  626. // 查找选中的累计运行时长项
  627. const selectedTimeOption = configDialog.current.timeAccumulatedAttrs?.find(
  628. item => item.pointName === configDialog.form.accumulatedTimeOption
  629. );
  630. if (selectedTimeOption) {
  631. configDialog.current.code = selectedTimeOption.pointName;
  632. // 优先使用接口值,没有则使用临时值
  633. configDialog.current.tempTotalRunTime = selectedTimeOption.totalRunTime;
  634. configDialog.current.isRuntimeFromTemp = true;
  635. // 只有接口未提供值时才使用临时值
  636. if (!configDialog.current.totalRunTime) {
  637. // configDialog.current.totalRunTime = selectedTimeOption.totalRunTime;
  638. }
  639. }
  640. }
  641. if (configDialog.current.mileageRule !== 0) {
  642. configDialog.current.type = null;
  643. configDialog.current.totalMileage = null;
  644. configDialog.form.accumulatedMileageOption = null; // 清除选择值
  645. } else if (configDialog.form.accumulatedMileageOption) {
  646. // 查找选中的累计运行公里数项
  647. const selectedMileageOption = configDialog.current.mileageAccumulatedAttrs?.find(
  648. item => item.pointName === configDialog.form.accumulatedMileageOption
  649. );
  650. if (selectedMileageOption) {
  651. configDialog.current.type = selectedMileageOption.pointName;
  652. configDialog.current.tempTotalMileage = selectedMileageOption.totalRunTime;
  653. configDialog.current.isMileageFromTemp = true;
  654. if (!configDialog.current.totalMileage) {
  655. // configDialog.current.totalMileage = selectedMileageOption.totalRunTime;
  656. }
  657. }
  658. }
  659. // 更新当前行的数据
  660. Object.assign(configDialog.current, updateData);
  661. configDialog.visible = false
  662. })
  663. }
  664. // 累计运行时长变更
  665. const handleAccumulatedTimeChange = (option) => {
  666. }
  667. // 累计运行公里数变更
  668. const handleAccumulatedMileageChange = (option) => {
  669. }
  670. const queryParams = reactive({
  671. deviceIds: undefined,
  672. planId: id,
  673. bomFlag: 'b'
  674. })
  675. // 处理保养规则变化 取消保养规则 时 清空已经设置的相应保养规则数据
  676. const handleRuleChange = (row: IotMaintenanceBomVO, ruleType: 'mileage' | 'runningTime') => {
  677. // 当规则关闭时(inactive-value=1)
  678. console.log('执行了保养规则变化事件' + row.totalRunTime + ' - ' + row.totalMileage)
  679. // 当前保养项行已经返回了 totalRunTime totalMileage 数据 不需要再清空 累计运行时长 累计公里数
  680. // 选择完设备匹配了保养项后 不能直接置空 因为可能是正常的累计时长 累计公里数
  681. if (ruleType === 'runningTime' && row.runningTimeRule === 1) {
  682. // 清除临时来源的值
  683. if (row.isRuntimeFromTemp) {
  684. row.totalRunTime = null;
  685. row.tempTotalRunTime = null;
  686. row.code = null;
  687. // row.isRuntimeFromTemp = false;
  688. }
  689. // 强制清除配置对话框中的值(如果打开的是当前行)
  690. if (configDialog.current?.deviceId === row.deviceId
  691. && configDialog.current?.bomNodeId === row.bomNodeId) {
  692. configDialog.form.accumulatedTimeOption = null;
  693. }
  694. } else if (ruleType === 'mileage' && row.mileageRule === 1) {
  695. if (row.isMileageFromTemp) {
  696. row.totalMileage = null;
  697. row.tempTotalMileage = null;
  698. row.type = null;
  699. // row.isMileageFromTemp = false;
  700. }
  701. // 强制清除配置对话框中的值(如果打开的是当前行)
  702. if (configDialog.current?.deviceId === row.deviceId &&
  703. configDialog.current?.bomNodeId === row.bomNodeId) {
  704. configDialog.form.accumulatedMileageOption = null;
  705. }
  706. }
  707. // 如果配置对话框打开的是当前行,同步清除对话框中的选择值
  708. if (configDialog.visible && configDialog.current &&
  709. configDialog.current.deviceId === row.deviceId &&
  710. configDialog.current.bomNodeId === row.bomNodeId) {
  711. if (ruleType === 'runningTime') {
  712. configDialog.form.accumulatedTimeOption = null;
  713. } else if (ruleType === 'mileage') {
  714. configDialog.form.accumulatedMileageOption = null;
  715. }
  716. }
  717. }
  718. const deviceChoose = async(selectedDevices) => {
  719. const newIds = selectedDevices.map(device => device.id)
  720. deviceIds.value = [...new Set([...deviceIds.value, ...newIds])]
  721. const params = {
  722. deviceIds: newIds.join(',') // 明确传递数组参数
  723. }
  724. queryParams.deviceIds = JSON.parse(JSON.stringify(params.deviceIds))
  725. queryParams.bomFlag = 'b'
  726. // 根据选择的设备筛选出设备BOM中与保养相关的节点项
  727. const res = await IotDeviceApi.deviceAssociateBomList(queryParams)
  728. const rawData = res || []
  729. if(rawData.length === 0){
  730. message.error('选择的设备不存在待保养BOM项')
  731. }
  732. if (!Array.isArray(rawData)) {
  733. console.error('接口返回数据结构异常:', rawData)
  734. return
  735. }
  736. // 创建当前列表的唯一键集合(关键修改)
  737. const existingKeys = new Set(
  738. list.value.map(item => `${item.deviceId}-${item.bomNodeId}`)
  739. )
  740. // 转换数据结构(根据你的接口定义调整)
  741. const newItems = rawData
  742. .filter(device => {
  743. // 排除已存在的项(设备ID+bom节点ID)
  744. const key = `${device.id}-${device.bomNodeId}`
  745. return !existingKeys.has(key)
  746. })
  747. .map(device => ({
  748. assetClass: device.assetClass,
  749. deviceCode: device.deviceCode,
  750. deviceName: device.deviceName,
  751. deviceStatus: device.deviceStatus,
  752. deptName: device.deptName,
  753. name: device.name,
  754. code: device.code,
  755. assetProperty: device.assetProperty,
  756. remark: null, // 初始化备注
  757. deviceId: device.id, // 移除操作需要
  758. bomNodeId: device.bomNodeId,
  759. totalRunTime: device.totalRunTime,
  760. totalMileage: device.totalMileage,
  761. nextRunningKilometers: 0,
  762. nextRunningTime: 0,
  763. nextNaturalDate: 0,
  764. lastNaturalDate: null, // 初始化为null而不是0
  765. // 保养规则 提前量
  766. kiloCycleLead: 0,
  767. timePeriodLead: 0,
  768. naturalDatePeriodLead: 0,
  769. tempTotalRunTime: null,
  770. tempTotalMileage: null,
  771. isRuntimeFromTemp: false,
  772. isMileageFromTemp: false,
  773. // 添加累计时长参数列表 属性
  774. timeAccumulatedAttrs: device.timeAccumulatedAttrs || [],
  775. // 添加累计里程参数列表 属性
  776. mileageAccumulatedAttrs: device.mileageAccumulatedAttrs || []
  777. }))
  778. // 获取选择的设备相关的id数组
  779. newItems.forEach(item => {
  780. deviceIds.value.push(item.deviceId)
  781. })
  782. // 合并到现有列表(去重)
  783. newItems.forEach(item => {
  784. const exists = list.value.some(
  785. existing => (existing.deviceId === item.deviceId && existing.bomNodeId === item.bomNodeId)
  786. )
  787. if (!exists) {
  788. list.value.push(item)
  789. }
  790. })
  791. }
  792. const deviceFormRef = ref<InstanceType<typeof MainPlanDeviceList>>()
  793. const openForm = () => {
  794. deviceFormRef.value?.open();
  795. }
  796. const close = () => {
  797. delView(unref(currentRoute))
  798. push({ name: 'IotMaintenancePlan', params:{}})
  799. }
  800. /** 提交表单 */
  801. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  802. const submitForm = async () => {
  803. // 校验表单
  804. await formRef.value.validate()
  805. // 校验表格数据
  806. const isValid = validateTableData()
  807. if (!isValid) return
  808. // 提交请求
  809. formLoading.value = true
  810. try {
  811. // 将值为NULL 的保养规则 设置为 1
  812. list.value.forEach(item => {
  813. // 确保保养规则不为null
  814. item.mileageRule = item.mileageRule ?? 1
  815. item.runningTimeRule = item.runningTimeRule ?? 1
  816. item.naturalDateRule = item.naturalDateRule ?? 1
  817. })
  818. // 转换日期格式
  819. const convertedList = list.value.map(item => ({
  820. ...item,
  821. lastNaturalDate: typeof item.lastNaturalDate === 'number'
  822. ? item.lastNaturalDate
  823. : (item.lastNaturalDate ? dayjs(item.lastNaturalDate).valueOf() : null)
  824. }));
  825. const data = {
  826. mainPlan: formData.value,
  827. mainPlanBom: convertedList
  828. }
  829. if (formType.value === 'create') {
  830. await IotMaintenancePlanApi.createIotMaintenancePlan(data)
  831. message.success(t('common.createSuccess'))
  832. close()
  833. } else {
  834. await IotMaintenancePlanApi.updatePlan(data)
  835. message.success(t('common.updateSuccess'))
  836. close()
  837. }
  838. // 发送操作成功的事件
  839. emit('success')
  840. } finally {
  841. formLoading.value = false
  842. }
  843. }
  844. // 新增表单校验规则
  845. const configFormRules = reactive({
  846. nextRunningKilometers: [{
  847. required: true,
  848. message: '里程周期必须填写',
  849. trigger: 'blur'
  850. }],
  851. kiloCycleLead: [{
  852. required: true,
  853. message: '提前量必须填写',
  854. trigger: 'blur'
  855. }],
  856. nextRunningTime: [{
  857. required: true,
  858. message: '时间周期必须填写',
  859. trigger: 'blur'
  860. }],
  861. timePeriodLead: [{
  862. required: true,
  863. message: '提前量必须填写',
  864. trigger: 'blur'
  865. }],
  866. nextNaturalDate: [{
  867. required: true,
  868. message: '自然日周期必须填写',
  869. trigger: 'blur'
  870. }],
  871. naturalDatePeriodLead: [{
  872. required: true,
  873. message: '提前量必须填写',
  874. trigger: 'blur'
  875. }]
  876. })
  877. /** 校验表格数据 */
  878. const validateTableData = (): boolean => {
  879. let isValid = true
  880. const errorMessages: string[] = []
  881. const noRulesErrorMessages: string[] = [] // 未设置任何保养项规则 的错误提示信息
  882. const noRules: string[] = [] // 行记录中设置了保养规则的记录数量
  883. const configErrors: string[] = [] // 保养规则配置弹出框
  884. let shouldBreak = false;
  885. if (list.value.length === 0) {
  886. errorMessages.push('请至少添加一条设备保养明细')
  887. isValid = false
  888. // 直接返回无需后续校验
  889. message.error('请至少添加一条设备保养明细')
  890. return isValid
  891. }
  892. list.value.forEach((row, index) => {
  893. if (shouldBreak) return;
  894. const rowNumber = index + 1 // 用户可见的行号从1开始
  895. const deviceIdentifier = `${row.deviceCode}-${row.name}` // 设备标识
  896. // 累计参数校验逻辑
  897. if (row.mileageRule === 0 &&
  898. row.mileageAccumulatedAttrs?.length &&
  899. (row.totalMileage==null || isNaN(row.totalMileage)) &&
  900. !row.type) {
  901. errorMessages.push(`第 ${rowNumber} 行(${deviceIdentifier}):请选择累计运行公里数参数`)
  902. isValid = false
  903. }
  904. if (row.runningTimeRule === 0 &&
  905. row.timeAccumulatedAttrs?.length &&
  906. (row.totalRunTime==null || isNaN(row.totalRunTime)) &&
  907. !row.code) {
  908. errorMessages.push(`第 ${rowNumber} 行(${deviceIdentifier}):请选择累计运行时长参数`)
  909. isValid = false
  910. }
  911. // 校验逻辑
  912. const checkConfig = (ruleName: string, ruleValue: number, configField: keyof typeof row) => {
  913. if (ruleValue === 0) { // 规则开启
  914. if (!row[configField] || row[configField] <= 0) {
  915. configErrors.push(`第 ${rowNumber} 行(${deviceIdentifier}):请点击【配置】维护${ruleName}上次保养值`)
  916. isValid = false
  917. }
  918. }
  919. }
  920. // 里程校验逻辑
  921. if (row.mileageRule === 0) { // 假设 0 表示开启状态
  922. if (!row.nextRunningKilometers || row.nextRunningKilometers <= 0) {
  923. errorMessages.push(`第 ${rowNumber} 行:开启里程规则必须填写有效的里程周期`)
  924. isValid = false
  925. }
  926. // 再校验配置值
  927. checkConfig('里程', row.mileageRule, 'lastRunningKilometers')
  928. } else {
  929. noRules.push(`第 ${rowNumber} 行:未设置里程规则`)
  930. }
  931. // 运行时间校验逻辑
  932. if (row.runningTimeRule === 0) {
  933. if (!row.nextRunningTime || row.nextRunningTime <= 0) {
  934. errorMessages.push(`第 ${rowNumber} 行:开启运行时间规则必须填写有效的时间周期`)
  935. isValid = false
  936. }
  937. checkConfig('运行时间', row.runningTimeRule, 'lastRunningTime')
  938. } else {
  939. noRules.push(`第 ${rowNumber} 行:未设置运行时间规则`)
  940. }
  941. // 自然日期校验逻辑
  942. if (row.naturalDateRule === 0) {
  943. if (!row.nextNaturalDate) {
  944. errorMessages.push(`第 ${rowNumber} 行:开启自然日期规则必须填写有效的自然日期周期`)
  945. isValid = false
  946. }
  947. checkConfig('自然日期', row.naturalDateRule, 'lastNaturalDate')
  948. } else {
  949. noRules.push(`第 ${rowNumber} 行:未设置自然日期规则`)
  950. }
  951. // 如果选中的一行记录未设置任何保养规则 提示 ‘保养项未设置任何保养规则’
  952. if (noRules.length === 3) {
  953. isValid = false
  954. shouldBreak = true; // 设置标志变量为true,退出循环
  955. noRulesErrorMessages.push('保养项至少设置1个保养规则')
  956. }
  957. noRules.length = 0;
  958. })
  959. if (errorMessages.length > 0) {
  960. message.error('设置保养规则后,请维护对应的周期值')
  961. } else if (noRulesErrorMessages.length > 0) {
  962. message.error(noRulesErrorMessages.pop())
  963. } else if (configErrors.length > 0) {
  964. message.error(configErrors.pop())
  965. }
  966. return isValid
  967. }
  968. // 修改后的排序应用方法
  969. const applySorting = () => {
  970. // 创建新数组并排序
  971. const sortedList = sortDeviceList(list.value)
  972. // 使用Vue的响应式方法更新数组
  973. list.value = sortedList
  974. // 重置分页到第一页
  975. currentPage.value = 1
  976. }
  977. // 保养项排序函数
  978. const sortDeviceList = (devices: IotMaintenanceBomVO[]) => {
  979. // 使用slice()创建数组副本,避免修改原数组
  980. return devices.slice().sort((a, b) => {
  981. // 处理可能的空值
  982. const aCode = a.deviceCode || ''
  983. const bCode = b.deviceCode || ''
  984. const aName = a.name || ''
  985. const bName = b.name || ''
  986. // 设备编码排序
  987. if (aCode !== bCode) {
  988. return aCode.localeCompare(bCode)
  989. }
  990. // 保养项名称排序
  991. return aName.localeCompare(bName)
  992. })
  993. };
  994. /** 重置表单 */
  995. const resetForm = () => {
  996. formData.value = {
  997. id: undefined,
  998. failureName: undefined,
  999. deviceId: undefined,
  1000. status: undefined,
  1001. ifStop: undefined,
  1002. failureTime: undefined,
  1003. failureInfluence: undefined,
  1004. failureSystem: undefined,
  1005. description: undefined,
  1006. pic: undefined,
  1007. solution: undefined,
  1008. maintainStartTime: undefined,
  1009. maintainEndTime: undefined,
  1010. remark: undefined,
  1011. deviceName: undefined,
  1012. processInstanceId: undefined,
  1013. auditStatus: undefined,
  1014. deptId: undefined
  1015. }
  1016. formRef.value?.resetFields()
  1017. }
  1018. onMounted(async () => {
  1019. const route = useRoute()
  1020. const deptId = useUserStore().getUser.deptId
  1021. // 优先从路由参数获取部门信息
  1022. if (route.query.deptId && route.query.deptName) {
  1023. formData.value.deptId = Number(route.query.deptId)
  1024. formData.value.name = `${route.query.deptName} - 保养计划`
  1025. } else {
  1026. // 查询当前登录人所属部门名称
  1027. dept.value = await DeptApi.getDept(deptId)
  1028. // 根据当前登录人部门信息生成生成 保养计划 名称
  1029. formData.value.name = dept.value.name + ' - 保养计划'
  1030. formData.value.deptId = deptId
  1031. }
  1032. if (id){
  1033. formType.value = 'update'
  1034. const plan = await IotMaintenancePlanApi.getIotMaintenancePlan(id);
  1035. deviceLabel.value = plan.deviceName
  1036. formData.value = plan
  1037. // 查询保养计划明细
  1038. const data = await IotMaintenanceBomApi.getMainPlanBOMs(queryParams);
  1039. list.value = []
  1040. if (Array.isArray(data)) {
  1041. list.value = data.map(item => ({
  1042. ...item,
  1043. // 这里可以添加必要的字段转换(如果有日期等需要格式化的字段)
  1044. lastNaturalDate: item.lastNaturalDate
  1045. }))
  1046. }
  1047. } else {
  1048. formType.value = 'create';
  1049. const { wsCache } = useCache()
  1050. const userInfo = wsCache.get(CACHE_KEY.USER)
  1051. formData.value.responsiblePerson = userInfo.user.id;
  1052. }
  1053. })
  1054. const handleDelete = async (str: string) => {
  1055. try {
  1056. // 1. 记录删除前状态
  1057. const currentPageBeforeDelete = currentPage.value;
  1058. const [deviceIdStr, bomNodeId] = str.split('-')
  1059. const deviceId = parseInt(deviceIdStr)
  1060. // 删除列表项
  1061. const index = list.value.findIndex((item) => (item.deviceId+'-'+item.bomNodeId) === str)
  1062. if (index !== -1) {
  1063. list.value.splice(index, 1)
  1064. deviceIds.value = []
  1065. }
  1066. // 更新设备ID列表(需要检查是否还有该设备的其他项)
  1067. const hasOtherItems = list.value.some(item => item.deviceId === deviceId)
  1068. if (!hasOtherItems) {
  1069. deviceIds.value = deviceIds.value.filter(id => id !== deviceId)
  1070. }
  1071. // message.success('移除成功')
  1072. // 2. 计算新总记录数和总页数
  1073. const newTotal = list.value.length;
  1074. const newTotalPages = Math.ceil(newTotal / pageSize.value);
  1075. // 3. 智能页码调整(核心修正)[1,5](@ref)
  1076. if (newTotal === 0) {
  1077. currentPage.value = 1; // 无数据时回首页
  1078. } else {
  1079. currentPage.value = currentPageBeforeDelete > newTotalPages
  1080. ? newTotalPages // 当前页超出范围时跳末页
  1081. : currentPageBeforeDelete; // 否则保持当前页
  1082. }
  1083. } catch (error) {
  1084. console.error('移除失败:', error)
  1085. message.error('移除失败')
  1086. }
  1087. // 检查是否需要调整页码
  1088. // if (list.value.length > 0 && pagedList.value.length === 0) {
  1089. // currentPage.value = Math.max(1, currentPage.value - 1)
  1090. // }
  1091. }
  1092. </script>
  1093. <style scoped>
  1094. .base-expandable-content {
  1095. overflow: hidden; /* 隐藏溢出的内容 */
  1096. transition: max-height 0.3s ease; /* 平滑过渡效果 */
  1097. }
  1098. :deep(.el-input-number .el-input__inner) {
  1099. text-align: left !important;
  1100. padding-left: 10px; /* 保持左侧间距 */
  1101. }
  1102. /* 分组容器样式 */
  1103. .form-group {
  1104. position: relative;
  1105. border: 1px solid #dcdfe6;
  1106. border-radius: 4px;
  1107. padding: 20px 15px 10px;
  1108. margin-bottom: 18px;
  1109. transition: border-color 0.2s;
  1110. }
  1111. /* 分组标题样式 */
  1112. .group-title {
  1113. position: absolute;
  1114. top: -10px;
  1115. left: 20px;
  1116. background: white;
  1117. padding: 0 8px;
  1118. color: #606266;
  1119. font-size: 12px;
  1120. font-weight: 500;
  1121. }
  1122. /* 确保分页组件右对齐 */
  1123. .el-pagination {
  1124. display: flex;
  1125. justify-content: flex-end;
  1126. margin-top: 20px;
  1127. }
  1128. /* 已完整填写行的背景色 */
  1129. :deep(.el-table .all-filled) {
  1130. background-color: #67c23a !important; /* 淡绿色背景 */
  1131. transition: background-color 0.3s ease; /* 平滑过渡效果 */
  1132. }
  1133. </style>