|
@@ -32,11 +32,16 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
- <el-col :span="24">
|
|
|
+ <el-col :span="16">
|
|
|
<el-form-item label="备注" prop="remark">
|
|
|
<el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
+ <el-col :span="8">
|
|
|
+ <el-form-item label="设备责任人" prop="devicePersons">
|
|
|
+ <el-input type="text" v-model="formData.devicePersons" disabled/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
</el-row>
|
|
|
</div>
|
|
|
</el-form>
|
|
@@ -68,6 +73,7 @@
|
|
|
width="60"
|
|
|
align="center"
|
|
|
/>
|
|
|
+ <el-table-column label="设备id" align="center" prop="deviceId" v-if="false"/>
|
|
|
<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" :formatter="erpPriceTableColumnFormatter"/>
|
|
@@ -130,7 +136,7 @@
|
|
|
style="vertical-align: middle"
|
|
|
link
|
|
|
type="danger"
|
|
|
- @click="handleDelete(scope.row.id+'-'+scope.row.bomNodeId)"
|
|
|
+ @click="handleDelete(scope.row.deviceId+'-'+scope.row.bomNodeId)"
|
|
|
>
|
|
|
移除
|
|
|
</el-button>
|
|
@@ -285,6 +291,14 @@
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
|
|
|
+ <div class="temp-list card" v-if="false">
|
|
|
+ <h3>已经选择的设备关联的负责人列表</h3>
|
|
|
+ <el-table :data="tempDevicePersons" style="width: 100%" >
|
|
|
+ <el-table-column prop="tempDeviceIds" label="设备id" width="200" />
|
|
|
+ <el-table-column prop="tempPersonNames" label="责任人姓名" />
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
import { IotMaintainApi, IotMaintainVO } from '@/api/pms/maintain'
|
|
@@ -293,6 +307,7 @@ import * as UserApi from '@/api/system/user'
|
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
import { ref } from 'vue'
|
|
|
import { IotMaintenanceBomApi, IotMaintenanceBomVO } from '@/api/pms/iotmaintenancebom'
|
|
|
+import { IotDevicePersonApi, IotDevicePersonVO } from '@/api/pms/iotdeviceperson'
|
|
|
import { IotMaintenancePlanApi, IotMaintenancePlanVO } from '@/api/pms/maintenance'
|
|
|
import { useTagsViewStore } from '@/store/modules/tagsView'
|
|
|
import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
|
|
@@ -316,7 +331,21 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加
|
|
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
|
|
const deviceLabel = ref('') // 表单的类型:create - 新增;update - 修改
|
|
|
const list = ref<IotMaintenanceBomVO[]>([]) // 设备bom关联列表的数据
|
|
|
+const devicePersonsMap = ref<Map<number, Set<string>>>(new Map()) // 存储设备-责任人映射
|
|
|
+const tempDevicePersons = ref<Array<{
|
|
|
+ tempDeviceIds: number[]
|
|
|
+ tempDeviceNames: string
|
|
|
+ tempPersonIds: number[]
|
|
|
+ tempPersonNames: string
|
|
|
+}>>([])
|
|
|
const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
|
|
|
+const totalDeviceIds = ref<number[]>([]) // 列表区域暂存的设备id数组 包括之前选择的+当前选择的
|
|
|
+
|
|
|
+/** 获取当前所有设备ID集合 */
|
|
|
+const getCurrentDeviceIds = (): number[] => {
|
|
|
+ return [...new Set(list.value.map(item => item.deviceId))]
|
|
|
+}
|
|
|
+
|
|
|
const { params, name } = useRoute() // 查询参数
|
|
|
const id = params.id
|
|
|
const formData = ref({
|
|
@@ -328,13 +357,20 @@ const formData = ref({
|
|
|
remark: undefined,
|
|
|
failureName: undefined,
|
|
|
status: undefined,
|
|
|
+ devicePersons: '',
|
|
|
})
|
|
|
+
|
|
|
const formRules = reactive({
|
|
|
name: [{ required: true, message: '计划名称不能为空', trigger: 'blur' }],
|
|
|
responsiblePerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
|
|
|
})
|
|
|
const formRef = ref() // 表单 Ref
|
|
|
|
|
|
+interface DevicePerson {
|
|
|
+ deviceId: number
|
|
|
+ personName: string
|
|
|
+}
|
|
|
+
|
|
|
// 新增配置相关状态
|
|
|
const configDialog = reactive({
|
|
|
visible: false,
|
|
@@ -445,6 +481,48 @@ const queryParams = reactive({
|
|
|
planId: id
|
|
|
})
|
|
|
|
|
|
+/**
|
|
|
+ * 根据选择的设备查询所有设备关联的 责任人姓名 逗号分隔
|
|
|
+ */
|
|
|
+async function getDevicePersons() {
|
|
|
+ // 获取当前已经选择的设备ID集合
|
|
|
+ const existDeviceIds = getCurrentDeviceIds()
|
|
|
+ if (existDeviceIds.length === 0) {
|
|
|
+ formData.value.devicePersons = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 调用接口获取数据
|
|
|
+ const params = {
|
|
|
+ deviceIds: existDeviceIds.join(',') // 明确传递数组参数
|
|
|
+ }
|
|
|
+ const res = await IotDevicePersonApi.getPersonsByDeviceIds(params)
|
|
|
+ const personsData = res || []
|
|
|
+ // 清空旧数据
|
|
|
+ devicePersonsMap.value.clear()
|
|
|
+ // 处理接口数据
|
|
|
+ personsData.forEach((item: { deviceId: number; personName: string }) => {
|
|
|
+ if (!devicePersonsMap.value.has(item.deviceId)) {
|
|
|
+ devicePersonsMap.value.set(item.deviceId, new Set())
|
|
|
+ }
|
|
|
+ devicePersonsMap.value.get(item.deviceId)?.add(item.personName)
|
|
|
+ })
|
|
|
+ // 生成展示字符串
|
|
|
+ updateDevicePersonsDisplay()
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取设备责任人失败:', error)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/** 更新责任人显示 */
|
|
|
+function updateDevicePersonsDisplay() {
|
|
|
+ const allNames = new Set<string>()
|
|
|
+ devicePersonsMap.value.forEach(names => {
|
|
|
+ names.forEach(name => allNames.add(name))
|
|
|
+ })
|
|
|
+ formData.value.devicePersons = Array.from(allNames).join(', ')
|
|
|
+}
|
|
|
+
|
|
|
const deviceChoose = async(selectedDevices) => {
|
|
|
const newIds = selectedDevices.map(device => device.id)
|
|
|
deviceIds.value = [...new Set([...deviceIds.value, ...newIds])]
|
|
@@ -499,6 +577,8 @@ const deviceChoose = async(selectedDevices) => {
|
|
|
list.value.push(item)
|
|
|
}
|
|
|
})
|
|
|
+ // 新增完设备后 查询现有设备-bom明细中 所有设备配置的负责人姓名 逗号分隔
|
|
|
+ await getDevicePersons();
|
|
|
}
|
|
|
|
|
|
const deviceFormRef = ref<InstanceType<typeof MainPlanDeviceList>>()
|
|
@@ -715,14 +795,35 @@ onMounted(async () => {
|
|
|
}
|
|
|
})
|
|
|
const handleDelete = async (str: string) => {
|
|
|
- try {
|
|
|
+ /* try {
|
|
|
const index = list.value.findIndex((item) => (item.id+'-'+item.bomNodeId) === str)
|
|
|
if (index !== -1) {
|
|
|
// 通过 splice 删除元素
|
|
|
list.value.splice(index, 1)
|
|
|
deviceIds.value = []
|
|
|
}
|
|
|
- } catch {}
|
|
|
+ } catch {} */
|
|
|
+ try {
|
|
|
+ const [deviceIdStr, bomNodeId] = str.split('-')
|
|
|
+ const deviceId = parseInt(deviceIdStr)
|
|
|
+ // 删除列表项
|
|
|
+ const index = list.value.findIndex((item) => (item.deviceId+'-'+item.bomNodeId) === str)
|
|
|
+ if (index !== -1) {
|
|
|
+ list.value.splice(index, 1)
|
|
|
+ deviceIds.value = []
|
|
|
+ }
|
|
|
+ // 更新设备ID列表(需要检查是否还有该设备的其他项)
|
|
|
+ const hasOtherItems = list.value.some(item => item.deviceId === deviceId)
|
|
|
+ if (!hasOtherItems) {
|
|
|
+ deviceIds.value = deviceIds.value.filter(id => id !== deviceId)
|
|
|
+ devicePersonsMap.value.delete(deviceId) // 移除对应设备的责任人
|
|
|
+ updateDevicePersonsDisplay() // 立即更新显示
|
|
|
+ }
|
|
|
+ // message.success('移除成功')
|
|
|
+ } catch (error) {
|
|
|
+ console.error('移除失败:', error)
|
|
|
+ message.error('移除失败')
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
<style scoped>
|