Explorar o código

Merge remote-tracking branch 'origin/master'

lipenghui hai 2 meses
pai
achega
8e2f2f179d

+ 3 - 0
src/locales/en.ts

@@ -600,6 +600,9 @@ export default {
     check:'Check',
     details:'Details'
   },
+  deviceAllot:{
+    setUp:'SetUp',
+  },
   devicePerson:{
     deviceName:'DeviceName',
     nameHolder:'Please enter DeviceName',

+ 3 - 0
src/locales/zh-CN.ts

@@ -594,6 +594,9 @@ export default {
     check:'查看',
     details:'详情'
   },
+  deviceAllot:{
+    setUp:'调拨设备',
+  },
   devicePerson:{
     deviceName:'设备名称',
     nameHolder:'请输入设备名称',

+ 6 - 2
src/views/pms/device/allotlog/ConfigDeviceAllot.vue

@@ -61,7 +61,7 @@
         type="primary"
         size="large"
         @click="submitRelations"
-        :disabled="tempRelations.length === 0"
+        :disabled="tempRelations.length === 0 || !formData.reason.trim()"
       >
         {{ t('iotMaintain.save') }}
       </el-button>
@@ -97,6 +97,8 @@ import * as DeptApi from "@/api/system/dept";
 import {IotDeviceApi, IotDeviceVO} from "@/api/pms/device";
 import DeptTree2 from "@/views/pms/device/DeptTree2.vue";
 import { useRouter } from 'vue-router'
+import { useTagsViewStore } from "@/store/modules/tagsView";
+
 const router = useRouter()
 const { t } = useI18n() // 国际化
 defineOptions({ name: 'ConfigDeviceAllot' })
@@ -104,6 +106,7 @@ const selectedDeptId = ref<number | string>('')
 const simpleDevices = ref<IotDeviceVO[]>([])
 const deptList = ref<Tree[]>([]) // 树形结构
 const selectedDevices = ref<number[]>([]) // 改为数组存储多选
+const { delView } = useTagsViewStore() // 视图操作
 
 const formData = ref({
   id: undefined,
@@ -192,7 +195,7 @@ const handleDeptChange = (deptId) => {
     // 重置部门选择
     selectedDeptId.value = ''
     deptTreeRef.value?.treeRef?.setCurrentKey(undefined) // 清除树的选择状态
-    deptTreeRef.value?.treeRef?.setCurrentNode(null)
+    deptTreeRef.value?.treeRef?.setCurrentNode(undefined)
     return
   }
   selectedDeptId.value = deptId
@@ -263,6 +266,7 @@ const submitRelations = async () => {
     console.log('提交数据:', submitData)
     ElMessage.success('提交成功')
     tempRelations.value = []
+    delView(unref(router.currentRoute.value))
     router.back()
   } catch (error) {
     ElMessage.error('提交失败,请重试')

+ 7 - 10
src/views/pms/device/allotlog/DeviceAllot.vue

@@ -110,7 +110,7 @@
               @click="openForm('create', undefined, queryParams.deptId)"
               v-hasPermi="['rq:iot-device:create']"
             >
-              <Icon icon="ep:plus" class="mr-5px" /> {{ t('devicePerson.setUp') }}
+              <Icon icon="ep:plus" class="mr-5px" /> {{ t('deviceAllot.setUp') }}
             </el-button>
             <el-button
               type="success"
@@ -233,14 +233,7 @@ const treeShow = ref(true)
 const currentDeviceId = ref() // 设备id
 const drawerVisible = ref<boolean>(false)
 const showDrawer = ref()
-const shou = (tree) =>{
-  treeShow.value = !tree
-  if (tree) {
-    contentSpan.value = 20
-  } else {
-    contentSpan.value = 24
-  }
-}
+
 /** 查询列表 */
 const getList = async () => {
   loading.value = true
@@ -274,9 +267,13 @@ const resetQuery = () => {
 }
 
 /** 查看设备调拨详情 */
-const handleView = async (deviceId) => {
+const handleView = async (deviceId: number) => {
   currentDeviceId.value = deviceId
   drawerVisible.value = true
+  // 强制重新加载数据
+  nextTick(() => {
+    showDrawer.value?.loadDeviceAllots(deviceId)
+  })
   showDrawer.value.openDrawer()
 }
 

+ 23 - 3
src/views/pms/device/allotlog/DeviceAllotLogDrawer.vue

@@ -31,7 +31,7 @@
           :total="total"
           v-model:page="queryParams.pageNo"
           v-model:limit="queryParams.pageSize"
-          @pagination="loadDeviceAllots(props.deviceId)"
+          @pagination="handlePagination"
         />
       </div>
     </template>
@@ -40,7 +40,7 @@
 </template>
 <script setup lang="ts">
 const { t } = useI18n() // 国际化
-import { ref, watch, defineOptions, defineEmits } from 'vue'
+import { ref, watch, defineOptions, defineEmits, toRefs } from 'vue'
 import { ElMessage } from 'element-plus'
 import {dateFormatter} from "@/utils/formatTime";
 import {IotDeviceAllotLogApi} from "@/api/pms/iotdeviceallotlog";
@@ -75,6 +75,16 @@ const props = defineProps({
   deviceId: Number
 })
 
+// 使用 toRefs 解构响应式属性
+const { modelValue, deviceId } = toRefs(props)
+
+// 监听抽屉打开事件
+watch(modelValue, (isOpen) => {
+  if (isOpen && deviceId.value) {
+    loadDeviceAllots(deviceId.value)
+  }
+})
+
 // 监听bom树节点ID变化
 watch(() => props.deviceId, async (newVal) => {
   if (newVal) {
@@ -83,7 +93,7 @@ watch(() => props.deviceId, async (newVal) => {
 })
 
 // 加载设备的状态调整记录
-const loadDeviceAllots = async (deviceId) => {
+const loadDeviceAllots = async (deviceId: number) => {
   queryParams.deviceId = deviceId
   queryParams.pageNo = 1
   try {
@@ -99,6 +109,15 @@ const loadDeviceAllots = async (deviceId) => {
   }
 }
 
+// 修改分页处理
+const handlePagination = (pagination: any) => {
+  queryParams.pageNo = pagination.page
+  queryParams.pageSize = pagination.limit
+  if (props.deviceId) {
+    loadDeviceAllots(props.deviceId)
+  }
+}
+
 // 打开抽屉
 const openDrawer = () => {
   drawerVisible.value = true
@@ -113,6 +132,7 @@ const closeDrawer = () => {
 const handleClose = () => {
   emit('update:modelValue', false)
   deviceAllots.value = []
+  total.value = 0
 }
 
 defineExpose({ openDrawer, closeDrawer, loadDeviceAllots }) // 暴露方法给父组件

+ 12 - 3
src/views/pms/device/personlog/ConfigDevicePerson.vue

@@ -88,7 +88,7 @@
         <el-table :data="tempRelations" style="width: 100%">
           <el-table-column prop="deviceNames" :label="t('devicePerson.deviceName')" width="200" />
           <el-table-column prop="userNames" :label="t('devicePerson.rp')" />
-          <el-table-column prop="reason" :label="t('devicePerson.reasonForAdjustment')" />
+          <el-table-column prop="reason" :label="t('configPerson.reasonForAdjustment')" />
           <el-table-column :label="t('devicePerson.operation')" width="120">
             <template #default="{ row }">
               <el-button
@@ -107,7 +107,7 @@
             type="primary"
             size="large"
             @click="submitRelations"
-            :disabled="tempRelations.length === 0"
+            :disabled="isSaveDisabled"
           >
             {{ t('iotMaintain.save') }}
           </el-button>
@@ -129,12 +129,15 @@ import {simpleUserList, UserVO} from "@/api/system/user";
 import { useRouter } from 'vue-router'
 const router = useRouter()
 const { t } = useI18n() // 国际化
+import { useTagsViewStore } from "@/store/modules/tagsView";
+
 defineOptions({ name: 'ConfigDevicePerson' })
 
 const simpleDevices = ref<IotDeviceVO[]>([])
 const simpleUsers = ref<UserVO[]>([])
 
 const deptList = ref<Tree[]>([]) // 树形结构
+const { delView } = useTagsViewStore() // 视图操作
 
 const formData = ref({
   id: undefined,
@@ -225,6 +228,12 @@ const handleDeptDeviceTreeNodeClick = async (row: { [key: string]: any }) => {
   await getDeviceList()
 }
 
+// 新增计算属性:判断保存按钮是否禁用
+const isSaveDisabled = computed(() => {
+  // 当没有调整记录或调整原因为空时禁用按钮
+  return tempRelations.value.length === 0 || !formData.value.reason.trim();
+});
+
 /** 获得 部门下的设备 列表 */
 const getDeviceList = async () => {
   try {
@@ -334,9 +343,9 @@ const submitRelations = async () => {
     })
     await IotDevicePersonApi.saveDevicePersonRelation(submitData)
     // 模拟API调用
-    console.log('提交数据:', submitData)
     ElMessage.success('提交成功')
     tempRelations.value = []
+    delView(unref(router.currentRoute.value))
     router.back()
   } catch (error) {
     ElMessage.error('提交失败,请重试')

+ 7 - 14
src/views/pms/device/personlog/DevicePerson.vue

@@ -194,7 +194,6 @@ const { push } = useRouter() // 路由跳转
 
 const loading = ref(true) // 列表的加载中
 const ifShow = ref(false)
-const isDetail = ref(false) // 是否查看详情
 const list = ref<IotDeviceVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
 const queryParams = reactive({
@@ -234,14 +233,7 @@ const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
 const contentSpan = ref(20)
 const treeShow = ref(true)
-const shou = (tree) =>{
-  treeShow.value = !tree
-  if (tree) {
-    contentSpan.value = 20
-  } else {
-    contentSpan.value = 24
-  }
-}
+
 /** 查询列表 */
 const getList = async () => {
   loading.value = true
@@ -319,17 +311,18 @@ const handleDetail = (id: number) => {
   push({ name: 'DeviceDetailInfo', params: { id } })
 }
 
-const handleUpload = (id: number) => {
-  push({ name: 'DeviceUpload', params: { id } })
-}
-
 /** 查看设备责任人调整详情 */
 const currentDeviceId = ref() // 设备id
 const drawerVisible = ref<boolean>(false)
 const showDrawer = ref()
-const handleView = async (deviceId) => {
+
+const handleView = async (deviceId: number) => {
   currentDeviceId.value = deviceId
   drawerVisible.value = true
+  // 强制重新加载数据
+  nextTick(() => {
+    showDrawer.value?.loadDevicePersons(deviceId)
+  })
   showDrawer.value.openDrawer()
 }
 

+ 25 - 5
src/views/pms/device/personlog/DevicePersonLogDrawer.vue

@@ -31,7 +31,7 @@
           :total="total"
           v-model:page="queryParams.pageNo"
           v-model:limit="queryParams.pageSize"
-          @pagination="loadDeviceStatuses(props.deviceId)"
+          @pagination="handlePagination"
         />
       </div>
     </template>
@@ -40,7 +40,7 @@
 </template>
 <script setup lang="ts">
 const { t } = useI18n() // 国际化
-import { ref, watch, defineOptions, defineEmits } from 'vue'
+import { ref, watch, defineOptions, defineEmits, toRefs } from 'vue'
 import { ElMessage } from 'element-plus'
 import {dateFormatter} from "@/utils/formatTime";
 import {DICT_TYPE} from "@/utils/dict";
@@ -76,15 +76,25 @@ const props = defineProps({
   deviceId: Number
 })
 
+// 使用 toRefs 解构响应式属性
+const { modelValue, deviceId } = toRefs(props)
+
+// 监听抽屉打开事件
+watch(modelValue, (isOpen) => {
+  if (isOpen && deviceId.value) {
+    loadDevicePersons(deviceId.value)
+  }
+})
+
 // 监听bom树节点ID变化
 watch(() => props.deviceId, async (newVal) => {
   if (newVal) {
-    await loadDeviceStatuses(newVal)
+    await loadDevicePersons(newVal)
   }
 })
 
 // 加载设备的状态调整记录
-const loadDeviceStatuses = async (deviceId) => {
+const loadDevicePersons = async (deviceId: number) => {
   queryParams.deviceId = deviceId
   queryParams.pageNo = 1
   try {
@@ -100,6 +110,15 @@ const loadDeviceStatuses = async (deviceId) => {
   }
 }
 
+// 修改分页处理
+const handlePagination = (pagination: any) => {
+  queryParams.pageNo = pagination.page
+  queryParams.pageSize = pagination.limit
+  if (props.deviceId) {
+    loadDevicePersons(props.deviceId)
+  }
+}
+
 // 打开抽屉
 const openDrawer = () => {
   drawerVisible.value = true
@@ -114,9 +133,10 @@ const closeDrawer = () => {
 const handleClose = () => {
   emit('update:modelValue', false)
   devicePersons.value = []
+  total.value = 0
 }
 
-defineExpose({ openDrawer, closeDrawer, loadDeviceStatuses }) // 暴露方法给父组件
+defineExpose({ openDrawer, closeDrawer, loadDevicePersons }) // 暴露方法给父组件
 
 </script>
 

+ 21 - 3
src/views/pms/device/statuslog/ConfigDeviceStatus.vue

@@ -105,7 +105,7 @@
           type="primary"
           size="large"
           @click="submitRelations"
-          :disabled="tempRelations.length === 0"
+          :disabled="isSaveDisabled"
         >
           {{ t('iotMaintain.save') }}
         </el-button>
@@ -123,7 +123,9 @@ import {IotDeviceApi, IotDeviceVO} from "@/api/pms/device";
 import {simpleUserList, UserVO} from "@/api/system/user";
 import {DICT_TYPE, getStrDictOptions} from "@/utils/dict";
 import { useRouter } from 'vue-router'
+import { useTagsViewStore } from "@/store/modules/tagsView";
 const router = useRouter()
+
 const { t } = useI18n() // 国际化
 defineOptions({ name: 'ConfigDeviceStatus' })
 
@@ -137,6 +139,8 @@ const currentDevice = computed(() => {
   return simpleDevices.value.find(d => d.id === selectedDevice.value)
 })
 
+const { delView } = useTagsViewStore() // 视图操作
+
 const formData = ref({
   id: undefined,
   deviceCode: undefined,
@@ -198,7 +202,7 @@ watch(selectedDevices, (newVal, oldVal) => {
 
 // 修改保存方法
 const saveCurrentRelation = () => {
-  if (!formData.value.deviceStatus || !formData.value.reason) return
+  if (!formData.value.deviceStatus /*|| !formData.value.reason*/) return
 
   const statusDict = getStrDictOptions(DICT_TYPE.PMS_DEVICE_STATUS)
     .find(d => d.value === formData.value.deviceStatus)
@@ -243,6 +247,12 @@ const getDeviceList = async () => {
   }
 }
 
+// 添加计算属性:判断保存按钮是否禁用
+const isSaveDisabled = computed(() => {
+  // 当没有调整记录或调整原因为空时禁用按钮
+  return tempRelations.value.length === 0 || !formData.value.reason.trim();
+});
+
 // 添加状态变更处理
 const handleStatusChange = () => {
   if (selectedDevices.value.length > 0) {
@@ -282,16 +292,24 @@ const removeTempRelation = (deviceId: number) => {
 // 提交时处理数据
 const submitRelations = async () => {
   try {
+    // 检查是否有空的原因
+    const hasEmptyReason = tempRelations.value.some(
+      item => !item.reason?.trim()
+    )
+    if (hasEmptyReason) {
+      ElMessage.error('请填写所有设备的调整原因')
+      return
+    }
     // 转换数据结构
     const submitData = tempRelations.value.map(r => ({
       deviceId: r.deviceId,
       status: r.status,
       reason: r.reason
     }))
-
     await IotDeviceApi.saveDeviceStatuses(submitData)
     ElMessage.success('提交成功')
     tempRelations.value = []
+    delView(unref(router.currentRoute.value))
     router.back()
   } catch (error) {
     ElMessage.error('提交失败')

+ 7 - 17
src/views/pms/device/statuslog/DeviceStatus.vue

@@ -111,7 +111,7 @@
               @click="openForm('create', undefined, queryParams.deptId)"
               v-hasPermi="['rq:iot-device:create']"
             >
-              <Icon icon="ep:plus" class="mr-5px" /> {{ t('devicePerson.setUp') }}
+              <Icon icon="ep:plus" class="mr-5px" /> {{ t('deviceStatus.setUp') }}
             </el-button>
             <el-button
               type="success"
@@ -205,7 +205,6 @@ const { push } = useRouter() // 路由跳转
 const drawerVisible = ref<boolean>(false)
 const loading = ref(true) // 列表的加载中
 const ifShow = ref(false)
-const isDetail = ref(false) // 是否查看详情
 const list = ref<IotDeviceVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
 const currentDeviceId = ref() // 设备id
@@ -246,14 +245,7 @@ const queryFormRef = ref() // 搜索的表单
 const exportLoading = ref(false) // 导出的加载中
 const contentSpan = ref(20)
 const treeShow = ref(true)
-const shou = (tree) =>{
-  treeShow.value = !tree
-  if (tree) {
-    contentSpan.value = 20
-  } else {
-    contentSpan.value = 24
-  }
-}
+
 /** 查询列表 */
 const getList = async () => {
   loading.value = true
@@ -285,12 +277,14 @@ const resultOptions = computed(() => [
 const showDrawer = ref()
 
 /** 查看设备状态调整详情 */
-const handleView = async (deviceId) => {
+const handleView = async (deviceId: number) => {
   currentDeviceId.value = deviceId
   drawerVisible.value = true
+  // 强制重新加载数据
+  nextTick(() => {
+    showDrawer.value?.loadDeviceStatuses(deviceId)
+  })
   showDrawer.value.openDrawer()
-  // 强制刷新物料数据
-  // await showDrawer.value.loadMaterials(nodeId)
 }
 
 /** 处理部门被点击 */
@@ -342,10 +336,6 @@ const handleDetail = (id: number) => {
   push({ name: 'DeviceDetailInfo', params: { id } })
 }
 
-const handleUpload = (id: number) => {
-  push({ name: 'DeviceUpload', params: { id } })
-}
-
 /** 导出按钮操作 */
 const handleExport = async () => {
   try {

+ 23 - 3
src/views/pms/device/statuslog/DeviceStatusLogDrawer.vue

@@ -39,7 +39,7 @@
           :total="total"
           v-model:page="queryParams.pageNo"
           v-model:limit="queryParams.pageSize"
-          @pagination="loadDeviceStatuses(props.deviceId)"
+          @pagination="handlePagination"
         />
       </div>
     </template>
@@ -48,7 +48,7 @@
 </template>
 <script setup lang="ts">
 
-import { ref, watch, defineOptions, defineEmits } from 'vue'
+import { ref, watch, defineOptions, defineEmits, toRefs } from 'vue'
 import { ElMessage } from 'element-plus'
 import * as IotDeviceStatusLogApi from '@/api/pms/iotdevicestatuslog'
 import {dateFormatter} from "@/utils/formatTime";
@@ -56,6 +56,7 @@ import {DICT_TYPE} from "@/utils/dict";
 const drawerVisible = ref<boolean>(false)
 const emit = defineEmits(['update:modelValue', 'add', 'delete'])
 const { t } = useI18n() // 国际化
+
 defineOptions({
   name: 'DeviceStatusLogDrawer'
 })
@@ -84,6 +85,16 @@ const props = defineProps({
   deviceId: Number
 })
 
+// 使用 toRefs 解构响应式属性
+const { modelValue, deviceId } = toRefs(props)
+
+// 监听抽屉打开事件
+watch(modelValue, (isOpen) => {
+  if (isOpen && deviceId.value) {
+    loadDeviceStatuses(deviceId.value)
+  }
+})
+
 // 监听bom树节点ID变化
 watch(() => props.deviceId, async (newVal) => {
   if (newVal) {
@@ -92,7 +103,7 @@ watch(() => props.deviceId, async (newVal) => {
 })
 
 // 加载设备的状态调整记录
-const loadDeviceStatuses = async (deviceId) => {
+const loadDeviceStatuses = async (deviceId: number) => {
   queryParams.deviceId = deviceId
   queryParams.pageNo = 1
   try {
@@ -108,6 +119,15 @@ const loadDeviceStatuses = async (deviceId) => {
   }
 }
 
+// 修改分页处理
+const handlePagination = (pagination: any) => {
+  queryParams.pageNo = pagination.page
+  queryParams.pageSize = pagination.limit
+  if (props.deviceId) {
+    loadDeviceStatuses(props.deviceId)
+  }
+}
+
 // 打开抽屉
 const openDrawer = () => {
   drawerVisible.value = true

+ 242 - 0
src/views/pms/iotmainworkorder/DeviceAlarmBomList.vue

@@ -0,0 +1,242 @@
+<template>
+  <Dialog v-model="dialogVisible"
+          title="保养BOM明细"
+          style="width: 1500px; max-height: 800px" @close="handleClose" >
+    <ContentWrap>
+      <el-table
+        v-loading="loading"
+        :data="list"
+        :stripe="true"
+        :show-overflow-tooltip="true"
+      >
+        <el-table-column label="设备编码" align="center" prop="deviceCode" />
+        <el-table-column label="设备名称" align="center" prop="deviceName" />
+        <el-table-column label="累计运行时间(H)" align="center" prop="totalRunTime" />
+        <el-table-column label="累计运行公里数(KM)" align="center" prop="totalMileage" />
+        <el-table-column label="保养项" align="center" prop="name" />
+        <el-table-column label="运行里程" align="center" prop="mileageRule" >
+          <template #default="scope">
+            <el-switch
+              v-model="scope.row.mileageRule"
+              :active-value="0"
+              :inactive-value="1"
+              :disabled="true"
+            />
+          </template>
+        </el-table-column>
+        <el-table-column label="运行时间" align="center" prop="runningTimeRule" >
+          <template #default="scope">
+            <el-switch
+              v-model="scope.row.runningTimeRule"
+              :active-value="0"
+              :inactive-value="1"
+              :disabled="true"
+            />
+          </template>
+        </el-table-column>
+        <el-table-column label="自然日期" align="center" prop="naturalDateRule" >
+          <template #default="scope">
+            <el-switch
+              v-model="scope.row.naturalDateRule"
+              :active-value="0"
+              :inactive-value="1"
+              :disabled="true"
+            />
+          </template>
+        </el-table-column>
+
+        <template v-if="showTimeColumns">
+          <el-table-column label="上次保养运行时间(H)" align="center" prop="lastRunningTime" />
+          <el-table-column label="运行时间周期(H)" align="center" prop="nextRunningTime" />
+          <el-table-column label="运行时间周期-提前量(H)" align="center" prop="timePeriodLead" />
+        </template>
+
+        <template v-if="showMileageColumns">
+          <el-table-column label="上次保养里程数(KM)" align="center" prop="lastRunningKilometers" />
+          <el-table-column label="运行里程周期(KM)" align="center" prop="nextRunningKilometers" />
+          <el-table-column label="运行里程周期-提前量(KM)" align="center" prop="kiloCycleLead" />
+        </template>
+
+        <template v-if="showNaturalDateColumns">
+          <el-table-column label="上次保养自然日期" align="center" prop="lastNaturalDate"  width="220">
+            <template #default="scope">
+              <el-date-picker
+                v-model="scope.row.lastNaturalDate"
+                type="date"
+                placeholder="选择日期"
+                format="YYYY-MM-DD"
+                value-format="YYYY-MM-DD"
+                style="width: 60%"
+                :disabled="true"
+              />
+            </template>
+          </el-table-column>
+          <el-table-column label="自然日周期(D)" align="center" prop="nextNaturalDate" />
+          <el-table-column label="自然日周期-提前量(D)" align="center" prop="naturalDatePeriodLead" />
+        </template>
+      </el-table>
+      <!-- 分页
+      <Pagination
+        :total="total"
+        v-model:page="queryParams.pageNo"
+        v-model:limit="queryParams.pageSize"
+        @pagination="getList"
+      /> -->
+    </ContentWrap>
+  </Dialog>
+</template>
+
+<script setup lang="ts">
+import { DictDataVO } from '@/api/system/dict/dict.data'
+import * as ModelApi from '@/api/pms/model'
+import { DICT_TYPE } from '@/utils/dict'
+import { dateFormatter } from '@/utils/formatTime'
+import dayjs from 'dayjs'
+import { IotMainWorkOrderBomApi, IotMainWorkOrderBomVO } from '@/api/pms/iotmainworkorderbom'
+import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
+import {propTypes} from "@/utils/propTypes";
+
+const emit = defineEmits(['close']) // 定义 success 事件,用于操作成功后的回调
+const dialogVisible = ref(false) // 弹窗的是否展示
+const loading = ref(true) // 列表的加载中
+const queryFormRef = ref() // 搜索的表单
+const list = ref<IotMaintenanceBomVO[]>([]) // 列表的数据
+const total = ref(0) // 列表的总页数
+const queryParams = reactive({
+  pageNo: 1,
+  pageSize: 10,
+  workOrderId: undefined,
+  planId: undefined,
+  deviceId: undefined
+})
+
+const props = defineProps({
+  flag: propTypes.oneOfType<string | string[]>([String, Array<String>]).isRequired,
+})
+
+const selectedRow = ref(null)
+
+// 处理单选逻辑
+const selectRow = (row) => {
+  selectedRow.value = selectedRow.value?.id === row.id ? null : row
+  emit('choose', row)
+  dialogVisible.value = false
+}
+
+// 点击整行选中
+const handleRowClick = (row) => {
+  selectRow(row)
+}
+const open = async (id?: number, flag?: string, deviceId?: number) => {
+  await nextTick() // 确保DOM更新完成
+  queryParams.deviceId = deviceId
+  if('workOrder' === flag) {
+    // 加载保养工单 BOM
+    queryParams.workOrderId = id
+    queryParams.planId = undefined
+    await getWorkOrderList()
+  } else if ('plan' === flag) {
+    queryParams.planId = id
+    queryParams.workOrderId = undefined
+    await getPlanList()
+  }
+  dialogVisible.value = true
+}
+
+defineExpose({ open }) // 提供 open 方法,用于打开弹窗
+
+const getWorkOrderList = async () => {
+  loading.value = true
+  try {
+    const data = await IotMainWorkOrderBomApi.getWorkOrderBOMs(queryParams)
+    // 格式化日期字段 - 新增代码
+    data.forEach(item => {
+      if (item.lastNaturalDate) {
+        // 将时间戳转换为 YYYY-MM-DD 格式
+        item.lastNaturalDate = dayjs(item.lastNaturalDate).format('YYYY-MM-DD')
+      } else {
+        // 处理空值情况
+        item.lastNaturalDate = ''
+      }
+    })
+    list.value = data
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+const getPlanList = async () => {
+  loading.value = true
+  try {
+    const data = await IotMaintenanceBomApi.getMainPlanBOMs(queryParams)
+    // 格式化日期字段 - 新增代码
+    data.forEach(item => {
+      if (item.lastNaturalDate) {
+        // 将时间戳转换为 YYYY-MM-DD 格式
+        item.lastNaturalDate = dayjs(item.lastNaturalDate).format('YYYY-MM-DD')
+      } else {
+        // 处理空值情况
+        item.lastNaturalDate = ''
+      }
+    })
+    list.value = data
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+const handleClose = () => {
+  // 重置状态避免多个弹窗出现
+  dialogVisible.value = false
+  loading.value = false
+  list.value = []
+
+  // 通知父组件弹窗已关闭
+  emit('close')
+}
+
+// 新增计算属性:控制时间相关列的显示
+const showTimeColumns = computed(() => {
+  return list.value.some(item => item.runningTimeRule === 0);
+});
+
+// 新增计算属性:控制里程相关列的显示
+const showMileageColumns = computed(() => {
+  return list.value.some(item => item.mileageRule === 0);
+});
+
+// 新增计算属性:自然日期相关列的显示
+const showNaturalDateColumns = computed(() => {
+  return list.value.some(item => item.naturalDateRule === 0);
+});
+
+/** 搜索按钮操作 */
+const handleQuery = () => {
+  queryParams.pageNo = 1
+  // getList()
+}
+const choose = (row: DictDataVO) => {
+  emit('choose', row)
+  dialogVisible.value = false
+}
+/** 重置按钮操作 */
+const resetQuery = () => {
+  queryFormRef.value.resetFields()
+  handleQuery()
+}
+/** 初始化 **/
+// onMounted(async () => {
+//   await getList()
+//   // 查询字典(精简)列表
+// })
+</script>
+<style lang="scss">
+.no-label-radio .el-radio__label {
+  display: none;
+}
+.no-label-radio .el-radio__inner {
+  margin-right: 0;
+}
+</style>

+ 46 - 23
src/views/pms/iotmainworkorder/IotDeviceMainAlarm.vue

@@ -73,9 +73,12 @@
           </el-table-column>
           <el-table-column label="距离保养" align="center">
             <template #default="scope">
-          <span :class="getDistanceClass(scope.row.mainDistance)">
-            {{ scope.row.mainDistance }}
-          </span>
+              <template v-if="hasMaintenancePlan(scope.row.mainDistance)">
+                <span :class="getDistanceClass(scope.row.mainDistance)">
+                  {{ scope.row.mainDistance }}
+                </span>
+              </template>
+              <span v-else>无保养计划</span>
             </template>
           </el-table-column>
           <el-table-column label="所在部门" align="center" prop="deptName" />
@@ -85,17 +88,17 @@
             </template>
           </el-table-column>
           <el-table-column label="操作" align="center" min-width="120px">
-            <!-- <template #default="scope">
-
+            <template #default="scope">
               <el-button
                 link
                 type="primary"
-                @click="handleView(scope.row.id)"
+                @click="openBomForm(scope.row)"
                 v-hasPermi="['rq:iot-device:query']"
+                v-if="hasMaintenancePlan(scope.row.mainDistance)"
               >
-                调整记录
+                详情
               </el-button>
-            </template> -->
+            </template>
           </el-table-column>
         </el-table>
         <!-- 分页 -->
@@ -108,6 +111,7 @@
       </ContentWrap>
     </el-col>
   </el-row>
+  <DeviceAlarmBomList ref="modelFormRef" :flag = "flag" />
 </template>
 
 <script setup lang="ts">
@@ -118,17 +122,18 @@ import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
 import { dateFormatter } from '@/utils/formatTime'
 import DeptTree from '@/views/system/user/DeptTree.vue'
 import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import DeviceAlarmBomList from "@/views/pms/iotmainworkorder/DeviceAlarmBomList.vue";
 
 /** 设备台账 列表 */
-defineOptions({ name: 'IotDevicePerson' })
+defineOptions({ name: 'IotDeviceMainAlarm' })
 
 const message = useMessage() // 消息弹窗
 const { t } = useI18n() // 国际化
 const { push } = useRouter() // 路由跳转
-
+const modelFormRef = ref()
 const loading = ref(true) // 列表的加载中
 const ifShow = ref(false)
-const isDetail = ref(false) // 是否查看详情
+
 const list = ref<IotDeviceVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
 const queryParams = reactive({
@@ -165,17 +170,11 @@ const queryParams = reactive({
   setFlag: ''
 })
 const queryFormRef = ref() // 搜索的表单
+const flag = ref() // 查询保养计划或保养工单的标识
 const exportLoading = ref(false) // 导出的加载中
 const contentSpan = ref(20)
 const treeShow = ref(true)
-const shou = (tree) =>{
-  treeShow.value = !tree
-  if (tree) {
-    contentSpan.value = 20
-  } else {
-    contentSpan.value = 24
-  }
-}
+
 /** 查询列表 */
 const getList = async () => {
   loading.value = true
@@ -245,6 +244,12 @@ const getDistanceClass = (distance: number | string | null) => {
   return '';
 };
 
+// 判断是否有保养计划
+const hasMaintenancePlan = (mainDistance: any) => {
+  // 检查:非null、非undefined、非空字符串
+  return mainDistance != null && mainDistance !== '';
+};
+
 /** 删除按钮操作 */
 const handleDelete = async (id: number) => {
   try {
@@ -286,10 +291,28 @@ const handleUpload = (id: number) => {
 const currentDeviceId = ref() // 设备id
 const drawerVisible = ref<boolean>(false)
 const showDrawer = ref()
-const handleView = async (deviceId) => {
-  currentDeviceId.value = deviceId
-  drawerVisible.value = true
-  showDrawer.value.openDrawer()
+
+const detail = (row: any) => {
+  // 如果有工单ID,跳转到保养工单详情页
+  if (row.workOrderId) {
+    push({ name: 'IotMainWorkOrderDetail', params: { id: row.workOrderId } })
+  } else if (row.planId) {
+    // 如果有计划ID,跳转到保养计划详情页
+    push({ name: 'IotMaintenancePlanDetail', params: { id: row.planId } })
+  }else {
+    // 两者都为空的情况处理
+    message.warning('当前设备无保养工单或保养计划')
+  }
+}
+
+const openBomForm = async (row) => {
+  if (row.workOrderId) {
+    flag.value = 'workOrder';
+    modelFormRef.value.open(row.workOrderId, flag.value, row.id)
+  } else if (row.planId) {
+    flag.value = 'plan';
+    modelFormRef.value.open(row.planId, flag.value, row.id)
+  }
 }
 
 /** 导出按钮操作 */