|
@@ -16,11 +16,27 @@
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
<el-col :span="8">
|
|
|
+ <el-form-item label="保养方式" prop="type">
|
|
|
+ <el-select v-model="formData.outsourcingFlag" placeholder="请选择保养方式" clearable>
|
|
|
+ <el-option
|
|
|
+ v-for="dict in getIntDictOptions(DICT_TYPE.PMS_ORDER_PROCESS_MODE)"
|
|
|
+ :key="dict.value"
|
|
|
+ :label="dict.label"
|
|
|
+ :value="dict.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <!--
|
|
|
<el-form-item label="工单编号" prop="orderNumber">
|
|
|
<el-input type="text" v-model="formData.orderNumber" disabled/>
|
|
|
</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-form-item label="责任人" prop="responsiblePerson">
|
|
|
<el-select v-model="formData.responsiblePerson" filterable clearable style="width: 100%" disabled>
|
|
|
<el-option
|
|
@@ -31,6 +47,7 @@
|
|
|
/>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
+ -->
|
|
|
</el-col>
|
|
|
<el-col :span="8">
|
|
|
<el-form-item label="实际保养开始时间" prop="actualStartTime">
|
|
@@ -143,10 +160,15 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
-->
|
|
|
- <el-table-column label="已选物料" align="center" width="100">
|
|
|
+ <el-table-column label="已选物料数" align="center" width="100">
|
|
|
+ <!--
|
|
|
<template #default="scope">
|
|
|
{{ hasMaterial(scope.row.bomNodeId) ? '是' : '否' }}
|
|
|
</template>
|
|
|
+ -->
|
|
|
+ <template #default="scope">
|
|
|
+ {{ getMaterialCount(scope.row.bomNodeId) }}
|
|
|
+ </template>
|
|
|
</el-table-column>
|
|
|
<el-table-column label="操作" align="center" min-width="120px">
|
|
|
<template #default="scope">
|
|
@@ -157,7 +179,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>
|
|
@@ -419,7 +441,8 @@ import {erpPriceTableColumnFormatter} from "@/utils";
|
|
|
import dayjs from 'dayjs'
|
|
|
import MaterialListDrawer from "@/views/pms/iotmainworkorder/SelectedMaterialDrawer.vue";
|
|
|
import WorkOrderMaterial from "@/views/pms/iotmainworkorder/WorkOrderMaterial.vue";
|
|
|
-
|
|
|
+import { IotDevicePersonApi, IotDevicePersonVO } from '@/api/pms/iotdeviceperson'
|
|
|
+import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from "@/utils/dict";
|
|
|
|
|
|
/** 保养计划 表单 */
|
|
|
defineOptions({ name: 'IotMainWorkOrderAdd' })
|
|
@@ -444,6 +467,8 @@ const materialList = ref<IotMainWorkOrderBomMaterialVO[]>([]) // 保养工单bom
|
|
|
const deviceIds = ref<number[]>([]) // 已经选择的设备id数组
|
|
|
const { params, name } = useRoute() // 查询参数
|
|
|
const id = params.id
|
|
|
+const devicePersonsMap = ref<Map<number, Set<string>>>(new Map()) // 存储设备-责任人映射
|
|
|
+
|
|
|
const formData = ref({
|
|
|
id: undefined,
|
|
|
deptId: undefined,
|
|
@@ -453,9 +478,18 @@ const formData = ref({
|
|
|
actualStartTime: undefined,
|
|
|
actualEndTime: undefined,
|
|
|
cost: undefined,
|
|
|
+ otherCost: undefined,
|
|
|
+ outsourcingFlag: 0,
|
|
|
remark: undefined,
|
|
|
status: undefined,
|
|
|
+ devicePersons: '',
|
|
|
})
|
|
|
+
|
|
|
+/** 获取当前所有设备ID集合 */
|
|
|
+const getCurrentDeviceIds = (): number[] => {
|
|
|
+ return [...new Set(list.value.map(item => item.deviceId))]
|
|
|
+}
|
|
|
+
|
|
|
const formRules = reactive({
|
|
|
name: [{ required: true, message: '工单名称不能为空', trigger: 'blur' }],
|
|
|
responsiblePerson: [{ required: true, message: '责任人不能为空', trigger: 'blur' }],
|
|
@@ -549,7 +583,12 @@ const openConfigDialog = (row: IotMainWorkOrderBomVO) => {
|
|
|
const openMaterialForm = (row: any) => {
|
|
|
bomNodeId.value = row.bomNodeId;
|
|
|
console.log('这是一个对象:', row.bomNodeId)
|
|
|
- materialFormRef.value.open(formData.value.deptId, bomNodeId.value)
|
|
|
+ materialFormRef.value.open(formData.value.deptId, bomNodeId.value, row.deviceId)
|
|
|
+}
|
|
|
+
|
|
|
+// 获取指定bomNodeId的物料数量
|
|
|
+const getMaterialCount = (bomNodeId: number) => {
|
|
|
+ return materialList.value.filter(item => item.bomNodeId === bomNodeId).length
|
|
|
}
|
|
|
|
|
|
const selectChoose = (selectedMaterial) => {
|
|
@@ -572,8 +611,6 @@ const selectChoose = (selectedMaterial) => {
|
|
|
materialList.value.push(newMaterial);
|
|
|
}
|
|
|
});
|
|
|
- console.log('选择完成的数据:', JSON.stringify(selectedMaterial))
|
|
|
- console.log('添加到本地列表的数据:', materialList.value)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -631,6 +668,8 @@ const deviceChoose = async(selectedDevices) => {
|
|
|
list.value.push(item)
|
|
|
}
|
|
|
})
|
|
|
+ // 新增完设备后 查询现有设备-bom明细中 所有设备配置的负责人姓名 逗号分隔
|
|
|
+ await getDevicePersons();
|
|
|
}
|
|
|
|
|
|
/** 查看已经选择的物料 并编辑 */
|
|
@@ -730,6 +769,7 @@ const handleInput = (value, obj) => {
|
|
|
}
|
|
|
|
|
|
const queryParams = reactive({
|
|
|
+ deviceIds: undefined,
|
|
|
workOrderId: id
|
|
|
})
|
|
|
|
|
@@ -738,6 +778,48 @@ const close = () => {
|
|
|
push({ name: 'IotMainWorkOrder', params:{}})
|
|
|
}
|
|
|
|
|
|
+/** 更新责任人显示 */
|
|
|
+function updateDevicePersonsDisplay() {
|
|
|
+ const allNames = new Set<string>()
|
|
|
+ devicePersonsMap.value.forEach(names => {
|
|
|
+ names.forEach(name => allNames.add(name))
|
|
|
+ })
|
|
|
+ formData.value.devicePersons = Array.from(allNames).join(', ')
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 根据选择的设备查询所有设备关联的 责任人姓名 逗号分隔
|
|
|
+ */
|
|
|
+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)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/** 提交表单 */
|
|
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
|
const submitForm = async () => {
|
|
@@ -803,10 +885,6 @@ const configFormRules = reactive({
|
|
|
const validateTableData = (): boolean => {
|
|
|
let isValid = true
|
|
|
const errorMessages: string[] = []
|
|
|
- const noRulesErrorMessages: string[] = [] // 未设置任何保养项规则 的错误提示信息
|
|
|
- const noRules: string[] = [] // 行记录中设置了保养规则的记录数量
|
|
|
- const configErrors: string[] = [] // 保养规则配置弹出框
|
|
|
- let shouldBreak = false;
|
|
|
|
|
|
if (list.value.length === 0) {
|
|
|
errorMessages.push('请至少添加一条设备保养明细')
|
|
@@ -822,7 +900,6 @@ const validateTableData = (): boolean => {
|
|
|
const resetForm = () => {
|
|
|
formData.value = {
|
|
|
id: undefined,
|
|
|
- deviceId: undefined,
|
|
|
status: undefined,
|
|
|
description: undefined,
|
|
|
pic: undefined,
|
|
@@ -842,12 +919,11 @@ onMounted(async () => {
|
|
|
formData.value.name = dept.value.name + ' - 保养工单'
|
|
|
deptUsers.value = await UserApi.getDeptUsersByDeptId(deptId)
|
|
|
formData.value.deptId = deptId
|
|
|
-
|
|
|
- // if (id){
|
|
|
- try{
|
|
|
+ try {
|
|
|
formType.value = 'create'
|
|
|
const { wsCache } = useCache()
|
|
|
const userInfo = wsCache.get(CACHE_KEY.USER)
|
|
|
+ // 手工新增保养工单 责任人为当前登录人
|
|
|
formData.value.responsiblePerson = userInfo.user.id;
|
|
|
} catch (error) {
|
|
|
console.error('数据加载失败:', error)
|
|
@@ -856,14 +932,35 @@ onMounted(async () => {
|
|
|
})
|
|
|
|
|
|
const handleDelete = async (str: string) => {
|
|
|
- try {
|
|
|
- const index = list.value.findIndex((item) => (item.id+'-'+item.bomNodeId) === str)
|
|
|
+ /* try {
|
|
|
+ const index = list.value.findIndex((item) => (item.deviceId+'-'+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>
|