|
@@ -79,35 +79,41 @@
|
|
|
<ContentWrap>
|
|
|
<!-- 列表 -->
|
|
|
<ContentWrap>
|
|
|
- <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
|
|
+ <el-table v-loading="loading" :data="paginatedList" :stripe="true" :show-overflow-tooltip="true" :header-cell-style="tableHeaderStyle">
|
|
|
<!-- 添加序号列 -->
|
|
|
<el-table-column
|
|
|
type="index"
|
|
|
:label="t('maintain.serial')"
|
|
|
- width="70"
|
|
|
align="center"
|
|
|
+ prop="serial"
|
|
|
+ :width="columnWidths.serial"
|
|
|
+ fixed="left"
|
|
|
/>
|
|
|
<el-table-column :label="t('bomList.bomNode')" align="center" prop="bomNodeId" v-if="false"/>
|
|
|
- <el-table-column :label="t('iotDevice.code')" align="center" prop="deviceCode" />
|
|
|
- <el-table-column :label="t('iotDevice.name')" align="center" prop="deviceName" />
|
|
|
- <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" :formatter="erpPriceTableColumnFormatter">
|
|
|
+ <el-table-column :label="t('iotDevice.code')" align="center" prop="deviceCode" :width="columnWidths.deviceCode" fixed="left">
|
|
|
<template #default="{ row }">
|
|
|
- {{ row.totalRunTime ?? row.tempTotalRunTime }}
|
|
|
+ <div class="full-content-cell"> <!-- 自定义样式 -->
|
|
|
+ {{ row.deviceCode }}
|
|
|
+ </div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" :formatter="erpPriceTableColumnFormatter">
|
|
|
+ <el-table-column :label="t('iotDevice.name')" align="center" prop="deviceName" :width="columnWidths.deviceName" fixed="left">
|
|
|
<template #default="{ row }">
|
|
|
- {{ row.totalMileage ?? row.tempTotalMileage }}
|
|
|
+ <div class="full-content-cell"> <!-- 自定义样式 -->
|
|
|
+ {{ row.deviceName }}
|
|
|
+ </div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('mainPlan.MaintItems')" align="center" prop="name" :show-overflow-tooltip="false" :width="maintItemsWidth" >
|
|
|
+ <el-table-column :label="t('mainPlan.MaintItems')" align="center" prop="name"
|
|
|
+ :show-overflow-tooltip="false" :width="columnWidths.name" fixed="left">
|
|
|
<template #default="{ row }">
|
|
|
<div class="full-content-cell"> <!-- 自定义样式 -->
|
|
|
{{ row.name }}
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('main.mileage')" key="mileageRule" width="80">
|
|
|
+ <el-table-column :label="t('main.mileage')" key="mileageRule" align="center"
|
|
|
+ :width="columnWidths.mileageRule" v-if="hasMileageRuleInCurrentPage">
|
|
|
<template #default="scope">
|
|
|
<el-switch
|
|
|
v-model="scope.row.mileageRule"
|
|
@@ -117,7 +123,8 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('main.runTime')" key="runningTimeRule" width="90">
|
|
|
+ <el-table-column :label="t('main.runTime')" key="runningTimeRule" align="center"
|
|
|
+ :width="columnWidths.runningTimeRule" v-if="hasTimeRuleInCurrentPage">
|
|
|
<template #default="scope">
|
|
|
<el-switch
|
|
|
v-model="scope.row.runningTimeRule"
|
|
@@ -127,7 +134,8 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('main.date')" key="naturalDateRule" width="80">
|
|
|
+ <el-table-column :label="t('main.date')" key="naturalDateRule" align="center"
|
|
|
+ :width="columnWidths.naturalDateRule" v-if="hasDateRuleInCurrentPage">
|
|
|
<template #default="scope">
|
|
|
<el-switch
|
|
|
v-model="scope.row.naturalDateRule"
|
|
@@ -137,78 +145,213 @@
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column
|
|
|
- v-if="shouldShowRunningTimeColumn"
|
|
|
- :label="t('mainPlan.RunTimeCycle')"
|
|
|
- align="center"
|
|
|
- width="120"
|
|
|
- >
|
|
|
- <template #default="scope">
|
|
|
- <el-input-number
|
|
|
- v-if="scope.row.runningTimeRule === 0"
|
|
|
- v-model="scope.row.nextRunningTime"
|
|
|
- :precision="1"
|
|
|
- :min="1"
|
|
|
- :controls="false"
|
|
|
- style="width: 100%"
|
|
|
- @change="validateRunningTime(scope.row)"
|
|
|
- />
|
|
|
- <span v-else>-</span>
|
|
|
- <!-- 错误提示 -->
|
|
|
- <div v-if="scope.row.timeError" class="error-text">
|
|
|
- {{ scope.row.timeError }}
|
|
|
+ <el-table-column :label="t('operationFillForm.sumTime')" align="center" prop="totalRunTime" v-if="hasTimeRuleInCurrentPage"
|
|
|
+ :formatter="erpPriceTableColumnFormatter" :width="columnWidths.totalRunTime">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.totalRunTime ?? row.tempTotalRunTime }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('operationFillForm.sumKil')" align="center" prop="totalMileage" v-if="hasMileageRuleInCurrentPage"
|
|
|
+ :formatter="erpPriceTableColumnFormatter" :width="columnWidths.totalMileage">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.totalMileage ?? row.tempTotalMileage }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.lastMaintenanceDate')" prop="lastMaintenanceDate" :width="columnWidths.lastMaintenanceDate">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <div class="full-content-cell">
|
|
|
+ {{ row.lastMaintenanceDate }}
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+ <!-- 保养里程 分组 -->
|
|
|
+ <el-table-column v-if="hasMileageRuleInCurrentPage" label="保养里程" align="center">
|
|
|
+ <el-table-column :label="t('mainPlan.lastMaintenanceMileage')" align="center" prop="lastRunningKilometers"
|
|
|
+ :formatter="erpPriceTableColumnFormatter" :width="columnWidths.lastRunningKilometers">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.lastRunningKilometers }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.nextMaintenanceKm')"
|
|
|
+ align="center" prop="nextMaintenanceKm" :width="columnWidths.nextMaintenanceKm">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.nextMaintenanceKm ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.remainKm')"
|
|
|
+ align="center" prop="remainKm" :width="columnWidths.remainKm">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.remainKm ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <!-- 保养时长 分组 -->
|
|
|
+ <el-table-column v-if="hasTimeRuleInCurrentPage" label="保养时长" align="center">
|
|
|
+ <el-table-column :label="t('mainPlan.lastMaintenanceOperationTime')" align="center" prop="lastRunningTime"
|
|
|
+ :formatter="erpPriceTableColumnFormatter" :width="columnWidths.lastRunningTime">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.lastRunningTime }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.nextMaintenanceH')"
|
|
|
+ align="center" prop="nextMaintenanceH" :width="columnWidths.nextMaintenanceH">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.nextMaintenanceH ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.remainH')"
|
|
|
+ align="center" prop="remainH" :width="columnWidths.remainH">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.remainH ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ v-if="shouldShowRunningTimeColumn"
|
|
|
+ :label="t('mainPlan.RunTimeCycle')"
|
|
|
+ align="center"
|
|
|
+ prop="nextRunningTime"
|
|
|
+ :width="columnWidths.nextRunningTime"
|
|
|
+ >
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input-number
|
|
|
+ v-if="scope.row.runningTimeRule === 0"
|
|
|
+ v-model="scope.row.nextRunningTime"
|
|
|
+ :precision="1"
|
|
|
+ :min="1"
|
|
|
+ :controls="false"
|
|
|
+ style="width: 100%"
|
|
|
+ @change="validateRunningTime(scope.row)"
|
|
|
+ />
|
|
|
+ <span v-else>-</span>
|
|
|
+ <!-- 错误提示 -->
|
|
|
+ <div v-if="scope.row.timeError" class="error-text">
|
|
|
+ {{ scope.row.timeError }}
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <!-- 保养日期 分组 -->
|
|
|
+ <el-table-column v-if="hasDateRuleInCurrentPage" label="保养日期" align="center">
|
|
|
+ <el-table-column :label="t('mainPlan.lastMaintenanceNaturalDate')" align="center" prop="tempLastNaturalDate"
|
|
|
+ :formatter="erpPriceTableColumnFormatter" :width="columnWidths.tempLastNaturalDate">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.tempLastNaturalDate }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.nextMaintDate')"
|
|
|
+ align="center" prop="nextMaintenanceDate" :width="columnWidths.nextMaintenanceDate">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.nextMaintenanceDate ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('mainPlan.remainDay')"
|
|
|
+ align="center" prop="remainDay" :width="columnWidths.remainDay">
|
|
|
+ <template #default="{ row }">
|
|
|
+ {{ row.remainDay ?? '-' }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
<el-table-column :label="t('common.status')" align="center" width="100">
|
|
|
<template #default="scope">
|
|
|
{{ getStatusText(scope.row) }}
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+
|
|
|
<el-table-column :label="t('iotMaintain.numberOfMaterials')" align="center" width="90">
|
|
|
<template #default="scope">
|
|
|
{{ getMaterialCount(scope.row.bomNodeId) }}
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="t('iotMaintain.operation')" align="center" min-width="120px">
|
|
|
+
|
|
|
+ <el-table-column :label="t('iotMaintain.operation')" align="center" prop="operation" :width="columnWidths.operation" fixed="right">
|
|
|
<template #default="scope">
|
|
|
- <el-dropdown trigger="hover" @command="handleDropdownCommand">
|
|
|
- <el-button type="primary" link>
|
|
|
- {{ t('action.more') }}<el-icon><arrow-down /></el-icon>
|
|
|
- </el-button>
|
|
|
- <template #dropdown>
|
|
|
- <el-dropdown-menu>
|
|
|
- <!-- 延迟保养按钮 -->
|
|
|
- <el-dropdown-item
|
|
|
- v-if="scope.row.status === 0"
|
|
|
- :command="{ action: 'delay', row: scope.row }"
|
|
|
- :icon="Clock"
|
|
|
- >
|
|
|
- {{ t('stock.DelayMaintenance') }}
|
|
|
- </el-dropdown-item>
|
|
|
-
|
|
|
- <!-- 选择物料按钮 -->
|
|
|
- <el-dropdown-item
|
|
|
- v-if="scope.row.status === 0"
|
|
|
- :command="{ action: 'material', row: scope.row }"
|
|
|
- :icon="Box"
|
|
|
- >
|
|
|
- {{ t('stock.selectMaterial') }}
|
|
|
- </el-dropdown-item>
|
|
|
-
|
|
|
- <!-- 物料详情按钮 -->
|
|
|
- <el-dropdown-item
|
|
|
- :command="{ action: 'detail', row: scope.row }"
|
|
|
- :icon="Document"
|
|
|
- >
|
|
|
- {{ t('bomList.materialDetail') }}
|
|
|
- </el-dropdown-item>
|
|
|
- </el-dropdown-menu>
|
|
|
- </template>
|
|
|
- </el-dropdown>
|
|
|
+ <div class="horizontal-actions">
|
|
|
+ <!-- 查看当前保养项已经绑定的物料列表 -->
|
|
|
+ <el-tooltip
|
|
|
+ v-if="scope.row.deviceBomMaterials && scope.row.deviceBomMaterials.length > 0"
|
|
|
+ effect="dark"
|
|
|
+ :content="t('mainPlan.deviceBomMaterials')"
|
|
|
+ placement="top"
|
|
|
+ :show-after="300"
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ link
|
|
|
+ :icon="View"
|
|
|
+ @click="handleDropdownCommand({ action: 'deviceBomMaterials', row: scope.row })"
|
|
|
+ class="action-button"
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+
|
|
|
+ <!-- 延迟保养按钮 -->
|
|
|
+ <el-tooltip
|
|
|
+ v-if="scope.row.status === 0"
|
|
|
+ effect="dark"
|
|
|
+ :content="t('stock.DelayMaintenance')"
|
|
|
+ placement="top"
|
|
|
+ :show-after="300"
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ link
|
|
|
+ :icon="Clock"
|
|
|
+ @click="handleDropdownCommand({ action: 'delay', row: scope.row })"
|
|
|
+ class="action-button"
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+
|
|
|
+ <!-- 选择物料按钮 -->
|
|
|
+ <el-tooltip
|
|
|
+ v-if="scope.row.status === 0"
|
|
|
+ effect="dark"
|
|
|
+ :content="t('stock.selectMaterial')"
|
|
|
+ placement="top"
|
|
|
+ :show-after="300"
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ link
|
|
|
+ :icon="Box"
|
|
|
+ @click="handleDropdownCommand({ action: 'material', row: scope.row })"
|
|
|
+ class="action-button"
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+
|
|
|
+ <!-- 物料详情按钮 -->
|
|
|
+ <el-tooltip
|
|
|
+ effect="dark"
|
|
|
+ :content="t('bomList.materialDetail')"
|
|
|
+ placement="top"
|
|
|
+ :show-after="300"
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ link
|
|
|
+ :icon="Document"
|
|
|
+ @click="handleDropdownCommand({ action: 'detail', row: scope.row })"
|
|
|
+ class="action-button"
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
+
|
|
|
+ <div style="margin-top: 20px; display: flex; justify-content: flex-end;">
|
|
|
+ <el-pagination
|
|
|
+ v-model:current-page="currentPage"
|
|
|
+ v-model:page-size="pageSize"
|
|
|
+ :page-sizes="[10]"
|
|
|
+ :background="true"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="list.length"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ @size-change="handleSizeChange"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
</ContentWrap>
|
|
|
|
|
|
<!-- 选择的物料列表 -->
|
|
@@ -470,6 +613,8 @@
|
|
|
</el-dialog>
|
|
|
<!-- 表单弹窗:添加/修改 -->
|
|
|
<WorkOrderMaterial ref="materialFormRef" @choose="selectChoose" />
|
|
|
+ <!-- 设备BOM节点绑定的物料列表 -->
|
|
|
+ <DeviceBomMaterials ref="deviceBomMaterialsRef" />
|
|
|
<!-- 抽屉组件 展示已经选择的物料 并编辑物料消耗 -->
|
|
|
<MaterialListDrawer
|
|
|
:model-value="drawerVisible"
|
|
@@ -484,6 +629,7 @@
|
|
|
import * as UserApi from '@/api/system/user'
|
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
import { ref } from 'vue'
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
|
|
|
import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
|
|
|
import { IotMainWorkOrderBomMaterialApi, IotMainWorkOrderBomMaterialVO } from '@/api/pms/iotmainworkorderbommaterial'
|
|
@@ -497,7 +643,7 @@ import WorkOrderMaterial from "@/views/pms/iotmainworkorder/WorkOrderMaterial.vu
|
|
|
import { IotDevicePersonApi, IotDevicePersonVO } from '@/api/pms/iotdeviceperson'
|
|
|
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
|
|
|
// 引入图标
|
|
|
-import { ArrowDown, Clock, Box, Document } from '@element-plus/icons-vue';
|
|
|
+import { View, Clock, Box, Document } from '@element-plus/icons-vue';
|
|
|
|
|
|
/** 保养计划 表单 */
|
|
|
defineOptions({ name: 'IotMainWorkOrderBom' })
|
|
@@ -526,9 +672,19 @@ const devicePersonsMap = ref<Map<number, Set<string>>>(new Map()) // 存储设
|
|
|
// 控制抽屉额外列的显示
|
|
|
const hideExtraColumnsInDrawer = ref(false)
|
|
|
|
|
|
+// 分页相关变量
|
|
|
+const currentPage = ref(1)
|
|
|
+const pageSize = ref(10)
|
|
|
+
|
|
|
+const tableRef = ref();
|
|
|
+
|
|
|
// 新增响应式变量
|
|
|
const maintItemsWidth = ref('auto')
|
|
|
|
|
|
+const lastNaturalDateWatchers = ref(new Map())
|
|
|
+
|
|
|
+const columnWidths = ref<Record<string, string>>({});
|
|
|
+
|
|
|
const formData = ref({
|
|
|
id: undefined,
|
|
|
deptId: undefined,
|
|
@@ -622,6 +778,8 @@ interface MaterialFormExpose {
|
|
|
|
|
|
const materialFormRef = ref<MaterialFormExpose>();
|
|
|
|
|
|
+const deviceBomMaterialsRef = ref<MaterialFormExpose>();
|
|
|
+
|
|
|
// 新增配置相关状态
|
|
|
const configDialog = reactive({
|
|
|
visible: false,
|
|
@@ -691,6 +849,31 @@ const validateRunningTime = (row: IotMainWorkOrderBomVO) => {
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
+// 计算属性:获取当前页的数据
|
|
|
+const paginatedList = computed(() => {
|
|
|
+ const start = (currentPage.value - 1) * pageSize.value
|
|
|
+ const end = start + pageSize.value
|
|
|
+ return list.value.slice(start, end)
|
|
|
+})
|
|
|
+
|
|
|
+// 页码改变处理
|
|
|
+const handleCurrentChange = (newPage: number) => {
|
|
|
+ currentPage.value = newPage
|
|
|
+}
|
|
|
+
|
|
|
+// 每页条数改变处理(保持10条)
|
|
|
+const handleSizeChange = (newSize: number) => {
|
|
|
+ pageSize.value = newSize
|
|
|
+ currentPage.value = 1 // 重置到第一页
|
|
|
+}
|
|
|
+
|
|
|
+// 列宽调整后的处理
|
|
|
+const handleHeaderDragEnd = () => {
|
|
|
+ nextTick(() => {
|
|
|
+ tableRef.value?.doLayout();
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
// 运行时间周期 全局校验方法(在submitForm中调用)
|
|
|
const validateAllRunningTimes = (): boolean => {
|
|
|
let isValid = true;
|
|
@@ -705,7 +888,6 @@ const validateAllRunningTimes = (): boolean => {
|
|
|
return isValid;
|
|
|
};
|
|
|
|
|
|
-// const materialFormRef = ref()
|
|
|
const openMaterialForm = (row: any) => {
|
|
|
bomNodeId.value = row.bomNodeId;
|
|
|
console.log('这是一个对象:', row.bomNodeId)
|
|
@@ -713,6 +895,13 @@ const openMaterialForm = (row: any) => {
|
|
|
materialFormRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
|
|
|
}
|
|
|
|
|
|
+// 查看当前保养项已经绑定的物料列表
|
|
|
+const openDeviceBomMaterials = (row: any) => {
|
|
|
+ bomNodeId.value = row.bomNodeId;
|
|
|
+ const type = 'maintenance'
|
|
|
+ deviceBomMaterialsRef.value.open(formData.value.deptId, bomNodeId.value, row, type)
|
|
|
+}
|
|
|
+
|
|
|
const selectChoose = (selectedMaterial) => {
|
|
|
selectedMaterial.bomNodeId = bomNodeId.value
|
|
|
// 关联 bomNodeId
|
|
@@ -1028,7 +1217,7 @@ const configFormRules = reactive({
|
|
|
})
|
|
|
|
|
|
// 计算文本宽度的辅助函数
|
|
|
-const getTextWidth = (text: string): number => {
|
|
|
+const getTextWidth = (text: string, fontSize = 14): number => {
|
|
|
const span = document.createElement('span')
|
|
|
span.style.visibility = 'hidden'
|
|
|
span.style.position = 'absolute'
|
|
@@ -1069,6 +1258,100 @@ const calculateMaintItemsWidth = () => {
|
|
|
maintItemsWidth.value = `${maxWidth}px`
|
|
|
}
|
|
|
|
|
|
+// 计算下次保养公里数(通用函数)
|
|
|
+const calculateNextMaintenanceKm = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 验证条件:规则开启 + 两个值都存在且 > 0
|
|
|
+ const isValid = row.mileageRule === 0 &&
|
|
|
+ row.lastRunningKilometers > 0 &&
|
|
|
+ row.nextRunningKilometers > 0;
|
|
|
+
|
|
|
+ return isValid
|
|
|
+ ? (row.lastRunningKilometers + row.nextRunningKilometers)
|
|
|
+ : null; // 不满足条件返回null
|
|
|
+};
|
|
|
+
|
|
|
+// 计算剩余保养公里数(通用函数)
|
|
|
+const calculateRemainKm = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 确定使用的里程值(优先totalMileage)
|
|
|
+ const mileageValue = row.totalMileage ?? row.tempTotalMileage;
|
|
|
+ // 验证条件:规则开启 + 3个值都存在且 > 0
|
|
|
+ const isValid = row.mileageRule === 0 &&
|
|
|
+ row.lastRunningKilometers > 0 &&
|
|
|
+ mileageValue > 0 &&
|
|
|
+ row.nextRunningKilometers > 0;
|
|
|
+
|
|
|
+ return isValid
|
|
|
+ ? (row.nextRunningKilometers - (mileageValue - row.lastRunningKilometers))
|
|
|
+ : null; // 不满足条件返回null
|
|
|
+};
|
|
|
+
|
|
|
+// 计算下次保养运行时长(通用函数)
|
|
|
+const calculateNextMaintenanceH = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 验证条件:规则开启 + 两个值都存在且 > 0
|
|
|
+ const isValid = row.runningTimeRule === 0 &&
|
|
|
+ row.lastRunningTime > 0 &&
|
|
|
+ row.nextRunningTime > 0;
|
|
|
+
|
|
|
+ return isValid
|
|
|
+ ? (row.lastRunningTime + row.nextRunningTime)
|
|
|
+ : null; // 不满足条件返回null
|
|
|
+};
|
|
|
+
|
|
|
+// 计算剩余运行时间(通用函数)
|
|
|
+const calculateRemainH = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 确定使用的 运行时长 值(优先 totalRunTime)
|
|
|
+ const runTimeValue = row.totalRunTime ?? row.tempTotalRunTime;
|
|
|
+ // 验证条件:规则开启 + 3个值都存在且 > 0
|
|
|
+ const isValid = row.runningTimeRule === 0 &&
|
|
|
+ row.lastRunningTime > 0 &&
|
|
|
+ runTimeValue > 0 &&
|
|
|
+ row.nextRunningTime > 0;
|
|
|
+
|
|
|
+ return isValid
|
|
|
+ ? (row.nextRunningTime - (runTimeValue - row.lastRunningTime))
|
|
|
+ : null; // 不满足条件返回null
|
|
|
+};
|
|
|
+
|
|
|
+// 计算下次保养日期(通用函数)
|
|
|
+const calculateNextMaintenanceDate = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 验证条件:规则开启 + 两个值都存在且 > 0
|
|
|
+ const isValid = row.naturalDateRule === 0 &&
|
|
|
+ row.lastNaturalDate &&
|
|
|
+ row.nextNaturalDate;
|
|
|
+
|
|
|
+ return isValid
|
|
|
+ ? dayjs(row.lastNaturalDate).add(row.nextNaturalDate, 'day').format('YYYY-MM-DD')
|
|
|
+ : null; // 不满足条件返回null
|
|
|
+};
|
|
|
+
|
|
|
+// 计算 自然日期保养 剩余天数(通用函数)
|
|
|
+const calculateRemainDay = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 验证条件:规则开启 + 两个值都存在且有效
|
|
|
+ const isValid = row.naturalDateRule === 0 &&
|
|
|
+ row.lastNaturalDate !== null &&
|
|
|
+ row.nextNaturalDate !== null &&
|
|
|
+ row.nextNaturalDate > 0;
|
|
|
+
|
|
|
+ if (!isValid) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 上次保养日期:将时间戳转换为 Day.js 对象
|
|
|
+ const lastNaturalDate = dayjs(row.lastNaturalDate);
|
|
|
+
|
|
|
+ // 计算下次保养日期
|
|
|
+ const nextMaintenanceDate = lastNaturalDate.add(row.nextNaturalDate, 'day');
|
|
|
+
|
|
|
+ // 计算剩余天数(当前日期到下次保养日期的天数差)
|
|
|
+ return nextMaintenanceDate.diff(dayjs(), 'day');
|
|
|
+ } catch (error) {
|
|
|
+ console.error('计算保养剩余天数错误:', error);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
const getStatusText = (row: any) => {
|
|
|
// 状态为1直接返回"完成"
|
|
|
if (row.status === 1) return t('mainPlan.completed');
|
|
@@ -1088,9 +1371,155 @@ const getStatusText = (row: any) => {
|
|
|
};
|
|
|
|
|
|
// 监听数据变化重新计算
|
|
|
-watch(() => list.value, () => {
|
|
|
+/* watch(() => list.value, () => {
|
|
|
calculateMaintItemsWidth()
|
|
|
-}, { deep: true })
|
|
|
+}, { deep: true }) */
|
|
|
+
|
|
|
+// 计算属性 - 检查当前页是否有开启的里程规则
|
|
|
+const hasMileageRuleInCurrentPage = computed(() => {
|
|
|
+ return paginatedList.value.some(row => row.mileageRule === 0);
|
|
|
+});
|
|
|
+
|
|
|
+// 计算属性 - 检查当前页是否有开启的 运行时间 规则
|
|
|
+const hasTimeRuleInCurrentPage = computed(() => {
|
|
|
+ return paginatedList.value.some(row => row.runningTimeRule === 0);
|
|
|
+});
|
|
|
+
|
|
|
+// 计算属性 - 检查当前页是否有开启的 自然日期 规则
|
|
|
+const hasDateRuleInCurrentPage = computed(() => {
|
|
|
+ return paginatedList.value.some(row => row.naturalDateRule === 0);
|
|
|
+});
|
|
|
+
|
|
|
+// 统一计算所有列宽
|
|
|
+const calculateAllColumnsWidth = () => {
|
|
|
+ const MIN_WIDTH = 70; // 最小列宽
|
|
|
+ const PADDING = 10; // 列内边距
|
|
|
+ const FIXED_COLUMN_PADDING = 10; // 固定列额外内边距
|
|
|
+ const GROUP_COLUMN_EXTRA = 20; // 分组列额外宽度
|
|
|
+
|
|
|
+ // 需要自适应的列配置
|
|
|
+ const autoColumns = [
|
|
|
+ { prop: 'serial', label: t('iotDevice.serial') },
|
|
|
+ { prop: 'deviceCode', label: t('iotMaintain.deviceCode') },
|
|
|
+ { prop: 'deviceName', label: t('iotMaintain.deviceName') },
|
|
|
+ {
|
|
|
+ prop: 'totalRunTime',
|
|
|
+ label: t('operationFillForm.sumTime'),
|
|
|
+ getValue: (row) => row.totalRunTime ?? row.tempTotalRunTime
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'totalMileage',
|
|
|
+ label: t('operationFillForm.sumKil'),
|
|
|
+ getValue: (row) => row.totalMileage ?? row.tempTotalMileage
|
|
|
+ },
|
|
|
+ { prop: 'name', label: t('bomList.bomNode') },
|
|
|
+ { prop: 'lastMaintenanceDate', label: t('mainPlan.lastMaintenanceDate') },
|
|
|
+ { prop: 'mileageRule', label: t('main.mileage') },
|
|
|
+ { prop: 'runningTimeRule', label: t('main.runTime') },
|
|
|
+ { prop: 'naturalDateRule', label: t('main.date') },
|
|
|
+ { prop: 'lastRunningKilometers', label: t('mainPlan.lastMaintenanceMileage') },
|
|
|
+ { prop: 'nextMaintenanceKm', label: t('mainPlan.nextMaintenanceKm') },
|
|
|
+ { prop: 'remainKm', label: t('mainPlan.remainKm') },
|
|
|
+ { prop: 'lastRunningTime', label: t('mainPlan.lastMaintenanceOperationTime') },
|
|
|
+ { prop: 'nextMaintenanceH', label: t('mainPlan.nextMaintenanceH') },
|
|
|
+ { prop: 'remainH', label: t('mainPlan.remainH') },
|
|
|
+ { prop: 'nextRunningTime', label: t('mainPlan.RunTimeCycle') },
|
|
|
+ { prop: 'tempLastNaturalDate', label: t('mainPlan.lastMaintenanceNaturalDate') },
|
|
|
+ { prop: 'nextMaintenanceDate', label: t('mainPlan.nextMaintDate') },
|
|
|
+ { prop: 'remainDay', label: t('mainPlan.remainDay') },
|
|
|
+ { prop: 'operation', label: t('operationFill.operation') }
|
|
|
+ ];
|
|
|
+
|
|
|
+ const newWidths: Record<string, number> = {};
|
|
|
+
|
|
|
+ autoColumns.forEach(col => {
|
|
|
+ const headerText = col.label;
|
|
|
+ // 计算表头宽度
|
|
|
+ const headerWidth = getTextWidth(headerText) * 1.2;
|
|
|
+
|
|
|
+ // 计算内容最大宽度
|
|
|
+ let contentMaxWidth = 0;
|
|
|
+ if (col.prop === 'operation') {
|
|
|
+ // 操作列固定宽度(根据按钮数量)
|
|
|
+ contentMaxWidth = 120;
|
|
|
+ } else if (['mileageRule', 'runningTimeRule', 'naturalDateRule'].includes(col.prop)) {
|
|
|
+ // 开关列固定宽度
|
|
|
+ contentMaxWidth = 80;
|
|
|
+ } else {
|
|
|
+ list.value.forEach(row => {
|
|
|
+ const text = col.getValue ? String(col.getValue(row)) : String(row[col.prop] || '');
|
|
|
+ const textWidth = getTextWidth(text);
|
|
|
+ if (textWidth > contentMaxWidth) contentMaxWidth = textWidth;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 取最大值并添加内边距
|
|
|
+ let finalWidth = Math.max(headerWidth, contentMaxWidth, MIN_WIDTH) + PADDING;
|
|
|
+ // 为分组列增加额外宽度(重点修改)
|
|
|
+ if ([
|
|
|
+ 'lastRunningKilometers',
|
|
|
+ 'nextMaintenanceKm',
|
|
|
+ 'remainKm',
|
|
|
+ 'lastRunningTime',
|
|
|
+ 'nextMaintenanceH',
|
|
|
+ 'remainH',
|
|
|
+ 'tempLastNaturalDate',
|
|
|
+ 'nextMaintenanceDate',
|
|
|
+ 'remainDay'
|
|
|
+ ].includes(col.prop)) {
|
|
|
+ finalWidth += GROUP_COLUMN_EXTRA;
|
|
|
+ }
|
|
|
+
|
|
|
+ newWidths[col.prop] = finalWidth;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 固定列特殊处理 - 增加额外空间
|
|
|
+ ['serial', 'deviceCode', 'deviceName', 'name'].forEach(prop => {
|
|
|
+ if (newWidths[prop]) {
|
|
|
+ newWidths[prop] += FIXED_COLUMN_PADDING;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 转换为CSS宽度值
|
|
|
+ Object.keys(newWidths).forEach(prop => {
|
|
|
+ columnWidths.value[prop] = `${newWidths[prop]}px`;
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+// 为每一行建立lastNaturalDate到tempLastNaturalDate的同步
|
|
|
+const setupNaturalDateSync = (row: IotMaintenanceBomVO) => {
|
|
|
+ // 如果该行已有watcher则跳过
|
|
|
+ if (lastNaturalDateWatchers.value.has(row.id)) return
|
|
|
+
|
|
|
+ // 为该行创建单独的watcher
|
|
|
+ const unwatch = watch(
|
|
|
+ () => row.lastNaturalDate,
|
|
|
+ (newVal) => {
|
|
|
+ // 转换日期格式 (时间戳 -> YYYY-MM-DD)
|
|
|
+ row.tempLastNaturalDate = newVal
|
|
|
+ ? dayjs(newVal).format('YYYY-MM-DD')
|
|
|
+ : null;
|
|
|
+ },
|
|
|
+ { immediate: true, deep: true }
|
|
|
+ )
|
|
|
+
|
|
|
+ // 保存watcher用于后续清理
|
|
|
+ lastNaturalDateWatchers.value.set(row.id, unwatch)
|
|
|
+}
|
|
|
+
|
|
|
+const tableHeaderStyle = ({ row, rowIndex }) => {
|
|
|
+ return {
|
|
|
+ border: '1px solid #333',
|
|
|
+ backgroundColor: rowIndex === 0 ? '#f0f9eb' : '#f5f7fa' // 分组行特殊背景
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 监听分页数据和规则变化 - 重新布局表格
|
|
|
+watch([paginatedList, hasMileageRuleInCurrentPage, hasTimeRuleInCurrentPage, hasDateRuleInCurrentPage], () => {
|
|
|
+ nextTick(() => {
|
|
|
+ tableRef.value?.doLayout();
|
|
|
+ calculateAllColumnsWidth(); // 重新计算列宽
|
|
|
+ });
|
|
|
+});
|
|
|
|
|
|
// 下拉菜单命令处理
|
|
|
const handleDropdownCommand = (command: { action: string; row: IotMainWorkOrderBomVO }) => {
|
|
@@ -1101,6 +1530,9 @@ const handleDropdownCommand = (command: { action: string; row: IotMainWorkOrderB
|
|
|
case 'material':
|
|
|
openMaterialForm(command.row);
|
|
|
break;
|
|
|
+ case 'deviceBomMaterials':
|
|
|
+ openDeviceBomMaterials(command.row);
|
|
|
+ break;
|
|
|
case 'detail':
|
|
|
handleView(command.row);
|
|
|
break;
|
|
@@ -1234,13 +1666,25 @@ onMounted(async () => {
|
|
|
const data = await IotMainWorkOrderBomApi.getWorkOrderBOMs(queryParams);
|
|
|
list.value = []
|
|
|
if (Array.isArray(data)) {
|
|
|
- // 添加过滤逻辑:只保留 status === 0 的记录
|
|
|
- list.value = data
|
|
|
- // .filter(item => item.status === 0) // 关键过滤代码
|
|
|
- .map(item => ({
|
|
|
- ...item,
|
|
|
- lastNaturalDate: item.lastNaturalDate
|
|
|
- }))
|
|
|
+ list.value = data.map(item => {
|
|
|
+ if (item.mileageRule === 0) {
|
|
|
+ item.nextMaintenanceKm = calculateNextMaintenanceKm(item);
|
|
|
+ item.remainKm = calculateRemainKm(item);
|
|
|
+ }
|
|
|
+ if (item.runningTimeRule === 0) {
|
|
|
+ item.nextMaintenanceH = calculateNextMaintenanceH(item);
|
|
|
+ item.remainH = calculateRemainH(item);
|
|
|
+ }
|
|
|
+ if (item.naturalDateRule === 0) {
|
|
|
+ item.nextMaintenanceDate = calculateNextMaintenanceDate(item);
|
|
|
+ item.remainDay = calculateRemainDay(item);
|
|
|
+ }
|
|
|
+ setupNaturalDateSync(item);
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ lastNaturalDate: item.lastNaturalDate
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
// 查询当前保养工单已经关联的所有物料
|
|
|
const materials = await IotMainWorkOrderBomMaterialApi.getWorkOrderBomMaterials(queryParams);
|
|
@@ -1255,8 +1699,14 @@ onMounted(async () => {
|
|
|
console.error('数据加载失败:', error)
|
|
|
message.error('数据加载失败,请重试')
|
|
|
}
|
|
|
- window.addEventListener('resize', handleResize)
|
|
|
- nextTick(calculateMaintItemsWidth)
|
|
|
+ nextTick(() => {
|
|
|
+ calculateAllColumnsWidth()
|
|
|
+ window.addEventListener('resize', calculateAllColumnsWidth);
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+onUnmounted(async () => {
|
|
|
+ window.removeEventListener('resize', calculateAllColumnsWidth);
|
|
|
})
|
|
|
|
|
|
</script>
|
|
@@ -1312,4 +1762,27 @@ onMounted(async () => {
|
|
|
white-space: nowrap; /* 禁止换行 */
|
|
|
overflow: visible; /* 允许内容溢出单元格 */
|
|
|
}
|
|
|
+
|
|
|
+/* 新增分组表头样式 */
|
|
|
+:deep(.el-table__header) {
|
|
|
+ border: 1px solid #dcdfe6 !important;
|
|
|
+}
|
|
|
+:deep(.el-table__header th) {
|
|
|
+ border-right: 1px solid #dcdfe6 !important;
|
|
|
+ border-bottom: 1px solid #dcdfe6 !important;
|
|
|
+}
|
|
|
+
|
|
|
+:deep(.el-table__header .is-group th) {
|
|
|
+ background-color: #f5f7fa !important;
|
|
|
+ border-bottom: 1px solid #dcdfe6 !important;
|
|
|
+ font-weight: 600;
|
|
|
+ position: relative;
|
|
|
+}
|
|
|
+:deep(.el-table__header .is-group th::after) {
|
|
|
+ display: none !important;
|
|
|
+}
|
|
|
+/* 分组标题下的子表头单元格 */
|
|
|
+:deep(.el-table__header .el-table__cell:not(.is-group)) {
|
|
|
+ border-top: 1px solid #dcdfe6 !important; /* 添加顶部边框连接分组标题 */
|
|
|
+}
|
|
|
</style>
|